Skip to content

Commit 2a7c5a8

Browse files
CopilotTomTasche
andcommitted
Refactor loadUri methods and fix RecentDocumentDialogFragment navigation
Co-authored-by: TomTasche <128734+TomTasche@users.noreply.github.com>
1 parent 55f47df commit 2a7c5a8

2 files changed

Lines changed: 29 additions & 22 deletions

File tree

app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import android.widget.CompoundButton;
2929
import android.widget.LinearLayout;
3030

31-
import androidx.activity.OnBackPressedCallback;
3231
import androidx.annotation.NonNull;
3332
import androidx.annotation.Nullable;
3433
import androidx.annotation.VisibleForTesting;
@@ -197,26 +196,6 @@ public void onClick(View view) {
197196
}
198197

199198
addMenuProvider(this, this);
200-
201-
// Set up back button handling
202-
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
203-
@Override
204-
public void handleOnBackPressed() {
205-
if (fullscreen) {
206-
leaveFullscreen();
207-
return;
208-
}
209-
210-
// If document is currently displayed and was opened internally, go back to landing
211-
if (documentContainer.getVisibility() == View.VISIBLE && documentOpenedInternally) {
212-
showLandingScreen();
213-
} else {
214-
// For external launches or when already on landing screen, use default behavior (close app)
215-
setEnabled(false);
216-
getOnBackPressedDispatcher().onBackPressed();
217-
}
218-
}
219-
});
220199
}
221200

222201
@Override
@@ -385,6 +364,18 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent)
385364
}
386365

387366
public void loadUri(Uri uri) {
367+
loadUriInternal(uri, false);
368+
}
369+
370+
public void loadUriFromInternalNavigation(Uri uri) {
371+
loadUriInternal(uri, true);
372+
}
373+
374+
private void loadUriInternal(Uri uri, boolean isInternal) {
375+
if (isInternal) {
376+
documentOpenedInternally = true;
377+
}
378+
388379
lastSaveUri = null;
389380
lastUri = uri;
390381

@@ -581,6 +572,22 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
581572
return super.onKeyDown(keyCode, event);
582573
}
583574

575+
@Override
576+
public void onBackPressed() {
577+
if (fullscreen) {
578+
leaveFullscreen();
579+
return;
580+
}
581+
582+
// If document is currently displayed and was opened internally, go back to landing
583+
if (documentContainer.getVisibility() == View.VISIBLE && documentOpenedInternally) {
584+
showLandingScreen();
585+
} else {
586+
// For external launches or when already on landing screen, use default behavior (close app)
587+
super.onBackPressed();
588+
}
589+
}
590+
584591
public void findDocument() {
585592
final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
586593
intent.addCategory(Intent.CATEGORY_OPENABLE);

app/src/main/java/at/tomtasche/reader/ui/widget/RecentDocumentDialogFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
102102
dismiss();
103103

104104
MainActivity activity = ((MainActivity) getActivity());
105-
activity.loadUri(Uri.parse(uri));
105+
activity.loadUriFromInternalNavigation(Uri.parse(uri));
106106
}
107107

108108
@Override

0 commit comments

Comments
 (0)