From 165d1430e3e081d8b76c6a34bab6428647836861 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Tue, 12 May 2020 17:39:03 +0300 Subject: [PATCH] refactor PoiHelper --- OsmAnd/src/net/osmand/plus/poi/PoiHelper.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiHelper.java index 1aa368b6c1..9934d41ff8 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiHelper.java @@ -112,11 +112,14 @@ public class PoiHelper { } private void replaceSavedFiles(List localMapsIndexes) { - helper.deleteFilesTable(helper.getWritableDatabase()); + files.clear(); + helper.deleteFilesTable(); for (LocalIndexInfo info : localMapsIndexes) { File f = new File(info.getPathToData()); - helper.addFile(f, helper.getWritableDatabase()); + helper.addFile(f); + files.put(f.getName(), f.lastModified()); } + helper.close(); } private void initCategoriesFromFiles() { @@ -133,10 +136,21 @@ public class PoiHelper { } private void replaceSavedCategories(List poiCategories) { - helper.deletePoiTypesTable(helper.getWritableDatabase()); + categories.clear(); + helper.deletePoiTypesTable(); for (PoiCategory category : poiCategories) { - helper.addCategory(category, helper.getWritableDatabase()); + helper.addCategory(category); + categories.put(category.getKeyName(), getSubCategoriesFilters(category.getPoiTypes())); } + helper.close(); + } + + private List getSubCategoriesFilters(List poiTypeList) { + List filters = new ArrayList<>(); + for (PoiType poiType : poiTypeList) { + filters.add(poiType.getKeyName()); + } + return filters; } public class PoiDbHelper { @@ -205,26 +219,30 @@ public class PoiHelper { conn.execSQL(POI_TYPES_TABLE_CREATE); } - protected void addFile(File f, SQLiteAPI.SQLiteConnection db) { + protected void addFile(File f) { + SQLiteAPI.SQLiteConnection db = getReadableDatabase(); if (db != null) { db.execSQL("INSERT INTO " + FILES_TABLE_NAME + " VALUES (?, ?)", new Object[]{f.getName(), f.lastModified()}); } } - protected void deleteFilesTable(SQLiteAPI.SQLiteConnection db) { + protected void deleteFilesTable() { + SQLiteAPI.SQLiteConnection db = getReadableDatabase(); if (db != null) { db.execSQL("DELETE FROM " + FILES_TABLE_NAME); } } - protected void deletePoiTypesTable(SQLiteAPI.SQLiteConnection db) { + protected void deletePoiTypesTable() { + SQLiteAPI.SQLiteConnection db = getReadableDatabase(); if (db != null) { db.execSQL("DELETE FROM " + POI_TYPES_TABLE_NAME); } } - protected void addCategory(PoiCategory poiCategory, SQLiteAPI.SQLiteConnection db) { + protected void addCategory(PoiCategory poiCategory) { + SQLiteAPI.SQLiteConnection db = getReadableDatabase(); if (db != null) { db.execSQL("INSERT INTO " + POI_TYPES_TABLE_NAME + " VALUES (?, ?)", new Object[]{poiCategory.getKeyName(), getSubCategoriesJson(poiCategory.getPoiTypes())});