Merge pull request #709 from TomHennen/swipe_to_mark_as_read

Swipe to mark as read
This commit is contained in:
Tom Hennen 2015-04-05 13:47:13 -04:00
commit 1fb8b64b34
8 changed files with 69 additions and 10 deletions

View File

@ -73,9 +73,9 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
// all episodes
openNavDrawer();
solo.clickOnText(solo.getString(R.string.all_episodes_label));
solo.clickOnText(solo.getString(R.string.new_episodes_label));
solo.waitForView(android.R.id.list);
assertEquals(solo.getString(R.string.all_episodes_label), getActionbarTitle());
assertEquals(solo.getString(R.string.new_episodes_label), getActionbarTitle());
// queue
openNavDrawer();

View File

@ -79,7 +79,7 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
private void startLocalPlayback() {
assertTrue(solo.waitForActivity(MainActivity.class));
openNavDrawer();
solo.clickOnText(solo.getString(R.string.all_episodes_label));
solo.clickOnText(solo.getString(R.string.new_episodes_label));
solo.waitForView(android.R.id.list);
solo.clickOnView(solo.getView(R.id.butSecondaryAction));
assertTrue(solo.waitForActivity(AudioplayerActivity.class));

View File

@ -66,8 +66,8 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
public static final String SAVE_TITLE = "title";
public static final int POS_NEW = 0,
POS_QUEUE = 1,
public static final int POS_QUEUE = 0,
POS_NEW = 1,
POS_DOWNLOADS = 2,
POS_HISTORY = 3,
POS_ADD = 4;

View File

@ -25,7 +25,7 @@ public class NavListAdapter extends BaseAdapter {
public static final int VIEW_TYPE_SECTION_DIVIDER = 1;
public static final int VIEW_TYPE_SUBSCRIPTION = 2;
public static final int[] NAV_TITLES = {R.string.all_episodes_label, R.string.queue_label, R.string.downloads_label, R.string.playback_history_label, R.string.add_feed_label};
public static final int[] NAV_TITLES = {R.string.queue_label, R.string.new_episodes_label, R.string.downloads_label, R.string.playback_history_label, R.string.add_feed_label};
private final Drawable[] drawables;
@ -132,7 +132,7 @@ public class NavListAdapter extends BaseAdapter {
} else {
holder.count.setVisibility(View.GONE);
}
} else if (NAV_TITLES[position] == R.string.all_episodes_label) {
} else if (NAV_TITLES[position] == R.string.new_episodes_label) {
int unreadItems = itemAccess.getNumberOfUnreadItems();
if (unreadItems > 0) {
holder.count.setVisibility(View.VISIBLE);

View File

@ -1,6 +1,7 @@
package de.danoeh.antennapod.adapter;
import android.content.Context;
import android.graphics.Color;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
@ -11,6 +12,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.nineoldandroids.view.ViewHelper;
import com.squareup.picasso.Picasso;
import de.danoeh.antennapod.R;
@ -140,6 +142,13 @@ public class NewEpisodesListAdapter extends BaseAdapter {
.fit()
.into(holder.imageView);
if (item.isRead()) {
// grey it out
ViewHelper.setAlpha(convertView, .2f);
} else {
ViewHelper.setAlpha(convertView, 1.0f);
}
return convertView;
}

View File

@ -7,8 +7,10 @@ import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -43,6 +45,8 @@ import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.QueueAccess;
import de.danoeh.antennapod.core.util.gui.FeedItemUndoToken;
import de.danoeh.antennapod.core.util.gui.UndoBarController;
import de.danoeh.antennapod.menuhandler.MenuItemUtils;
import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
@ -67,6 +71,8 @@ public class NewEpisodesFragment extends Fragment {
private TextView txtvEmpty;
private ProgressBar progLoading;
private UndoBarController undoBarController;
private List<FeedItem> unreadItems;
private List<FeedItem> recentItems;
private QueueAccess queueAccess;
@ -134,6 +140,7 @@ public class NewEpisodesFragment extends Fragment {
listAdapter = null;
activity.set(null);
viewsCreated = false;
undoBarController = null;
if (downloadObserver != null) {
downloadObserver.onPause();
}
@ -224,7 +231,7 @@ public class NewEpisodesFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.all_episodes_label);
((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.new_episodes_label);
View root = inflater.inflate(R.layout.new_episodes_fragment, container, false);
@ -243,6 +250,33 @@ public class NewEpisodesFragment extends Fragment {
}
});
listView.setRemoveListener(new DragSortListView.RemoveListener() {
@Override
public void remove(int which) {
Log.d(TAG, "remove("+which+")");
stopItemLoader();
FeedItem item = (FeedItem) listView.getAdapter().getItem(which);
DBWriter.markItemRead(getActivity(), item.getId(), true);
undoBarController.showUndoBar(false,
getString(R.string.marked_as_read_label), new FeedItemUndoToken(item,
which)
);
}
});
undoBarController = new UndoBarController(root.findViewById(R.id.undobar), new UndoBarController.UndoListener() {
@Override
public void onUndo(Parcelable token) {
// Perform the undo
FeedItemUndoToken undoToken = (FeedItemUndoToken) token;
if (token != null) {
long itemId = undoToken.getFeedItemId();
int position = undoToken.getPosition();
DBWriter.markItemRead(getActivity(), itemId, false);
}
}
});
final int secondColor = (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) ? R.color.swipe_refresh_secondary_color_dark : R.color.swipe_refresh_secondary_color_light;
if (!itemsLoaded) {
@ -346,7 +380,7 @@ public class NewEpisodesFragment extends Fragment {
private void updateShowOnlyEpisodes() {
SharedPreferences prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
showOnlyNewEpisodes = prefs.getBoolean(PREF_EPISODE_FILTER_BOOL, false);
showOnlyNewEpisodes = prefs.getBoolean(PREF_EPISODE_FILTER_BOOL, true);
}
private void setShowOnlyNewEpisodes(boolean newVal) {

View File

@ -16,7 +16,8 @@
android:paddingBottom="@dimen/list_vertical_padding"
android:clipToPadding="false"
dslv:collapsed_height="2dp"
dslv:drag_enabled="false"
dslv:drag_enabled="true"
dslv:drag_handle_id="@id/drag_handle"
dslv:drag_scroll_start="0.33"
dslv:float_alpha="0.6"
dslv:max_drag_scroll_speed="0.5"
@ -49,4 +50,18 @@
tools:layout_height="64dp"
tools:background="@android:color/holo_red_light"/>
<LinearLayout
android:id="@+id/undobar"
style="@style/UndoBar">
<TextView
android:id="@+id/undobar_message"
style="@style/UndoBarMessage"/>
<Button
android:id="@+id/undobar_button"
style="@style/UndoBarButton"/>
</LinearLayout>
</FrameLayout>

View File

@ -100,6 +100,7 @@
<string name="remove_episode_lable">Remove episode</string>
<string name="mark_read_label">Mark as read</string>
<string name="mark_unread_label">Mark as unread</string>
<string name="marked_as_read_label">Marked as read</string>
<string name="add_to_queue_label">Add to Queue</string>
<string name="remove_from_queue_label">Remove from Queue</string>
<string name="visit_website_label">Visit Website</string>