swipe dismiss: set article back to unread if it was before

This commit is contained in:
Andrew Dolgov 2017-06-01 19:42:54 +03:00
parent 9b16a179e8
commit f6162a8d72

View File

@ -372,26 +372,38 @@ public class HeadlinesFragment extends Fragment {
try { try {
final Article article = getArticleAtPosition(position); final Article article = getArticleAtPosition(position);
final boolean wasUnread;
if (article != null) { if (article != null) {
if (article.unread) { if (article.unread) {
wasUnread = true;
article.unread = false; article.unread = false;
m_activity.saveArticleUnread(article); m_activity.saveArticleUnread(article);
} else {
wasUnread = false;
} }
m_articles.remove(position);
m_adapter.notifyDataSetChanged();
Snackbar.make(m_list, R.string.headline_undo_row_prompt, Snackbar.LENGTH_LONG)
.setAction(getString(R.string.headline_undo_row_button), new OnClickListener() {
@Override
public void onClick(View v) {
if (wasUnread) {
article.unread = true;
m_activity.saveArticleUnread(article);
}
m_articles.add(position, article);
m_adapter.notifyDataSetChanged();
}
}).show();
} }
m_articles.remove(position);
m_adapter.notifyDataSetChanged();
Snackbar.make(m_list, R.string.headline_undo_row_prompt, Snackbar.LENGTH_LONG)
.setAction(getString(R.string.headline_undo_row_button), new OnClickListener() {
@Override
public void onClick(View v) {
m_articles.add(position, article);
m_adapter.notifyDataSetChanged();
}
}).show();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }