Add show saved articles without obf file
This commit is contained in:
parent
d7a1212705
commit
bab02a6d54
4 changed files with 34 additions and 10 deletions
|
@ -33,6 +33,7 @@ public class TravelArticle {
|
|||
String lang;
|
||||
String contentsJson;
|
||||
String aggregatedPartOf;
|
||||
String fullContent;
|
||||
|
||||
|
||||
public String getTitle() {
|
||||
|
|
|
@ -9,7 +9,6 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
|||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.plus.wikipedia.WikiArticleHelper;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
@ -119,6 +118,7 @@ public class TravelLocalDataHelper {
|
|||
saved.lat = article.lat;
|
||||
saved.lon = article.lon;
|
||||
saved.routeId = article.routeId;
|
||||
saved.fullContent = article.getContent();
|
||||
savedArticles.add(saved);
|
||||
dbHelper.addSavedArticle(saved);
|
||||
notifySavedUpdated();
|
||||
|
@ -162,6 +162,17 @@ public class TravelLocalDataHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TravelArticle getSavedArticle(String routeId) {
|
||||
for (TravelArticle article : savedArticles) {
|
||||
if (article.routeId != null && article.routeId.equals(routeId)) {
|
||||
article.content = article.fullContent;
|
||||
return article;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
|
||||
void savedArticlesUpdated();
|
||||
|
@ -169,7 +180,7 @@ public class TravelLocalDataHelper {
|
|||
|
||||
private static class WikivoyageLocalDataDbHelper {
|
||||
|
||||
private static final int DB_VERSION = 5;
|
||||
private static final int DB_VERSION = 6;
|
||||
private static final String DB_NAME = "wikivoyage_local_data";
|
||||
|
||||
private static final String HISTORY_TABLE_NAME = "wikivoyage_search_history";
|
||||
|
@ -204,6 +215,7 @@ public class TravelLocalDataHelper {
|
|||
private static final String BOOKMARKS_COL_LAT = "lat";
|
||||
private static final String BOOKMARKS_COL_LON = "lon";
|
||||
private static final String BOOKMARKS_COL_ROUTE_ID = "route_id";
|
||||
private static final String BOOKMARKS_COL_CONTENT = "content";
|
||||
|
||||
private static final String BOOKMARKS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " +
|
||||
BOOKMARKS_TABLE_NAME + " (" +
|
||||
|
@ -215,7 +227,8 @@ public class TravelLocalDataHelper {
|
|||
BOOKMARKS_COL_TRAVEL_BOOK + " TEXT, " +
|
||||
BOOKMARKS_COL_LAT + " double, " +
|
||||
BOOKMARKS_COL_LON + " double, " +
|
||||
BOOKMARKS_COL_ROUTE_ID + " TEXT" + ");";
|
||||
BOOKMARKS_COL_ROUTE_ID + " TEXT, " +
|
||||
BOOKMARKS_COL_CONTENT + " TEXT" + ");";
|
||||
|
||||
private static final String BOOKMARKS_TABLE_SELECT = "SELECT " +
|
||||
BOOKMARKS_COL_ARTICLE_TITLE + ", " +
|
||||
|
@ -225,7 +238,8 @@ public class TravelLocalDataHelper {
|
|||
BOOKMARKS_COL_PARTIAL_CONTENT + ", " +
|
||||
BOOKMARKS_COL_LAT + ", " +
|
||||
BOOKMARKS_COL_LON + ", " +
|
||||
BOOKMARKS_COL_ROUTE_ID +
|
||||
BOOKMARKS_COL_ROUTE_ID + ", " +
|
||||
BOOKMARKS_COL_CONTENT +
|
||||
" FROM " + BOOKMARKS_TABLE_NAME;
|
||||
|
||||
private final OsmandApplication context;
|
||||
|
@ -278,6 +292,9 @@ public class TravelLocalDataHelper {
|
|||
if (oldVersion < 5) {
|
||||
conn.execSQL("ALTER TABLE " + BOOKMARKS_TABLE_NAME + " ADD " + BOOKMARKS_COL_ROUTE_ID + " TEXT");
|
||||
}
|
||||
if (oldVersion < 6) {
|
||||
conn.execSQL("ALTER TABLE " + BOOKMARKS_TABLE_NAME + " ADD " + BOOKMARKS_COL_CONTENT + " TEXT");
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -428,11 +445,12 @@ public class TravelLocalDataHelper {
|
|||
BOOKMARKS_COL_TRAVEL_BOOK + ", " +
|
||||
BOOKMARKS_COL_LAT + ", " +
|
||||
BOOKMARKS_COL_LON + ", " +
|
||||
BOOKMARKS_COL_ROUTE_ID +
|
||||
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
BOOKMARKS_COL_ROUTE_ID + ", " +
|
||||
BOOKMARKS_COL_CONTENT +
|
||||
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
conn.execSQL(query, new Object[]{article.title, article.lang,
|
||||
article.aggregatedPartOf, article.imageTitle, article.content,
|
||||
travelBook, article.lat, article.lon, article.routeId});
|
||||
travelBook, article.lat, article.lon, article.routeId, article.fullContent});
|
||||
} finally {
|
||||
conn.close();
|
||||
}
|
||||
|
@ -484,6 +502,7 @@ public class TravelLocalDataHelper {
|
|||
res.lat = cursor.getDouble(cursor.getColumnIndex(BOOKMARKS_COL_LAT));
|
||||
res.lon = cursor.getDouble(cursor.getColumnIndex(BOOKMARKS_COL_LON));
|
||||
res.routeId = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_ROUTE_ID));
|
||||
res.fullContent = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_CONTENT));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -169,9 +169,12 @@ public class TravelObfHelper implements TravelHelper {
|
|||
TravelArticle article = cachedArticles.get(routeId);
|
||||
if (article != null) {
|
||||
return article;
|
||||
} else {
|
||||
}
|
||||
article = getArticleByIdFromTravelBooks(routeId, lang);
|
||||
if (article != null) {
|
||||
return getArticleByIdFromTravelBooks(routeId, lang);
|
||||
}
|
||||
return localDataHelper.getSavedArticle(routeId);
|
||||
}
|
||||
|
||||
public TravelArticle getArticleByIdFromTravelBooks(final String routeId, final String lang) {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav
|
|||
public void openArticle(TravelArticle article) {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (fm != null) {
|
||||
WikivoyageArticleDialogFragment.showInstanceByTitle(app, fm, article.getTitle(), article.getLang());
|
||||
WikivoyageArticleDialogFragment.showInstance(app, fm, article.getRouteId(), article.getLang());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -161,7 +161,8 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav
|
|||
}
|
||||
TravelArticle oldArticle = (TravelArticle) oldItem;
|
||||
TravelArticle newArticle = (TravelArticle) newItem;
|
||||
return oldArticle.getRouteId().equals(newArticle.getRouteId())
|
||||
return oldArticle.getRouteId() != null && newArticle.getRouteId() != null &&
|
||||
oldArticle.getRouteId().equals(newArticle.getRouteId())
|
||||
&& oldArticle.getLang().equals(newArticle.getLang());
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue