2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 21: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:
Erik Duisters
2018-12-07 18:13:28 +01:00
parent 9f498f8127
commit 3a189d1af4

View File

@@ -127,7 +127,6 @@ public class MainActivity extends AppCompatActivity {
});
// Decide which menu entry should be selected at start
String savedDevice;
int savedMenuEntry;
if (getIntent().hasExtra("forceOverview")) {
@@ -157,14 +156,19 @@ public class MainActivity extends AppCompatActivity {
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
if (savedMenuEntry >= MENU_ENTRY_DEVICE_FIRST_ID && savedDevice != null) {
onDeviceSelected(savedDevice);
} else {
mCurrentMenuEntry = savedMenuEntry;
mNavigationView.setCheckedItem(savedMenuEntry);
if (mCurrentMenuEntry == MENU_ENTRY_SETTINGS) {
setContentFragment(new SettingsFragment());
} else {
@@ -226,7 +230,6 @@ public class MainActivity extends AppCompatActivity {
}
private void updateDeviceList() {
BackgroundService.RunCommand(MainActivity.this, service -> {
Menu menu = mNavigationView.getMenu();