Rename travel db helper and introduce settings for markers

This commit is contained in:
Victor Shcherb 2018-04-15 18:39:07 +02:00
parent d16f3ddebe
commit 263d3e764e
14 changed files with 51 additions and 29 deletions

View file

@ -47,7 +47,7 @@ import net.osmand.plus.voice.CommandPlayer;
import net.osmand.plus.voice.CommandPlayerException;
import net.osmand.plus.voice.MediaCommandPlayerImpl;
import net.osmand.plus.voice.TTSCommandPlayerImpl;
import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper;
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.render.RenderingRulesStorage;
import net.osmand.router.RoutingConfiguration;
import net.osmand.util.Algorithms;
@ -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 WikivoyageDbHelper(app), WikivoyageDbHelper.class);
app.wikivoyageDbHelper = startupInit(new TravelDbHelper(app), TravelDbHelper.class);
initOpeningHoursParser();
}

View file

@ -6,7 +6,6 @@ import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.data.FavouritePoint;
@ -20,6 +19,8 @@ import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
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.util.Algorithms;
import net.osmand.util.MapUtils;
@ -497,6 +498,26 @@ public class MapMarkersHelper {
}
return res;
}
@NonNull
public List<MapMarkersGroup> getGroupsForSavedArticlesTravelBook() {
List<MapMarkersGroup> res = new ArrayList<>();
TravelDbHelper travelDbHelper = ctx.getTravelDbHelper();
if(travelDbHelper.getSelectedTravelBook() != null) {
List<WikivoyageArticle> savedArticles = travelDbHelper.getLocalDataHelper().getSavedArticles();
for (WikivoyageArticle art : savedArticles) {
String gpxName = travelDbHelper.getGPXName(art);
File path = ctx.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
MapMarkersGroup group = getOrCreateGroup(new File(path.getAbsolutePath()));
if (!isGroupSynced(group.getId())) {
group.disabled = true;
createHeaderInGroup(group);
res.add(group);
}
}
}
return res;
}
@Nullable
public MapMarker getMapMarker(WptPt wptPt) {

View file

@ -56,7 +56,7 @@ import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.search.QuickSearchHelper;
import net.osmand.plus.voice.CommandPlayer;
import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper;
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.router.RoutingConfiguration;
import net.osmand.search.SearchUICore;
import net.osmand.util.Algorithms;
@ -119,7 +119,7 @@ public class OsmandApplication extends MultiDexApplication {
OsmandRegions regions;
GeocodingLookupService geocodingLookupService;
QuickSearchHelper searchUICore;
WikivoyageDbHelper wikivoyageDbHelper;
TravelDbHelper travelDbHelper;
RoutingConfiguration.Builder defaultRoutingConfig;
private Locale preferredLocale = null;
@ -392,8 +392,8 @@ public class OsmandApplication extends MultiDexApplication {
return searchUICore;
}
public WikivoyageDbHelper getWikivoyageDbHelper() {
return wikivoyageDbHelper;
public TravelDbHelper getTravelDbHelper() {
return travelDbHelper;
}
public CommandPlayer getPlayer() {

View file

@ -63,7 +63,7 @@ import net.osmand.plus.views.MapControlsLayer;
import net.osmand.plus.views.MapTileLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.wikivoyage.explore.WikivoyageExploreDialogFragment;
import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper;
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.router.GeneralRouter;
import org.apache.commons.logging.Log;
@ -771,7 +771,7 @@ public class MapActivityActions implements DialogProvider {
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
getMyApplication().getWikivoyageDbHelper().initTravelBooks();
getMyApplication().getTravelDbHelper().initTravelBooks();
MapActivity.clearPrevActivityIntent();
WikivoyageExploreDialogFragment.showInstance(mapActivity.getSupportFragmentManager());
return true;

View file

@ -93,6 +93,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
helper.updateGroups();
List<MapMarkersGroup> groups = new ArrayList<>(helper.getMapMarkersGroups());
groups.addAll(helper.getGroupsForDisplayedGpx());
groups.addAll(helper.getGroupsForSavedArticlesTravelBook());
for (int i = 0; i < groups.size(); i++) {
MapMarkersGroup group = groups.get(i);
if (!group.isVisible()) {

View file

@ -48,7 +48,7 @@ public class WikivoyageWebViewClient extends WebViewClient {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
long articleId = app.getWikivoyageDbHelper().getArticleId(articleName, lang);
long articleId = app.getTravelDbHelper().getArticleId(articleName, lang);
if (articleId != 0) {
WikivoyageArticleDialogFragment.showInstance(app, mFragmentManager,
articleId, lang);

View file

@ -35,7 +35,7 @@ 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.WikivoyageDbHelper;
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
import net.osmand.util.Algorithms;
@ -178,7 +178,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
return;
}
final GPXFile gpx = article.getGpxFile();
WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper();
TravelDbHelper dbHelper = getMyApplication().getTravelDbHelper();
File file = getMyApplication().getAppPath(IndexConstants.GPX_TRAVEL_DIR + dbHelper.getGPXName(article));
GPXUtilities.writeGpxFile(file, gpx, getMyApplication());
@ -267,7 +267,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
private void updateSaveButton() {
if (article != null) {
final WikivoyageLocalDataHelper helper = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();
final WikivoyageLocalDataHelper 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));
@ -326,7 +326,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
selectedLang = langs.get(0);
}
articleToolbarText.setText("");
article = getMyApplication().getWikivoyageDbHelper().getArticle(cityId, selectedLang);
article = getMyApplication().getTravelDbHelper().getArticle(cityId, selectedLang);
if (article == null) {
return;
}
@ -335,7 +335,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
trackButton.setText(getString(R.string.points) + " (" + article.getGpxFile().getPointsSize() +")");
}
WikivoyageLocalDataHelper ldh = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();
WikivoyageLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper();
ldh.addToHistory(article);
updateSaveButton();
@ -387,7 +387,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
@NonNull FragmentManager fm,
long cityId,
@Nullable String selectedLang) {
ArrayList<String> langs = app.getWikivoyageDbHelper().getArticleLangs(cityId);
ArrayList<String> langs = app.getTravelDbHelper().getArticleLangs(cityId);
return showInstance(fm, cityId, langs, selectedLang);
}

View file

@ -29,9 +29,9 @@ import org.apache.commons.logging.Log;
import gnu.trove.map.hash.TLongObjectHashMap;
public class WikivoyageDbHelper {
public class TravelDbHelper {
private static final Log LOG = PlatformUtil.getLog(WikivoyageDbHelper.class);
private static final Log LOG = PlatformUtil.getLog(TravelDbHelper.class);
private static final String ARTICLES_TABLE_NAME = "wikivoyage_articles";
private static final String ARTICLES_COL_ID = "article_id";
@ -79,7 +79,7 @@ public class WikivoyageDbHelper {
private boolean initialized = false;
public WikivoyageDbHelper(OsmandApplication application) {
public TravelDbHelper(OsmandApplication application) {
this.application = application;
collator = OsmAndCollator.primaryCollator();
if(application.getSettings().SELECTED_TRAVEL_BOOK.get() != null) {

View file

@ -246,8 +246,8 @@ public class WikivoyageLocalDataHelper {
if (oldVersion < 3) {
conn.execSQL("ALTER TABLE " + HISTORY_TABLE_NAME + " ADD " + HISTORY_COL_TRAVEL_BOOK + " TEXT");
conn.execSQL("ALTER TABLE " + BOOKMARKS_TABLE_NAME + " ADD " + BOOKMARKS_COL_TRAVEL_BOOK + " TEXT");
if(context.getWikivoyageDbHelper().getSelectedTravelBook() != null) {
Object[] args = new Object[]{context.getWikivoyageDbHelper().getSelectedTravelBook().getName()};
if(context.getTravelDbHelper().getSelectedTravelBook() != null) {
Object[] args = new Object[]{context.getTravelDbHelper().getSelectedTravelBook().getName()};
conn.execSQL("UPDATE " + HISTORY_TABLE_NAME + " SET " + HISTORY_COL_TRAVEL_BOOK + " = ?", args);
conn.execSQL("UPDATE " + BOOKMARKS_TABLE_NAME + " SET " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?", args);
}

View file

@ -191,7 +191,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
Object item = getItemByPosition();
if (item != null && item instanceof WikivoyageArticle) {
final WikivoyageArticle article = (WikivoyageArticle) item;
final WikivoyageLocalDataHelper ldh = app.getWikivoyageDbHelper().getLocalDataHelper();;
final WikivoyageLocalDataHelper 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() {

View file

@ -37,7 +37,7 @@ 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 = app.getWikivoyageDbHelper().getLocalDataHelper();
dataHelper = app.getTravelDbHelper().getLocalDataHelper();
final View mainView = inflater.inflate(R.layout.fragment_saved_articles_tab, container, false);

View file

@ -21,7 +21,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
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.WikivoyageDbHelper;
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
import java.io.File;
@ -35,7 +35,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
final OsmandSettings.CommonPreference<WikivoyageShowImages> showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES;
final WikivoyageDbHelper dbHelper = app.getWikivoyageDbHelper();
final TravelDbHelper dbHelper = app.getTravelDbHelper();
items.add(new TitleItem(getString(R.string.shared_string_options)));
@ -110,7 +110,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WikivoyageLocalDataHelper ldh = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();
WikivoyageLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper();
ldh.clearHistory();
dismiss();
}
@ -120,7 +120,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
}
protected void selectTravelBookDialog() {
final WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper();
final TravelDbHelper dbHelper = getMyApplication().getTravelDbHelper();
final List<File> list = dbHelper.getExistingTravelBooks();
String[] ls = new String[list.size()];
for (int i = 0; i < ls.length; i++) {

View file

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

View file

@ -42,7 +42,7 @@ public class WikivoyageSearchHelper {
}
if (!isCancelled()) {
List<WikivoyageSearchResult> results = application.getWikivoyageDbHelper().search(query);
List<WikivoyageSearchResult> results = application.getTravelDbHelper().search(query);
if (!isCancelled()) {
rm.publish(results);
}