Rename travel db helper and introduce settings for markers

This commit is contained in:
Victor Shcherb 2018-04-15 18:40:09 +02:00
parent 263d3e764e
commit 899941c2fc
11 changed files with 64 additions and 64 deletions

View file

@ -445,7 +445,7 @@ public class AppInitializer implements IProgress {
app.mapMarkersDbHelper = startupInit(new MapMarkersDbHelper(app), MapMarkersDbHelper.class);
app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class);
app.searchUICore = startupInit(new QuickSearchHelper(app), QuickSearchHelper.class);
app.wikivoyageDbHelper = startupInit(new TravelDbHelper(app), TravelDbHelper.class);
app.travelDbHelper = startupInit(new TravelDbHelper(app), TravelDbHelper.class);
initOpeningHoursParser();
}

View file

@ -20,7 +20,7 @@ import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.mapmarkers.MarkersPlanRouteContext;
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@ -504,8 +504,8 @@ public class MapMarkersHelper {
List<MapMarkersGroup> res = new ArrayList<>();
TravelDbHelper travelDbHelper = ctx.getTravelDbHelper();
if(travelDbHelper.getSelectedTravelBook() != null) {
List<WikivoyageArticle> savedArticles = travelDbHelper.getLocalDataHelper().getSavedArticles();
for (WikivoyageArticle art : savedArticles) {
List<TravelArticle> savedArticles = travelDbHelper.getLocalDataHelper().getSavedArticles();
for (TravelArticle art : savedArticles) {
String gpxName = travelDbHelper.getGPXName(art);
File path = ctx.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
MapMarkersGroup group = getOrCreateGroup(new File(path.getAbsolutePath()));

View file

@ -34,9 +34,9 @@ import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
import net.osmand.plus.wikivoyage.WikivoyageShowPicturesDialogFragment;
import net.osmand.plus.wikivoyage.WikivoyageWebViewClient;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
import net.osmand.util.Algorithms;
import java.io.File;
@ -98,7 +98,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
private long cityId = NO_VALUE;
private ArrayList<String> langs;
private String selectedLang;
private WikivoyageArticle article;
private TravelArticle article;
private TextView trackButton;
private TextView selectedLangTv;
@ -267,7 +267,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
private void updateSaveButton() {
if (article != null) {
final WikivoyageLocalDataHelper helper = getMyApplication().getTravelDbHelper().getLocalDataHelper();
final TravelLocalDataHelper helper = getMyApplication().getTravelDbHelper().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));
@ -335,7 +335,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
trackButton.setText(getString(R.string.points) + " (" + article.getGpxFile().getPointsSize() +")");
}
WikivoyageLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper();
TravelLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper();
ldh.addToHistory(article);
updateSaveButton();
@ -348,12 +348,12 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
}
@NonNull
private String createHtmlContent(@NonNull WikivoyageArticle article) {
private String createHtmlContent(@NonNull TravelArticle article) {
StringBuilder sb = new StringBuilder(HEADER_INNER);
String imageTitle = article.getImageTitle();
if (!TextUtils.isEmpty(imageTitle)) {
String url = WikivoyageArticle.getImageUrl(imageTitle, false);
String url = TravelArticle.getImageUrl(imageTitle, false);
sb.append("<div class=\"title-image\" style=\"background-image: url(").append(url).append(")\"></div>");
}
sb.append("<div class=\"main\">\n");

View file

@ -11,7 +11,7 @@ import net.osmand.plus.GPXUtilities.GPXFile;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
public class WikivoyageArticle {
public class TravelArticle {
private static final String IMAGE_ROOT_URL = "https://upload.wikimedia.org/wikipedia/commons/";
private static final String THUMB_PREFIX = "320px-";

View file

@ -75,7 +75,7 @@ public class TravelDbHelper {
private File selectedTravelBook = null;
private List<File> existingTravelBooks = new ArrayList<>();
private Collator collator;
private WikivoyageLocalDataHelper localDataHelper;
private TravelLocalDataHelper localDataHelper;
private boolean initialized = false;
@ -87,7 +87,7 @@ public class TravelDbHelper {
}
}
public WikivoyageLocalDataHelper getLocalDataHelper() {
public TravelLocalDataHelper getLocalDataHelper() {
initTravelBooks();
return localDataHelper;
}
@ -100,7 +100,7 @@ public class TravelDbHelper {
File[] possibleFiles = application.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles();
String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get();
existingTravelBooks.clear();
localDataHelper = new WikivoyageLocalDataHelper(application);
localDataHelper = new TravelLocalDataHelper(application);
if (possibleFiles != null) {
for (File f : possibleFiles) {
if (f.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) {
@ -243,8 +243,8 @@ public class TravelDbHelper {
}
@Nullable
public WikivoyageArticle getArticle(long cityId, String lang) {
WikivoyageArticle res = null;
public TravelArticle getArticle(long cityId, String lang) {
TravelArticle res = null;
SQLiteConnection conn = openConnection();
if (conn != null) {
SQLiteCursor cursor = conn.rawQuery(ARTICLES_TABLE_SELECT + " WHERE " + ARTICLES_COL_CITY_ID + " = ? AND "
@ -302,8 +302,8 @@ public class TravelDbHelper {
}
@NonNull
private WikivoyageArticle readArticle(SQLiteCursor cursor) {
WikivoyageArticle res = new WikivoyageArticle();
private TravelArticle readArticle(SQLiteCursor cursor) {
TravelArticle res = new TravelArticle();
res.id = cursor.getString(0);
res.title = cursor.getString(1);
@ -339,7 +339,7 @@ public class TravelDbHelper {
return nm.substring(0, nm.indexOf('.')).replace('_', ' ');
}
public String getGPXName(WikivoyageArticle article) {
public String getGPXName(TravelArticle article) {
return article.getTitle().replace('/', '_').replace('\'', '_').replace('\"', '_') + ".gpx";
}
}

View file

@ -14,14 +14,14 @@ import java.util.List;
import gnu.trove.map.hash.TLongObjectHashMap;
public class WikivoyageLocalDataHelper {
public class TravelLocalDataHelper {
private static final int HISTORY_ITEMS_LIMIT = 300;
private WikivoyageLocalDataDbHelper dbHelper;
private TLongObjectHashMap<WikivoyageSearchHistoryItem> historyMap;
private List<WikivoyageArticle> savedArticles;
private List<TravelArticle> savedArticles;
private Listener listener;
@ -29,7 +29,7 @@ public class WikivoyageLocalDataHelper {
this.listener = listener;
}
WikivoyageLocalDataHelper(OsmandApplication app) {
TravelLocalDataHelper(OsmandApplication app) {
dbHelper = new WikivoyageLocalDataDbHelper(app);
refreshCachedData();
}
@ -60,7 +60,7 @@ public class WikivoyageLocalDataHelper {
dbHelper.clearAllHistory();
}
public void addToHistory(@NonNull WikivoyageArticle article) {
public void addToHistory(@NonNull TravelArticle article) {
addToHistory(article.getCityId(), article.getTitle(), article.getLang(), article.getIsPartOf());
}
@ -90,13 +90,13 @@ public class WikivoyageLocalDataHelper {
}
@NonNull
public List<WikivoyageArticle> getSavedArticles() {
public List<TravelArticle> getSavedArticles() {
return new ArrayList<>(savedArticles);
}
public void addArticleToSaved(@NonNull WikivoyageArticle article) {
public void addArticleToSaved(@NonNull TravelArticle article) {
if (!isArticleSaved(article)) {
WikivoyageArticle saved = new WikivoyageArticle();
TravelArticle saved = new TravelArticle();
saved.cityId = article.cityId;
saved.title = article.title;
saved.lang = article.lang;
@ -109,7 +109,7 @@ public class WikivoyageLocalDataHelper {
}
}
public void restoreSavedArticle(@NonNull WikivoyageArticle article) {
public void restoreSavedArticle(@NonNull TravelArticle article) {
if (!isArticleSaved(article)) {
savedArticles.add(article);
dbHelper.addSavedArticle(article);
@ -117,8 +117,8 @@ public class WikivoyageLocalDataHelper {
}
}
public void removeArticleFromSaved(@NonNull WikivoyageArticle article) {
WikivoyageArticle savedArticle = getArticle(article.cityId, article.lang);
public void removeArticleFromSaved(@NonNull TravelArticle article) {
TravelArticle savedArticle = getArticle(article.cityId, article.lang);
if (savedArticle != null) {
savedArticles.remove(savedArticle);
dbHelper.removeSavedArticle(savedArticle);
@ -126,7 +126,7 @@ public class WikivoyageLocalDataHelper {
}
}
public boolean isArticleSaved(@NonNull WikivoyageArticle article) {
public boolean isArticleSaved(@NonNull TravelArticle article) {
return getArticle(article.cityId, article.lang) != null;
}
@ -137,8 +137,8 @@ public class WikivoyageLocalDataHelper {
}
@Nullable
private WikivoyageArticle getArticle(long cityId, String lang) {
for (WikivoyageArticle article : savedArticles) {
private TravelArticle getArticle(long cityId, String lang) {
for (TravelArticle article : savedArticles) {
if (article.cityId == cityId && article.lang != null && article.lang.equals(lang)) {
return article;
}
@ -340,8 +340,8 @@ public class WikivoyageLocalDataHelper {
}
@NonNull
List<WikivoyageArticle> getSavedArticles() {
List<WikivoyageArticle> res = new ArrayList<>();
List<TravelArticle> getSavedArticles() {
List<TravelArticle> res = new ArrayList<>();
SQLiteConnection conn = openConnection(true);
if (conn != null) {
try {
@ -361,7 +361,7 @@ public class WikivoyageLocalDataHelper {
return res;
}
void addSavedArticle(WikivoyageArticle article) {
void addSavedArticle(TravelArticle article) {
SQLiteConnection conn = openConnection(false);
if (conn != null) {
try {
@ -375,7 +375,7 @@ public class WikivoyageLocalDataHelper {
}
}
void removeSavedArticle(WikivoyageArticle article) {
void removeSavedArticle(TravelArticle article) {
SQLiteConnection conn = openConnection(false);
if (conn != null) {
try {
@ -403,8 +403,8 @@ public class WikivoyageLocalDataHelper {
return res;
}
private WikivoyageArticle readSavedArticle(SQLiteCursor cursor) {
WikivoyageArticle res = new WikivoyageArticle();
private TravelArticle readSavedArticle(SQLiteCursor cursor) {
TravelArticle res = new TravelArticle();
res.cityId = cursor.getLong(0);
res.title = cursor.getString(1);

View file

@ -23,8 +23,8 @@ import net.osmand.plus.R;
import net.osmand.plus.widgets.tools.CropCircleTransformation;
import net.osmand.plus.widgets.tools.CropRectTransformation;
import net.osmand.plus.wikivoyage.WikivoyageUtils;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
import java.util.ArrayList;
import java.util.List;
@ -80,10 +80,10 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
holder.description.setText(String.valueOf(items.size() - 1));
} else {
final ItemVH holder = (ItemVH) viewHolder;
WikivoyageArticle article = (WikivoyageArticle) getItem(position);
TravelArticle article = (TravelArticle) getItem(position);
boolean lastItem = position == getItemCount() - 1;
RequestCreator rc = Picasso.get()
.load(WikivoyageArticle.getImageUrl(article.getImageTitle(), false));
.load(TravelArticle.getImageUrl(article.getImageTitle(), false));
WikivoyageUtils.setupNetworkPolicy(settings, rc);
rc.transform(USE_ALTERNATIVE_CARD ? new CropRectTransformation() : new CropCircleTransformation())
.into(holder.icon, new Callback() {
@ -174,9 +174,9 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
@Override
public void onClick(View view) {
Object item = getItemByPosition();
if (item != null && item instanceof WikivoyageArticle) {
if (item != null && item instanceof TravelArticle) {
if (listener != null) {
listener.openArticle((WikivoyageArticle) item);
listener.openArticle((TravelArticle) item);
}
}
}
@ -189,9 +189,9 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
@Override
public void onClick(View view) {
Object item = getItemByPosition();
if (item != null && item instanceof WikivoyageArticle) {
final WikivoyageArticle article = (WikivoyageArticle) item;
final WikivoyageLocalDataHelper ldh = app.getTravelDbHelper().getLocalDataHelper();;
if (item != null && item instanceof TravelArticle) {
final TravelArticle article = (TravelArticle) item;
final TravelLocalDataHelper ldh = app.getTravelDbHelper().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() {
@ -218,6 +218,6 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
}
interface Listener {
void openArticle(WikivoyageArticle article);
void openArticle(TravelArticle article);
}
}

View file

@ -16,8 +16,8 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
import org.apache.commons.logging.Log;
@ -25,11 +25,11 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class SavedArticlesTabFragment extends BaseOsmAndFragment implements WikivoyageLocalDataHelper.Listener {
public class SavedArticlesTabFragment extends BaseOsmAndFragment implements TravelLocalDataHelper.Listener {
protected static final Log LOG = PlatformUtil.getLog(SavedArticlesTabFragment.class);
private WikivoyageLocalDataHelper dataHelper;
private TravelLocalDataHelper dataHelper;
private SavedArticlesRvAdapter adapter;
@ -44,7 +44,7 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Wiki
adapter = new SavedArticlesRvAdapter(app);
adapter.setListener(new SavedArticlesRvAdapter.Listener() {
@Override
public void openArticle(WikivoyageArticle article) {
public void openArticle(TravelArticle article) {
FragmentManager fm = getFragmentManager();
if (fm != null) {
WikivoyageArticleDialogFragment.showInstance(app, fm, article.getCityId(), article.getLang());
@ -84,7 +84,7 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Wiki
private List<Object> getItems() {
List<Object> items = new ArrayList<>();
List<WikivoyageArticle> savedArticles = dataHelper.getSavedArticles();
List<TravelArticle> savedArticles = dataHelper.getSavedArticles();
if (!savedArticles.isEmpty()) {
Collections.reverse(savedArticles);
items.add(getString(R.string.saved_articles));
@ -126,12 +126,12 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Wiki
Object newItem = newItems.get(newItemPosition);
if (oldItem instanceof String && newItem instanceof String) {
return false;
} else if (oldItem instanceof WikivoyageArticle && newItem instanceof WikivoyageArticle) {
} else if (oldItem instanceof TravelArticle && newItem instanceof TravelArticle) {
if (newItemPosition == newItems.size() - 1 && lastItemChanged()) {
return false;
}
WikivoyageArticle oldArticle = (WikivoyageArticle) oldItem;
WikivoyageArticle newArticle = (WikivoyageArticle) newItem;
TravelArticle oldArticle = (TravelArticle) oldItem;
TravelArticle newArticle = (TravelArticle) newItem;
return oldArticle.getCityId() == newArticle.getCityId()
&& oldArticle.getLang().equals(newArticle.getLang());
}

View file

@ -22,7 +22,7 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
import java.io.File;
import java.util.List;
@ -110,7 +110,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WikivoyageLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper();
TravelLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper();
ldh.clearHistory();
dismiss();
}

View file

@ -20,7 +20,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.widgets.tools.CropCircleTransformation;
import net.osmand.plus.wikivoyage.WikivoyageUtils;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
import net.osmand.util.Algorithms;
@ -77,7 +77,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
if (item instanceof WikivoyageSearchResult) {
WikivoyageSearchResult searchRes = (WikivoyageSearchResult) item;
RequestCreator rc = Picasso.get()
.load(WikivoyageArticle.getImageUrl(searchRes.getImageTitle(), true));
.load(TravelArticle.getImageUrl(searchRes.getImageTitle(), true));
WikivoyageUtils.setupNetworkPolicy(app.getSettings(), rc);
rc.transform(new CropCircleTransformation())
.placeholder(placeholder)

View file

@ -22,7 +22,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
@ -147,7 +147,7 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
private void setAdapterItems(@Nullable List<WikivoyageSearchResult> items) {
if (items == null || items.isEmpty()) {
WikivoyageLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper();
TravelLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper();
adapter.setHistoryItems(ldh.getAllHistory());
} else {
adapter.setItems(items);