Skip to content

Commit

Permalink
Editor: Fix crash at activity state restoring, closes #1565, by @gsan…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Jan 22, 2022
1 parent 440189b commit d4d8f41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public static void askUserIfWantsToOpenFileInThisApp(final Activity activity, fi
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AppSettings.clearDebugLog();
if (savedInstanceState != null && savedInstanceState.containsKey(DocumentEditFragment.SAVESTATE_DOCUMENT)) {
_document = (Document) savedInstanceState.getSerializable(DocumentEditFragment.SAVESTATE_DOCUMENT);
}
if (nextLaunchTransparentBg) {
//getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
nextLaunchTransparentBg = false;
Expand Down Expand Up @@ -264,7 +267,7 @@ public void showTextEditor(@Nullable Document document, @Nullable File file, boo
boolean sameDocumentRequested = false;
if (currentFragment instanceof DocumentEditFragment) {
String reqPath = (reqFile != null) ? reqFile.getPath() : "";
sameDocumentRequested = reqPath.equals(((DocumentEditFragment) currentFragment).getDocument().getPath());
sameDocumentRequested = reqPath.equals(((DocumentEditFragment) currentFragment).getDocument(_document).getPath());
}

if (!sameDocumentRequested) {
Expand Down Expand Up @@ -359,4 +362,10 @@ private void onToolbarTitleClicked(View v) {
def.onToolbarTitleClicked(_toolbar);
}
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(DocumentEditFragment.SAVESTATE_DOCUMENT, _document);

This comment has been minimized.

Copy link
@harshad1

harshad1 Jan 23, 2022

Collaborator

@gsantner IMO it may be cleaner to not have an instance of Document in DocumentActivity at all... Always use DocumentEditFragment.getDocument(). That way we there is no chance that the Activity and Fragment will refer to different documents.

This comment has been minimized.

Copy link
@gsantner

gsantner Jan 23, 2022

Author Owner

this was a hotfix.

this one produced a crash on every activity state change:

grafik

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@
@SuppressWarnings({"UnusedReturnValue"})
@SuppressLint("NonConstantResourceId")
public class DocumentEditFragment extends GsFragmentBase implements TextFormat.TextFormatApplier {
public static final int HISTORY_DELTA = 5000;
public static final String FRAGMENT_TAG = "DocumentEditFragment";
private static final String SAVESTATE_DOCUMENT = "DOCUMENT";
public static final String SAVESTATE_DOCUMENT = "DOCUMENT";
private static final String SAVESTATE_CURSOR_POS = "CURSOR_POS";
private static final String SAVESTATE_PREVIEW_ON = "SAVESTATE_PREVIEW_ON";

Expand Down Expand Up @@ -818,7 +817,13 @@ public boolean onLongClick(View v) {
//
//

public Document getDocument() {
/**
* Get document of this fragment. if no document set yet, fallback to other passed instances (i.e. from onSavedInstanceState)
*/
public Document getDocument(Document... fallback) {
if (_document == null && fallback != null && fallback.length > 0 && fallback[0] != null) {
_document = fallback[0];
}
return _document;
}

Expand Down

0 comments on commit d4d8f41

Please sign in to comment.