diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java index 061eec74b..f217ecffa 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java @@ -16,6 +16,10 @@ import de.danoeh.antennapod.core.storage.APCleanupAlgorithm; import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm; import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm; import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm; +import de.danoeh.antennapod.fragment.EpisodesFragment; +import de.danoeh.antennapod.fragment.QueueFragment; +import de.danoeh.antennapod.fragment.SubscriptionFragment; + import org.hamcrest.Matcher; import org.junit.After; import org.junit.Before; @@ -473,9 +477,31 @@ public class PreferencesTest { solo.waitForDialogToOpen(); solo.clickOnText(solo.getString(R.string.back_button_go_to_page)); solo.waitForDialogToOpen(); + solo.clickOnText(solo.getString(R.string.queue_label)); + solo.clickOnText(solo.getString(R.string.confirm_label)); + assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE, + Timeout.getLargeTimeout())); + assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonGoToPage().equals(QueueFragment.TAG), + Timeout.getLargeTimeout())); + clickPreference(withText(R.string.pref_back_button_behavior_title)); + solo.waitForDialogToOpen(); + solo.clickOnText(solo.getString(R.string.back_button_go_to_page)); + solo.waitForDialogToOpen(); + solo.clickOnText(solo.getString(R.string.episodes_label)); + solo.clickOnText(solo.getString(R.string.confirm_label)); + assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE, + Timeout.getLargeTimeout())); + assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonGoToPage().equals(EpisodesFragment.TAG), + Timeout.getLargeTimeout())); + clickPreference(withText(R.string.pref_back_button_behavior_title)); + solo.waitForDialogToOpen(); + solo.clickOnText(solo.getString(R.string.back_button_go_to_page)); + solo.waitForDialogToOpen(); solo.clickOnText(solo.getString(R.string.subscriptions_label)); solo.clickOnText(solo.getString(R.string.confirm_label)); - assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_SUBSCRIPTIONS, + assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE, + Timeout.getLargeTimeout())); + assertTrue(solo.waitForCondition(() -> UserPreferences.getBackButtonGoToPage().equals(SubscriptionFragment.TAG), Timeout.getLargeTimeout())); } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 4c25c5c28..d2a0c3aab 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -669,25 +669,11 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi super.onBackPressed(); } break; - case GO_TO_QUEUE: - if(getLastNavFragment().equals(QueueFragment.TAG)) { + case GO_TO_PAGE: + if(getLastNavFragment().equals(UserPreferences.getBackButtonGoToPage())) { super.onBackPressed(); } else { - loadFragment(QueueFragment.TAG, null); - } - break; - case GO_TO_EPISODES: - if(getLastNavFragment().equals(EpisodesFragment.TAG)) { - super.onBackPressed(); - } else { - loadFragment(EpisodesFragment.TAG, null); - } - break; - case GO_TO_SUBSCRIPTIONS: - if(getLastNavFragment().equals(SubscriptionFragment.TAG)) { - super.onBackPressed(); - } else { - loadFragment(SubscriptionFragment.TAG, null); + loadFragment(UserPreferences.getBackButtonGoToPage(), null); } break; default: super.onBackPressed(); diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index 56af71dc4..ec1767062 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -232,17 +232,19 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc if(newValue.equals("page")) { final Context context = ui.getActivity(); final String[] navTitles = context.getResources().getStringArray(R.array.back_button_go_to_pages); - final int choice[] = { UserPreferences.getBackButtonGoToPage() }; + final String[] navTags = new String[3]; + System.arraycopy(MainActivity.NAV_DRAWER_TAGS, 0, navTags, 0, 3); + final String choice[] = { UserPreferences.getBackButtonGoToPage() }; AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.back_button_go_to_page_title); - builder.setSingleChoiceItems(navTitles, choice[0], (dialogInterface, i) -> { + builder.setSingleChoiceItems(navTitles, ArrayUtils.indexOf(navTags, UserPreferences.getBackButtonGoToPage()), (dialogInterface, i) -> { if(i >= 0) { - choice[0] = i; + choice[0] = navTags[i]; } }); builder.setPositiveButton(R.string.confirm_label, (dialogInterface, i) -> { - if (choice[0] != UserPreferences.getBackButtonGoToPage()) { + if (!choice[0].equals(UserPreferences.getBackButtonGoToPage())) { UserPreferences.setBackButtonGoToPage(choice[0]); } }); diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index f964fd23a..c44999c88 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -813,7 +813,7 @@ public class UserPreferences { } public enum BackButtonBehavior { - DEFAULT, OPEN_DRAWER, DOUBLE_TAP, SHOW_PROMPT, GO_TO_QUEUE, GO_TO_EPISODES, GO_TO_SUBSCRIPTIONS + DEFAULT, OPEN_DRAWER, DOUBLE_TAP, SHOW_PROMPT, GO_TO_PAGE } public static BackButtonBehavior getBackButtonBehavior() { @@ -822,24 +822,18 @@ public class UserPreferences { case "drawer": return BackButtonBehavior.OPEN_DRAWER; case "doubletap": return BackButtonBehavior.DOUBLE_TAP; case "prompt": return BackButtonBehavior.SHOW_PROMPT; - case "page": - switch (UserPreferences.getBackButtonGoToPage()) { - case 0: return BackButtonBehavior.GO_TO_QUEUE; - case 1: return BackButtonBehavior.GO_TO_EPISODES; - case 2: return BackButtonBehavior.GO_TO_SUBSCRIPTIONS; - default: return BackButtonBehavior.GO_TO_QUEUE; - } + case "page": return BackButtonBehavior.GO_TO_PAGE; default: return BackButtonBehavior.DEFAULT; } } - public static int getBackButtonGoToPage() { - return prefs.getInt(PREF_BACK_BUTTON_GO_TO_PAGE, 0); + public static String getBackButtonGoToPage() { + return prefs.getString(PREF_BACK_BUTTON_GO_TO_PAGE, "QueueFragment"); } - public static void setBackButtonGoToPage(int page) { + public static void setBackButtonGoToPage(String tag) { prefs.edit() - .putInt(PREF_BACK_BUTTON_GO_TO_PAGE, page) + .putString(PREF_BACK_BUTTON_GO_TO_PAGE, tag) .apply(); } }