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:
break;
case OFF:
rc.networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.OFFLINE);
rc.networkPolicy(NetworkPolicy.OFFLINE);
break;
case WIFI:
if (!settings.isWifiConnected()) {

View file

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

View file

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

View file

@ -1,7 +1,6 @@
package net.osmand.plus.wikivoyage.explore;
import android.os.Bundle;
import org.apache.commons.logging.Log;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
@ -11,6 +10,7 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
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.WikivoyageLocalDataHelper;
import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class SavedArticlesTabFragment extends BaseOsmAndFragment implements WikivoyageLocalDataHelper.Listener {
private static final Log LOG = PlatformUtil.getLog(SavedArticlesTabFragment.class);
private WikivoyageLocalDataHelper dataHelper;
private final static Log LOG = PlatformUtil.getLog(SavedArticlesTabFragment.class);
private SavedArticlesRvAdapter adapter;
@ -36,6 +39,7 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Wiki
final OsmandApplication app = getMyApplication();
dataHelper = app.getWikivoyageDbHelper().getLocalDataHelper();
LOG.debug("Data helper null:" + (dataHelper != null));
final View mainView = inflater.inflate(R.layout.fragment_saved_articles_tab, container, false);
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.base.MenuBottomSheetDialogFragment;
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.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
@ -32,32 +31,12 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
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
public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
final OsmandSettings.CommonPreference<WikivoyageShowImages> showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES;
final WikivoyageDbHelper dbHelper = app.getWikivoyageDbHelper();
items.add(new TitleItem(getString(R.string.shared_string_options)));
if (dbHelper.getExistingTravelBooks().size() > 1) {
@ -75,7 +54,6 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
})
.create();
items.add(selectTravelBook);
}
BaseBottomSheetItem showImagesItem = new BottomSheetItemWithDescription.Builder()
@ -141,5 +119,23 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
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();
}
}