Merge branch 'master' of https://github.com/osmandapp/Osmand into JsonContentsParser
This commit is contained in:
commit
6dffedfa3d
5 changed files with 51 additions and 52 deletions
|
@ -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()) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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>() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<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) {
|
||||
|
||||
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<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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue