Moved Feedmenu into separate file

This commit is contained in:
daniel oeh 2012-06-23 16:19:53 +02:00
parent 3608ba18b6
commit b7f9d066b9
4 changed files with 106 additions and 28 deletions

View File

@ -8,12 +8,17 @@ import android.util.Log;
import android.view.View; import android.view.View;
import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import de.podfetcher.R; import de.podfetcher.R;
import de.podfetcher.asynctask.FeedRemover;
import de.podfetcher.feed.Feed; import de.podfetcher.feed.Feed;
import de.podfetcher.feed.FeedManager; import de.podfetcher.feed.FeedManager;
import de.podfetcher.fragment.FeedItemlistFragment; import de.podfetcher.fragment.FeedItemlistFragment;
import de.podfetcher.fragment.FeedlistFragment; import de.podfetcher.fragment.FeedlistFragment;
import de.podfetcher.util.FeedMenuHandler;
/** Displays a List of FeedItems */ /** Displays a List of FeedItems */
public class FeedItemlistActivity extends SherlockFragmentActivity { public class FeedItemlistActivity extends SherlockFragmentActivity {
@ -44,8 +49,36 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
fT.commit(); fT.commit();
} }
/*
public void onButActionClicked(View v) { @Override
Log.d(TAG, "Button clicked"); public boolean onCreateOptionsMenu(Menu menu) {
}*/ return FeedMenuHandler.onCreateOptionsMenu(new MenuInflater(this), menu);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
return FeedMenuHandler.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (FeedMenuHandler.onOptionsItemClicked(this, item, feed)) {
filf.getListAdapter().notifyDataSetChanged();
} else {
switch(item.getItemId()) {
case R.id.remove_item:
FeedRemover remover = new FeedRemover(this) {
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
finish();
}
};
remover.execute(feed);
break;
}
}
return true;
}
} }

View File

@ -24,6 +24,7 @@ import de.podfetcher.storage.DownloadRequester;
import de.podfetcher.util.FeedItemMenuHandler; import de.podfetcher.util.FeedItemMenuHandler;
public class FeedItemlistFragment extends SherlockListFragment { public class FeedItemlistFragment extends SherlockListFragment {
@Override @Override
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
this.getListView().setItemsCanFocus(true); this.getListView().setItemsCanFocus(true);
@ -128,4 +129,9 @@ public class FeedItemlistFragment extends SherlockListFragment {
} }
}; };
public FeedItemlistAdapter getListAdapter() {
return fila;
}
} }

View File

@ -7,6 +7,7 @@ import de.podfetcher.adapter.FeedlistAdapter;
import de.podfetcher.asynctask.FeedRemover; import de.podfetcher.asynctask.FeedRemover;
import de.podfetcher.storage.DownloadRequester; import de.podfetcher.storage.DownloadRequester;
import de.podfetcher.service.DownloadService; import de.podfetcher.service.DownloadService;
import de.podfetcher.util.FeedMenuHandler;
import android.os.Bundle; import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.View; import android.view.View;
@ -58,11 +59,8 @@ public class FeedlistFragment extends SherlockListFragment {
fla = new FeedlistAdapter(pActivity, 0, manager.getFeeds()); fla = new FeedlistAdapter(pActivity, 0, manager.getFeeds());
setListAdapter(fla); setListAdapter(fla);
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
@ -89,7 +87,6 @@ public class FeedlistFragment extends SherlockListFragment {
mActionMode = getSherlockActivity().startActionMode( mActionMode = getSherlockActivity().startActionMode(
mActionModeCallback); mActionModeCallback);
} }
return true; return true;
} }
@ -137,8 +134,7 @@ public class FeedlistFragment extends SherlockListFragment {
@Override @Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater(); FeedMenuHandler.onCreateOptionsMenu(mode.getMenuInflater(), menu);
inflater.inflate(R.menu.feedlist, menu);
mode.setTitle(selectedFeed.getTitle()); mode.setTitle(selectedFeed.getTitle());
return true; return true;
} }
@ -150,9 +146,13 @@ public class FeedlistFragment extends SherlockListFragment {
@Override @Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (FeedMenuHandler.onOptionsItemClicked(getSherlockActivity(),
item, selectedFeed)) {
fla.notifyDataSetChanged();
} else {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.remove_item: case R.id.remove_item:
FeedRemover remover = new FeedRemover(getSherlockActivity()){ FeedRemover remover = new FeedRemover(getSherlockActivity()) {
@Override @Override
protected void onPostExecute(Void result) { protected void onPostExecute(Void result) {
super.onPostExecute(result); super.onPostExecute(result);
@ -161,12 +161,7 @@ public class FeedlistFragment extends SherlockListFragment {
}; };
remover.execute(selectedFeed); remover.execute(selectedFeed);
break; break;
case R.id.mark_all_read_item:
for (FeedItem feeditem : selectedFeed.getItems()) {
manager.markItemRead(getSherlockActivity(), feeditem, true);
} }
fla.notifyDataSetChanged();
break;
} }
mode.finish(); mode.finish();
return true; return true;

View File

@ -0,0 +1,44 @@
package de.podfetcher.util;
import android.content.Context;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import de.podfetcher.R;
import de.podfetcher.feed.Feed;
import de.podfetcher.feed.FeedItem;
import de.podfetcher.feed.FeedManager;
/** Handles interactions with the FeedItemMenu. */
public class FeedMenuHandler {
public static boolean onCreateOptionsMenu(MenuInflater inflater, Menu menu) {
inflater.inflate(R.menu.feedlist, menu);
return true;
}
public static boolean onPrepareOptionsMenu(Menu menu) {
return true;
}
/** NOTE: This method does not handle clicks on the 'remove feed' - item. */
public static boolean onOptionsItemClicked(Context context, MenuItem item, Feed selectedFeed) {
FeedManager manager = FeedManager.getInstance();
switch (item.getItemId()) {
case R.id.mark_all_read_item:
for (FeedItem feeditem : selectedFeed.getItems()) {
manager.markItemRead(context, feeditem, true);
}
break;
default:
return false;
}
return true;
}
}