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:
|
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()) {
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ public class WikivoyageDbHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String formatTravelBookName(File tb) {
|
public String formatTravelBookName(File tb) {
|
||||||
if(tb == null) {
|
if (tb == null) {
|
||||||
return application.getString(R.string.shared_string_none);
|
return application.getString(R.string.shared_string_none);
|
||||||
}
|
}
|
||||||
String nm = tb.getName();
|
String nm = tb.getName();
|
||||||
|
|
|
@ -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>() {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
@ -35,7 +38,8 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Wiki
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
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);
|
||||||
|
|
|
@ -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,50 +31,29 @@ 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) {
|
||||||
BaseBottomSheetItem selectTravelBook = new BottomSheetItemWithDescription.Builder()
|
BaseBottomSheetItem selectTravelBook = new BottomSheetItemWithDescription.Builder()
|
||||||
.setDescription(dbHelper.formatTravelBookName(dbHelper.getSelectedTravelBook()))
|
.setDescription(dbHelper.formatTravelBookName(dbHelper.getSelectedTravelBook()))
|
||||||
.setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light)
|
.setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light)
|
||||||
.setTitle(getString(R.string.shared_string_travel_book))
|
.setTitle(getString(R.string.shared_string_travel_book))
|
||||||
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
|
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
selectTravelBookDialog();
|
selectTravelBookDialog();
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue