Fix issues

This commit is contained in:
Victor Shcherb 2018-04-15 02:31:44 +02:00
parent 5c965d4085
commit 4fbacaa1e7
8 changed files with 45 additions and 26 deletions

View file

@ -9,10 +9,12 @@
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
-->
<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="images_cache">Images cache</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="shared_string_wikivoyage">Wikivoyage</string>
<string name="article_removed">Article removed</string>

View file

@ -155,7 +155,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
private void updateSaveButton() {
if (article != null) {
final WikivoyageLocalDataHelper helper = WikivoyageLocalDataHelper.getInstance(getMyApplication());
final WikivoyageLocalDataHelper helper = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();
final boolean saved = helper.isArticleSaved(article);
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));
@ -219,7 +219,8 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
return;
}
WikivoyageLocalDataHelper.getInstance(getMyApplication()).addToHistory(article);
WikivoyageLocalDataHelper ldh = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();
ldh.addToHistory(article);
updateSaveButton();
selectedLangTv.setText(Algorithms.capitalizeFirstLetter(selectedLang));

View file

@ -67,16 +67,22 @@ public class WikivoyageDbHelper {
private File selectedTravelBook = null;
private List<File> existingTravelBooks = new ArrayList<>();
private Collator collator;
private WikivoyageLocalDataHelper localDataHelper;
public WikivoyageDbHelper(OsmandApplication application) {
this.application = application;
collator = OsmAndCollator.primaryCollator();
}
public WikivoyageLocalDataHelper getLocalDataHelper() {
return localDataHelper;
}
public void initTravelBooks() {
File[] possibleFiles = application.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles();
String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get();
existingTravelBooks.clear();
localDataHelper = new WikivoyageLocalDataHelper(application);
if (possibleFiles != null) {
for (File f : possibleFiles) {
if (f.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) {
@ -107,6 +113,16 @@ 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();
}
}
public void closeConnection() {
if (connection != null) {

View file

@ -18,8 +18,6 @@ public class WikivoyageLocalDataHelper {
private static final int HISTORY_ITEMS_LIMIT = 300;
private static WikivoyageLocalDataHelper instance;
private WikivoyageLocalDataDbHelper dbHelper;
private TLongObjectHashMap<WikivoyageSearchHistoryItem> historyMap;
@ -31,18 +29,16 @@ public class WikivoyageLocalDataHelper {
this.listener = listener;
}
private WikivoyageLocalDataHelper(OsmandApplication app) {
protected WikivoyageLocalDataHelper(OsmandApplication app) {
dbHelper = new WikivoyageLocalDataDbHelper(app);
refreshHistoryArticles();
}
public void refreshHistoryArticles() {
historyMap = dbHelper.getAllHistoryMap();
savedArticles = dbHelper.getSavedArticles();
}
public static WikivoyageLocalDataHelper getInstance(OsmandApplication app) {
if (instance == null) {
instance = new WikivoyageLocalDataHelper(app);
}
return instance;
}
public List<WikivoyageSearchHistoryItem> getAllHistory() {
List<WikivoyageSearchHistoryItem> res = new ArrayList<>(historyMap.valueCollection());
@ -357,6 +353,7 @@ public class WikivoyageLocalDataHelper {
res.add(readSavedArticle(cursor));
} while (cursor.moveToNext());
}
cursor.close();
} finally {
conn.close();
}

View file

@ -189,12 +189,13 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
Object item = getItemByPosition();
if (item != null && item instanceof WikivoyageArticle) {
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)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
WikivoyageLocalDataHelper.getInstance(app).restoreSavedArticle(article);
ldh.restoreSavedArticle(article);
}
});
AndroidUtils.setSnackbarTextColor(snackbar, R.color.wikivoyage_active_dark);

View file

@ -1,6 +1,7 @@
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;
@ -10,7 +11,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;
import net.osmand.plus.base.BaseOsmAndFragment;
@ -25,6 +26,7 @@ import java.util.List;
public class SavedArticlesTabFragment extends BaseOsmAndFragment implements WikivoyageLocalDataHelper.Listener {
private WikivoyageLocalDataHelper dataHelper;
private final static Log LOG = PlatformUtil.getLog(SavedArticlesTabFragment.class);
private SavedArticlesRvAdapter adapter;
@ -32,8 +34,8 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Wiki
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
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);
adapter = new SavedArticlesRvAdapter(app);

View file

@ -32,20 +32,19 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment";
protected void selectTravelBookDialog() {
WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper();
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("Select travel book"); // TODO externalize
builder.setTitle(R.string.select_travel_book);
builder.setItems(ls, new OnClickListener() {
@Override
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);
@ -64,7 +63,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
BaseBottomSheetItem selectTravelBook = new BottomSheetItemWithDescription.Builder()
.setDescription(dbHelper.formatTravelBookName(dbHelper.getSelectedTravelBook()))
.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)
.setOnClickListener(new View.OnClickListener() {
@Override
@ -81,7 +80,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
BaseBottomSheetItem showImagesItem = new BottomSheetItemWithCompoundButton.Builder()
.setChecked(showImagesPref.get())
.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)
.setOnClickListener(new View.OnClickListener() {
@Override
@ -118,7 +117,8 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WikivoyageLocalDataHelper.getInstance(app).clearHistory();
WikivoyageLocalDataHelper ldh = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();
ldh.clearHistory();
dismiss();
}
})

View file

@ -147,8 +147,8 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
private void setAdapterItems(@Nullable List<WikivoyageSearchResult> items) {
if (items == null || items.isEmpty()) {
adapter.setHistoryItems(WikivoyageLocalDataHelper
.getInstance(getMyApplication()).getAllHistory());
WikivoyageLocalDataHelper ldh = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();
adapter.setHistoryItems(ldh.getAllHistory());
} else {
adapter.setItems(items);
}