Remove trip id from necessary column for wikivoyage
This commit is contained in:
parent
87e098f8a5
commit
aa3d30d7a0
3 changed files with 42 additions and 35 deletions
|
@ -83,7 +83,7 @@ public class BinaryInspector {
|
|||
// "-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/Diff.obf"
|
||||
System.getProperty("maps.dir")+"/Map.obf"
|
||||
System.getProperty("maps.dir")+"/Andorra_europe.wiki.obf"
|
||||
});
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.osmand.plus.wikivoyage.data;
|
||||
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
|
@ -12,9 +12,10 @@ import java.io.File;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import gnu.trove.map.hash.TLongObjectHashMap;
|
||||
|
||||
public class TravelLocalDataHelper {
|
||||
|
||||
|
@ -22,7 +23,7 @@ public class TravelLocalDataHelper {
|
|||
|
||||
private WikivoyageLocalDataDbHelper dbHelper;
|
||||
|
||||
private TLongObjectHashMap<WikivoyageSearchHistoryItem> historyMap;
|
||||
private Map<String, WikivoyageSearchHistoryItem> historyMap;
|
||||
private List<TravelArticle> savedArticles = new ArrayList<>();
|
||||
|
||||
private Listener listener;
|
||||
|
@ -41,7 +42,7 @@ public class TravelLocalDataHelper {
|
|||
}
|
||||
|
||||
public List<WikivoyageSearchHistoryItem> getAllHistory() {
|
||||
List<WikivoyageSearchHistoryItem> res = new ArrayList<>(historyMap.valueCollection());
|
||||
List<WikivoyageSearchHistoryItem> res = new ArrayList<>(historyMap.values());
|
||||
Collections.sort(res, new Comparator<WikivoyageSearchHistoryItem>() {
|
||||
@Override
|
||||
public int compare(WikivoyageSearchHistoryItem item1, WikivoyageSearchHistoryItem item2) {
|
||||
|
@ -62,15 +63,15 @@ public class TravelLocalDataHelper {
|
|||
}
|
||||
|
||||
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) {
|
||||
WikivoyageSearchHistoryItem item = historyMap.get(cityId);
|
||||
public void addToHistory(String title, String lang, String isPartOf) {
|
||||
String key = getHistoryKey(lang, title);
|
||||
WikivoyageSearchHistoryItem item = historyMap.get(key);
|
||||
boolean newItem = item == null;
|
||||
if (newItem) {
|
||||
item = new WikivoyageSearchHistoryItem();
|
||||
item.cityId = cityId;
|
||||
}
|
||||
item.articleTitle = title;
|
||||
item.lang = lang;
|
||||
|
@ -78,7 +79,7 @@ public class TravelLocalDataHelper {
|
|||
item.lastAccessed = System.currentTimeMillis();
|
||||
if (newItem) {
|
||||
dbHelper.addHistoryItem(item);
|
||||
historyMap.put(item.cityId, item);
|
||||
historyMap.put(key, item);
|
||||
} else {
|
||||
dbHelper.updateHistoryItem(item);
|
||||
}
|
||||
|
@ -86,10 +87,14 @@ public class TravelLocalDataHelper {
|
|||
List<WikivoyageSearchHistoryItem> allHistory = getAllHistory();
|
||||
WikivoyageSearchHistoryItem lastItem = allHistory.get(allHistory.size() - 1);
|
||||
dbHelper.removeHistoryItem(lastItem);
|
||||
historyMap.remove(lastItem.cityId);
|
||||
historyMap.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
static String getHistoryKey(String lang, String title) {
|
||||
return lang + ":"+title;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<TravelArticle> getSavedArticles() {
|
||||
return new ArrayList<>(savedArticles);
|
||||
|
@ -159,7 +164,6 @@ public class TravelLocalDataHelper {
|
|||
private static final String DB_NAME = "wikivoyage_local_data";
|
||||
|
||||
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_LANG = "lang";
|
||||
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 " +
|
||||
HISTORY_TABLE_NAME + " (" +
|
||||
HISTORY_COL_CITY_ID + " long, " +
|
||||
HISTORY_COL_ARTICLE_TITLE + " TEXT, " +
|
||||
HISTORY_COL_LANG + " TEXT, " +
|
||||
HISTORY_COL_IS_PART_OF + " TEXT, " +
|
||||
|
@ -176,7 +179,6 @@ public class TravelLocalDataHelper {
|
|||
HISTORY_COL_TRAVEL_BOOK + " TEXT);";
|
||||
|
||||
private static final String HISTORY_TABLE_SELECT = "SELECT " +
|
||||
HISTORY_COL_CITY_ID + ", " +
|
||||
HISTORY_COL_ARTICLE_TITLE + ", " +
|
||||
HISTORY_COL_LANG + ", " +
|
||||
HISTORY_COL_IS_PART_OF + ", " +
|
||||
|
@ -265,8 +267,8 @@ public class TravelLocalDataHelper {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
TLongObjectHashMap<WikivoyageSearchHistoryItem> getAllHistoryMap() {
|
||||
TLongObjectHashMap<WikivoyageSearchHistoryItem> res = new TLongObjectHashMap<>();
|
||||
Map<String, WikivoyageSearchHistoryItem> getAllHistoryMap() {
|
||||
Map<String, WikivoyageSearchHistoryItem> res = new LinkedHashMap<>();
|
||||
String travelBook = getSelectedTravelBookName();
|
||||
if (travelBook == null) {
|
||||
return res;
|
||||
|
@ -279,7 +281,7 @@ public class TravelLocalDataHelper {
|
|||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
WikivoyageSearchHistoryItem item = readHistoryItem(cursor);
|
||||
res.put(item.cityId, item);
|
||||
res.put(item.getKey(), item);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
|
@ -298,9 +300,10 @@ public class TravelLocalDataHelper {
|
|||
SQLiteConnection conn = openConnection(false);
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.execSQL("INSERT INTO " + HISTORY_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{item.cityId, item.articleTitle, item.lang,
|
||||
item.isPartOf, item.lastAccessed, travelBook});
|
||||
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 });
|
||||
} finally {
|
||||
conn.close();
|
||||
}
|
||||
|
@ -316,14 +319,13 @@ public class TravelLocalDataHelper {
|
|||
if (conn != null) {
|
||||
try {
|
||||
conn.execSQL("UPDATE " + HISTORY_TABLE_NAME + " SET " +
|
||||
HISTORY_COL_ARTICLE_TITLE + " = ?, " +
|
||||
HISTORY_COL_LANG + " = ?, " +
|
||||
HISTORY_COL_IS_PART_OF + " = ?, " +
|
||||
HISTORY_COL_LAST_ACCESSED + " = ? " +
|
||||
"WHERE " + HISTORY_COL_CITY_ID + " = ? " +
|
||||
"AND " + HISTORY_COL_TRAVEL_BOOK + " = ?",
|
||||
new Object[]{item.articleTitle, item.lang, item.isPartOf,
|
||||
item.lastAccessed, item.cityId, travelBook});
|
||||
"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});
|
||||
} finally {
|
||||
conn.close();
|
||||
}
|
||||
|
@ -339,9 +341,10 @@ public class TravelLocalDataHelper {
|
|||
if (conn != null) {
|
||||
try {
|
||||
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 + " = ?",
|
||||
new Object[]{item.cityId, travelBook});
|
||||
new Object[]{item.articleTitle, item.lang, travelBook});
|
||||
} finally {
|
||||
conn.close();
|
||||
}
|
||||
|
@ -447,8 +450,6 @@ public class TravelLocalDataHelper {
|
|||
|
||||
private WikivoyageSearchHistoryItem readHistoryItem(SQLiteCursor cursor) {
|
||||
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.lang = cursor.getString(cursor.getColumnIndex(HISTORY_COL_LANG));
|
||||
res.isPartOf = cursor.getString(cursor.getColumnIndex(HISTORY_COL_IS_PART_OF));
|
||||
|
|
|
@ -2,16 +2,17 @@ package net.osmand.plus.wikivoyage.data;
|
|||
|
||||
public class WikivoyageSearchHistoryItem {
|
||||
|
||||
long cityId;
|
||||
String articleTitle;
|
||||
String lang;
|
||||
String isPartOf;
|
||||
long lastAccessed;
|
||||
|
||||
public long getCityId() {
|
||||
return cityId;
|
||||
|
||||
|
||||
public String getKey() {
|
||||
return TravelLocalDataHelper.getHistoryKey(lang, articleTitle);
|
||||
}
|
||||
|
||||
|
||||
public String getArticleTitle() {
|
||||
return articleTitle;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue