From 290f3af026ba0d3d26fef49032261c74e3b5b34f Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Sun, 11 Apr 2021 23:01:04 +0300 Subject: [PATCH 1/5] Init --- .../wikivoyage/article/WikivoyageArticleDialogFragment.java | 6 ++++-- .../wikivoyage/explore/travelcards/ArticleTravelCard.java | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index b281e85f84..e12d162e6e 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -69,9 +69,9 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme private static final String SELECTED_LANG_KEY = "selected_lang"; private static final String EMPTY_URL = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d4//"; - + private static final int MENU_ITEM_SHARE = 0; - + private TravelArticleIdentifier articleId; private ArrayList langs; private String selectedLang; @@ -256,6 +256,8 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme public void onClick(View view) { if (article != null) { if (saved) { + GPXFile gpxFile = article.getGpxFile(); + getMyApplication().getSelectedGpxHelper().selectGpxFile(gpxFile, false, true); helper.removeArticleFromSaved(article); } else { getMyApplication().getTravelHelper().createGpxFile(article); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java index b955273d01..92bbe1af95 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java @@ -13,6 +13,7 @@ import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import com.squareup.picasso.RequestCreator; +import net.osmand.GPXUtilities; import net.osmand.PicassoUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -102,10 +103,12 @@ public class ArticleTravelCard extends BaseTravelCard { public void onClick(View view) { if (article != null) { if (saved) { + GPXUtilities.GPXFile gpxFile = article.getGpxFile(); + app.getSelectedGpxHelper().selectGpxFile(gpxFile, false, true); helper.removeArticleFromSaved(article); } else { - app.getTravelHelper().createGpxFile(article); helper.addArticleToSaved(article); + app.getTravelHelper().createGpxFile(article); } updateSaveButton(holder); } From ab605a035ba9f494ce1cc8d2424a7eecb169a42b Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Mon, 12 Apr 2021 19:22:55 +0300 Subject: [PATCH 2/5] Bookmarking article without viewing it, adds empty GPX to My Places. --- .../travelcards/ArticleTravelCard.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java index 92bbe1af95..e7b70ccb40 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java @@ -13,7 +13,6 @@ import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import com.squareup.picasso.RequestCreator; -import net.osmand.GPXUtilities; import net.osmand.PicassoUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -24,6 +23,8 @@ import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; +import static net.osmand.GPXUtilities.GPXFile; + public class ArticleTravelCard extends BaseTravelCard { public static final int TYPE = 2; @@ -93,6 +94,8 @@ public class ArticleTravelCard extends BaseTravelCard { private void updateSaveButton(final ArticleTravelVH holder) { if (article != null) { + article = app.getTravelHelper().getArticleById(article.generateIdentifier(), article.getLang(), true, + null); final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper(); final boolean saved = helper.isArticleSaved(article); Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later); @@ -101,17 +104,15 @@ public class ArticleTravelCard extends BaseTravelCard { holder.rightButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (article != null) { - if (saved) { - GPXUtilities.GPXFile gpxFile = article.getGpxFile(); - app.getSelectedGpxHelper().selectGpxFile(gpxFile, false, true); - helper.removeArticleFromSaved(article); - } else { - helper.addArticleToSaved(article); - app.getTravelHelper().createGpxFile(article); - } - updateSaveButton(holder); + if (saved) { + GPXFile gpxFile = article.getGpxFile(); + app.getSelectedGpxHelper().selectGpxFile(gpxFile, false, true); + helper.removeArticleFromSaved(article); + } else { + helper.addArticleToSaved(article); + app.getTravelHelper().createGpxFile(article); } + updateSaveButton(holder); } }); } From 3a5e8c6230bc7a59d6504be16a02ef0b62166630 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Mon, 12 Apr 2021 20:33:04 +0300 Subject: [PATCH 3/5] Unbookmarking travel article should hide GPX file --- .../article/WikivoyageArticleDialogFragment.java | 7 +++---- .../wikivoyage/explore/travelcards/ArticleTravelCard.java | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index e12d162e6e..0205feaaf6 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -254,18 +254,17 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme saveBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (article != null) { + getMyApplication().getTravelHelper().createGpxFile(article); + GPXFile gpxFile = article.getGpxFile(); if (saved) { - GPXFile gpxFile = article.getGpxFile(); getMyApplication().getSelectedGpxHelper().selectGpxFile(gpxFile, false, true); helper.removeArticleFromSaved(article); } else { - getMyApplication().getTravelHelper().createGpxFile(article); + getMyApplication().getSelectedGpxHelper().selectGpxFile(gpxFile, true, true); helper.addArticleToSaved(article); } updateSaveButton(); } - } }); } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java index e7b70ccb40..ef59c079a3 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java @@ -104,13 +104,14 @@ public class ArticleTravelCard extends BaseTravelCard { holder.rightButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + app.getTravelHelper().createGpxFile(article); + GPXFile gpxFile = article.getGpxFile(); if (saved) { - GPXFile gpxFile = article.getGpxFile(); app.getSelectedGpxHelper().selectGpxFile(gpxFile, false, true); helper.removeArticleFromSaved(article); } else { + app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, true); helper.addArticleToSaved(article); - app.getTravelHelper().createGpxFile(article); } updateSaveButton(holder); } From c3ee44ffac94ddd37cc2f8e126409e595c6579f6 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Mon, 12 Apr 2021 21:37:41 +0300 Subject: [PATCH 4/5] Fix possible NPE, remove unnecessary track visibility set --- .../WikivoyageArticleDialogFragment.java | 17 +++++++++-------- .../explore/travelcards/ArticleTravelCard.java | 5 +++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index 0205feaaf6..ba4f5b6f85 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -254,17 +254,18 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme saveBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - getMyApplication().getTravelHelper().createGpxFile(article); - GPXFile gpxFile = article.getGpxFile(); - if (saved) { + getMyApplication().getTravelHelper().createGpxFile(article); + GPXFile gpxFile = article.getGpxFile(); + if (saved) { + if (gpxFile != null) { getMyApplication().getSelectedGpxHelper().selectGpxFile(gpxFile, false, true); - helper.removeArticleFromSaved(article); - } else { - getMyApplication().getSelectedGpxHelper().selectGpxFile(gpxFile, true, true); - helper.addArticleToSaved(article); } - updateSaveButton(); + helper.removeArticleFromSaved(article); + } else { + helper.addArticleToSaved(article); } + updateSaveButton(); + } }); } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java index ef59c079a3..0a81e48c6d 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/ArticleTravelCard.java @@ -107,10 +107,11 @@ public class ArticleTravelCard extends BaseTravelCard { app.getTravelHelper().createGpxFile(article); GPXFile gpxFile = article.getGpxFile(); if (saved) { - app.getSelectedGpxHelper().selectGpxFile(gpxFile, false, true); + if (gpxFile != null) { + app.getSelectedGpxHelper().selectGpxFile(gpxFile, false, true); + } helper.removeArticleFromSaved(article); } else { - app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, true); helper.addArticleToSaved(article); } updateSaveButton(holder); From f17cfdf426042b359f849498d12660200d1e38d6 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 13 Apr 2021 01:38:50 +0300 Subject: [PATCH 5/5] Fix #5473 --- .../WikivoyageArticleDialogFragment.java | 15 +- .../plus/wikivoyage/data/TravelDbHelper.java | 9 ++ .../plus/wikivoyage/data/TravelHelper.java | 2 + .../data/TravelLocalDataHelper.java | 141 ++++++++++-------- .../plus/wikivoyage/data/TravelObfHelper.java | 11 +- .../explore/SavedArticlesRvAdapter.java | 21 +-- .../travelcards/ArticleTravelCard.java | 15 +- .../explore/travelcards/TravelGpxCard.java | 13 +- 8 files changed, 115 insertions(+), 112 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index ba4f5b6f85..7ea563edcc 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -246,24 +246,15 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme private void updateSaveButton() { if (article != null) { - final TravelLocalDataHelper helper = getMyApplication().getTravelHelper().getBookmarksHelper(); - final boolean saved = helper.isArticleSaved(article); + final TravelHelper helper = getMyApplication().getTravelHelper(); + final boolean saved = helper.getBookmarksHelper().isArticleSaved(article); 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.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null); saveBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - getMyApplication().getTravelHelper().createGpxFile(article); - GPXFile gpxFile = article.getGpxFile(); - if (saved) { - if (gpxFile != null) { - getMyApplication().getSelectedGpxHelper().selectGpxFile(gpxFile, false, true); - } - helper.removeArticleFromSaved(article); - } else { - helper.addArticleToSaved(article); - } + helper.saveOrRemoveArticle(article, !saved); updateSaveButton(); } }); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index 627f6d7945..c1a3bc3405 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -193,6 +193,15 @@ public class TravelDbHelper implements TravelHelper { 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 getExistingTravelBooks() { return existingTravelBooks; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java index 0cde849fbf..5a545ceffe 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java @@ -70,4 +70,6 @@ public interface TravelHelper { String getSelectedTravelBookName(); String getWikivoyageFileName(); + + void saveOrRemoveArticle(@NonNull TravelArticle article, boolean save); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index e84765a376..4f85cb8b82 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -4,11 +4,13 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; +import net.osmand.plus.wikivoyage.data.TravelHelper.GpxReadCallback; import net.osmand.util.Algorithms; 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) { TravelArticle savedArticle = getArticle(article.title, article.lang); if (savedArticle != null) { @@ -305,7 +299,7 @@ public class TravelLocalDataHelper { conn.execSQL("ALTER TABLE " + BOOKMARKS_TABLE_NAME + " ADD " + BOOKMARKS_COL_TRAVEL_BOOK + " TEXT"); String selectedTravelBookName = context.getTravelHelper().getSelectedTravelBookName(); 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 " + 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 + ", " + HISTORY_COL_LANG + ", " + HISTORY_COL_IS_PART_OF + ", " + HISTORY_COL_LAST_ACCESSED + ", " + 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 { conn.close(); } @@ -389,8 +383,8 @@ public class TravelLocalDataHelper { "WHERE " + HISTORY_COL_ARTICLE_TITLE + " = ? " + " AND " + HISTORY_COL_LANG + " = ?" + " AND " + HISTORY_COL_TRAVEL_BOOK + " = ?", - new Object[]{item.isPartOf, item.lastAccessed, - item.articleTitle, item.lang, travelBook}); + new Object[] {item.isPartOf, item.lastAccessed, + item.articleTitle, item.lang, travelBook}); } finally { conn.close(); } @@ -406,10 +400,10 @@ public class TravelLocalDataHelper { if (conn != null) { try { conn.execSQL("DELETE FROM " + HISTORY_TABLE_NAME + - " WHERE " + HISTORY_COL_ARTICLE_TITLE+ " = ?" + + " WHERE " + HISTORY_COL_ARTICLE_TITLE + " = ?" + " AND " + HISTORY_COL_LANG + " = ?" + " AND " + HISTORY_COL_TRAVEL_BOOK + " = ?", - new Object[]{item.articleTitle, item.lang, travelBook}); + new Object[] {item.articleTitle, item.lang, travelBook}); } finally { conn.close(); } @@ -480,63 +474,84 @@ public class TravelLocalDataHelper { if (travelBook == null) { return; } - context.getTravelHelper().getArticleById(article.generateIdentifier(), article.lang, true, - new TravelHelper.GpxReadCallback() { - @Override - public void onGpxFileReading() { + final TravelHelper travelHelper = context.getTravelHelper(); + travelHelper.getArticleById(article.generateIdentifier(), article.lang, true, new GpxReadCallback() { + @Override + public void onGpxFileReading() { - } + } - @Override - public void onGpxFileRead(@Nullable GPXUtilities.GPXFile gpxFile) { - SQLiteConnection conn = openConnection(false); - if (conn != null) { - try { - String query = "INSERT INTO " + BOOKMARKS_TABLE_NAME + " (" + - BOOKMARKS_COL_ARTICLE_TITLE + ", " + - BOOKMARKS_COL_LANG + ", " + - BOOKMARKS_COL_IS_PART_OF + ", " + - BOOKMARKS_COL_IMAGE_TITLE + ", " + - BOOKMARKS_COL_TRAVEL_BOOK + ", " + - BOOKMARKS_COL_LAT + ", " + - BOOKMARKS_COL_LON + ", " + - BOOKMARKS_COL_ROUTE_ID + ", " + - BOOKMARKS_COL_CONTENT_JSON + ", " + - BOOKMARKS_COL_CONTENT + ", " + - BOOKMARKS_COL_LAST_MODIFIED + ", " + - BOOKMARKS_COL_GPX_GZ + - ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - conn.execSQL(query, new Object[]{article.title, article.lang, - article.aggregatedPartOf, article.imageTitle, - travelBook, article.lat, article.lon, article.routeId, article.contentsJson, - article.content, article.getFile().lastModified(), - Algorithms.stringToGzip(GPXUtilities.asString(article.gpxFile))}); - } finally { - conn.close(); - } - } + @Override + public void onGpxFileRead(@Nullable GPXFile gpxFile) { + if (gpxFile != null) { + travelHelper.createGpxFile(article); + } + + SQLiteConnection conn = openConnection(false); + if (conn != null) { + try { + String query = "INSERT INTO " + BOOKMARKS_TABLE_NAME + " (" + + BOOKMARKS_COL_ARTICLE_TITLE + ", " + + BOOKMARKS_COL_LANG + ", " + + BOOKMARKS_COL_IS_PART_OF + ", " + + BOOKMARKS_COL_IMAGE_TITLE + ", " + + BOOKMARKS_COL_TRAVEL_BOOK + ", " + + BOOKMARKS_COL_LAT + ", " + + BOOKMARKS_COL_LON + ", " + + BOOKMARKS_COL_ROUTE_ID + ", " + + BOOKMARKS_COL_CONTENT_JSON + ", " + + BOOKMARKS_COL_CONTENT + ", " + + BOOKMARKS_COL_LAST_MODIFIED + ", " + + BOOKMARKS_COL_GPX_GZ + + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + conn.execSQL(query, new Object[] {article.title, article.lang, + article.aggregatedPartOf, article.imageTitle, + 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) { - String travelBook = article.getTravelBook(context); + void removeSavedArticle(@NonNull final TravelArticle article) { + final String travelBook = article.getTravelBook(context); if (travelBook == null) { return; } - 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(); + final TravelHelper travelHelper = context.getTravelHelper(); + travelHelper.getArticleById(article.generateIdentifier(), article.lang, true, new GpxReadCallback() { + @Override + public void onGpxFileReading() { + } - } + + @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) { @@ -563,7 +578,7 @@ public class TravelLocalDataHelper { " AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" + " AND " + BOOKMARKS_COL_LANG + " = ?" + " 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.lon, newArticle.routeId, newArticle.contentsJson, newArticle.content, newArticle.getLastModified(), diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index cdd90e21bd..1cde05050b 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -56,10 +56,10 @@ import static net.osmand.GPXUtilities.WptPt; import static net.osmand.GPXUtilities.writeGpxFile; 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.TravelGpx.ACTIVITY_TYPE; 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.DISTANCE; -import static net.osmand.plus.wikivoyage.data.TravelGpx.ACTIVITY_TYPE; import static net.osmand.plus.wikivoyage.data.TravelGpx.USER; import static net.osmand.util.Algorithms.capitalizeFirstLetter; @@ -1029,6 +1029,15 @@ public class TravelObfHelper implements TravelHelper { 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 { private final TravelArticle article; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java index 9bccece08d..482ce36814 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java @@ -31,13 +31,13 @@ import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.plus.wikivoyage.WikivoyageUtils; import net.osmand.plus.wikivoyage.data.TravelArticle; 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 java.util.ArrayList; 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; public class SavedArticlesRvAdapter extends RecyclerView.Adapter { @@ -182,20 +182,15 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter