Bux fixes, tests
This commit is contained in:
parent
fc124a5f1a
commit
4aa68e74e0
|
@ -7,11 +7,21 @@ import android.widget.ListView;
|
|||
|
||||
import com.robotium.solo.Solo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.DefaultOnlineFeedViewActivity;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||
import de.danoeh.antennapod.fragment.AllEpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.DownloadsFragment;
|
||||
import de.danoeh.antennapod.fragment.NewEpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
|
||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
import de.danoeh.antennapod.preferences.PreferenceController;
|
||||
|
||||
/**
|
||||
|
@ -71,11 +81,11 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
|
|||
public void testClickNavDrawer() throws Exception {
|
||||
uiTestUtils.addLocalFeedData(false);
|
||||
|
||||
// all episodes
|
||||
// queue
|
||||
openNavDrawer();
|
||||
solo.clickOnText(solo.getString(R.string.all_episodes_label));
|
||||
solo.clickOnText(solo.getString(R.string.queue_label));
|
||||
solo.waitForView(android.R.id.list);
|
||||
assertEquals(solo.getString(R.string.all_episodes_label), getActionbarTitle());
|
||||
assertEquals(solo.getString(R.string.queue_label), getActionbarTitle());
|
||||
|
||||
// new episodes
|
||||
openNavDrawer();
|
||||
|
@ -83,11 +93,11 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
|
|||
solo.waitForView(android.R.id.list);
|
||||
assertEquals(solo.getString(R.string.new_episodes_label), getActionbarTitle());
|
||||
|
||||
// queue
|
||||
// all episodes
|
||||
openNavDrawer();
|
||||
solo.clickOnText(solo.getString(R.string.queue_label));
|
||||
solo.clickOnText(solo.getString(R.string.all_episodes_label));
|
||||
solo.waitForView(android.R.id.list);
|
||||
assertEquals(solo.getString(R.string.queue_label), getActionbarTitle());
|
||||
assertEquals(solo.getString(R.string.all_episodes_label), getActionbarTitle());
|
||||
|
||||
// downloads
|
||||
openNavDrawer();
|
||||
|
@ -128,4 +138,54 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
|
|||
solo.clickOnMenuItem(solo.getString(R.string.settings_label));
|
||||
solo.waitForActivity(PreferenceController.getPreferenceActivity());
|
||||
}
|
||||
|
||||
public void testDrawerPreferencesHideSomeElements() {
|
||||
UserPreferences.setHiddenDrawerItems(getInstrumentation().getTargetContext(), new ArrayList<String>());
|
||||
openNavDrawer();
|
||||
solo.clickLongOnText(solo.getString(R.string.queue_label));
|
||||
solo.waitForDialogToOpen();
|
||||
solo.clickOnText(solo.getString(R.string.all_episodes_label));
|
||||
solo.clickOnText(solo.getString(R.string.playback_history_label));
|
||||
solo.clickOnText(solo.getString(R.string.confirm_label));
|
||||
solo.waitForDialogToClose();
|
||||
List<String> hidden = UserPreferences.getHiddenDrawerItems();
|
||||
assertEquals(2, hidden.size());
|
||||
assertTrue(hidden.contains(AllEpisodesFragment.TAG));
|
||||
assertTrue(hidden.contains(PlaybackHistoryFragment.TAG));
|
||||
}
|
||||
|
||||
public void testDrawerPreferencesUnhideSomeElements() {
|
||||
List<String> hidden = Arrays.asList(NewEpisodesFragment.TAG, DownloadsFragment.TAG);
|
||||
UserPreferences.setHiddenDrawerItems(getInstrumentation().getTargetContext(), hidden);
|
||||
openNavDrawer();
|
||||
solo.clickLongOnText(solo.getString(R.string.queue_label));
|
||||
solo.waitForDialogToOpen();
|
||||
solo.clickOnText(solo.getString(R.string.downloads_label));
|
||||
solo.clickOnText(solo.getString(R.string.queue_label));
|
||||
solo.clickOnText(solo.getString(R.string.confirm_label));
|
||||
solo.waitForDialogToClose();
|
||||
hidden = UserPreferences.getHiddenDrawerItems();
|
||||
assertEquals(2, hidden.size());
|
||||
assertTrue(hidden.contains(QueueFragment.TAG));
|
||||
assertTrue(hidden.contains(NewEpisodesFragment.TAG));
|
||||
}
|
||||
|
||||
public void testDrawerPreferencesHideAllElements() {
|
||||
UserPreferences.setHiddenDrawerItems(getInstrumentation().getTargetContext(), new ArrayList<String>());
|
||||
String[] titles = getInstrumentation().getTargetContext().getResources().getStringArray(R.array.nav_drawer_titles);
|
||||
|
||||
openNavDrawer();
|
||||
solo.clickLongOnText(solo.getString(R.string.queue_label));
|
||||
solo.waitForDialogToOpen();
|
||||
for(String title : titles) {
|
||||
solo.clickOnText(title);
|
||||
}
|
||||
solo.clickOnText(solo.getString(R.string.confirm_label));
|
||||
solo.waitForDialogToClose();
|
||||
List<String> hidden = UserPreferences.getHiddenDrawerItems();
|
||||
assertEquals(6, hidden.size());
|
||||
for(String tag : MainActivity.NAV_DRAWER_TAGS) {
|
||||
assertTrue(hidden.contains(tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,6 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
|||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
navList = (ListView) findViewById(R.id.nav_list);
|
||||
navDrawer = findViewById(R.id.nav_layout);
|
||||
Log.i(TAG, "");
|
||||
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close) {
|
||||
@Override
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
|
@ -254,24 +253,27 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
|||
}
|
||||
|
||||
public void loadFragment(int index, Bundle args) {
|
||||
int numTags = navAdapter.getTags().size();
|
||||
if (index <= numTags) {
|
||||
if (index < navAdapter.getSubscriptionOffset()) {
|
||||
String tag = navAdapter.getTags().get(index);
|
||||
loadFragment(tag, args);
|
||||
} else {
|
||||
int pos = index - numTags;
|
||||
int pos = index - navAdapter.getSubscriptionOffset();
|
||||
loadFeedFragmentByPosition(pos, args);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadFragment(final String tag, Bundle args) {
|
||||
Log.d(TAG, "loadFragment(\"" + tag + "\", " + args + ")");
|
||||
Fragment fragment = null;
|
||||
switch (tag) {
|
||||
case QueueFragment.TAG:
|
||||
fragment = new QueueFragment();
|
||||
break;
|
||||
case NewEpisodesFragment.TAG:
|
||||
fragment = new NewEpisodesFragment();
|
||||
break;
|
||||
case QueueFragment.TAG:
|
||||
fragment = new QueueFragment();
|
||||
case AllEpisodesFragment.TAG:
|
||||
fragment = new AllEpisodesFragment();
|
||||
break;
|
||||
case DownloadsFragment.TAG:
|
||||
fragment = new DownloadsFragment();
|
||||
|
@ -283,8 +285,8 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
|||
fragment = new AddFeedFragment();
|
||||
break;
|
||||
}
|
||||
String title = navAdapter.getLabel(tag);
|
||||
getSupportActionBar().setTitle(title);
|
||||
currentTitle = navAdapter.getLabel(tag);
|
||||
getSupportActionBar().setTitle(currentTitle);
|
||||
selectedNavListIndex = navAdapter.getTags().indexOf(tag);
|
||||
if (args != null) {
|
||||
fragment.setArguments(args);
|
||||
|
@ -299,7 +301,8 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
|||
Feed feed = itemAccess.getItem(relPos);
|
||||
Fragment fragment = ItemlistFragment.newInstance(feed.getId());
|
||||
selectedNavListIndex = navAdapter.getSubscriptionOffset() + relPos;
|
||||
getSupportActionBar().setTitle("");
|
||||
currentTitle = "";
|
||||
getSupportActionBar().setTitle(currentTitle);
|
||||
loadFragment(fragment);
|
||||
}
|
||||
|
||||
|
@ -420,7 +423,8 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
|||
StorageUtils.checkStorageAvailability(this);
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (navDrawerData != null && intent.hasExtra(EXTRA_NAV_INDEX) && intent.hasExtra(EXTRA_NAV_TYPE)) {
|
||||
if (navDrawerData != null && intent.hasExtra(EXTRA_NAV_TYPE) &&
|
||||
(intent.hasExtra(EXTRA_NAV_INDEX) || intent.hasExtra(EXTRA_FRAGMENT_TAG))) {
|
||||
handleNavIntent();
|
||||
}
|
||||
|
||||
|
@ -538,8 +542,10 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
|||
};
|
||||
|
||||
private void handleNavIntent() {
|
||||
Log.d(TAG, "handleNavIntent()");
|
||||
Intent intent = getIntent();
|
||||
if (intent.hasExtra(EXTRA_NAV_INDEX) && intent.hasExtra(EXTRA_NAV_TYPE)) {
|
||||
if (intent.hasExtra(EXTRA_NAV_TYPE) &&
|
||||
intent.hasExtra(EXTRA_NAV_INDEX) || intent.hasExtra(EXTRA_FRAGMENT_TAG)) {
|
||||
int index = intent.getIntExtra(EXTRA_NAV_INDEX, -1);
|
||||
String tag = intent.getStringExtra(EXTRA_FRAGMENT_TAG);
|
||||
Bundle args = intent.getBundleExtra(EXTRA_FRAGMENT_ARGS);
|
||||
|
|
|
@ -36,7 +36,8 @@ import de.danoeh.antennapod.fragment.QueueFragment;
|
|||
/**
|
||||
* BaseAdapter for the navigation drawer
|
||||
*/
|
||||
public class NavListAdapter extends BaseAdapter {
|
||||
public class NavListAdapter extends BaseAdapter
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public static final int VIEW_TYPE_COUNT = 3;
|
||||
public static final int VIEW_TYPE_NAV = 0;
|
||||
public static final int VIEW_TYPE_SECTION_DIVIDER = 1;
|
||||
|
@ -48,17 +49,6 @@ public class NavListAdapter extends BaseAdapter {
|
|||
private ItemAccess itemAccess;
|
||||
private Context context;
|
||||
|
||||
private SharedPreferences.OnSharedPreferenceChangeListener listener =
|
||||
new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if(key.equals(UserPreferences.PREF_HIDDEN_DRAWER_ITEMS)) {
|
||||
loadItems();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public NavListAdapter(ItemAccess itemAccess, Context context) {
|
||||
this.itemAccess = itemAccess;
|
||||
this.context = context;
|
||||
|
@ -67,7 +57,13 @@ public class NavListAdapter extends BaseAdapter {
|
|||
loadItems();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefs.registerOnSharedPreferenceChangeListener(listener);
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key.equals(UserPreferences.PREF_HIDDEN_DRAWER_ITEMS)) {
|
||||
loadItems();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadItems() {
|
||||
|
@ -122,7 +118,7 @@ public class NavListAdapter extends BaseAdapter {
|
|||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return tags.size() + itemAccess.getCount() + (tags.size() > 0 ? 1 : 0);
|
||||
return getSubscriptionOffset() + itemAccess.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -146,7 +142,7 @@ public class NavListAdapter extends BaseAdapter {
|
|||
public int getItemViewType(int position) {
|
||||
if (0 <= position && position < tags.size()) {
|
||||
return VIEW_TYPE_NAV;
|
||||
} else if (position < tags.size() + 1) {
|
||||
} else if (position < getSubscriptionOffset()) {
|
||||
return VIEW_TYPE_SECTION_DIVIDER;
|
||||
} else {
|
||||
return VIEW_TYPE_SUBSCRIPTION;
|
||||
|
@ -159,7 +155,7 @@ public class NavListAdapter extends BaseAdapter {
|
|||
}
|
||||
|
||||
public int getSubscriptionOffset() {
|
||||
return tags.size() + 1;
|
||||
return tags.size() > 0 ? tags.size() + 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -66,4 +66,12 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
<View
|
||||
android:layout_width="@dimen/drawer_width"
|
||||
android:layout_height="1dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_above="@id/nav_settings"
|
||||
android:background="?android:attr/listDivider"
|
||||
tools:background="@android:color/holo_red_dark" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -546,12 +546,12 @@ public class UserPreferences implements
|
|||
|
||||
public static void setHiddenDrawerItems(Context context, List<String> items) {
|
||||
instanceAvailable();
|
||||
instance.hiddenDrawerItems = items;
|
||||
String str = StringUtils.join(items, ',');
|
||||
PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext())
|
||||
.edit()
|
||||
.putString(PREF_HIDDEN_DRAWER_ITEMS, str)
|
||||
.commit();
|
||||
instance.hiddenDrawerItems = items;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue