Remove trip id from necessary column for wikivoyage

This commit is contained in:
Victor Shcherb 2018-05-20 14:00:28 +02:00
parent 87e098f8a5
commit aa3d30d7a0
3 changed files with 42 additions and 35 deletions

View file

@ -83,7 +83,7 @@ public class BinaryInspector {
// "-osm="+System.getProperty("maps.dir")+"/map_full_1.obf.osm", // "-osm="+System.getProperty("maps.dir")+"/map_full_1.obf.osm",
// System.getProperty("maps.dir")+"/diff/Bulgaria_europe_01_00.obf" // System.getProperty("maps.dir")+"/diff/Bulgaria_europe_01_00.obf"
// System.getProperty("maps.dir")+"/diff/Diff.obf" // System.getProperty("maps.dir")+"/diff/Diff.obf"
System.getProperty("maps.dir")+"/Map.obf" System.getProperty("maps.dir")+"/Andorra_europe.wiki.obf"
}); });
} else { } else {
in.inspector(args); in.inspector(args);
@ -1240,7 +1240,12 @@ public class BinaryInspector {
} }
} }
println(object.getType().getKeyName() + ": " + object.getSubType() + " " + object.getName() + " " + object.getLocation() + " osmid=" + (object.getId() >> 1) + " " + s); long id = (object.getId() );
if(id > 0) {
id = id >> 1;
}
println(object.getType().getKeyName() + ": " + object.getSubType() + " " + object.getName() +
" " + object.getLocation() + " osmid=" + id + " " + s);
return false; return false;
} }

View file

