Fix issues
This commit is contained in:
parent
5c965d4085
commit
4fbacaa1e7
8 changed files with 45 additions and 26 deletions
|
@ -9,10 +9,12 @@
|
||||||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
<string name="select_travel_book">Select travel book</string>
|
||||||
|
<string name="shared_string_travel_book">Travel book</string>
|
||||||
<string name="online_webpage_warning">This page is only available online. Do you wish to open it in a web browser?</string>
|
<string name="online_webpage_warning">This page is only available online. Do you wish to open it in a web browser?</string>
|
||||||
<string name="images_cache">Images cache</string>
|
<string name="images_cache">Images cache</string>
|
||||||
<string name="delete_search_history">Delete search history</string>
|
<string name="delete_search_history">Delete search history</string>
|
||||||
<string name="show_images">Show images</string>
|
<string name="download_images">Download images</string>
|
||||||
<string name="download_maps_travel">Travel maps</string>
|
<string name="download_maps_travel">Travel maps</string>
|
||||||
<string name="shared_string_wikivoyage">Wikivoyage</string>
|
<string name="shared_string_wikivoyage">Wikivoyage</string>
|
||||||
<string name="article_removed">Article removed</string>
|
<string name="article_removed">Article removed</string>
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
||||||
|
|
||||||
private void updateSaveButton() {
|
private void updateSaveButton() {
|
||||||
if (article != null) {
|
if (article != null) {
|
||||||
final WikivoyageLocalDataHelper helper = WikivoyageLocalDataHelper.getInstance(getMyApplication());
|
final WikivoyageLocalDataHelper helper = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();
|
||||||
final boolean saved = helper.isArticleSaved(article);
|
final boolean saved = helper.isArticleSaved(article);
|
||||||
Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later);
|
Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later);
|
||||||
saveBtn.setText(getString(saved ? R.string.shared_string_delete : R.string.shared_string_save));
|
saveBtn.setText(getString(saved ? R.string.shared_string_delete : R.string.shared_string_save));
|
||||||
|
@ -219,7 +219,8 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WikivoyageLocalDataHelper.getInstance(getMyApplication()).addToHistory(article);
|
WikivoyageLocalDataHelper ldh = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();
|
||||||
|
ldh.addToHistory(article);
|
||||||
|
|
||||||
updateSaveButton();
|
updateSaveButton();
|
||||||
selectedLangTv.setText(Algorithms.capitalizeFirstLetter(selectedLang));
|
selectedLangTv.setText(Algorithms.capitalizeFirstLetter(selectedLang));
|
||||||
|
|
|
@ -67,16 +67,22 @@ public class WikivoyageDbHelper {
|
||||||
private File selectedTravelBook = null;
|
private File selectedTravelBook = null;
|
||||||
private List<File> existingTravelBooks = new ArrayList<>();
|
private List<File> existingTravelBooks = new ArrayList<>();
|
||||||
private Collator collator;
|
private Collator collator;
|
||||||
|
private WikivoyageLocalDataHelper localDataHelper;
|
||||||
|
|
||||||
public WikivoyageDbHelper(OsmandApplication application) {
|
public WikivoyageDbHelper(OsmandApplication application) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
collator = OsmAndCollator.primaryCollator();
|
collator = OsmAndCollator.primaryCollator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WikivoyageLocalDataHelper getLocalDataHelper() {
|
||||||
|
return localDataHelper;
|
||||||
|
}
|
||||||
|
|
||||||
public void initTravelBooks() {
|
public void initTravelBooks() {
|
||||||
File[] possibleFiles = application.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles();
|
File[] possibleFiles = application.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles();
|
||||||
String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get();
|
String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||||
existingTravelBooks.clear();
|
existingTravelBooks.clear();
|
||||||
|
localDataHelper = new WikivoyageLocalDataHelper(application);
|
||||||
if (possibleFiles != null) {
|
if (possibleFiles != null) {
|
||||||
for (File f : possibleFiles) {
|
for (File f : possibleFiles) {
|
||||||
if (f.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) {
|
if (f.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) {
|
||||||
|
@ -107,6 +113,16 @@ public class WikivoyageDbHelper {
|
||||||
}
|
}
|
||||||
return connection;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void closeConnection() {
|
public void closeConnection() {
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
|
|
|
@ -18,8 +18,6 @@ public class WikivoyageLocalDataHelper {
|
||||||
|
|
||||||
private static final int HISTORY_ITEMS_LIMIT = 300;
|
private static final int HISTORY_ITEMS_LIMIT = 300;
|
||||||
|
|
||||||
private static WikivoyageLocalDataHelper instance;
|
|
||||||
|
|
||||||
private WikivoyageLocalDataDbHelper dbHelper;
|
private WikivoyageLocalDataDbHelper dbHelper;
|
||||||
|
|
||||||
private TLongObjectHashMap<WikivoyageSearchHistoryItem> historyMap;
|
private TLongObjectHashMap<WikivoyageSearchHistoryItem> historyMap;
|
||||||
|
@ -31,18 +29,16 @@ public class WikivoyageLocalDataHelper {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WikivoyageLocalDataHelper(OsmandApplication app) {
|
protected WikivoyageLocalDataHelper(OsmandApplication app) {
|
||||||
dbHelper = new WikivoyageLocalDataDbHelper(app);
|
dbHelper = new WikivoyageLocalDataDbHelper(app);
|
||||||
|
refreshHistoryArticles();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshHistoryArticles() {
|
||||||
historyMap = dbHelper.getAllHistoryMap();
|
historyMap = dbHelper.getAllHistoryMap();
|
||||||
savedArticles = dbHelper.getSavedArticles();
|
savedArticles = dbHelper.getSavedArticles();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WikivoyageLocalDataHelper getInstance(OsmandApplication app) {
|
|
||||||
if (instance == null) {
|
|
||||||
instance = new WikivoyageLocalDataHelper(app);
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<WikivoyageSearchHistoryItem> getAllHistory() {
|
public List<WikivoyageSearchHistoryItem> getAllHistory() {
|
||||||
List<WikivoyageSearchHistoryItem> res = new ArrayList<>(historyMap.valueCollection());
|
List<WikivoyageSearchHistoryItem> res = new ArrayList<>(historyMap.valueCollection());
|
||||||
|
@ -357,6 +353,7 @@ public class WikivoyageLocalDataHelper {
|
||||||
res.add(readSavedArticle(cursor));
|
res.add(readSavedArticle(cursor));
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
}
|
}
|
||||||
|
cursor.close();
|
||||||
} finally {
|
} finally {
|
||||||
conn.close();
|
conn.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,12 +189,13 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
Object item = getItemByPosition();
|
Object item = getItemByPosition();
|
||||||
if (item != null && item instanceof WikivoyageArticle) {
|
if (item != null && item instanceof WikivoyageArticle) {
|
||||||
final WikivoyageArticle article = (WikivoyageArticle) item;
|
final WikivoyageArticle article = (WikivoyageArticle) item;
|
||||||
WikivoyageLocalDataHelper.getInstance(app).removeArticleFromSaved(article);
|
final WikivoyageLocalDataHelper ldh = app.getWikivoyageDbHelper().getLocalDataHelper();;
|
||||||
|
ldh.removeArticleFromSaved(article);
|
||||||
Snackbar snackbar = Snackbar.make(itemView, R.string.article_removed, Snackbar.LENGTH_LONG)
|
Snackbar snackbar = Snackbar.make(itemView, R.string.article_removed, Snackbar.LENGTH_LONG)
|
||||||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
WikivoyageLocalDataHelper.getInstance(app).restoreSavedArticle(article);
|
ldh.restoreSavedArticle(article);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AndroidUtils.setSnackbarTextColor(snackbar, R.color.wikivoyage_active_dark);
|
AndroidUtils.setSnackbarTextColor(snackbar, R.color.wikivoyage_active_dark);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
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;
|
||||||
|
@ -10,7 +11,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.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||||
|
@ -25,6 +26,7 @@ import java.util.List;
|
||||||
public class SavedArticlesTabFragment extends BaseOsmAndFragment implements WikivoyageLocalDataHelper.Listener {
|
public class SavedArticlesTabFragment extends BaseOsmAndFragment implements WikivoyageLocalDataHelper.Listener {
|
||||||
|
|
||||||
private WikivoyageLocalDataHelper dataHelper;
|
private WikivoyageLocalDataHelper dataHelper;
|
||||||
|
private final static Log LOG = PlatformUtil.getLog(SavedArticlesTabFragment.class);
|
||||||
|
|
||||||
private SavedArticlesRvAdapter adapter;
|
private SavedArticlesRvAdapter adapter;
|
||||||
|
|
||||||
|
@ -32,8 +34,8 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Wiki
|
||||||
@Override
|
@Override
|
||||||
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 = WikivoyageLocalDataHelper.getInstance(app);
|
dataHelper = app.getWikivoyageDbHelper().getLocalDataHelper();
|
||||||
|
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);
|
||||||
|
|
|
@ -32,20 +32,19 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
|
||||||
public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment";
|
public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment";
|
||||||
|
|
||||||
protected void selectTravelBookDialog() {
|
protected void selectTravelBookDialog() {
|
||||||
WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper();
|
final WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper();
|
||||||
final List<File> list = dbHelper.getExistingTravelBooks();
|
final List<File> list = dbHelper.getExistingTravelBooks();
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
String[] ls = new String[list.size()];
|
String[] ls = new String[list.size()];
|
||||||
for (int i = 0; i < ls.length; i++) {
|
for (int i = 0; i < ls.length; i++) {
|
||||||
ls[i] = dbHelper.formatTravelBookName(list.get(i));
|
ls[i] = dbHelper.formatTravelBookName(list.get(i));
|
||||||
}
|
}
|
||||||
builder.setTitle("Select travel book"); // TODO externalize
|
builder.setTitle(R.string.select_travel_book);
|
||||||
builder.setItems(ls, new OnClickListener() {
|
builder.setItems(ls, new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
Toast.makeText(getMyApplication(), list.get(which).getName(), Toast.LENGTH_LONG).show();
|
dbHelper.selectTravelBook(list.get(which));
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(R.string.shared_string_dismiss, null);
|
builder.setNegativeButton(R.string.shared_string_dismiss, null);
|
||||||
|
@ -64,7 +63,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
|
||||||
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("Travel book") // TODO think & externalize
|
.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
|
||||||
|
@ -81,7 +80,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
|
||||||
BaseBottomSheetItem showImagesItem = new BottomSheetItemWithCompoundButton.Builder()
|
BaseBottomSheetItem showImagesItem = new BottomSheetItemWithCompoundButton.Builder()
|
||||||
.setChecked(showImagesPref.get())
|
.setChecked(showImagesPref.get())
|
||||||
.setIcon(getContentIcon(R.drawable.ic_type_img))
|
.setIcon(getContentIcon(R.drawable.ic_type_img))
|
||||||
.setTitle(getString(R.string.show_images))
|
.setTitle(getString(R.string.download_images))
|
||||||
.setLayoutId(R.layout.bottom_sheet_item_with_switch)
|
.setLayoutId(R.layout.bottom_sheet_item_with_switch)
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -118,7 +117,8 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
WikivoyageLocalDataHelper.getInstance(app).clearHistory();
|
WikivoyageLocalDataHelper ldh = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();
|
||||||
|
ldh.clearHistory();
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -147,8 +147,8 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
|
||||||
|
|
||||||
private void setAdapterItems(@Nullable List<WikivoyageSearchResult> items) {
|
private void setAdapterItems(@Nullable List<WikivoyageSearchResult> items) {
|
||||||
if (items == null || items.isEmpty()) {
|
if (items == null || items.isEmpty()) {
|
||||||
adapter.setHistoryItems(WikivoyageLocalDataHelper
|
WikivoyageLocalDataHelper ldh = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();
|
||||||
.getInstance(getMyApplication()).getAllHistory());
|
adapter.setHistoryItems(ldh.getAllHistory());
|
||||||
} else {
|
} else {
|
||||||
adapter.setItems(items);
|
adapter.setItems(items);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue