Skip to content
Open
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
20 changes: 12 additions & 8 deletions app/src/main/java/com/httrack/android/HTTrackActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.OnBackPressedCallback;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
Expand Down Expand Up @@ -497,6 +498,8 @@ protected void onCreate(final Bundle savedInstanceState) {
Log.d(getClass().getSimpleName(), "onCreate");
super.onCreate(savedInstanceState);

getOnBackPressedDispatcher().addCallback(this, stayAliveWhileMirroring);

// Attempt to load the native library.
// Fetch httrack engine version
if (HTTrackLib.loadLibraries()) {
Expand Down Expand Up @@ -2159,6 +2162,7 @@ private void setPane(final int position) {

// Switch pane
pane_id = position;
stayAliveWhileMirroring.setEnabled(pane_id == LAYOUT_MIRROR_PROGRESS);
setContentView(layouts[pane_id]);

// Entering a new pane: restore data
Expand Down Expand Up @@ -2827,14 +2831,14 @@ private void goToHome() {
startActivity(intent);
}

@Override
public void onBackPressed() {
// Downloading data
if (pane_id == LAYOUT_MIRROR_PROGRESS) {
// Do not go home, or our fragment will die.
/*
* Enabled only on the progress pane, where finishing would take the retained fragment, and
* the crawl with it, down. Everywhere else it stays disabled so back does its usual thing.
*/
private final OnBackPressedCallback stayAliveWhileMirroring = new OnBackPressedCallback(false) {
@Override
public void handleOnBackPressed() {
goToHome();
} else {
super.onBackPressed();
}
}
};
}
45 changes: 27 additions & 18 deletions app/src/main/java/com/httrack/android/OptionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@
import android.widget.EditText;
import android.widget.LinearLayout;

import androidx.activity.OnBackPressedCallback;
import androidx.fragment.app.FragmentActivity;

/**
* The options activity.
*
* FragmentActivity rather than Activity: predictive back is dispatched through the AndroidX
* OnBackPressedDispatcher, which a plain Activity does not have.
*/
public class OptionsActivity extends Activity implements View.OnClickListener {
public class OptionsActivity extends FragmentActivity implements View.OnClickListener {
/* List of all tabs. */
@SuppressWarnings("unchecked")
protected static Class<? extends Tab>[] tabClasses = new Class[] {
Expand Down Expand Up @@ -335,6 +341,8 @@ private void setViewMenu() {
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getOnBackPressedDispatcher().addCallback(this, backCallback);

// Large screen ? Enable special tablet features in such case...
// "xlarge screens are at least 960dp x 720dp"
isTabletMode = getResources().getBoolean(R.bool.isTablet)
Expand Down Expand Up @@ -388,27 +396,28 @@ public void finish() {
}

/**
* Override back to propagate settings. <br />
* FIXME: we should probably do better than that!
* Back propagates the settings, and on a sub-tab returns to the menu rather than leaving.
* Always enabled: neither branch wants the default, which would finish without saving.
*/
@Override
public void onBackPressed() {
// Back from activity
if (isTabletMode || activityClass == null) {
if (isTabletMode && activityClass != null) {
private final OnBackPressedCallback backCallback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
// Back from activity. finish() is overridden above to carry the settings back.
if (isTabletMode || activityClass == null) {
if (isTabletMode && activityClass != null) {
save();
}
finish();
}
// Leave sub-activity (activityClass != null)
else {
notifyHideTab();
save();
activityClass = null;
setViewMenu();
}
super.onBackPressed();
finish();
}
// Leave sub-activity (activityClass != null)
else {
notifyHideTab();
save();
activityClass = null;
setViewMenu();
}
}
};

/*
* Return current field ID's for the activity view.
Expand Down
Loading