summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Lehmann <ByteHamster@users.noreply.github.com>2019-09-09 18:52:53 +0200
committerGitHub <noreply@github.com>2019-09-09 18:52:53 +0200
commit60faccb27a175f66dbe2f5e2b02893a912a997e1 (patch)
tree694db63641fefec30afd4e4a03af496a7f8d1fcf
parenta6e131a5429451ac9a4f0e0456331566b9dd4e82 (diff)
parent6b79f740b207fc70d6d67253d883c4c2348d44df (diff)
downloadAntennaPod-60faccb27a175f66dbe2f5e2b02893a912a997e1.zip
Merge pull request #3396 from ByteHamster/crash-keep-empty-queue-sorted
Fixed crash when clicking keep sorted on empty queue
-rw-r--r--app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java9
-rw-r--r--app/src/androidTest/java/de/test/antennapod/ui/QueueFragmentTest.java58
-rw-r--r--app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java2
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java6
4 files changed, 72 insertions, 3 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java b/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java
index 02ee9a487..9e86275fc 100644
--- a/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java
+++ b/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java
@@ -1,6 +1,7 @@
package de.test.antennapod;
import android.content.Context;
+import android.content.SharedPreferences;
import android.support.annotation.StringRes;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.PerformException;
@@ -15,6 +16,7 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
import de.danoeh.antennapod.dialog.RatingDialog;
+import de.danoeh.antennapod.fragment.QueueFragment;
import org.hamcrest.Matcher;
import java.io.File;
@@ -97,6 +99,13 @@ public class EspressoTestUtils {
RatingDialog.saveRated();
}
+ public static void setLastNavFragment(String tag) {
+ InstrumentationRegistry.getTargetContext().getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE)
+ .edit()
+ .putString(MainActivity.PREF_LAST_FRAGMENT_TAG, tag)
+ .commit();
+ }
+
public static void clearDatabase() {
PodDBAdapter.init(InstrumentationRegistry.getTargetContext());
PodDBAdapter.deleteDatabase();
diff --git a/app/src/androidTest/java/de/test/antennapod/ui/QueueFragmentTest.java b/app/src/androidTest/java/de/test/antennapod/ui/QueueFragmentTest.java
new file mode 100644
index 000000000..d1023dd9e
--- /dev/null
+++ b/app/src/androidTest/java/de/test/antennapod/ui/QueueFragmentTest.java
@@ -0,0 +1,58 @@
+package de.test.antennapod.ui;
+
+import android.content.Intent;
+import android.support.test.espresso.Espresso;
+import android.support.test.espresso.intent.rule.IntentsTestRule;
+import android.support.test.runner.AndroidJUnit4;
+import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.activity.MainActivity;
+import de.danoeh.antennapod.fragment.QueueFragment;
+import de.test.antennapod.EspressoTestUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.action.ViewActions.click;
+import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
+import static android.support.test.espresso.matcher.ViewMatchers.withText;
+
+/**
+ * User interface tests for queue fragment
+ */
+@RunWith(AndroidJUnit4.class)
+public class QueueFragmentTest {
+
+ @Rule
+ public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(MainActivity.class, false, false);
+
+ @Before
+ public void setUp() {
+ EspressoTestUtils.clearPreferences();
+ EspressoTestUtils.makeNotFirstRun();
+ EspressoTestUtils.clearDatabase();
+ EspressoTestUtils.setLastNavFragment(QueueFragment.TAG);
+ mActivityRule.launchActivity(new Intent());
+ }
+
+ @Test
+ public void testLockEmptyQueue() {
+ onView(withContentDescription(R.string.lock_queue)).perform(click());
+ onView(withContentDescription(R.string.unlock_queue)).perform(click());
+ }
+
+ @Test
+ public void testSortEmptyQueue() {
+ Espresso.openContextualActionModeOverflowMenu();
+ onView(withText(R.string.sort)).perform(click());
+ onView(withText(R.string.random)).perform(click());
+ }
+
+ @Test
+ public void testKeepEmptyQueueSorted() {
+ Espresso.openContextualActionModeOverflowMenu();
+ onView(withText(R.string.sort)).perform(click());
+ onView(withText(R.string.keep_sorted)).perform(click());
+ }
+}
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 ab4f584fe..339ce01c2 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java
@@ -87,7 +87,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
public static final String PREF_NAME = "MainActivityPrefs";
public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch";
- private static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag";
+ public static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag";
public static final String EXTRA_NAV_TYPE = "nav_type";
public static final String EXTRA_NAV_INDEX = "nav_index";
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java
index 4f07e1b59..9763f8f2d 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java
@@ -378,8 +378,10 @@ public class QueueFragment extends Fragment {
if (keepSortedNew) {
SortOrder sortOrder = UserPreferences.getQueueKeepSortedOrder();
QueueSorter.sort(sortOrder, true);
- recyclerAdapter.setLocked(true);
- } else {
+ if (recyclerAdapter != null) {
+ recyclerAdapter.setLocked(true);
+ }
+ } else if (recyclerAdapter != null) {
recyclerAdapter.setLocked(UserPreferences.isQueueLocked());
}
getActivity().invalidateOptionsMenu();