Add 'default screen' setting (replaces 'back button behavior') (#6041)
This commit is contained in:
parent
5ace16b31b
commit
ad9de4467b
@ -172,12 +172,16 @@ public class EspressoTestUtils {
|
|||||||
RatingDialog.saveRated();
|
RatingDialog.saveRated();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLastNavFragment(String tag) {
|
public static void setLaunchScreen(String tag) {
|
||||||
InstrumentationRegistry.getInstrumentation().getTargetContext()
|
InstrumentationRegistry.getInstrumentation().getTargetContext()
|
||||||
.getSharedPreferences(NavDrawerFragment.PREF_NAME, Context.MODE_PRIVATE)
|
.getSharedPreferences(NavDrawerFragment.PREF_NAME, Context.MODE_PRIVATE)
|
||||||
.edit()
|
.edit()
|
||||||
.putString(NavDrawerFragment.PREF_LAST_FRAGMENT_TAG, tag)
|
.putString(NavDrawerFragment.PREF_LAST_FRAGMENT_TAG, tag)
|
||||||
.commit();
|
.commit();
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(InstrumentationRegistry.getInstrumentation().getTargetContext())
|
||||||
|
.edit()
|
||||||
|
.putString(UserPreferences.PREF_DEFAULT_PAGE, UserPreferences.DEFAULT_PAGE_REMEMBER)
|
||||||
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearDatabase() {
|
public static void clearDatabase() {
|
||||||
|
@ -48,7 +48,7 @@ public class ShareDialogTest {
|
|||||||
context = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
context = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||||
EspressoTestUtils.clearPreferences();
|
EspressoTestUtils.clearPreferences();
|
||||||
EspressoTestUtils.clearDatabase();
|
EspressoTestUtils.clearDatabase();
|
||||||
EspressoTestUtils.setLastNavFragment(AllEpisodesFragment.TAG);
|
EspressoTestUtils.setLaunchScreen(AllEpisodesFragment.TAG);
|
||||||
UITestUtils uiTestUtils = new UITestUtils(context);
|
UITestUtils uiTestUtils = new UITestUtils(context);
|
||||||
uiTestUtils.setup();
|
uiTestUtils.setup();
|
||||||
uiTestUtils.addLocalFeedData(true);
|
uiTestUtils.addLocalFeedData(true);
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
package de.test.antennapod.ui;
|
package de.test.antennapod.ui;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import androidx.test.espresso.Espresso;
|
import androidx.test.espresso.Espresso;
|
||||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
import de.danoeh.antennapod.R;
|
||||||
import com.robotium.solo.Solo;
|
import de.danoeh.antennapod.activity.MainActivity;
|
||||||
|
import de.danoeh.antennapod.model.feed.Feed;
|
||||||
import de.danoeh.antennapod.storage.database.PodDBAdapter;
|
import de.danoeh.antennapod.storage.database.PodDBAdapter;
|
||||||
|
import de.test.antennapod.EspressoTestUtils;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@ -19,27 +18,14 @@ import org.junit.runner.RunWith;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import de.danoeh.antennapod.R;
|
|
||||||
import de.danoeh.antennapod.activity.MainActivity;
|
|
||||||
import de.danoeh.antennapod.model.feed.Feed;
|
|
||||||
import de.test.antennapod.EspressoTestUtils;
|
|
||||||
|
|
||||||
import static androidx.test.espresso.Espresso.onView;
|
import static androidx.test.espresso.Espresso.onView;
|
||||||
import static androidx.test.espresso.action.ViewActions.click;
|
import static androidx.test.espresso.action.ViewActions.click;
|
||||||
import static androidx.test.espresso.action.ViewActions.replaceText;
|
import static androidx.test.espresso.action.ViewActions.replaceText;
|
||||||
import static androidx.test.espresso.action.ViewActions.scrollTo;
|
import static androidx.test.espresso.action.ViewActions.scrollTo;
|
||||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
|
||||||
import static androidx.test.espresso.contrib.ActivityResultMatchers.hasResultCode;
|
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
|
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||||
import static de.test.antennapod.EspressoTestUtils.clickPreference;
|
|
||||||
import static de.test.antennapod.EspressoTestUtils.openNavDrawer;
|
import static de.test.antennapod.EspressoTestUtils.openNavDrawer;
|
||||||
import static de.test.antennapod.EspressoTestUtils.waitForViewGlobally;
|
import static de.test.antennapod.EspressoTestUtils.waitForViewGlobally;
|
||||||
import static org.hamcrest.Matchers.allOf;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User interface tests for MainActivity.
|
* User interface tests for MainActivity.
|
||||||
@ -47,7 +33,6 @@ import static org.junit.Assert.assertTrue;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class MainActivityTest {
|
public class MainActivityTest {
|
||||||
|
|
||||||
private Solo solo;
|
|
||||||
private UITestUtils uiTestUtils;
|
private UITestUtils uiTestUtils;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@ -62,8 +47,6 @@ public class MainActivityTest {
|
|||||||
|
|
||||||
uiTestUtils = new UITestUtils(InstrumentationRegistry.getInstrumentation().getTargetContext());
|
uiTestUtils = new UITestUtils(InstrumentationRegistry.getInstrumentation().getTargetContext());
|
||||||
uiTestUtils.setup();
|
uiTestUtils.setup();
|
||||||
|
|
||||||
solo = new Solo(InstrumentationRegistry.getInstrumentation(), activityRule.getActivity());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@ -91,79 +74,4 @@ public class MainActivityTest {
|
|||||||
// wait for podcast feed item list
|
// wait for podcast feed item list
|
||||||
waitForViewGlobally(withId(R.id.butShowSettings), 15000);
|
waitForViewGlobally(withId(R.id.butShowSettings), 15000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBackButtonBehaviorGoToPage() {
|
|
||||||
openNavDrawer();
|
|
||||||
onView(withText(R.string.settings_label)).perform(click());
|
|
||||||
clickPreference(R.string.user_interface_label);
|
|
||||||
clickPreference(R.string.pref_back_button_behavior_title);
|
|
||||||
|
|
||||||
onView(withText(R.string.back_button_go_to_page)).perform(click());
|
|
||||||
onView(withText(R.string.subscriptions_label)).perform(click());
|
|
||||||
onView(withText(R.string.confirm_label)).perform(click());
|
|
||||||
|
|
||||||
solo.goBackToActivity(MainActivity.class.getSimpleName());
|
|
||||||
solo.goBack();
|
|
||||||
solo.goBack();
|
|
||||||
onView(allOf(withId(R.id.toolbar), isDisplayed())).check(
|
|
||||||
matches(hasDescendant(withText(R.string.subscriptions_label))));
|
|
||||||
solo.goBack();
|
|
||||||
assertThat(activityRule.getActivityResult(), hasResultCode(Activity.RESULT_CANCELED));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBackButtonBehaviorOpenDrawer() {
|
|
||||||
openNavDrawer();
|
|
||||||
onView(withText(R.string.settings_label)).perform(click());
|
|
||||||
clickPreference(R.string.user_interface_label);
|
|
||||||
clickPreference(R.string.pref_back_button_behavior_title);
|
|
||||||
onView(withText(R.string.back_button_open_drawer)).perform(click());
|
|
||||||
solo.goBackToActivity(MainActivity.class.getSimpleName());
|
|
||||||
solo.goBack();
|
|
||||||
solo.goBack();
|
|
||||||
assertTrue(((MainActivity) solo.getCurrentActivity()).isDrawerOpen());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBackButtonBehaviorDoubleTap() {
|
|
||||||
openNavDrawer();
|
|
||||||
onView(withText(R.string.settings_label)).perform(click());
|
|
||||||
clickPreference(R.string.user_interface_label);
|
|
||||||
clickPreference(R.string.pref_back_button_behavior_title);
|
|
||||||
onView(withText(R.string.back_button_double_tap)).perform(click());
|
|
||||||
solo.goBackToActivity(MainActivity.class.getSimpleName());
|
|
||||||
solo.goBack();
|
|
||||||
solo.goBack();
|
|
||||||
solo.goBack();
|
|
||||||
assertThat(activityRule.getActivityResult(), hasResultCode(Activity.RESULT_CANCELED));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBackButtonBehaviorPrompt() throws Exception {
|
|
||||||
openNavDrawer();
|
|
||||||
onView(withText(R.string.settings_label)).perform(click());
|
|
||||||
clickPreference(R.string.user_interface_label);
|
|
||||||
clickPreference(R.string.pref_back_button_behavior_title);
|
|
||||||
onView(withText(R.string.back_button_show_prompt)).perform(click());
|
|
||||||
solo.goBackToActivity(MainActivity.class.getSimpleName());
|
|
||||||
solo.goBack();
|
|
||||||
solo.goBack();
|
|
||||||
onView(withText(R.string.yes)).perform(click());
|
|
||||||
Thread.sleep(100);
|
|
||||||
assertThat(activityRule.getActivityResult(), hasResultCode(Activity.RESULT_CANCELED));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBackButtonBehaviorDefault() {
|
|
||||||
openNavDrawer();
|
|
||||||
onView(withText(R.string.settings_label)).perform(click());
|
|
||||||
clickPreference(R.string.user_interface_label);
|
|
||||||
clickPreference(R.string.pref_back_button_behavior_title);
|
|
||||||
onView(withText(R.string.back_button_default)).perform(click());
|
|
||||||
solo.goBackToActivity(MainActivity.class.getSimpleName());
|
|
||||||
solo.goBack();
|
|
||||||
solo.goBack();
|
|
||||||
assertThat(activityRule.getActivityResult(), hasResultCode(Activity.RESULT_CANCELED));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,6 @@ import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm;
|
|||||||
import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm;
|
import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm;
|
||||||
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
|
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
|
||||||
import de.danoeh.antennapod.core.storage.ExceptFavoriteCleanupAlgorithm;
|
import de.danoeh.antennapod.core.storage.ExceptFavoriteCleanupAlgorithm;
|
||||||
import de.danoeh.antennapod.fragment.AllEpisodesFragment;
|
|
||||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
|
||||||
import de.danoeh.antennapod.fragment.SubscriptionFragment;
|
|
||||||
import de.test.antennapod.EspressoTestUtils;
|
import de.test.antennapod.EspressoTestUtils;
|
||||||
|
|
||||||
import static androidx.test.espresso.Espresso.onData;
|
import static androidx.test.espresso.Espresso.onData;
|
||||||
@ -503,35 +500,6 @@ public class PreferencesTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBackButtonBehaviorGoToPageSelector() {
|
|
||||||
clickPreference(R.string.user_interface_label);
|
|
||||||
clickPreference(R.string.pref_back_button_behavior_title);
|
|
||||||
onView(withText(R.string.back_button_go_to_page)).perform(click());
|
|
||||||
onView(withText(R.string.queue_label)).perform(click());
|
|
||||||
onView(withText(R.string.confirm_label)).perform(click());
|
|
||||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
|
||||||
.until(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE);
|
|
||||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
|
||||||
.until(() -> UserPreferences.getBackButtonGoToPage().equals(QueueFragment.TAG));
|
|
||||||
clickPreference(R.string.pref_back_button_behavior_title);
|
|
||||||
onView(withText(R.string.back_button_go_to_page)).perform(click());
|
|
||||||
onView(withText(R.string.episodes_label)).perform(click());
|
|
||||||
onView(withText(R.string.confirm_label)).perform(click());
|
|
||||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
|
||||||
.until(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE);
|
|
||||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
|
||||||
.until(() -> UserPreferences.getBackButtonGoToPage().equals(AllEpisodesFragment.TAG));
|
|
||||||
clickPreference(R.string.pref_back_button_behavior_title);
|
|
||||||
onView(withText(R.string.back_button_go_to_page)).perform(click());
|
|
||||||
onView(withText(R.string.subscriptions_label)).perform(click());
|
|
||||||
onView(withText(R.string.confirm_label)).perform(click());
|
|
||||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
|
||||||
.until(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE);
|
|
||||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
|
||||||
.until(() -> UserPreferences.getBackButtonGoToPage().equals(SubscriptionFragment.TAG));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteRemovesFromQueue() {
|
public void testDeleteRemovesFromQueue() {
|
||||||
clickPreference(R.string.storage_pref);
|
clickPreference(R.string.storage_pref);
|
||||||
|
@ -33,7 +33,7 @@ public class QueueFragmentTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
EspressoTestUtils.clearPreferences();
|
EspressoTestUtils.clearPreferences();
|
||||||
EspressoTestUtils.clearDatabase();
|
EspressoTestUtils.clearDatabase();
|
||||||
EspressoTestUtils.setLastNavFragment(QueueFragment.TAG);
|
EspressoTestUtils.setLaunchScreen(QueueFragment.TAG);
|
||||||
activityRule.launchActivity(new Intent());
|
activityRule.launchActivity(new Intent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,11 +16,9 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
@ -88,7 +86,6 @@ public class MainActivity extends CastEnabledActivity {
|
|||||||
private @Nullable ActionBarDrawerToggle drawerToggle;
|
private @Nullable ActionBarDrawerToggle drawerToggle;
|
||||||
private View navDrawer;
|
private View navDrawer;
|
||||||
private LockableBottomSheetBehavior sheetBehavior;
|
private LockableBottomSheetBehavior sheetBehavior;
|
||||||
private long lastBackButtonPressTime = 0;
|
|
||||||
private RecyclerView.RecycledViewPool recycledViewPool = new RecyclerView.RecycledViewPool();
|
private RecyclerView.RecycledViewPool recycledViewPool = new RecyclerView.RecycledViewPool();
|
||||||
private int lastTheme = 0;
|
private int lastTheme = 0;
|
||||||
|
|
||||||
@ -117,17 +114,21 @@ public class MainActivity extends CastEnabledActivity {
|
|||||||
|
|
||||||
final FragmentManager fm = getSupportFragmentManager();
|
final FragmentManager fm = getSupportFragmentManager();
|
||||||
if (fm.findFragmentByTag(MAIN_FRAGMENT_TAG) == null) {
|
if (fm.findFragmentByTag(MAIN_FRAGMENT_TAG) == null) {
|
||||||
String lastFragment = NavDrawerFragment.getLastNavFragment(this);
|
if (!UserPreferences.DEFAULT_PAGE_REMEMBER.equals(UserPreferences.getDefaultPage())) {
|
||||||
if (ArrayUtils.contains(NavDrawerFragment.NAV_DRAWER_TAGS, lastFragment)) {
|
loadFragment(UserPreferences.getDefaultPage(), null);
|
||||||
loadFragment(lastFragment, null);
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
String lastFragment = NavDrawerFragment.getLastNavFragment(this);
|
||||||
loadFeedFragmentById(Integer.parseInt(lastFragment), null);
|
if (ArrayUtils.contains(NavDrawerFragment.NAV_DRAWER_TAGS, lastFragment)) {
|
||||||
} catch (NumberFormatException e) {
|
loadFragment(lastFragment, null);
|
||||||
// it's not a number, this happens if we removed
|
} else {
|
||||||
// a label from the NAV_DRAWER_TAGS
|
try {
|
||||||
// give them a nice default...
|
loadFeedFragmentById(Integer.parseInt(lastFragment), null);
|
||||||
loadFragment(QueueFragment.TAG, null);
|
} catch (NumberFormatException e) {
|
||||||
|
// it's not a number, this happens if we removed
|
||||||
|
// a label from the NAV_DRAWER_TAGS
|
||||||
|
// give them a nice default...
|
||||||
|
loadFragment(HomeFragment.TAG, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -467,36 +468,12 @@ public class MainActivity extends CastEnabledActivity {
|
|||||||
} else if (getSupportFragmentManager().getBackStackEntryCount() != 0) {
|
} else if (getSupportFragmentManager().getBackStackEntryCount() != 0) {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
} else {
|
} else {
|
||||||
switch (UserPreferences.getBackButtonBehavior()) {
|
String toPage = UserPreferences.getDefaultPage();
|
||||||
case OPEN_DRAWER:
|
if (NavDrawerFragment.getLastNavFragment(this).equals(toPage)
|
||||||
if (drawerLayout != null) { // Tablet layout does not have drawer
|
|| UserPreferences.DEFAULT_PAGE_REMEMBER.equals(toPage)) {
|
||||||
drawerLayout.openDrawer(navDrawer);
|
super.onBackPressed();
|
||||||
}
|
} else {
|
||||||
break;
|
loadFragment(toPage, null);
|
||||||
case SHOW_PROMPT:
|
|
||||||
new AlertDialog.Builder(this)
|
|
||||||
.setMessage(R.string.close_prompt)
|
|
||||||
.setPositiveButton(R.string.yes, (dialogInterface, i) -> MainActivity.super.onBackPressed())
|
|
||||||
.setNegativeButton(R.string.no, null)
|
|
||||||
.setCancelable(false)
|
|
||||||
.show();
|
|
||||||
break;
|
|
||||||
case DOUBLE_TAP:
|
|
||||||
if (lastBackButtonPressTime < System.currentTimeMillis() - 2000) {
|
|
||||||
Toast.makeText(this, R.string.double_tap_toast, Toast.LENGTH_SHORT).show();
|
|
||||||
lastBackButtonPressTime = System.currentTimeMillis();
|
|
||||||
} else {
|
|
||||||
super.onBackPressed();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case GO_TO_PAGE:
|
|
||||||
if (NavDrawerFragment.getLastNavFragment(this).equals(UserPreferences.getBackButtonGoToPage())) {
|
|
||||||
super.onBackPressed();
|
|
||||||
} else {
|
|
||||||
loadFragment(UserPreferences.getBackButtonGoToPage(), null);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default: super.onBackPressed();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package de.danoeh.antennapod.dialog;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import de.danoeh.antennapod.R;
|
||||||
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
|
import de.danoeh.antennapod.fragment.NavDrawerFragment;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DrawerPreferencesDialog {
|
||||||
|
public static void show(Context context, Runnable callback) {
|
||||||
|
final List<String> hiddenDrawerItems = UserPreferences.getHiddenDrawerItems();
|
||||||
|
final String[] navTitles = context.getResources().getStringArray(R.array.nav_drawer_titles);
|
||||||
|
boolean[] checked = new boolean[NavDrawerFragment.NAV_DRAWER_TAGS.length];
|
||||||
|
for (int i = 0; i < NavDrawerFragment.NAV_DRAWER_TAGS.length; i++) {
|
||||||
|
String tag = NavDrawerFragment.NAV_DRAWER_TAGS[i];
|
||||||
|
if (!hiddenDrawerItems.contains(tag)) {
|
||||||
|
checked[i] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
builder.setTitle(R.string.drawer_preferences);
|
||||||
|
builder.setMultiChoiceItems(navTitles, checked, (dialog, which, isChecked) -> {
|
||||||
|
if (isChecked) {
|
||||||
|
hiddenDrawerItems.remove(NavDrawerFragment.NAV_DRAWER_TAGS[which]);
|
||||||
|
} else {
|
||||||
|
hiddenDrawerItems.add(NavDrawerFragment.NAV_DRAWER_TAGS[which]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
|
||||||
|
UserPreferences.setHiddenDrawerItems(hiddenDrawerItems);
|
||||||
|
|
||||||
|
if (hiddenDrawerItems.contains(UserPreferences.getDefaultPage())) {
|
||||||
|
for (String tag : NavDrawerFragment.NAV_DRAWER_TAGS) {
|
||||||
|
if (!hiddenDrawerItems.contains(tag)) {
|
||||||
|
UserPreferences.setDefaultPage(tag);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callback != null) {
|
||||||
|
callback.run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(R.string.cancel_label, null);
|
||||||
|
builder.create().show();
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,6 @@ import android.widget.ProgressBar;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.core.util.Pair;
|
import androidx.core.util.Pair;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
@ -32,6 +31,7 @@ import de.danoeh.antennapod.core.preferences.UserPreferences;
|
|||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
import de.danoeh.antennapod.core.storage.NavDrawerData;
|
import de.danoeh.antennapod.core.storage.NavDrawerData;
|
||||||
|
import de.danoeh.antennapod.dialog.DrawerPreferencesDialog;
|
||||||
import de.danoeh.antennapod.dialog.RemoveFeedDialog;
|
import de.danoeh.antennapod.dialog.RemoveFeedDialog;
|
||||||
import de.danoeh.antennapod.dialog.RenameItemDialog;
|
import de.danoeh.antennapod.dialog.RenameItemDialog;
|
||||||
import de.danoeh.antennapod.dialog.SubscriptionsFilterDialog;
|
import de.danoeh.antennapod.dialog.SubscriptionsFilterDialog;
|
||||||
@ -219,35 +219,6 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS
|
|||||||
loadData();
|
loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDrawerPreferencesDialog() {
|
|
||||||
final List<String> hiddenDrawerItems = UserPreferences.getHiddenDrawerItems();
|
|
||||||
String[] navLabels = new String[NAV_DRAWER_TAGS.length];
|
|
||||||
final boolean[] checked = new boolean[NAV_DRAWER_TAGS.length];
|
|
||||||
for (int i = 0; i < NAV_DRAWER_TAGS.length; i++) {
|
|
||||||
String tag = NAV_DRAWER_TAGS[i];
|
|
||||||
navLabels[i] = navAdapter.getLabel(tag);
|
|
||||||
if (!hiddenDrawerItems.contains(tag)) {
|
|
||||||
checked[i] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
|
||||||
builder.setTitle(R.string.drawer_preferences);
|
|
||||||
builder.setMultiChoiceItems(navLabels, checked, (dialog, which, isChecked) -> {
|
|
||||||
if (isChecked) {
|
|
||||||
hiddenDrawerItems.remove(NAV_DRAWER_TAGS[which]);
|
|
||||||
} else {
|
|
||||||
hiddenDrawerItems.add(NAV_DRAWER_TAGS[which]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
|
|
||||||
UserPreferences.setHiddenDrawerItems(hiddenDrawerItems);
|
|
||||||
navAdapter.notifyDataSetChanged(); // Update selection
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(R.string.cancel_label, null);
|
|
||||||
builder.create().show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private final NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() {
|
private final NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() {
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
@ -367,7 +338,7 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS
|
|||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(int position) {
|
public boolean onItemLongClick(int position) {
|
||||||
if (position < navAdapter.getFragmentTags().size()) {
|
if (position < navAdapter.getFragmentTags().size()) {
|
||||||
showDrawerPreferencesDialog();
|
DrawerPreferencesDialog.show(getContext(), () -> navAdapter.notifyDataSetChanged());
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
contextPressedItem = flatItemList.get(position - navAdapter.getSubscriptionOffset());
|
contextPressedItem = flatItemList.get(position - navAdapter.getSubscriptionOffset());
|
||||||
|
@ -3,20 +3,19 @@ package de.danoeh.antennapod.fragment.preferences;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import android.widget.ListView;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
import android.widget.ListView;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.activity.PreferenceActivity;
|
import de.danoeh.antennapod.activity.PreferenceActivity;
|
||||||
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
|
import de.danoeh.antennapod.dialog.DrawerPreferencesDialog;
|
||||||
|
import de.danoeh.antennapod.dialog.FeedSortDialog;
|
||||||
|
import de.danoeh.antennapod.dialog.SubscriptionsFilterDialog;
|
||||||
import de.danoeh.antennapod.event.PlayerStatusEvent;
|
import de.danoeh.antennapod.event.PlayerStatusEvent;
|
||||||
import de.danoeh.antennapod.event.UnreadItemsUpdateEvent;
|
import de.danoeh.antennapod.event.UnreadItemsUpdateEvent;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
|
||||||
import de.danoeh.antennapod.dialog.SubscriptionsFilterDialog;
|
|
||||||
import de.danoeh.antennapod.dialog.FeedSortDialog;
|
|
||||||
import de.danoeh.antennapod.fragment.NavDrawerFragment;
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -55,7 +54,7 @@ public class UserInterfacePreferencesFragment extends PreferenceFragmentCompat {
|
|||||||
|
|
||||||
findPreference(UserPreferences.PREF_HIDDEN_DRAWER_ITEMS)
|
findPreference(UserPreferences.PREF_HIDDEN_DRAWER_ITEMS)
|
||||||
.setOnPreferenceClickListener(preference -> {
|
.setOnPreferenceClickListener(preference -> {
|
||||||
showDrawerPreferencesDialog();
|
DrawerPreferencesDialog.show(getContext(), null);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -64,31 +63,6 @@ public class UserInterfacePreferencesFragment extends PreferenceFragmentCompat {
|
|||||||
showNotificationButtonsDialog();
|
showNotificationButtonsDialog();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
findPreference(UserPreferences.PREF_BACK_BUTTON_BEHAVIOR)
|
|
||||||
.setOnPreferenceChangeListener((preference, newValue) -> {
|
|
||||||
if (!newValue.equals("page")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
final Context context = getActivity();
|
|
||||||
final String[] navTitles = context.getResources().getStringArray(R.array.back_button_go_to_pages);
|
|
||||||
final String[] navTags = context.getResources().getStringArray(R.array.back_button_go_to_pages_tags);
|
|
||||||
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, ArrayUtils.indexOf(navTags,
|
|
||||||
UserPreferences.getBackButtonGoToPage()), (dialogInterface, i) -> {
|
|
||||||
if (i >= 0) {
|
|
||||||
choice[0] = navTags[i];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setPositiveButton(R.string.confirm_label, (dialogInterface, i) -> UserPreferences.setBackButtonGoToPage(choice[0]));
|
|
||||||
builder.setNegativeButton(R.string.cancel_label, null);
|
|
||||||
builder.create().show();
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
findPreference(UserPreferences.PREF_FILTER_FEED)
|
findPreference(UserPreferences.PREF_FILTER_FEED)
|
||||||
.setOnPreferenceClickListener((preference -> {
|
.setOnPreferenceClickListener((preference -> {
|
||||||
SubscriptionsFilterDialog.showDialog(requireContext());
|
SubscriptionsFilterDialog.showDialog(requireContext());
|
||||||
@ -111,33 +85,6 @@ public class UserInterfacePreferencesFragment extends PreferenceFragmentCompat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDrawerPreferencesDialog() {
|
|
||||||
final Context context = getActivity();
|
|
||||||
final List<String> hiddenDrawerItems = UserPreferences.getHiddenDrawerItems();
|
|
||||||
final String[] navTitles = context.getResources().getStringArray(R.array.nav_drawer_titles);
|
|
||||||
final String[] NAV_DRAWER_TAGS = NavDrawerFragment.NAV_DRAWER_TAGS;
|
|
||||||
boolean[] checked = new boolean[NavDrawerFragment.NAV_DRAWER_TAGS.length];
|
|
||||||
for (int i = 0; i < NAV_DRAWER_TAGS.length; i++) {
|
|
||||||
String tag = NAV_DRAWER_TAGS[i];
|
|
||||||
if (!hiddenDrawerItems.contains(tag)) {
|
|
||||||
checked[i] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
||||||
builder.setTitle(R.string.drawer_preferences);
|
|
||||||
builder.setMultiChoiceItems(navTitles, checked, (dialog, which, isChecked) -> {
|
|
||||||
if (isChecked) {
|
|
||||||
hiddenDrawerItems.remove(NAV_DRAWER_TAGS[which]);
|
|
||||||
} else {
|
|
||||||
hiddenDrawerItems.add(NAV_DRAWER_TAGS[which]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setPositiveButton(R.string.confirm_label, (dialog, which) ->
|
|
||||||
UserPreferences.setHiddenDrawerItems(hiddenDrawerItems));
|
|
||||||
builder.setNegativeButton(R.string.cancel_label, null);
|
|
||||||
builder.create().show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showNotificationButtonsDialog() {
|
private void showNotificationButtonsDialog() {
|
||||||
final Context context = getActivity();
|
final Context context = getActivity();
|
||||||
final List<Integer> preferredButtons = UserPreferences.getCompactNotificationButtons();
|
final List<Integer> preferredButtons = UserPreferences.getCompactNotificationButtons();
|
||||||
|
@ -77,12 +77,12 @@
|
|||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory android:title="@string/behavior">
|
<PreferenceCategory android:title="@string/behavior">
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:entryValues="@array/back_button_behavior_values"
|
android:entryValues="@array/default_page_values"
|
||||||
android:entries="@array/back_button_behavior_options"
|
android:entries="@array/default_page_titles"
|
||||||
android:key="prefBackButtonBehavior"
|
android:key="prefDefaultPage"
|
||||||
android:title="@string/pref_back_button_behavior_title"
|
android:title="@string/pref_default_page"
|
||||||
android:summary="@string/pref_back_button_behavior_sum"
|
android:summary="@string/pref_default_page_sum"
|
||||||
android:defaultValue="default"/>
|
android:defaultValue="HomeFragment"/>
|
||||||
<Preference
|
<Preference
|
||||||
android:key="prefSwipe"
|
android:key="prefSwipe"
|
||||||
android:summary="@string/swipeactions_summary"
|
android:summary="@string/swipeactions_summary"
|
||||||
|
@ -61,8 +61,7 @@ public class UserPreferences {
|
|||||||
public static final String PREF_LOCKSCREEN_BACKGROUND = "prefLockscreenBackground";
|
public static final String PREF_LOCKSCREEN_BACKGROUND = "prefLockscreenBackground";
|
||||||
private static final String PREF_SHOW_DOWNLOAD_REPORT = "prefShowDownloadReport";
|
private static final String PREF_SHOW_DOWNLOAD_REPORT = "prefShowDownloadReport";
|
||||||
private static final String PREF_SHOW_AUTO_DOWNLOAD_REPORT = "prefShowAutoDownloadReport";
|
private static final String PREF_SHOW_AUTO_DOWNLOAD_REPORT = "prefShowAutoDownloadReport";
|
||||||
public static final String PREF_BACK_BUTTON_BEHAVIOR = "prefBackButtonBehavior";
|
public static final String PREF_DEFAULT_PAGE = "prefDefaultPage";
|
||||||
private static final String PREF_BACK_BUTTON_GO_TO_PAGE = "prefBackButtonGoToPage";
|
|
||||||
public static final String PREF_FILTER_FEED = "prefSubscriptionsFilter";
|
public static final String PREF_FILTER_FEED = "prefSubscriptionsFilter";
|
||||||
public static final String PREF_SUBSCRIPTION_TITLE = "prefSubscriptionTitle";
|
public static final String PREF_SUBSCRIPTION_TITLE = "prefSubscriptionTitle";
|
||||||
|
|
||||||
@ -137,6 +136,7 @@ public class UserPreferences {
|
|||||||
public static final int FEED_ORDER_COUNTER = 0;
|
public static final int FEED_ORDER_COUNTER = 0;
|
||||||
public static final int FEED_ORDER_ALPHABETICAL = 1;
|
public static final int FEED_ORDER_ALPHABETICAL = 1;
|
||||||
public static final int FEED_ORDER_MOST_PLAYED = 3;
|
public static final int FEED_ORDER_MOST_PLAYED = 3;
|
||||||
|
public static final String DEFAULT_PAGE_REMEMBER = "remember";
|
||||||
|
|
||||||
private static Context context;
|
private static Context context;
|
||||||
private static SharedPreferences prefs;
|
private static SharedPreferences prefs;
|
||||||
@ -901,29 +901,12 @@ public class UserPreferences {
|
|||||||
return getUpdateTimeOfDay().length == 2;
|
return getUpdateTimeOfDay().length == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum BackButtonBehavior {
|
public static String getDefaultPage() {
|
||||||
DEFAULT, OPEN_DRAWER, DOUBLE_TAP, SHOW_PROMPT, GO_TO_PAGE
|
return prefs.getString(PREF_DEFAULT_PAGE, "HomeFragment");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BackButtonBehavior getBackButtonBehavior() {
|
public static void setDefaultPage(String defaultPage) {
|
||||||
switch (prefs.getString(PREF_BACK_BUTTON_BEHAVIOR, "default")) {
|
prefs.edit().putString(PREF_DEFAULT_PAGE, defaultPage).apply();
|
||||||
case "drawer": return BackButtonBehavior.OPEN_DRAWER;
|
|
||||||
case "doubletap": return BackButtonBehavior.DOUBLE_TAP;
|
|
||||||
case "prompt": return BackButtonBehavior.SHOW_PROMPT;
|
|
||||||
case "page": return BackButtonBehavior.GO_TO_PAGE;
|
|
||||||
case "default": // Deliberate fall-through
|
|
||||||
default: return BackButtonBehavior.DEFAULT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getBackButtonGoToPage() {
|
|
||||||
return prefs.getString(PREF_BACK_BUTTON_GO_TO_PAGE, "QueueFragment");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setBackButtonGoToPage(String tag) {
|
|
||||||
prefs.edit()
|
|
||||||
.putString(PREF_BACK_BUTTON_GO_TO_PAGE, tag)
|
|
||||||
.apply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean timeRespectsSpeed() {
|
public static boolean timeRespectsSpeed() {
|
||||||
|
@ -263,35 +263,21 @@
|
|||||||
<item>@string/skip_episode_label</item>
|
<item>@string/skip_episode_label</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="back_button_behavior_options">
|
<string-array name="default_page_values">
|
||||||
<item>@string/back_button_default</item>
|
|
||||||
<item>@string/back_button_go_to_page</item>
|
|
||||||
<item>@string/back_button_open_drawer</item>
|
|
||||||
<item>@string/back_button_double_tap</item>
|
|
||||||
<item>@string/back_button_show_prompt</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array name="back_button_behavior_values">
|
|
||||||
<item>default</item>
|
|
||||||
<item>page</item>
|
|
||||||
<item>drawer</item>
|
|
||||||
<item>doubletap</item>
|
|
||||||
<item>prompt</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array name="back_button_go_to_pages">
|
|
||||||
<item>@string/home_label</item>
|
|
||||||
<item>@string/queue_label</item>
|
|
||||||
<item>@string/inbox_label</item>
|
|
||||||
<item>@string/episodes_label</item>
|
|
||||||
<item>@string/subscriptions_label</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array name="back_button_go_to_pages_tags">
|
|
||||||
<item>HomeFragment</item>
|
<item>HomeFragment</item>
|
||||||
<item>QueueFragment</item>
|
<item>QueueFragment</item>
|
||||||
<item>InboxFragment</item>
|
<item>InboxFragment</item>
|
||||||
<item>EpisodesFragment</item>
|
<item>EpisodesFragment</item>
|
||||||
<item>SubscriptionFragment</item>
|
<item>SubscriptionFragment</item>
|
||||||
|
<item>remember</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="default_page_titles">
|
||||||
|
<item>@string/home_label</item>
|
||||||
|
<item>@string/queue_label</item>
|
||||||
|
<item>@string/inbox_label</item>
|
||||||
|
<item>@string/episodes_label</item>
|
||||||
|
<item>@string/subscriptions_label</item>
|
||||||
|
<item>@string/remember_last_page</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -519,16 +519,9 @@
|
|||||||
<string name="media_player_switched_to_exoplayer">Switched to ExoPlayer.</string>
|
<string name="media_player_switched_to_exoplayer">Switched to ExoPlayer.</string>
|
||||||
<string name="pref_skip_silence_title">Skip Silence in Audio</string>
|
<string name="pref_skip_silence_title">Skip Silence in Audio</string>
|
||||||
<string name="behavior">Behavior</string>
|
<string name="behavior">Behavior</string>
|
||||||
<string name="pref_back_button_behavior_title">Back Button Behavior</string>
|
<string name="pref_default_page">Default Page</string>
|
||||||
<string name="pref_back_button_behavior_sum">Change behavior of the back button.</string>
|
<string name="pref_default_page_sum">Screen that is opened when starting AntennaPod.</string>
|
||||||
<string name="back_button_default">Default</string>
|
<string name="remember_last_page">Remember last page</string>
|
||||||
<string name="back_button_open_drawer">Open navigation drawer</string>
|
|
||||||
<string name="back_button_double_tap">Double tap to exit</string>
|
|
||||||
<string name="back_button_show_prompt">Confirm to exit</string>
|
|
||||||
<string name="close_prompt">Are you sure you want to close AntennaPod?</string>
|
|
||||||
<string name="double_tap_toast">Tap back button again to exit</string>
|
|
||||||
<string name="back_button_go_to_page">Go to page…</string>
|
|
||||||
<string name="back_button_go_to_page_title">Select page</string>
|
|
||||||
<string name="pref_delete_removes_from_queue_title">Delete removes from Queue</string>
|
<string name="pref_delete_removes_from_queue_title">Delete removes from Queue</string>
|
||||||
<string name="pref_delete_removes_from_queue_sum">Automatically remove an episode from the queue when it is deleted.</string>
|
<string name="pref_delete_removes_from_queue_sum">Automatically remove an episode from the queue when it is deleted.</string>
|
||||||
<string name="pref_filter_feed_title">Subscription Filter</string>
|
<string name="pref_filter_feed_title">Subscription Filter</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user