Fix initialization of travel books
This commit is contained in:
parent
ab6e2c8783
commit
cba427d70d
1 changed files with 24 additions and 10 deletions
|
@ -3,6 +3,7 @@ package net.osmand.plus.wikivoyage.data;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import net.osmand.Collator;
|
||||
import net.osmand.CollatorStringMatcher;
|
||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||
|
@ -116,18 +117,16 @@ public class TravelDbHelper {
|
|||
}
|
||||
|
||||
public void initTravelBooks() {
|
||||
File[] possibleFiles = application.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles();
|
||||
List<File> files = getPossibleFiles();
|
||||
String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||
existingTravelBooks.clear();
|
||||
if (possibleFiles != null && possibleFiles.length > 0) {
|
||||
for (File f : possibleFiles) {
|
||||
if (f.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) {
|
||||
existingTravelBooks.add(f);
|
||||
if (selectedTravelBook == null) {
|
||||
selectedTravelBook = f;
|
||||
} else if (Algorithms.objectEquals(travelBook, f.getName())) {
|
||||
selectedTravelBook = f;
|
||||
}
|
||||
if (files != null && !files.isEmpty()) {
|
||||
for (File f : files) {
|
||||
existingTravelBooks.add(f);
|
||||
if (selectedTravelBook == null) {
|
||||
selectedTravelBook = f;
|
||||
} else if (Algorithms.objectEquals(travelBook, f.getName())) {
|
||||
selectedTravelBook = f;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -135,6 +134,21 @@ public class TravelDbHelper {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private List<File> getPossibleFiles() {
|
||||
File[] files = application.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles();
|
||||
if (files != null) {
|
||||
List<File> res = new ArrayList<>();
|
||||
for (File file : files) {
|
||||
if (file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) {
|
||||
res.add(file);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void loadDataForSelectedTravelBook() {
|
||||
localDataHelper.refreshCachedData();
|
||||
loadPopularArticles();
|
||||
|
|
Loading…
Reference in a new issue