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 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.asynctask.FeedRemover;
import de.podfetcher.feed.Feed;
import de.podfetcher.feed.FeedManager;
import de.podfetcher.fragment.FeedItemlistFragment;
import de.podfetcher.fragment.FeedlistFragment;
import de.podfetcher.util.FeedMenuHandler;
/** Displays a List of FeedItems */
public class FeedItemlistActivity extends SherlockFragmentActivity {
@ -44,8 +49,36 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
fT.commit();
}
/*
public void onButActionClicked(View v) {
Log.d(TAG, "Button clicked");
}*/
@Override
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;
public class FeedItemlistFragment extends SherlockListFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
this.getListView().setItemsCanFocus(true);
@ -127,5 +128,10 @@ public class FeedItemlistFragment extends SherlockListFragment {
return true;
}
};
public FeedItemlistAdapter getListAdapter() {
return fila;
}
}

View File

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