Use title instead of city id for saved articles

This commit is contained in:
Alex Sytnyk 2018-05-16 23:25:37 +03:00
parent a7b07f3ce0
commit 1ee1e1a3d7
4 changed files with 29 additions and 17 deletions

View file

@ -447,7 +447,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
@Override
public void onClick(View v) {
if (mapActivity.getSupportFragmentManager() != null) {
WikivoyageArticleDialogFragment.showInstance(app, mapActivity.getSupportFragmentManager(), article.getTripId(), article.getLang());
WikivoyageArticleDialogFragment.showInstance(app, mapActivity.getSupportFragmentManager(), article.getTitle(), article.getLang());
}
}
};

View file

@ -350,6 +350,14 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme
return sb.toString();
}
public static boolean showInstance(@NonNull OsmandApplication app,
@NonNull FragmentManager fm,
@NonNull String title,
@NonNull String lang) {
long cityId = app.getTravelDbHelper().getArticleId(title, lang);
return showInstance(app, fm, cityId, lang);
}
public static boolean showInstance(@NonNull OsmandApplication app,
@NonNull FragmentManager fm,
long cityId,

View file

@ -98,7 +98,6 @@ public class TravelLocalDataHelper {
public void addArticleToSaved(@NonNull TravelArticle article) {
if (!isArticleSaved(article)) {
TravelArticle saved = new TravelArticle();
saved.tripId = article.tripId;
saved.title = article.title;
saved.lang = article.lang;
saved.aggregatedPartOf = article.aggregatedPartOf;
@ -121,7 +120,7 @@ public class TravelLocalDataHelper {
}
public void removeArticleFromSaved(@NonNull TravelArticle article) {
TravelArticle savedArticle = getArticle(article.tripId, article.lang);
TravelArticle savedArticle = getArticle(article.title, article.lang);
if (savedArticle != null) {
savedArticles.remove(savedArticle);
dbHelper.removeSavedArticle(savedArticle);
@ -130,7 +129,7 @@ public class TravelLocalDataHelper {
}
public boolean isArticleSaved(@NonNull TravelArticle article) {
return getArticle(article.tripId, article.lang) != null;
return getArticle(article.title, article.lang) != null;
}
private void notifySavedUpdated() {
@ -140,9 +139,9 @@ public class TravelLocalDataHelper {
}
@Nullable
private TravelArticle getArticle(long cityId, String lang) {
private TravelArticle getArticle(String title, String lang) {
for (TravelArticle article : savedArticles) {
if (article.tripId == cityId && article.lang != null && article.lang.equals(lang)) {
if (article.title != null && article.title.equals(title) && article.lang != null && article.lang.equals(lang)) {
return article;
}
}
@ -185,7 +184,6 @@ public class TravelLocalDataHelper {
" FROM " + HISTORY_TABLE_NAME;
private static final String BOOKMARKS_TABLE_NAME = "wikivoyage_saved_articles";
private static final String BOOKMARKS_COL_CITY_ID = "city_id";
private static final String BOOKMARKS_COL_ARTICLE_TITLE = "article_title";
private static final String BOOKMARKS_COL_LANG = "lang";
private static final String BOOKMARKS_COL_IS_PART_OF = "is_part_of";
@ -197,7 +195,6 @@ public class TravelLocalDataHelper {
private static final String BOOKMARKS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " +
BOOKMARKS_TABLE_NAME + " (" +
BOOKMARKS_COL_CITY_ID + " long, " +
BOOKMARKS_COL_ARTICLE_TITLE + " TEXT, " +
BOOKMARKS_COL_LANG + " TEXT, " +
BOOKMARKS_COL_IS_PART_OF + " TEXT, " +
@ -208,7 +205,6 @@ public class TravelLocalDataHelper {
BOOKMARKS_COL_LON + " double);";
private static final String BOOKMARKS_TABLE_SELECT = "SELECT " +
BOOKMARKS_COL_CITY_ID + ", " +
BOOKMARKS_COL_ARTICLE_TITLE + ", " +
BOOKMARKS_COL_LANG + ", " +
BOOKMARKS_COL_IS_PART_OF + ", " +
@ -402,10 +398,19 @@ public class TravelLocalDataHelper {
SQLiteConnection conn = openConnection(false);
if (conn != null) {
try {
conn.execSQL("INSERT INTO " + BOOKMARKS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
new Object[]{article.tripId, article.title, article.lang,
article.aggregatedPartOf, article.imageTitle, article.content,
travelBook, article.lat, article.lon});
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_PARTIAL_CONTENT + ", " +
BOOKMARKS_COL_TRAVEL_BOOK + ", " +
BOOKMARKS_COL_LAT + ", " +
BOOKMARKS_COL_LON +
") VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
conn.execSQL(query, new Object[]{article.title, article.lang,
article.aggregatedPartOf, article.imageTitle, article.content,
travelBook, article.lat, article.lon});
} finally {
conn.close();
}
@ -421,10 +426,10 @@ public class TravelLocalDataHelper {
if (conn != null) {
try {
conn.execSQL("DELETE FROM " + BOOKMARKS_TABLE_NAME +
" WHERE " + BOOKMARKS_COL_CITY_ID + " = ?" +
" WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" +
" AND " + BOOKMARKS_COL_LANG + " = ?" +
" AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?",
new Object[]{article.tripId, article.lang, travelBook});
new Object[]{article.title, article.lang, travelBook});
} finally {
conn.close();
}
@ -455,7 +460,6 @@ public class TravelLocalDataHelper {
private TravelArticle readSavedArticle(SQLiteCursor cursor) {
TravelArticle res = new TravelArticle();
res.tripId = cursor.getLong(cursor.getColumnIndex(BOOKMARKS_COL_CITY_ID));
res.title = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_ARTICLE_TITLE));
res.lang = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_LANG));
res.aggregatedPartOf = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_IS_PART_OF));

View file

@ -49,7 +49,7 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav
FragmentActivity activity = getActivity();
if (activity != null) {
FragmentManager fm = activity.getSupportFragmentManager();
WikivoyageArticleDialogFragment.showInstance(app, fm, article.getTripId(), article.getLang());
WikivoyageArticleDialogFragment.showInstance(app, fm, article.getTitle(), article.getLang());
}
}
});