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
2 changes: 1 addition & 1 deletion Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ dependencies {
androidTestImplementation 'androidx.annotation:annotation:1.3.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
// UI libraries.
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.appcompat:appcompat:1.7.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
Expand Down
36 changes: 23 additions & 13 deletions Android/app/src/main/java/app/intra/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.DrawableRes;
import androidx.annotation.IdRes;
import androidx.annotation.StringRes;
Expand Down Expand Up @@ -177,6 +178,8 @@ protected void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_main);

getOnBackPressedDispatcher().addCallback(this, backToHomeCallback);

// Set up the toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Expand Down Expand Up @@ -724,20 +727,23 @@ private void syncDnsStatus() {
}
}

@Override
public void onBackPressed() {
if (isShowingHomeView()) {
// Back button should leave the app if we are currently looking at the home view.
super.onBackPressed();
return;
/**
* Handles the back button on the settings and info views by returning to the home view.
*
* <p>This must not be an {@code onBackPressed()} override. Apps targeting SDK 36 can no
* longer opt out of predictive back, and the platform routes back gestures through
* {@link androidx.activity.OnBackPressedDispatcher} instead of calling
* {@code onBackPressed()}.
*
* <p>The callback stays disabled while the home view is showing, so that back exits the
* app as usual. {@link #chooseView} keeps that state in sync.
*/
private final OnBackPressedCallback backToHomeCallback = new OnBackPressedCallback(false) {
@Override
public void handleOnBackPressed() {
chooseView(R.id.frame_main);
}
chooseView(R.id.frame_main);
}

private boolean isShowingHomeView() {
View home = findViewById(R.id.frame_main);
return home.getVisibility() == View.VISIBLE;
}
};

private void showSettings() {
settingsFragment = new SettingsFragment();
Expand Down Expand Up @@ -780,6 +786,10 @@ private View chooseView(int id) {
drawerToggle.setDrawerIndicatorEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
}

// Intercept back only on the screens the arrow points away from. On the home view the
// callback is disabled, so back falls through to the system and leaves the app.
backToHomeCallback.setEnabled(id != R.id.frame_main);
return selected;
}

Expand Down
Loading
Loading