Merge pull request #3396 from ByteHamster/crash-keep-empty-queue-sorted
Fixed crash when clicking keep sorted on empty queue
This commit is contained in:
commit
60faccb27a
|
@ -1,6 +1,7 @@
|
||||||
package de.test.antennapod;
|
package de.test.antennapod;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.test.InstrumentationRegistry;
|
import android.support.test.InstrumentationRegistry;
|
||||||
import android.support.test.espresso.PerformException;
|
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.activity.MainActivity;
|
||||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||||
import de.danoeh.antennapod.dialog.RatingDialog;
|
import de.danoeh.antennapod.dialog.RatingDialog;
|
||||||
|
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -97,6 +99,13 @@ public class EspressoTestUtils {
|
||||||
RatingDialog.saveRated();
|
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() {
|
public static void clearDatabase() {
|
||||||
PodDBAdapter.init(InstrumentationRegistry.getTargetContext());
|
PodDBAdapter.init(InstrumentationRegistry.getTargetContext());
|
||||||
PodDBAdapter.deleteDatabase();
|
PodDBAdapter.deleteDatabase();
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -87,7 +87,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
|
||||||
|
|
||||||
public static final String PREF_NAME = "MainActivityPrefs";
|
public static final String PREF_NAME = "MainActivityPrefs";
|
||||||
public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch";
|
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_TYPE = "nav_type";
|
||||||
public static final String EXTRA_NAV_INDEX = "nav_index";
|
public static final String EXTRA_NAV_INDEX = "nav_index";
|
||||||
|
|
|
@ -378,8 +378,10 @@ public class QueueFragment extends Fragment {
|
||||||
if (keepSortedNew) {
|
if (keepSortedNew) {
|
||||||
SortOrder sortOrder = UserPreferences.getQueueKeepSortedOrder();
|
SortOrder sortOrder = UserPreferences.getQueueKeepSortedOrder();
|
||||||
QueueSorter.sort(sortOrder, true);
|
QueueSorter.sort(sortOrder, true);
|
||||||
|
if (recyclerAdapter != null) {
|
||||||
recyclerAdapter.setLocked(true);
|
recyclerAdapter.setLocked(true);
|
||||||
} else {
|
}
|
||||||
|
} else if (recyclerAdapter != null) {
|
||||||
recyclerAdapter.setLocked(UserPreferences.isQueueLocked());
|
recyclerAdapter.setLocked(UserPreferences.isQueueLocked());
|
||||||
}
|
}
|
||||||
getActivity().invalidateOptionsMenu();
|
getActivity().invalidateOptionsMenu();
|
||||||
|
|
Loading…
Reference in New Issue