Feeditems can now be marked as read or unread

This commit is contained in:
daniel oeh 2012-06-17 12:51:14 +02:00
parent 324cbdc86c
commit 5001182aee
5 changed files with 65 additions and 23 deletions

View File

@ -4,6 +4,8 @@
<item android:id="@+id/remove_item" android:icon="@drawable/content_discard" android:title="@string/remove_label" android:visible="false"></item>
<item android:id="@+id/play_item" android:title="@string/play_label" android:visible="false" android:icon="@drawable/av_play"></item>
<item android:id="@+id/cancel_download_item" android:icon="@drawable/navigation_cancel" android:title="@string/cancel_download_label" android:visible="false"></item>
<item android:id="@+id/mark_read_item" android:title="@string/mark_read_label" android:showAsAction="collapseActionView" android:visible="false"></item>
<item android:id="@+id/mark_unread_item" android:title="@string/mark_unread_label" android:visible="false" android:showAsAction="collapseActionView"></item>
</menu>

View File

@ -37,4 +37,6 @@
<string name="player_error_msg">Error!</string>
<string name="player_stopped_msg">Stopped</string>
<string name="player_preparing_msg">Preparing...</string>
<string name="mark_read_label">Mark read</string>
<string name="mark_unread_label">Mark unread</string>
</resources>

View File

@ -12,8 +12,6 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
import de.podfetcher.R;
import de.podfetcher.fragment.FeedlistFragment;
public class PodfetcherActivity extends SherlockFragmentActivity {
private static final String TAG = "PodfetcherActivity";
@ -29,27 +27,34 @@ public class PodfetcherActivity extends SherlockFragmentActivity {
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
Tab tab = actionBar.newTab()
Tab tab = actionBar
.newTab()
.setText(getText(R.string.feeds_label).toString())
.setTabListener(new TabListener<FeedlistFragment>(
this, getText(R.string.feeds_label).toString(), FeedlistFragment.class));
.setTabListener(
new TabListener<FeedlistFragment>(this, getText(
R.string.feeds_label).toString(),
FeedlistFragment.class));
actionBar.addTab(tab);
tab = actionBar.newTab()
tab = actionBar
.newTab()
.setText(getText(R.string.new_label).toString())
.setTabListener(new TabListener<FeedlistFragment>(
this, getText(R.string.new_label).toString(), FeedlistFragment.class));
.setTabListener(
new TabListener<FeedlistFragment>(this, getText(
R.string.new_label).toString(),
FeedlistFragment.class));
actionBar.addTab(tab);
}
/** TabListener for navigating between the main lists. */
private class TabListener<T extends Fragment> implements ActionBar.TabListener {
private class TabListener<T extends Fragment> implements
ActionBar.TabListener {
private final Activity activity;
private final String tag;
private final Class<T> fClass;
private Fragment fragment;
private boolean attachedOnce = false;
public TabListener(Activity activity, String tag, Class<T> fClass) {
this.activity = activity;
@ -57,10 +62,24 @@ public class PodfetcherActivity extends SherlockFragmentActivity {
this.fClass = fClass;
}
@SuppressWarnings("unused")
public TabListener(Activity activity, String tag, Fragment fragment,
Class<T> fClass) {
super();
this.activity = activity;
this.tag = tag;
this.fragment = fragment;
this.fClass = fClass;
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (fragment == null) {
fragment = Fragment.instantiate(activity, fClass.getName());
ft.replace(R.id.main_fragment, fragment);
attachedOnce = true;
} else if (!attachedOnce) {
ft.replace(R.id.main_fragment, fragment);
attachedOnce = true;
} else {
ft.attach(fragment);
}

View File

@ -13,6 +13,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.content.Context;
import android.graphics.Typeface;
public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
private OnClickListener onButActionClicked;
@ -42,6 +43,11 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
}
holder.title.setText(item.getTitle());
if (!item.isRead()) {
holder.title.setTypeface(Typeface.DEFAULT_BOLD);
} else {
holder.title.setTypeface(Typeface.DEFAULT);
}
holder.size.setText(Converter.byteToString(item.getMedia().getSize()));
holder.butAction.setOnClickListener(onButActionClicked);
return convertView;

View File

@ -120,6 +120,12 @@ public class FeedItemlistFragment extends SherlockListFragment {
menu.findItem(R.id.cancel_download_item).setVisible(true);
}
if (selectedItem.isRead()) {
menu.findItem(R.id.mark_unread_item).setVisible(true);
} else {
menu.findItem(R.id.mark_read_item).setVisible(true);
}
return true;
}
@ -143,8 +149,15 @@ public class FeedItemlistFragment extends SherlockListFragment {
requester.cancelDownload(getSherlockActivity(), selectedItem
.getMedia().getDownloadId());
break;
case R.id.mark_read_item:
selectedItem.setRead(true);
break;
case R.id.mark_unread_item:
selectedItem.setRead(false);
break;
}
fila.notifyDataSetChanged();
mode.finish();
return true;
}