Merge pull request #11399 from osmandapp/Unbookmark_gpx

Fix #5473
This commit is contained in:
Vitaliy 2021-04-13 01:40:15 +03:00 committed by GitHub
commit a92e002db3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 119 additions and 108 deletions

View file

@ -246,23 +246,16 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme
private void updateSaveButton() { private void updateSaveButton() {
if (article != null) { if (article != null) {
final TravelLocalDataHelper helper = getMyApplication().getTravelHelper().getBookmarksHelper(); final TravelHelper helper = getMyApplication().getTravelHelper();
final boolean saved = helper.isArticleSaved(article); final boolean saved = helper.getBookmarksHelper().isArticleSaved(article);
Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later); Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later);
saveBtn.setText(getString(saved ? R.string.shared_string_remove : R.string.shared_string_bookmark)); saveBtn.setText(getString(saved ? R.string.shared_string_remove : R.string.shared_string_bookmark));
saveBtn.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null); saveBtn.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null);
saveBtn.setOnClickListener(new View.OnClickListener() { saveBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (article != null) { helper.saveOrRemoveArticle(article, !saved);
if (saved) { updateSaveButton();
helper.removeArticleFromSaved(article);
} else {
getMyApplication().getTravelHelper().createGpxFile(article);
helper.addArticleToSaved(article);
}
updateSaveButton();
}
} }
}); });
} }

View file

@ -193,6 +193,15 @@ public class TravelDbHelper implements TravelHelper {
return WORLD_WIKIVOYAGE_FILE_NAME; return WORLD_WIKIVOYAGE_FILE_NAME;
} }
@Override
public void saveOrRemoveArticle(@NonNull TravelArticle article, boolean save) {
if (save) {
localDataHelper.addArticleToSaved(article);
} else {
localDataHelper.removeArticleFromSaved(article);
}
}
public List<File> getExistingTravelBooks() { public List<File> getExistingTravelBooks() {
return existingTravelBooks; return existingTravelBooks;
} }

View file

@ -70,4 +70,6 @@ public interface TravelHelper {
String getSelectedTravelBookName(); String getSelectedTravelBookName();
String getWikivoyageFileName(); String getWikivoyageFileName();
void saveOrRemoveArticle(@NonNull TravelArticle article, boolean save);
} }

View file

