diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageUtils.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageUtils.java index 3a2710f633..70f500d176 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageUtils.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageUtils.java @@ -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()) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java index a5f75e08fe..b6856d1b04 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java @@ -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; @@ -73,7 +74,7 @@ public class WikivoyageDbHelper { this.application = application; collator = OsmAndCollator.primaryCollator(); } - + public WikivoyageLocalDataHelper getLocalDataHelper() { return localDataHelper; } @@ -113,18 +114,18 @@ public class WikivoyageDbHelper { } return connection; } - + public void selectTravelBook(File f) { closeConnection(); if (f.exists()) { 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; } @@ -310,7 +310,7 @@ public class WikivoyageDbHelper { } public String formatTravelBookName(File tb) { - if(tb == null) { + if (tb == null) { return application.getString(R.string.shared_string_none); } String nm = tb.getName(); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageLocalDataHelper.java index 0d17413002..5f0e191ff8 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageLocalDataHelper.java @@ -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 getAllHistory() { List res = new ArrayList<>(historyMap.valueCollection()); Collections.sort(res, new Comparator() { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesTabFragment.java index 5b86fbd74e..82a82f1f87 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesTabFragment.java @@ -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; @@ -35,7 +38,8 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Wiki public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final OsmandApplication app = getMyApplication(); 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); adapter = new SavedArticlesRvAdapter(app); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java index f14fe30c73..f37e61a91d 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java @@ -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,50 +31,29 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment"; - protected void selectTravelBookDialog() { - final WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper(); - final List 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 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) { + + if (dbHelper.getExistingTravelBooks().size() > 1) { BaseBottomSheetItem selectTravelBook = new BottomSheetItemWithDescription.Builder() - .setDescription(dbHelper.formatTravelBookName(dbHelper.getSelectedTravelBook())) - .setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light) - .setTitle(getString(R.string.shared_string_travel_book)) - .setLayoutId(R.layout.bottom_sheet_item_with_right_descr) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - selectTravelBookDialog(); - dismiss(); - } - }) - .create(); + .setDescription(dbHelper.formatTravelBookName(dbHelper.getSelectedTravelBook())) + .setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light) + .setTitle(getString(R.string.shared_string_travel_book)) + .setLayoutId(R.layout.bottom_sheet_item_with_right_descr) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + selectTravelBookDialog(); + dismiss(); + } + }) + .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 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(); + } }