Browse Source

Fixed lifecycle crashes

main
M66B 6 years ago
parent
commit
8b7bc70c9e
5 changed files with 14 additions and 5 deletions
  1. +3
    -1
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  2. +3
    -1
      app/src/main/java/eu/faircode/email/FragmentFolder.java
  3. +3
    -1
      app/src/main/java/eu/faircode/email/FragmentFolders.java
  4. +2
    -1
      app/src/main/java/eu/faircode/email/FragmentMessage.java
  5. +3
    -1
      app/src/main/java/eu/faircode/email/FragmentMessages.java

+ 3
- 1
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -76,6 +76,7 @@ import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.cursoradapter.widget.SimpleCursorAdapter; import androidx.cursoradapter.widget.SimpleCursorAdapter;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -799,7 +800,8 @@ public class FragmentCompose extends FragmentEx {
public void onChanged(final EntityMessage draft) { public void onChanged(final EntityMessage draft) {
// Draft was deleted // Draft was deleted
if (draft == null || draft.ui_hide) { if (draft == null || draft.ui_hide) {
getFragmentManager().popBackStack();
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
getFragmentManager().popBackStack();
return; return;
} }
} }


+ 3
- 1
app/src/main/java/eu/faircode/email/FragmentFolder.java View File

@ -33,6 +33,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
public class FragmentFolder extends FragmentEx { public class FragmentFolder extends FragmentEx {
@ -148,7 +149,8 @@ public class FragmentFolder extends FragmentEx {
@Override @Override
public void onChanged(@Nullable EntityFolder folder) { public void onChanged(@Nullable EntityFolder folder) {
if (folder == null) { if (folder == null) {
getFragmentManager().popBackStack();
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
getFragmentManager().popBackStack();
return; return;
} }


+ 3
- 1
app/src/main/java/eu/faircode/email/FragmentFolders.java View File

@ -33,6 +33,7 @@ import java.util.List;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -108,7 +109,8 @@ public class FragmentFolders extends FragmentEx {
@Override @Override
public void onChanged(@Nullable List<TupleFolderEx> folders) { public void onChanged(@Nullable List<TupleFolderEx> folders) {
if (folders == null) { if (folders == null) {
getFragmentManager().popBackStack();
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
getFragmentManager().popBackStack();
return; return;
} }


+ 2
- 1
app/src/main/java/eu/faircode/email/FragmentMessage.java View File

@ -64,6 +64,7 @@ import androidx.browser.customtabs.CustomTabsIntent;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -305,7 +306,7 @@ public class FragmentMessage extends FragmentEx {
public void onChanged(@Nullable final TupleMessageEx message) { public void onChanged(@Nullable final TupleMessageEx message) {
if (message == null || (!(debug && BuildConfig.DEBUG) && message.ui_hide)) { if (message == null || (!(debug && BuildConfig.DEBUG) && message.ui_hide)) {
// Message gone (moved, deleted) // Message gone (moved, deleted)
if (FragmentMessage.this.isVisible())
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
getFragmentManager().popBackStack(); getFragmentManager().popBackStack();
} else { } else {
setSubtitle(Helper.localizeFolderName(getContext(), message.folderName)); setSubtitle(Helper.localizeFolderName(getContext(), message.folderName));


+ 3
- 1
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -40,6 +40,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.paging.LivePagedListBuilder; import androidx.paging.LivePagedListBuilder;
@ -154,7 +155,8 @@ public class FragmentMessages extends FragmentEx {
@Override @Override
public void onChanged(@Nullable PagedList<TupleMessageEx> messages) { public void onChanged(@Nullable PagedList<TupleMessageEx> messages) {
if (messages == null) { if (messages == null) {
getFragmentManager().popBackStack();
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
getFragmentManager().popBackStack();
return; return;
} }


Loading…
Cancel
Save