Merge branch 'master' of https://github.com/osmandapp/Osmand into JsonContentsParser

This commit is contained in:
PaulStets 2018-04-15 13:47:05 +03:00
commit 6dffedfa3d
5 changed files with 51 additions and 52 deletions

View file

@ -12,7 +12,7 @@ public class WikivoyageUtils {
case ON: case ON:
break; break;
case OFF: case OFF:
rc.networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.OFFLINE); rc.networkPolicy(NetworkPolicy.OFFLINE);
break; break;
case WIFI: case WIFI:
if (!settings.isWifiConnected()) { if (!settings.isWifiConnected()) {

View file

@ -2,6 +2,7 @@ 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.Collator; import net.osmand.Collator;
import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher;
import net.osmand.CollatorStringMatcher.StringMatcherMode; import net.osmand.CollatorStringMatcher.StringMatcherMode;
@ -120,11 +121,11 @@ public class WikivoyageDbHelper {
connection = application.getSQLiteAPI().openByAbsolutePath(f.getAbsolutePath(), true); connection = application.getSQLiteAPI().openByAbsolutePath(f.getAbsolutePath(), true);
selectedTravelBook = f; selectedTravelBook = f;
application.getSettings().SELECTED_TRAVEL_BOOK.set(selectedTravelBook.getName()); application.getSettings().SELECTED_TRAVEL_BOOK.set(selectedTravelBook.getName());
localDataHelper.refreshHistoryArticles(); localDataHelper.refreshCachedData();
} }
} }
public void closeConnection() { private void closeConnection() {
if (connection != null) { if (connection != null) {
connection.close(); connection.close();
connection = null; connection = null;
@ -279,7 +280,6 @@ public class WikivoyageDbHelper {
} while (cursor.moveToNext()); } while (cursor.moveToNext());
} }
cursor.close(); cursor.close();
} }
return res; return res;
} }

View file

@ -29,17 +29,16 @@ public class WikivoyageLocalDataHelper {
this.listener = listener; this.listener = listener;
} }
protected WikivoyageLocalDataHelper(OsmandApplication app) { WikivoyageLocalDataHelper(OsmandApplication app) {
dbHelper = new WikivoyageLocalDataDbHelper(app); dbHelper = new WikivoyageLocalDataDbHelper(app);
refreshHistoryArticles(); refreshCachedData();
} }
public void refreshHistoryArticles() { public void refreshCachedData() {
historyMap = dbHelper.getAllHistoryMap(); historyMap = dbHelper.getAllHistoryMap();
savedArticles = dbHelper.getSavedArticles(); savedArticles = dbHelper.getSavedArticles();
} }
public List<WikivoyageSearchHistoryItem> getAllHistory() { public List<WikivoyageSearchHistoryItem> getAllHistory() {
List<WikivoyageSearchHistoryItem> res = new ArrayList<>(historyMap.valueCollection()); List<WikivoyageSearchHistoryItem> res = new ArrayList<>(historyMap.valueCollection());
Collections.sort(res, new Comparator<WikivoyageSearchHistoryItem>() { Collections.sort(res, new Comparator<WikivoyageSearchHistoryItem>() {

View file

@ -1,7 +1,6 @@
package net.osmand.plus.wikivoyage.explore; package net.osmand.plus.wikivoyage.explore;
import android.os.Bundle; import android.os.Bundle;
import org.apache.commons.logging.Log;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
@ -11,6 +10,7 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -19,14 +19,17 @@ import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle; import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper; import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
import org.apache.commons.logging.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class SavedArticlesTabFragment extends BaseOsmAndFragment implements WikivoyageLocalDataHelper.Listener { public class SavedArticlesTabFragment extends BaseOsmAndFragment implements WikivoyageLocalDataHelper.Listener {
private static final Log LOG = PlatformUtil.getLog(SavedArticlesTabFragment.class);
private WikivoyageLocalDataHelper dataHelper; private WikivoyageLocalDataHelper dataHelper;
private final static Log LOG = PlatformUtil.getLog(SavedArticlesTabFragment.class);
private SavedArticlesRvAdapter adapter; private SavedArticlesRvAdapter adapter;
@ -36,6 +39,7 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Wiki
final OsmandApplication app = getMyApplication(); final OsmandApplication app = getMyApplication();
dataHelper = app.getWikivoyageDbHelper().getLocalDataHelper(); dataHelper = app.getWikivoyageDbHelper().getLocalDataHelper();
LOG.debug("Data helper null:" + (dataHelper != null)); LOG.debug("Data helper null:" + (dataHelper != null));
final View mainView = inflater.inflate(R.layout.fragment_saved_articles_tab, container, false); final View mainView = inflater.inflate(R.layout.fragment_saved_articles_tab, container, false);
adapter = new SavedArticlesRvAdapter(app); adapter = new SavedArticlesRvAdapter(app);

View file

@ -17,7 +17,6 @@ import net.osmand.plus.OsmandSettings.WikivoyageShowImages;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
@ -32,32 +31,12 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment"; public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment";
protected void selectTravelBookDialog() {
final WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper();
final List<File> list = dbHelper.getExistingTravelBooks();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
String[] ls = new String[list.size()];
for (int i = 0; i < ls.length; i++) {
ls[i] = dbHelper.formatTravelBookName(list.get(i));
}
builder.setTitle(R.string.select_travel_book);
builder.setItems(ls, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dbHelper.selectTravelBook(list.get(which));
}
});
builder.setNegativeButton(R.string.shared_string_dismiss, null);
builder.show();
}
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication(); final OsmandApplication app = getMyApplication();
final OsmandSettings.CommonPreference<WikivoyageShowImages> showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES; final OsmandSettings.CommonPreference<WikivoyageShowImages> showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES;
final WikivoyageDbHelper dbHelper = app.getWikivoyageDbHelper(); final WikivoyageDbHelper dbHelper = app.getWikivoyageDbHelper();
items.add(new TitleItem(getString(R.string.shared_string_options))); items.add(new TitleItem(getString(R.string.shared_string_options)));
if (dbHelper.getExistingTravelBooks().size() > 1) { if (dbHelper.getExistingTravelBooks().size() > 1) {
@ -75,7 +54,6 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
}) })
.create(); .create();
items.add(selectTravelBook); items.add(selectTravelBook);
} }
BaseBottomSheetItem showImagesItem = new BottomSheetItemWithDescription.Builder() BaseBottomSheetItem showImagesItem = new BottomSheetItemWithDescription.Builder()
@ -141,5 +119,23 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
items.add(clearHistoryItem); items.add(clearHistoryItem);
} }
protected void selectTravelBookDialog() {
final WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper();
final List<File> list = dbHelper.getExistingTravelBooks();
String[] ls = new String[list.size()];
for (int i = 0; i < ls.length; i++) {
ls[i] = dbHelper.formatTravelBookName(list.get(i));
}
new AlertDialog.Builder(getContext())
.setTitle(R.string.select_travel_book)
.setItems(ls, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dbHelper.selectTravelBook(list.get(which));
}
})
.setNegativeButton(R.string.shared_string_dismiss, null)
.show();
}
} }