Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
4a6d0aa590
5 changed files with 61 additions and 22 deletions
|
@ -343,6 +343,10 @@ public class MapMarkersHelper {
|
|||
|
||||
|
||||
public void enableGroup(@NonNull MapMarkersGroup gr) {
|
||||
// check if group doesn't exist internally
|
||||
if(!mapMarkersGroups.contains(gr)) {
|
||||
addGroupInternally(gr);
|
||||
}
|
||||
if (gr.isDisabled()) {
|
||||
updateGroupDisabled(gr, false);
|
||||
}
|
||||
|
|
|
@ -418,7 +418,11 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
}
|
||||
}
|
||||
}
|
||||
if(!disabled) {
|
||||
mapMarkersHelper.enableGroup(group);
|
||||
} else {
|
||||
mapMarkersHelper.runSynchronization(group);
|
||||
}
|
||||
|
||||
|
||||
if (disabled) {
|
||||
|
|
|
@ -177,15 +177,10 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
if (article == null || fm == null) {
|
||||
return;
|
||||
}
|
||||
final GPXFile gpx = article.getGpxFile();
|
||||
TravelDbHelper dbHelper = getMyApplication().getTravelDbHelper();
|
||||
File file = getMyApplication().getAppPath(IndexConstants.GPX_TRAVEL_DIR + dbHelper.getGPXName(article));
|
||||
|
||||
GPXUtilities.writeGpxFile(file, gpx, getMyApplication());
|
||||
Bundle args = new Bundle();
|
||||
args.putString(WikivoyageArticleContentsFragment.CONTENTS_JSON_KEY, article.getContentsJson());
|
||||
File path = dbHelper.createGpxFile(article);
|
||||
Intent newIntent = new Intent(getActivity(), getMyApplication().getAppCustomization().getTrackActivity());
|
||||
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, gpx.path);
|
||||
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, path.getAbsolutePath());
|
||||
// newIntent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
|
||||
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(newIntent);
|
||||
|
@ -279,6 +274,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
if (saved) {
|
||||
helper.removeArticleFromSaved(article);
|
||||
} else {
|
||||
getMyApplication().getTravelDbHelper().createGpxFile(article);
|
||||
helper.addArticleToSaved(article);
|
||||
}
|
||||
updateSaveButton();
|
||||
|
|
|
@ -2,7 +2,6 @@ package net.osmand.plus.wikivoyage.data;
|
|||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import net.osmand.Collator;
|
||||
import net.osmand.CollatorStringMatcher;
|
||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||
|
@ -12,6 +11,7 @@ import net.osmand.PlatformUtil;
|
|||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -76,7 +76,6 @@ public class TravelDbHelper {
|
|||
private List<File> existingTravelBooks = new ArrayList<>();
|
||||
private Collator collator;
|
||||
private TravelLocalDataHelper localDataHelper;
|
||||
private boolean initialized = false;
|
||||
|
||||
|
||||
public TravelDbHelper(OsmandApplication application) {
|
||||
|
@ -90,10 +89,6 @@ public class TravelDbHelper {
|
|||
}
|
||||
|
||||
public void initTravelBooks() {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
initialized = true;
|
||||
File[] possibleFiles = application.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles();
|
||||
String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||
existingTravelBooks.clear();
|
||||
|
@ -339,4 +334,11 @@ public class TravelDbHelper {
|
|||
public String getGPXName(TravelArticle article) {
|
||||
return article.getTitle().replace('/', '_').replace('\'', '_').replace('\"', '_') + ".gpx";
|
||||
}
|
||||
|
||||
public File createGpxFile(TravelArticle article) {
|
||||
final GPXFile gpx = article.getGpxFile();
|
||||
File file = application.getAppPath(IndexConstants.GPX_TRAVEL_DIR + getGPXName(article));
|
||||
GPXUtilities.writeGpxFile(file, gpx, application);
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -259,11 +259,14 @@ public class TravelLocalDataHelper {
|
|||
@NonNull
|
||||
TLongObjectHashMap<WikivoyageSearchHistoryItem> getAllHistoryMap() {
|
||||
TLongObjectHashMap<WikivoyageSearchHistoryItem> res = new TLongObjectHashMap<>();
|
||||
String travelBook = getSelectedTravelBookName();
|
||||
if (travelBook == null) {
|
||||
return res;
|
||||
}
|
||||
SQLiteConnection conn = openConnection(true);
|
||||
if (conn != null) {
|
||||
try {
|
||||
String query = HISTORY_TABLE_SELECT + " WHERE " + HISTORY_COL_TRAVEL_BOOK + " = ?";
|
||||
String travelBook = context.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||
SQLiteCursor cursor = conn.rawQuery(query, new String[]{travelBook});
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
|
@ -279,10 +282,13 @@ public class TravelLocalDataHelper {
|
|||
}
|
||||
|
||||
void addHistoryItem(WikivoyageSearchHistoryItem item) {
|
||||
String travelBook = getSelectedTravelBookName();
|
||||
if (travelBook == null) {
|
||||
return;
|
||||
}
|
||||
SQLiteConnection conn = openConnection(false);
|
||||
if (conn != null) {
|
||||
try {
|
||||
String travelBook = context.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||
conn.execSQL("INSERT INTO " + HISTORY_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{item.cityId, item.articleTitle, item.lang,
|
||||
item.isPartOf, item.lastAccessed, travelBook});
|
||||
|
@ -293,10 +299,13 @@ public class TravelLocalDataHelper {
|
|||
}
|
||||
|
||||
void updateHistoryItem(WikivoyageSearchHistoryItem item) {
|
||||
String travelBook = getSelectedTravelBookName();
|
||||
if (travelBook == null) {
|
||||
return;
|
||||
}
|
||||
SQLiteConnection conn = openConnection(false);
|
||||
if (conn != null) {
|
||||
try {
|
||||
String travelBook = context.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||
conn.execSQL("UPDATE " + HISTORY_TABLE_NAME + " SET " +
|
||||
HISTORY_COL_ARTICLE_TITLE + " = ?, " +
|
||||
HISTORY_COL_LANG + " = ?, " +
|
||||
|
@ -313,10 +322,13 @@ public class TravelLocalDataHelper {
|
|||
}
|
||||
|
||||
void removeHistoryItem(WikivoyageSearchHistoryItem item) {
|
||||
String travelBook = getSelectedTravelBookName();
|
||||
if (travelBook == null) {
|
||||
return;
|
||||
}
|
||||
SQLiteConnection conn = openConnection(false);
|
||||
if (conn != null) {
|
||||
try {
|
||||
String travelBook = context.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||
conn.execSQL("DELETE FROM " + HISTORY_TABLE_NAME +
|
||||
" WHERE " + HISTORY_COL_CITY_ID + " = ?" +
|
||||
" AND " + HISTORY_COL_TRAVEL_BOOK + " = ?",
|
||||
|
@ -328,10 +340,13 @@ public class TravelLocalDataHelper {
|
|||
}
|
||||
|
||||
void clearAllHistory() {
|
||||
String travelBook = getSelectedTravelBookName();
|
||||
if (travelBook == null) {
|
||||
return;
|
||||
}
|
||||
SQLiteConnection conn = openConnection(false);
|
||||
if (conn != null) {
|
||||
try {
|
||||
String travelBook = context.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||
conn.execSQL("DELETE FROM " + HISTORY_TABLE_NAME +
|
||||
" WHERE " + HISTORY_COL_TRAVEL_BOOK + " = ?",
|
||||
new Object[]{travelBook});
|
||||
|
@ -344,11 +359,14 @@ public class TravelLocalDataHelper {
|
|||
@NonNull
|
||||
List<TravelArticle> getSavedArticles() {
|
||||
List<TravelArticle> res = new ArrayList<>();
|
||||
String travelBook = getSelectedTravelBookName();
|
||||
if (travelBook == null) {
|
||||
return res;
|
||||
}
|
||||
SQLiteConnection conn = openConnection(true);
|
||||
if (conn != null) {
|
||||
try {
|
||||
String query = BOOKMARKS_TABLE_SELECT + " WHERE " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?";
|
||||
String travelBook = context.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||
SQLiteCursor cursor = conn.rawQuery(query, new String[]{travelBook});
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
|
@ -364,10 +382,13 @@ public class TravelLocalDataHelper {
|
|||
}
|
||||
|
||||
void addSavedArticle(TravelArticle article) {
|
||||
String travelBook = getSelectedTravelBookName();
|
||||
if (travelBook == null) {
|
||||
return;
|
||||
}
|
||||
SQLiteConnection conn = openConnection(false);
|
||||
if (conn != null) {
|
||||
try {
|
||||
String travelBook = context.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||
conn.execSQL("INSERT INTO " + BOOKMARKS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{article.cityId, article.title, article.lang,
|
||||
article.aggregatedPartOf, article.imageTitle, article.content, travelBook});
|
||||
|
@ -378,10 +399,13 @@ public class TravelLocalDataHelper {
|
|||
}
|
||||
|
||||
void removeSavedArticle(TravelArticle article) {
|
||||
String travelBook = getSelectedTravelBookName();
|
||||
if (travelBook == null) {
|
||||
return;
|
||||
}
|
||||
SQLiteConnection conn = openConnection(false);
|
||||
if (conn != null) {
|
||||
try {
|
||||
String travelBook = context.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||
conn.execSQL("DELETE FROM " + BOOKMARKS_TABLE_NAME +
|
||||
" WHERE " + BOOKMARKS_COL_CITY_ID + " = ?" +
|
||||
" AND " + BOOKMARKS_COL_LANG + " = ?" +
|
||||
|
@ -393,6 +417,15 @@ public class TravelLocalDataHelper {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getSelectedTravelBookName() {
|
||||
File selectedTravelBook = context.getTravelDbHelper().getSelectedTravelBook();
|
||||
if (selectedTravelBook != null) {
|
||||
return selectedTravelBook.getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private WikivoyageSearchHistoryItem readHistoryItem(SQLiteCursor cursor) {
|
||||
WikivoyageSearchHistoryItem res = new WikivoyageSearchHistoryItem();
|
||||
|
||||
|
|
Loading…
Reference in a new issue