Defered finish

pull/50/head
M66B 6 years ago
parent a1aee23488
commit e578051c2c

@ -76,7 +76,6 @@ 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;
@ -804,8 +803,7 @@ 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) {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) finish();
getFragmentManager().popBackStack();
return; return;
} }
} }

@ -30,9 +30,11 @@ import android.view.inputmethod.InputMethodManager;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.Lifecycle;
public class FragmentEx extends Fragment { public class FragmentEx extends Fragment {
private String subtitle = " "; private String subtitle = " ";
private boolean finish = false;
protected void setSubtitle(int resid) { protected void setSubtitle(int resid) {
setSubtitle(getString(resid)); setSubtitle(getString(resid));
@ -43,6 +45,13 @@ public class FragmentEx extends Fragment {
updateSubtitle(); updateSubtitle();
} }
protected void finish() {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
getFragmentManager().popBackStack();
else
finish = true;
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
Log.i(Helper.TAG, "Create " + this); Log.i(Helper.TAG, "Create " + this);
@ -66,6 +75,10 @@ public class FragmentEx extends Fragment {
Log.i(Helper.TAG, "Resume " + this); Log.i(Helper.TAG, "Resume " + this);
super.onResume(); super.onResume();
updateSubtitle(); updateSubtitle();
if (finish) {
getFragmentManager().popBackStack();
finish = false;
}
} }
@Override @Override

@ -33,7 +33,6 @@ 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 {
@ -149,8 +148,7 @@ 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) {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) finish();
getFragmentManager().popBackStack();
return; return;
} }

@ -33,7 +33,6 @@ 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;
@ -109,8 +108,7 @@ 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) {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) finish();
getFragmentManager().popBackStack();
return; return;
} }

@ -65,7 +65,6 @@ 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;
@ -313,8 +312,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 (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) finish();
getFragmentManager().popBackStack();
return; return;
} }

@ -40,7 +40,6 @@ 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;
@ -155,8 +154,7 @@ 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) {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) finish();
getFragmentManager().popBackStack();
return; return;
} }

Loading…
Cancel
Save