Drawer: (Easier) Feed list context menu
This commit is contained in:
parent
7648b5d319
commit
c13dd34f09
|
@ -102,7 +102,7 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||||
private View navDrawer;
|
private View navDrawer;
|
||||||
private ListView navList;
|
private ListView navList;
|
||||||
private NavListAdapter navAdapter;
|
private NavListAdapter navAdapter;
|
||||||
private AdapterView.AdapterContextMenuInfo lastMenuInfo = null;
|
private int mPosition = -1;
|
||||||
|
|
||||||
private ActionBarDrawerToggle drawerToggle;
|
private ActionBarDrawerToggle drawerToggle;
|
||||||
|
|
||||||
|
@ -139,11 +139,8 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||||
|
|
||||||
final FragmentManager fm = getSupportFragmentManager();
|
final FragmentManager fm = getSupportFragmentManager();
|
||||||
|
|
||||||
fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
|
fm.addOnBackStackChangedListener(() -> {
|
||||||
@Override
|
|
||||||
public void onBackStackChanged() {
|
|
||||||
drawerToggle.setDrawerIndicatorEnabled(fm.getBackStackEntryCount() == 0);
|
drawerToggle.setDrawerIndicatorEnabled(fm.getBackStackEntryCount() == 0);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
@ -153,6 +150,7 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||||
navList.setAdapter(navAdapter);
|
navList.setAdapter(navAdapter);
|
||||||
navList.setOnItemClickListener(navListClickListener);
|
navList.setOnItemClickListener(navListClickListener);
|
||||||
navList.setOnItemLongClickListener(newListLongClickListener);
|
navList.setOnItemLongClickListener(newListLongClickListener);
|
||||||
|
registerForContextMenu(navList);
|
||||||
|
|
||||||
navAdapter.registerDataSetObserver(new DataSetObserver() {
|
navAdapter.registerDataSetObserver(new DataSetObserver() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -161,12 +159,9 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
findViewById(R.id.nav_settings).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.nav_settings).setOnClickListener(v -> {
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
drawerLayout.closeDrawer(navDrawer);
|
drawerLayout.closeDrawer(navDrawer);
|
||||||
startActivity(new Intent(MainActivity.this, PreferenceController.getPreferenceActivity()));
|
startActivity(new Intent(MainActivity.this, PreferenceController.getPreferenceActivity()));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
FragmentTransaction transaction = fm.beginTransaction();
|
FragmentTransaction transaction = fm.beginTransaction();
|
||||||
|
@ -218,12 +213,7 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||||
private void checkFirstLaunch() {
|
private void checkFirstLaunch() {
|
||||||
SharedPreferences prefs = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
|
SharedPreferences prefs = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
|
||||||
if (prefs.getBoolean(PREF_IS_FIRST_LAUNCH, true)) {
|
if (prefs.getBoolean(PREF_IS_FIRST_LAUNCH, true)) {
|
||||||
new Handler().postDelayed(new Runnable() {
|
new Handler().postDelayed(() -> drawerLayout.openDrawer(navDrawer), 1500);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
drawerLayout.openDrawer(navDrawer);
|
|
||||||
}
|
|
||||||
}, 1500);
|
|
||||||
|
|
||||||
SharedPreferences.Editor edit = prefs.edit();
|
SharedPreferences.Editor edit = prefs.edit();
|
||||||
edit.putBoolean(PREF_IS_FIRST_LAUNCH, false);
|
edit.putBoolean(PREF_IS_FIRST_LAUNCH, false);
|
||||||
|
@ -245,21 +235,15 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
||||||
builder.setTitle(R.string.drawer_preferences);
|
builder.setTitle(R.string.drawer_preferences);
|
||||||
builder.setMultiChoiceItems(navLabels, checked, new DialogInterface.OnMultiChoiceClickListener() {
|
builder.setMultiChoiceItems(navLabels, checked, (dialog, which, isChecked) -> {
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
hiddenDrawerItems.remove(NAV_DRAWER_TAGS[which]);
|
hiddenDrawerItems.remove(NAV_DRAWER_TAGS[which]);
|
||||||
} else {
|
} else {
|
||||||
hiddenDrawerItems.add(NAV_DRAWER_TAGS[which]);
|
hiddenDrawerItems.add(NAV_DRAWER_TAGS[which]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
builder.setPositiveButton(R.string.confirm_label, new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
UserPreferences.setHiddenDrawerItems(hiddenDrawerItems);
|
UserPreferences.setHiddenDrawerItems(hiddenDrawerItems);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(R.string.cancel_label, null);
|
builder.setNegativeButton(R.string.cancel_label, null);
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
|
@ -422,6 +406,7 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||||
showDrawerPreferencesDialog();
|
showDrawerPreferencesDialog();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
mPosition = position;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -521,6 +506,68 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||||
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
|
if(v.getId() != R.id.nav_list) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AdapterView.AdapterContextMenuInfo adapterInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||||
|
int position = adapterInfo.position;
|
||||||
|
if(position < navAdapter.getSubscriptionOffset()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MenuInflater inflater = getMenuInflater();
|
||||||
|
inflater.inflate(R.menu.nav_feed_context, menu);
|
||||||
|
Feed feed = navDrawerData.feeds.get(position - navAdapter.getSubscriptionOffset());
|
||||||
|
menu.setHeaderTitle(feed.getTitle());
|
||||||
|
// episodes are not loaded, so we cannot check if the podcast has new or unplayed ones!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
|
final int position = mPosition;
|
||||||
|
mPosition = -1; // reset
|
||||||
|
if(position < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Feed feed = navDrawerData.feeds.get(position - navAdapter.getSubscriptionOffset());
|
||||||
|
switch(item.getItemId()) {
|
||||||
|
case R.id.mark_all_seen_item:
|
||||||
|
DBWriter.markFeedSeen(feed.getId());
|
||||||
|
return true;
|
||||||
|
case R.id.mark_all_read_item:
|
||||||
|
DBWriter.markFeedRead(feed.getId());
|
||||||
|
return true;
|
||||||
|
case R.id.remove_item:
|
||||||
|
final FeedRemover remover = new FeedRemover(this, feed) {
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void result) {
|
||||||
|
super.onPostExecute(result);
|
||||||
|
if(getSelectedNavListIndex() == position) {
|
||||||
|
loadFragment(EpisodesFragment.TAG, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ConfirmationDialog conDialog = new ConfirmationDialog(this,
|
||||||
|
R.string.remove_feed_label,
|
||||||
|
R.string.feed_delete_confirmation_msg) {
|
||||||
|
@Override
|
||||||
|
public void onConfirmButtonPressed(
|
||||||
|
DialogInterface dialog) {
|
||||||
|
dialog.dismiss();
|
||||||
|
remover.executeAsync();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
conDialog.createNewDialog().show();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onContextItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private DBReader.NavDrawerData navDrawerData;
|
private DBReader.NavDrawerData navDrawerData;
|
||||||
private AsyncTask<Void, Void, DBReader.NavDrawerData> loadTask;
|
private AsyncTask<Void, Void, DBReader.NavDrawerData> loadTask;
|
||||||
private int selectedNavListIndex = 0;
|
private int selectedNavListIndex = 0;
|
||||||
|
|
Loading…
Reference in New Issue