+ // Display the fragments. This must be done from `onCreateOptionsMenu()` instead of `onCreate()` because `populateDomainsListView()` needs `deleteMenuItem` to be inflated.
+ if (restartAfterRotate && domainSettingsDisplayedBeforeRotate) { // The device was rotated and domain settings were displayed previously.
+ if (twoPanedMode) { // The device is in two-paned mode.
+ // Reset `restartAfterRotate`.
+ restartAfterRotate = false;
+
+ // Display `DomainsListFragment`.
+ DomainsListFragment domainsListFragment = new DomainsListFragment();
+ fragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit();
+ fragmentManager.executePendingTransactions();
+
+ // Populate the list of domains. `domainSettingsDatabaseId` highlights the domain that was highlighted before the rotation.
+ populateDomainsListView(domainSettingsDatabaseIdBeforeRotate);
+ } else { // The device is in single-paned mode.
+ // Reset `restartAfterRotate`.
+ restartAfterRotate = false;
+
+ // Store the current domain database ID.
+ currentDomainDatabaseId = domainSettingsDatabaseIdBeforeRotate;
+
+ // Add `currentDomainDatabaseId` to `argumentsBundle`.
+ Bundle argumentsBundle = new Bundle();
+ argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, currentDomainDatabaseId);
+
+ // Add `argumentsBundle` to `domainSettingsFragment`.
+ DomainSettingsFragment domainSettingsFragment = new DomainSettingsFragment();
+ domainSettingsFragment.setArguments(argumentsBundle);
+
+ // Show `deleteMenuItem`.
+ deleteMenuItem.setVisible(true);
+
+ // Hide the add domain floating action button.
+ addDomainFAB.hide();
+
+ // Display `domainSettingsFragment`.
+ fragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit();
+ }
+ } else { // The device was not rotated or, if it was, domain settings were not displayed previously.
+ if (goDirectlyToDatabaseId >=0) { // Load the indicated domain settings.
+ // Store the current domain database ID.
+ currentDomainDatabaseId = goDirectlyToDatabaseId;
+
+ if (twoPanedMode) { // The device is in two-paned mode.
+ // Display `DomainsListFragment`.
+ DomainsListFragment domainsListFragment = new DomainsListFragment();
+ fragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit();
+ fragmentManager.executePendingTransactions();
+
+ // Populate the list of domains. `domainSettingsDatabaseId` highlights the domain that was highlighted before the rotation.
+ populateDomainsListView(goDirectlyToDatabaseId);
+ } else { // The device is in single-paned mode.
+ // Add the domain ID to be loaded to `argumentsBundle`.
+ Bundle argumentsBundle = new Bundle();
+ argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, goDirectlyToDatabaseId);
+
+ // Add `argumentsBundle` to `domainSettingsFragment`.
+ DomainSettingsFragment domainSettingsFragment = new DomainSettingsFragment();
+ domainSettingsFragment.setArguments(argumentsBundle);
+
+ // Show `deleteMenuItem`.
+ deleteMenuItem.setVisible(true);
+
+ // Hide the add domain floating action button.
+ addDomainFAB.hide();
+
+ // Display `domainSettingsFragment`.
+ fragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit();
+ }
+ } else { // Highlight the first domain.
+ // Display `DomainsListFragment`.
+ DomainsListFragment domainsListFragment = new DomainsListFragment();
+ fragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit();
+ fragmentManager.executePendingTransactions();
+
+ // Populate the list of domains. `-1` highlights the first domain.
+ populateDomainsListView(-1);
+ }
+ }