@ -1,8 +1,8 @@
package net.osmand.plus.wikivoyage.data; package net.osmand.plus.wikivoyage.data;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
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;
@ -12,9 +12,10 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import gnu.trove.map.hash.TLongObjectHashMap;
public class TravelLocalDataHelper { public class TravelLocalDataHelper {
@ -22,7 +23,7 @@ public class TravelLocalDataHelper {
private WikivoyageLocalDataDbHelper dbHelper; private WikivoyageLocalDataDbHelper dbHelper;
private TLongObjectHashMap<WikivoyageSearchHistoryItem> historyMap; private Map<String, WikivoyageSearchHistoryItem> historyMap;
private List<TravelArticle> savedArticles = new ArrayList<>(); private List<TravelArticle> savedArticles = new ArrayList<>();
private Listener listener; private Listener listener;
@ -41,7 +42,7 @@ public class TravelLocalDataHelper {
} }
public List<WikivoyageSearchHistoryItem> getAllHistory() { public List<WikivoyageSearchHistoryItem> getAllHistory() {
List<WikivoyageSearchHistoryItem> res = new ArrayList<>(historyMap.valueCollection()); List<WikivoyageSearchHistoryItem> res = new ArrayList<>(historyMap.values());
Collections.sort(res, new Comparator<WikivoyageSearchHistoryItem>() { Collections.sort(res, new Comparator<WikivoyageSearchHistoryItem>() {
@Override @Override
public int compare(WikivoyageSearchHistoryItem item1, WikivoyageSearchHistoryItem item2) { public int compare(WikivoyageSearchHistoryItem item1, WikivoyageSearchHistoryItem item2) {
@ -62,15 +63,15 @@ public class TravelLocalDataHelper {
} }
public void addToHistory(@NonNull TravelArticle article) { public void addToHistory(@NonNull TravelArticle article) {
addToHistory(article.getTripId(), article.getTitle(), article.getLang(), article.getIsPartOf()); addToHistory(article.getTitle(), article.getLang(), article.getIsPartOf());
} }
public void addToHistory(long cityId, String title, String lang, String isPartOf) { public void addToHistory(String title, String lang, String isPartOf) {
WikivoyageSearchHistoryItem item = historyMap.get(cityId); String key = getHistoryKey(lang, title);
WikivoyageSearchHistoryItem item = historyMap.get(key);
boolean newItem = item == null; boolean newItem = item == null;
if (newItem) { if (newItem) {
item = new WikivoyageSearchHistoryItem(); item = new WikivoyageSearchHistoryItem();
item.cityId = cityId;
} }
item.articleTitle = title; item.articleTitle = title;
item.lang = lang; item.lang = lang;
@ -78,7 +79,7 @@ public class TravelLocalDataHelper {
item.lastAccessed = System.currentTimeMillis(); item.lastAccessed = System.currentTimeMillis();
if (newItem) { if (newItem) {
dbHelper.addHistoryItem(item); dbHelper.addHistoryItem(item);
historyMap.put(item.cityId, item); historyMap.put(key, item);
} else { } else {
dbHelper.updateHistoryItem(item); dbHelper.updateHistoryItem(item);
} }
@ -86,10 +87,14 @@ public class TravelLocalDataHelper {
List<WikivoyageSearchHistoryItem> allHistory = getAllHistory(); List<WikivoyageSearchHistoryItem> allHistory = getAllHistory();
WikivoyageSearchHistoryItem lastItem = allHistory.get(allHistory.size() - 1); WikivoyageSearchHistoryItem lastItem = allHistory.get(allHistory.size() - 1);
dbHelper.removeHistoryItem(lastItem); dbHelper.removeHistoryItem(lastItem);
historyMap.remove(lastItem.cityId); historyMap.remove(key);
} }
} }
static String getHistoryKey(String lang, String title) {
return lang + ":"+title;
}
@NonNull @NonNull
public List<TravelArticle> getSavedArticles() { public List<TravelArticle> getSavedArticles() {
return new ArrayList<>(savedArticles); return new ArrayList<>(savedArticles);
@ -159,7 +164,6 @@ public class TravelLocalDataHelper {
private static final String DB_NAME = "wikivoyage_local_data"; private static final String DB_NAME = "wikivoyage_local_data";
private static final String HISTORY_TABLE_NAME = "wikivoyage_search_history"; private static final String HISTORY_TABLE_NAME = "wikivoyage_search_history";
private static final String HISTORY_COL_CITY_ID = "city_id";
private static final String HISTORY_COL_ARTICLE_TITLE = "article_title"; private static final String HISTORY_COL_ARTICLE_TITLE = "article_title";
private static final String HISTORY_COL_LANG = "lang"; private static final String HISTORY_COL_LANG = "lang";
private static final String HISTORY_COL_IS_PART_OF = "is_part_of"; private static final String HISTORY_COL_IS_PART_OF = "is_part_of";
@ -168,7 +172,6 @@ public class TravelLocalDataHelper {
private static final String HISTORY_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + private static final String HISTORY_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " +
HISTORY_TABLE_NAME + " (" + HISTORY_TABLE_NAME + " (" +
HISTORY_COL_CITY_ID + " long, " +
HISTORY_COL_ARTICLE_TITLE + " TEXT, " + HISTORY_COL_ARTICLE_TITLE + " TEXT, " +
HISTORY_COL_LANG + " TEXT, " + HISTORY_COL_LANG + " TEXT, " +
HISTORY_COL_IS_PART_OF + " TEXT, " + HISTORY_COL_IS_PART_OF + " TEXT, " +
@ -176,7 +179,6 @@ public class TravelLocalDataHelper {
HISTORY_COL_TRAVEL_BOOK + " TEXT);"; HISTORY_COL_TRAVEL_BOOK + " TEXT);";
private static final String HISTORY_TABLE_SELECT = "SELECT " + private static final String HISTORY_TABLE_SELECT = "SELECT " +
HISTORY_COL_CITY_ID + ", " +
HISTORY_COL_ARTICLE_TITLE + ", " + HISTORY_COL_ARTICLE_TITLE + ", " +
HISTORY_COL_LANG + ", " + HISTORY_COL_LANG + ", " +
HISTORY_COL_IS_PART_OF + ", " + HISTORY_COL_IS_PART_OF + ", " +
@ -265,8 +267,8 @@ public class TravelLocalDataHelper {
} }
@NonNull @NonNull
TLongObjectHashMap<WikivoyageSearchHistoryItem> getAllHistoryMap() { Map<String, WikivoyageSearchHistoryItem> getAllHistoryMap() {
TLongObjectHashMap<WikivoyageSearchHistoryItem> res = new TLongObjectHashMap<>(); Map<String, WikivoyageSearchHistoryItem> res = new LinkedHashMap<>();
String travelBook = getSelectedTravelBookName(); String travelBook = getSelectedTravelBookName();
if (travelBook == null) { if (travelBook == null) {
return res; return res;
@ -279,7 +281,7 @@ public class TravelLocalDataHelper {
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
do { do {
WikivoyageSearchHistoryItem item = readHistoryItem(cursor); WikivoyageSearchHistoryItem item = readHistoryItem(cursor);
res.put(item.cityId, item); res.put(item.getKey(), item);
} while (cursor.moveToNext()); } while (cursor.moveToNext());
} }
cursor.close(); cursor.close();
@ -298,9 +300,10 @@ public class TravelLocalDataHelper {
SQLiteConnection conn = openConnection(false); SQLiteConnection conn = openConnection(false);
if (conn != null) { if (conn != null) {
try { try {
conn.execSQL("INSERT INTO " + HISTORY_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?)", conn.execSQL("INSERT INTO " + HISTORY_TABLE_NAME + "(" + HISTORY_COL_ARTICLE_TITLE + ", "
new Object[]{item.cityId, item.articleTitle, item.lang, + HISTORY_COL_LANG + ", " + HISTORY_COL_IS_PART_OF + ", " + HISTORY_COL_LAST_ACCESSED
item.isPartOf, item.lastAccessed, travelBook}); + ", " + HISTORY_COL_TRAVEL_BOOK + ") VALUES (?, ?, ?, ?, ?)", new Object[] {
item.articleTitle, item.lang, item.isPartOf, item.lastAccessed, travelBook });
} finally { } finally {
conn.close(); conn.close();
} }
@ -316,14 +319,13 @@ public class TravelLocalDataHelper {
if (conn != null) { if (conn != null) {
try { try {
conn.execSQL("UPDATE " + HISTORY_TABLE_NAME + " SET " + conn.execSQL("UPDATE " + HISTORY_TABLE_NAME + " SET " +
HISTORY_COL_ARTICLE_TITLE + " = ?, " +
HISTORY_COL_LANG + " = ?, " +
HISTORY_COL_IS_PART_OF + " = ?, " + HISTORY_COL_IS_PART_OF + " = ?, " +
HISTORY_COL_LAST_ACCESSED + " = ? " + HISTORY_COL_LAST_ACCESSED + " = ? " +
"WHERE " + HISTORY_COL_CITY_ID + " = ? " + "WHERE " + HISTORY_COL_ARTICLE_TITLE + " = ? " +
"AND " + HISTORY_COL_TRAVEL_BOOK + " = ?", " AND " + HISTORY_COL_LANG + " = ?" +
new Object[]{item.articleTitle, item.lang, item.isPartOf, " AND " + HISTORY_COL_TRAVEL_BOOK + " = ?",
item.lastAccessed, item.cityId, travelBook}); new Object[]{item.isPartOf, item.lastAccessed,
item.articleTitle, item.lang, travelBook});
} finally { } finally {
conn.close(); conn.close();
} }
@ -339,9 +341,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_CITY_ID + " = ?" + " WHERE " + HISTORY_COL_ARTICLE_TITLE+ " = ?" +
" AND " + HISTORY_COL_LANG + " = ?" +
" AND " + HISTORY_COL_TRAVEL_BOOK + " = ?", " AND " + HISTORY_COL_TRAVEL_BOOK + " = ?",
new Object[]{item.cityId, travelBook}); new Object[]{item.articleTitle, item.lang, travelBook});
} finally { } finally {
conn.close(); conn.close();
} }
@ -447,8 +450,6 @@ public class TravelLocalDataHelper {
private WikivoyageSearchHistoryItem readHistoryItem(SQLiteCursor cursor) { private WikivoyageSearchHistoryItem readHistoryItem(SQLiteCursor cursor) {
WikivoyageSearchHistoryItem res = new WikivoyageSearchHistoryItem(); WikivoyageSearchHistoryItem res = new WikivoyageSearchHistoryItem();
res.cityId = cursor.getLong(cursor.getColumnIndex(HISTORY_COL_CITY_ID));
res.articleTitle = cursor.getString(cursor.getColumnIndex(HISTORY_COL_ARTICLE_TITLE)); res.articleTitle = cursor.getString(cursor.getColumnIndex(HISTORY_COL_ARTICLE_TITLE));
res.lang = cursor.getString(cursor.getColumnIndex(HISTORY_COL_LANG)); res.lang = cursor.getString(cursor.getColumnIndex(HISTORY_COL_LANG));
res.isPartOf = cursor.getString(cursor.getColumnIndex(HISTORY_COL_IS_PART_OF)); res.isPartOf = cursor.getString(cursor.getColumnIndex(HISTORY_COL_IS_PART_OF));

View file

@ -2,16 +2,17 @@ package net.osmand.plus.wikivoyage.data;
public class WikivoyageSearchHistoryItem { public class WikivoyageSearchHistoryItem {
long cityId;
String articleTitle; String articleTitle;
String lang; String lang;
String isPartOf; String isPartOf;
long lastAccessed; long lastAccessed;
public long getCityId() {
return cityId; public String getKey() {
return TravelLocalDataHelper.getHistoryKey(lang, articleTitle);
} }
public String getArticleTitle() { public String getArticleTitle() {
return articleTitle; return articleTitle;
} }