Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class ContentDeleteProgressFragment extends Fragment {

private final DeleteSession session = ContentDeleteService.session();

/** One-shot guard so a re-entrant render() does not schedule the back-pop twice. */
private boolean leaving;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle s) {
Expand Down Expand Up @@ -137,9 +140,41 @@ private void renderSettled(boolean running, String error) {
message.setVisibility(View.VISIBLE);
}

@Override
public void onDestroyView() {
// The scheduled pop runs on the view's handler; if the view is gone it will not run, so clear
// the guard here so it does not stay true across a view recreation.
leaving = false;
super.onDestroyView();
}

/**
* Leave this progress screen. The pop is deferred to the next main-loop tick and re-checked there.
* render() runs from onResume() and from the session listener, which the FragmentManager can drive
* from inside a transaction; the foreground service also begins the session on a later message, so
* the first render can see no session yet. Deferring plus the enqueued popBackStack() (never a
* synchronous onBackPressed) avoids "FragmentManager is already executing transactions" (K2GO-427),
* and re-checking hasSession() on the tick keeps the screen if a run just started.
*/
private void goBack() {
if (isAdded()) {
requireActivity().getOnBackPressedDispatcher().onBackPressed();
if (leaving) {
return;
}
View v = getView();
if (v == null) {
return;
}
leaving = true;
v.post(() -> {
if (!isAdded()) {
return;
}
if (session.hasSession()) {
leaving = false; // a run exists now: stay, and let a later leave (Finish) reschedule
return;
}
// Enqueued pop of this screen's own back-stack entry: deterministic and async-safe.
getParentFragmentManager().popBackStack();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class ExportProgressFragment extends Fragment {

private final ExportSession session = ContentExportService.session();

/** One-shot guard so a re-entrant render() does not schedule the back-pop twice. */
private boolean leaving;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle s) {
Expand Down Expand Up @@ -281,9 +284,41 @@ private static String formatEta(long seconds) {
return String.format(Locale.US, "%d:%02d", m, s);
}

@Override
public void onDestroyView() {
// The scheduled pop runs on the view's handler; if the view is gone it will not run, so clear
// the guard here so it does not stay true across a view recreation.
leaving = false;
super.onDestroyView();
}

/**
* Leave this progress screen. The pop is deferred to the next main-loop tick and re-checked there.
* render() runs from onResume() and from the session listener, which the FragmentManager can drive
* from inside a transaction; the foreground service also begins the session on a later message, so
* the first render can see no session yet. Deferring plus the enqueued popBackStack() (never a
* synchronous onBackPressed) avoids "FragmentManager is already executing transactions" (K2GO-427),
* and re-checking hasSession() on the tick keeps the screen if a run just started.
*/
private void goBack() {
if (isAdded()) {
requireActivity().getOnBackPressedDispatcher().onBackPressed();
if (leaving) {
return;
}
View v = getView();
if (v == null) {
return;
}
leaving = true;
v.post(() -> {
if (!isAdded()) {
return;
}
if (session.hasSession()) {
leaving = false; // a run exists now: stay, and let a later leave (Finish) reschedule
return;
}
// Enqueued pop of this screen's own back-stack entry: deterministic and async-safe.
getParentFragmentManager().popBackStack();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class ImportProgressFragment extends Fragment {

private final ImportSession session = ContentImportService.session();

/** One-shot guard so a re-entrant render() does not schedule the back-pop twice. */
private boolean leaving;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle s) {
Expand Down Expand Up @@ -174,9 +177,41 @@ private static String formatEta(long seconds) {
return String.format(Locale.US, "%d:%02d", m, s);
}

@Override
public void onDestroyView() {
// The scheduled pop runs on the view's handler; if the view is gone it will not run, so clear
// the guard here so it does not stay true across a view recreation.
leaving = false;
super.onDestroyView();
}

/**
* Leave this progress screen. The pop is deferred to the next main-loop tick and re-checked there.
* render() runs from onResume() and from the session listener, which the FragmentManager can drive
* from inside a transaction; the foreground service also begins the session on a later message, so
* the first render can see no session yet. Deferring plus the enqueued popBackStack() (never a
* synchronous onBackPressed) avoids "FragmentManager is already executing transactions" (K2GO-427),
* and re-checking hasSession() on the tick keeps the screen if a run just started.
*/
private void goBack() {
if (isAdded()) {
requireActivity().getOnBackPressedDispatcher().onBackPressed();
if (leaving) {
return;
}
View v = getView();
if (v == null) {
return;
}
leaving = true;
v.post(() -> {
if (!isAdded()) {
return;
}
if (session.hasSession()) {
leaving = false; // a run exists now: stay, and let a later leave (Finish) reschedule
return;
}
// Enqueued pop of this screen's own back-stack entry: deterministic and async-safe.
getParentFragmentManager().popBackStack();
});
}
}
Loading