@ -4,11 +4,13 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.plus.wikivoyage.data.TravelHelper.GpxReadCallback;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -124,14 +126,6 @@ public class TravelLocalDataHelper {
} }
} }
public void restoreSavedArticle(@NonNull TravelArticle article) {
if (!isArticleSaved(article)) {
savedArticles.add(article);
dbHelper.addSavedArticle(article);
notifySavedUpdated();
}
}
public void removeArticleFromSaved(@NonNull TravelArticle article) { public void removeArticleFromSaved(@NonNull TravelArticle article) {
TravelArticle savedArticle = getArticle(article.title, article.lang); TravelArticle savedArticle = getArticle(article.title, article.lang);
if (savedArticle != null) { if (savedArticle != null) {
@ -305,7 +299,7 @@ public class TravelLocalDataHelper {
conn.execSQL("ALTER TABLE " + BOOKMARKS_TABLE_NAME + " ADD " + BOOKMARKS_COL_TRAVEL_BOOK + " TEXT"); conn.execSQL("ALTER TABLE " + BOOKMARKS_TABLE_NAME + " ADD " + BOOKMARKS_COL_TRAVEL_BOOK + " TEXT");
String selectedTravelBookName = context.getTravelHelper().getSelectedTravelBookName(); String selectedTravelBookName = context.getTravelHelper().getSelectedTravelBookName();
if (selectedTravelBookName != null) { if (selectedTravelBookName != null) {
Object[] args = new Object[]{selectedTravelBookName}; Object[] args = new Object[] {selectedTravelBookName};
conn.execSQL("UPDATE " + HISTORY_TABLE_NAME + " SET " + HISTORY_COL_TRAVEL_BOOK + " = ?", args); conn.execSQL("UPDATE " + HISTORY_TABLE_NAME + " SET " + HISTORY_COL_TRAVEL_BOOK + " = ?", args);
conn.execSQL("UPDATE " + BOOKMARKS_TABLE_NAME + " SET " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?", args); conn.execSQL("UPDATE " + BOOKMARKS_TABLE_NAME + " SET " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?", args);
} }
@ -368,7 +362,7 @@ public class TravelLocalDataHelper {
conn.execSQL("INSERT INTO " + HISTORY_TABLE_NAME + "(" + HISTORY_COL_ARTICLE_TITLE + ", " conn.execSQL("INSERT INTO " + HISTORY_TABLE_NAME + "(" + HISTORY_COL_ARTICLE_TITLE + ", "
+ HISTORY_COL_LANG + ", " + HISTORY_COL_IS_PART_OF + ", " + HISTORY_COL_LAST_ACCESSED + HISTORY_COL_LANG + ", " + HISTORY_COL_IS_PART_OF + ", " + HISTORY_COL_LAST_ACCESSED
+ ", " + HISTORY_COL_TRAVEL_BOOK + ") VALUES (?, ?, ?, ?, ?)", new Object[] { + ", " + HISTORY_COL_TRAVEL_BOOK + ") VALUES (?, ?, ?, ?, ?)", new Object[] {
item.articleTitle, item.lang, item.isPartOf, item.lastAccessed, travelBook }); item.articleTitle, item.lang, item.isPartOf, item.lastAccessed, travelBook});
} finally { } finally {
conn.close(); conn.close();
} }
@ -389,8 +383,8 @@ public class TravelLocalDataHelper {
"WHERE " + HISTORY_COL_ARTICLE_TITLE + " = ? " + "WHERE " + HISTORY_COL_ARTICLE_TITLE + " = ? " +
" AND " + HISTORY_COL_LANG + " = ?" + " AND " + HISTORY_COL_LANG + " = ?" +
" AND " + HISTORY_COL_TRAVEL_BOOK + " = ?", " AND " + HISTORY_COL_TRAVEL_BOOK + " = ?",
new Object[]{item.isPartOf, item.lastAccessed, new Object[] {item.isPartOf, item.lastAccessed,
item.articleTitle, item.lang, travelBook}); item.articleTitle, item.lang, travelBook});
} finally { } finally {
conn.close(); conn.close();
} }
@ -406,10 +400,10 @@ public class TravelLocalDataHelper {
if (conn != null) { if (conn != null) {
try { try {
conn.execSQL("DELETE FROM " + HISTORY_TABLE_NAME + conn.execSQL("DELETE FROM " + HISTORY_TABLE_NAME +
" WHERE " + HISTORY_COL_ARTICLE_TITLE+ " = ?" + " WHERE " + HISTORY_COL_ARTICLE_TITLE + " = ?" +
" AND " + HISTORY_COL_LANG + " = ?" + " AND " + HISTORY_COL_LANG + " = ?" +
" AND " + HISTORY_COL_TRAVEL_BOOK + " = ?", " AND " + HISTORY_COL_TRAVEL_BOOK + " = ?",
new Object[]{item.articleTitle, item.lang, travelBook}); new Object[] {item.articleTitle, item.lang, travelBook});
} finally { } finally {
conn.close(); conn.close();
} }
@ -480,63 +474,84 @@ public class TravelLocalDataHelper {
if (travelBook == null) { if (travelBook == null) {
return; return;
} }
context.getTravelHelper().getArticleById(article.generateIdentifier(), article.lang, true, final TravelHelper travelHelper = context.getTravelHelper();
new TravelHelper.GpxReadCallback() { travelHelper.getArticleById(article.generateIdentifier(), article.lang, true, new GpxReadCallback() {
@Override @Override
public void onGpxFileReading() { public void onGpxFileReading() {
} }
@Override @Override
public void onGpxFileRead(@Nullable GPXUtilities.GPXFile gpxFile) { public void onGpxFileRead(@Nullable GPXFile gpxFile) {
SQLiteConnection conn = openConnection(false); if (gpxFile != null) {
if (conn != null) { travelHelper.createGpxFile(article);
try { }
String query = "INSERT INTO " + BOOKMARKS_TABLE_NAME + " (" +
BOOKMARKS_COL_ARTICLE_TITLE + ", " + SQLiteConnection conn = openConnection(false);
BOOKMARKS_COL_LANG + ", " + if (conn != null) {
BOOKMARKS_COL_IS_PART_OF + ", " + try {
BOOKMARKS_COL_IMAGE_TITLE + ", " + String query = "INSERT INTO " + BOOKMARKS_TABLE_NAME + " (" +
BOOKMARKS_COL_TRAVEL_BOOK + ", " + BOOKMARKS_COL_ARTICLE_TITLE + ", " +
BOOKMARKS_COL_LAT + ", " + BOOKMARKS_COL_LANG + ", " +
BOOKMARKS_COL_LON + ", " + BOOKMARKS_COL_IS_PART_OF + ", " +
BOOKMARKS_COL_ROUTE_ID + ", " + BOOKMARKS_COL_IMAGE_TITLE + ", " +
BOOKMARKS_COL_CONTENT_JSON + ", " + BOOKMARKS_COL_TRAVEL_BOOK + ", " +
BOOKMARKS_COL_CONTENT + ", " + BOOKMARKS_COL_LAT + ", " +
BOOKMARKS_COL_LAST_MODIFIED + ", " + BOOKMARKS_COL_LON + ", " +
BOOKMARKS_COL_GPX_GZ + BOOKMARKS_COL_ROUTE_ID + ", " +
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; BOOKMARKS_COL_CONTENT_JSON + ", " +
conn.execSQL(query, new Object[]{article.title, article.lang, BOOKMARKS_COL_CONTENT + ", " +
article.aggregatedPartOf, article.imageTitle, BOOKMARKS_COL_LAST_MODIFIED + ", " +
travelBook, article.lat, article.lon, article.routeId, article.contentsJson, BOOKMARKS_COL_GPX_GZ +
article.content, article.getFile().lastModified(), ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
Algorithms.stringToGzip(GPXUtilities.asString(article.gpxFile))}); conn.execSQL(query, new Object[] {article.title, article.lang,
} finally { article.aggregatedPartOf, article.imageTitle,
conn.close(); travelBook, article.lat, article.lon, article.routeId, article.contentsJson,
} article.content, article.getFile().lastModified(),
} Algorithms.stringToGzip(GPXUtilities.asString(article.gpxFile))});
} finally {
conn.close();
} }
}); }
}
});
} }
void removeSavedArticle(@NonNull TravelArticle article) { void removeSavedArticle(@NonNull final TravelArticle article) {
String travelBook = article.getTravelBook(context); final String travelBook = article.getTravelBook(context);
if (travelBook == null) { if (travelBook == null) {
return; return;
} }
SQLiteConnection conn = openConnection(false); final TravelHelper travelHelper = context.getTravelHelper();
if (conn != null) { travelHelper.getArticleById(article.generateIdentifier(), article.lang, true, new GpxReadCallback() {
try { @Override
String query = "DELETE FROM " + BOOKMARKS_TABLE_NAME + public void onGpxFileReading() {
" WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" +
" AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" +
" AND " + BOOKMARKS_COL_LANG + ((article.lang != null) ? " = '" + article.lang + "'" : " IS NULL") +
" AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?";
conn.execSQL(query, new Object[]{article.title, article.routeId, travelBook});
} finally {
conn.close();
} }
}
@Override
public void onGpxFileRead(@Nullable GPXFile gpxFile) {
if (gpxFile != null) {
String name = travelHelper.getGPXName(article);
gpxFile.path = context.getAppPath(IndexConstants.GPX_TRAVEL_DIR + name).getAbsolutePath();
context.getSelectedGpxHelper().selectGpxFile(gpxFile, false, true);
}
SQLiteConnection conn = openConnection(false);
if (conn != null) {
try {
String query = "DELETE FROM " + BOOKMARKS_TABLE_NAME +
" WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" +
" AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" +
" AND " + BOOKMARKS_COL_LANG + ((article.lang != null) ? " = '" + article.lang + "'" : " IS NULL") +
" AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?";
conn.execSQL(query, new Object[] {article.title, article.routeId, travelBook});
} finally {
conn.close();
}
}
}
});
} }
void updateSavedArticle(@NonNull TravelArticle odlArticle, @NonNull TravelArticle newArticle) { void updateSavedArticle(@NonNull TravelArticle odlArticle, @NonNull TravelArticle newArticle) {
@ -563,7 +578,7 @@ public class TravelLocalDataHelper {
" AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" + " AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" +
" AND " + BOOKMARKS_COL_LANG + " = ?" + " AND " + BOOKMARKS_COL_LANG + " = ?" +
" AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?", " AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?",
new Object[]{newArticle.title, newArticle.lang, newArticle.aggregatedPartOf, new Object[] {newArticle.title, newArticle.lang, newArticle.aggregatedPartOf,
newArticle.imageTitle, newArticle.getTravelBook(context), newArticle.lat, newArticle.imageTitle, newArticle.getTravelBook(context), newArticle.lat,
newArticle.lon, newArticle.routeId, newArticle.contentsJson, newArticle.content, newArticle.lon, newArticle.routeId, newArticle.contentsJson, newArticle.content,
newArticle.getLastModified(), newArticle.getLastModified(),

View file

@ -56,10 +56,10 @@ import static net.osmand.GPXUtilities.WptPt;
import static net.osmand.GPXUtilities.writeGpxFile; import static net.osmand.GPXUtilities.writeGpxFile;
import static net.osmand.plus.helpers.GpxUiHelper.getGpxTitle; import static net.osmand.plus.helpers.GpxUiHelper.getGpxTitle;
import static net.osmand.plus.wikivoyage.data.PopularArticles.ARTICLES_PER_PAGE; import static net.osmand.plus.wikivoyage.data.PopularArticles.ARTICLES_PER_PAGE;
import static net.osmand.plus.wikivoyage.data.TravelGpx.ACTIVITY_TYPE;
import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_DOWN; import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_DOWN;
import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_UP; import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_UP;
import static net.osmand.plus.wikivoyage.data.TravelGpx.DISTANCE; import static net.osmand.plus.wikivoyage.data.TravelGpx.DISTANCE;
import static net.osmand.plus.wikivoyage.data.TravelGpx.ACTIVITY_TYPE;
import static net.osmand.plus.wikivoyage.data.TravelGpx.USER; import static net.osmand.plus.wikivoyage.data.TravelGpx.USER;
import static net.osmand.util.Algorithms.capitalizeFirstLetter; import static net.osmand.util.Algorithms.capitalizeFirstLetter;
@ -1029,6 +1029,15 @@ public class TravelObfHelper implements TravelHelper {
return WORLD_WIKIVOYAGE_FILE_NAME; return WORLD_WIKIVOYAGE_FILE_NAME;
} }
@Override
public void saveOrRemoveArticle(@NonNull TravelArticle article, boolean save) {
if (save) {
localDataHelper.addArticleToSaved(article);
} else {
localDataHelper.removeArticleFromSaved(article);
}
}
private class GpxFileReader extends AsyncTask<Void, Void, GPXFile> { private class GpxFileReader extends AsyncTask<Void, Void, GPXFile> {
private final TravelArticle article; private final TravelArticle article;

View file

@ -31,13 +31,13 @@ import net.osmand.plus.wikipedia.WikiArticleHelper;
import net.osmand.plus.wikivoyage.WikivoyageUtils; import net.osmand.plus.wikivoyage.WikivoyageUtils;
import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelGpx;
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import net.osmand.plus.wikivoyage.data.TravelHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.*; import static net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.TravelGpxVH;
import static net.osmand.util.Algorithms.capitalizeFirstLetterAndLowercase; import static net.osmand.util.Algorithms.capitalizeFirstLetterAndLowercase;
public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -182,20 +182,15 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
private void updateSaveButton(final TravelGpxVH holder, final TravelGpx article) { private void updateSaveButton(final TravelGpxVH holder, final TravelGpx article) {
if (article != null) { if (article != null) {
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper(); final TravelHelper helper = app.getTravelHelper();
final boolean saved = helper.isArticleSaved(article); final boolean saved = helper.getBookmarksHelper().isArticleSaved(article);
Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later); Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later);
holder.rightButton.setText(saved ? R.string.shared_string_remove : R.string.shared_string_save); holder.rightButton.setText(saved ? R.string.shared_string_remove : R.string.shared_string_save);
holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null); holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null);
holder.rightButton.setOnClickListener(new View.OnClickListener() { holder.rightButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (saved) { helper.saveOrRemoveArticle(article, !saved);
helper.removeArticleFromSaved(article);
} else {
app.getTravelHelper().createGpxFile(article);
helper.addArticleToSaved(article);
}
updateSaveButton(holder, article); updateSaveButton(holder, article);
} }
}); });
@ -286,13 +281,13 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
Object item = getItemByPosition(); Object item = getItemByPosition();
if (item instanceof TravelArticle) { if (item instanceof TravelArticle) {
final TravelArticle article = (TravelArticle) item; final TravelArticle article = (TravelArticle) item;
final TravelLocalDataHelper ldh = app.getTravelHelper().getBookmarksHelper(); final TravelHelper helper = app.getTravelHelper();
ldh.removeArticleFromSaved(article); helper.saveOrRemoveArticle(article, false);
Snackbar snackbar = Snackbar.make(itemView, R.string.article_removed, Snackbar.LENGTH_LONG) Snackbar snackbar = Snackbar.make(itemView, R.string.article_removed, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() { .setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
ldh.restoreSavedArticle(article); helper.saveOrRemoveArticle(article, true);
} }
}); });
boolean nightMode = !settings.isLightContent(); boolean nightMode = !settings.isLightContent();

View file

@ -100,15 +100,8 @@ public class ArticleTravelCard extends BaseTravelCard {
holder.rightButton.setOnClickListener(new View.OnClickListener() { holder.rightButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (article != null) { app.getTravelHelper().saveOrRemoveArticle(article, !saved);
if (saved) { updateSaveButton(holder);
helper.removeArticleFromSaved(article);
} else {
app.getTravelHelper().createGpxFile(article);
helper.addArticleToSaved(article);
}
updateSaveButton(holder);
}
} }
}); });
} }

