mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-01 22:55:10 +00:00
Do not create a new content fragment on orientation change
Summary: When an orientation change occurs the fragment manager will automatically re-create the content fragment for us. Test Plan: Set the content fragment to DeviceFragment and change orientation Result: DeviceFragment is shown for the correct device and the correct navigation view menu item is checked Set the content fragment to PairingFragment and change orientation Result: PairingFragment is shown for the correct device and the "Pair new device" navigation view menu item is checked Reviewers: #kde_connect, nicolasfella Reviewed By: #kde_connect, nicolasfella Subscribers: kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D17409
This commit is contained in:
@@ -127,7 +127,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Decide which menu entry should be selected at start
|
// Decide which menu entry should be selected at start
|
||||||
|
|
||||||
String savedDevice;
|
String savedDevice;
|
||||||
int savedMenuEntry;
|
int savedMenuEntry;
|
||||||
if (getIntent().hasExtra("forceOverview")) {
|
if (getIntent().hasExtra("forceOverview")) {
|
||||||
@@ -157,14 +156,19 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
savedMenuEntry = (savedDevice != null)? MENU_ENTRY_DEVICE_UNKNOWN : MENU_ENTRY_ADD_DEVICE;
|
savedMenuEntry = (savedDevice != null)? MENU_ENTRY_DEVICE_UNKNOWN : MENU_ENTRY_ADD_DEVICE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mCurrentMenuEntry = savedMenuEntry;
|
||||||
|
mCurrentDevice = savedDevice;
|
||||||
|
mNavigationView.setCheckedItem(savedMenuEntry);
|
||||||
|
|
||||||
|
//FragmentManager will restore whatever fragment was there
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Activate the chosen fragment and select the entry in the menu
|
// Activate the chosen fragment and select the entry in the menu
|
||||||
|
|
||||||
if (savedMenuEntry >= MENU_ENTRY_DEVICE_FIRST_ID && savedDevice != null) {
|
if (savedMenuEntry >= MENU_ENTRY_DEVICE_FIRST_ID && savedDevice != null) {
|
||||||
onDeviceSelected(savedDevice);
|
onDeviceSelected(savedDevice);
|
||||||
} else {
|
} else {
|
||||||
mCurrentMenuEntry = savedMenuEntry;
|
|
||||||
mNavigationView.setCheckedItem(savedMenuEntry);
|
|
||||||
if (mCurrentMenuEntry == MENU_ENTRY_SETTINGS) {
|
if (mCurrentMenuEntry == MENU_ENTRY_SETTINGS) {
|
||||||
setContentFragment(new SettingsFragment());
|
setContentFragment(new SettingsFragment());
|
||||||
} else {
|
} else {
|
||||||
@@ -226,7 +230,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateDeviceList() {
|
private void updateDeviceList() {
|
||||||
|
|
||||||
BackgroundService.RunCommand(MainActivity.this, service -> {
|
BackgroundService.RunCommand(MainActivity.this, service -> {
|
||||||
|
|
||||||
Menu menu = mNavigationView.getMenu();
|
Menu menu = mNavigationView.getMenu();
|
||||||
|
Reference in New Issue
Block a user