Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
verification_notes.md

## Android.gitignore
# Built application files
*.apk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.widget.CompoundButton;
import android.widget.LinearLayout;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
Expand Down Expand Up @@ -101,6 +102,7 @@ private static boolean isTesting() {
private Uri lastUri;
private Uri loadOnStart;
private Uri lastSaveUri;
private boolean documentOpenedInternally = false;

@Nullable
private CountingIdlingResource openFileIdlingResource;
Expand Down Expand Up @@ -182,6 +184,7 @@ public void onClick(View view) {
// (i.e. after bringing app back from background)
if (getIntent().getData() != null) {
loadOnStart = getIntent().getData();
documentOpenedInternally = false; // External launch

analyticsManager.report(FirebaseAnalytics.Event.SELECT_CONTENT, FirebaseAnalytics.Param.CONTENT_TYPE, "other");
} else {
Expand All @@ -194,6 +197,26 @@ public void onClick(View view) {
}

addMenuProvider(this, this);

// Set up modern back button handling
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
if (fullscreen) {
leaveFullscreen();
return;
}

// If document is currently displayed and was opened internally, go back to landing
if (documentContainer.getVisibility() == View.VISIBLE && documentOpenedInternally) {
showLandingScreen();
} else {
// For external launches or when already on landing screen, use default behavior (close app)
setEnabled(false);
getOnBackPressedDispatcher().onBackPressed();
}
}
});
}

@Override
Expand Down Expand Up @@ -321,6 +344,7 @@ protected void onNewIntent(Intent intent) {
if (intent.getData() != null) {
crashManager.log("onNewIntent loadUri");

documentOpenedInternally = false; // External launch
loadUri(intent.getData());

analyticsManager.report(FirebaseAnalytics.Event.SELECT_CONTENT, FirebaseAnalytics.Param.CONTENT_TYPE, "other");
Expand Down Expand Up @@ -361,6 +385,18 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent)
}

public void loadUri(Uri uri) {
loadUriInternal(uri, false);
}

public void loadUriFromInternalNavigation(Uri uri) {
loadUriInternal(uri, true);
}

private void loadUriInternal(Uri uri, boolean isInternal) {
if (isInternal) {
documentOpenedInternally = true;
}

lastSaveUri = null;
lastUri = uri;

Expand Down Expand Up @@ -606,6 +642,8 @@ public void onClick(DialogInterface dialog, int which) {
openFileIdlingResource.increment();
}

// Mark that the next document will be opened internally
documentOpenedInternally = true;
startActivityForResult(intent, 42);
} catch (Exception e) {
if (null != openFileIdlingResource) {
Expand Down Expand Up @@ -663,6 +701,21 @@ protected void onDestroy() {
}
}

private void showLandingScreen() {
landingContainer.setVisibility(View.VISIBLE);
documentContainer.setVisibility(View.GONE);

// Clear the document state
lastUri = null;
lastSaveUri = null;
documentOpenedInternally = false;

// Clear the action bar title
setTitle("");

analyticsManager.setCurrentScreen(this, "screen_main");
}

public CrashManager getCrashManager() {
return crashManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
dismiss();

MainActivity activity = ((MainActivity) getActivity());
activity.loadUri(Uri.parse(uri));
activity.loadUriFromInternalNavigation(Uri.parse(uri));
}

@Override
Expand Down