View file

@ -20,7 +20,6 @@ import net.osmand.plus.R;
import net.osmand.plus.track.TrackMenuFragment; import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelGpx;
import net.osmand.plus.wikivoyage.data.TravelHelper; import net.osmand.plus.wikivoyage.data.TravelHelper;
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.io.File; import java.io.File;
@ -37,7 +36,7 @@ public class TravelGpxCard extends BaseTravelCard {
private boolean isLastItem; private boolean isLastItem;
public TravelGpxCard(@NonNull OsmandApplication app, boolean nightMode, @NonNull TravelGpx article, public TravelGpxCard(@NonNull OsmandApplication app, boolean nightMode, @NonNull TravelGpx article,
@NonNull FragmentActivity activity) { @NonNull FragmentActivity activity) {
super(app, nightMode); super(app, nightMode);
this.article = article; this.article = article;
readIcon = getActiveIcon(R.drawable.ic_action_read_article); readIcon = getActiveIcon(R.drawable.ic_action_read_article);
@ -104,19 +103,15 @@ public class TravelGpxCard extends BaseTravelCard {
private void updateSaveButton(final TravelGpxVH holder) { private void updateSaveButton(final TravelGpxVH holder) {
if (article != null) { if (article != null) {
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper(); final TravelHelper helper = app.getTravelHelper();
final boolean saved = helper.isArticleSaved(article); final boolean saved = helper.getBookmarksHelper().isArticleSaved(article);
Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later); Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later);
holder.rightButton.setText(saved ? R.string.shared_string_remove : R.string.shared_string_save); holder.rightButton.setText(saved ? R.string.shared_string_remove : R.string.shared_string_save);
holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null); holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null);
holder.rightButton.setOnClickListener(new View.OnClickListener() { holder.rightButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (saved) { helper.saveOrRemoveArticle(article, !saved);
helper.removeArticleFromSaved(article);
} else {
helper.addArticleToSaved(article);
}
updateSaveButton(holder); updateSaveButton(holder);
} }
}); });