diff --git a/Android/app/build.gradle b/Android/app/build.gradle index a23a65fd..8ce0d23c 100644 --- a/Android/app/build.gradle +++ b/Android/app/build.gradle @@ -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' diff --git a/Android/app/src/main/java/app/intra/ui/MainActivity.java b/Android/app/src/main/java/app/intra/ui/MainActivity.java index 4a91bb8c..9256a211 100644 --- a/Android/app/src/main/java/app/intra/ui/MainActivity.java +++ b/Android/app/src/main/java/app/intra/ui/MainActivity.java @@ -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; @@ -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); @@ -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. + * + *

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()}. + * + *

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(); @@ -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; } diff --git a/Android/gradle/verification-metadata.xml b/Android/gradle/verification-metadata.xml index 775a04b4..a5dcc702 100644 --- a/Android/gradle/verification-metadata.xml +++ b/Android/gradle/verification-metadata.xml @@ -18,6 +18,14 @@ + + + + + + + + @@ -34,6 +42,11 @@ + + + + + @@ -47,6 +60,22 @@ + + + + + + + + + + + + + + + + @@ -55,6 +84,14 @@ + + + + + + + + @@ -63,6 +100,14 @@ + + + + + + + + @@ -76,6 +121,14 @@ + + + + + + + + @@ -92,6 +145,14 @@ + + + + + + + + @@ -153,6 +214,14 @@ + + + + + + + + @@ -161,6 +230,22 @@ + + + + + + + + + + + + + + + + @@ -289,6 +374,14 @@ + + + + + + + + @@ -297,6 +390,19 @@ + + + + + + + + + + + + + @@ -305,6 +411,14 @@ + + + + + + + + @@ -342,6 +456,19 @@ + + + + + + + + + + + + + @@ -350,6 +477,14 @@ + + + + + + + + @@ -358,6 +493,24 @@ + + + + + + + + + + + + + + + + + + @@ -366,6 +519,24 @@ + + + + + + + + + + + + + + + + + + @@ -387,6 +558,19 @@ + + + + + + + + + + + + + @@ -395,6 +579,19 @@ + + + + + + + + + + + + + @@ -403,6 +600,19 @@ + + + + + + + + + + + + + @@ -451,6 +661,14 @@ + + + + + + + + @@ -467,6 +685,14 @@ + + + + + + + + @@ -475,6 +701,14 @@ + + + + + + + + @@ -483,6 +717,14 @@ + + + + + + + + @@ -4212,6 +4454,14 @@ + + + + + + + +