diff --git a/OsmAnd-java/src/net/osmand/IndexConstants.java b/OsmAnd-java/src/net/osmand/IndexConstants.java index d6834bcf4d..a829bbc47f 100644 --- a/OsmAnd-java/src/net/osmand/IndexConstants.java +++ b/OsmAnd-java/src/net/osmand/IndexConstants.java @@ -52,6 +52,7 @@ public class IndexConstants { public static final String GPX_INDEX_DIR = "tracks/"; public static final String GPX_RECORDED_INDEX_DIR = GPX_INDEX_DIR + "rec/"; public static final String GPX_IMPORT_DIR = GPX_INDEX_DIR + "import/"; + public static final String TILES_INDEX_DIR= "tiles/"; public static final String LIVE_INDEX_DIR= "live/"; public static final String TOURS_INDEX_DIR= "tours/"; @@ -59,6 +60,7 @@ public class IndexConstants { public static final String ROADS_INDEX_DIR = "roads/"; //$NON-NLS-1$ public static final String WIKI_INDEX_DIR = "wiki/"; //$NON-NLS-1$ public static final String WIKIVOYAGE_INDEX_DIR = "travel/"; + public static final String GPX_TRAVEL_DIR = GPX_INDEX_DIR + WIKIVOYAGE_INDEX_DIR; public static final String AV_INDEX_DIR = "avnotes/"; //$NON-NLS-1$ public static final String FONT_INDEX_DIR = "fonts/"; //$NON-NLS-1$ public static final String VOICE_INDEX_DIR = "voice/"; //$NON-NLS-1$ diff --git a/OsmAnd/.externalToolBuilders/com.android.ide.eclipse.adt.PreCompilerBuilder.launch b/OsmAnd/.externalToolBuilders/com.android.ide.eclipse.adt.PreCompilerBuilder.launch new file mode 100644 index 0000000000..c72add1121 --- /dev/null +++ b/OsmAnd/.externalToolBuilders/com.android.ide.eclipse.adt.PreCompilerBuilder.launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/OsmAnd/.externalToolBuilders/com.android.ide.eclipse.adt.ResourceManagerBuilder.launch b/OsmAnd/.externalToolBuilders/com.android.ide.eclipse.adt.ResourceManagerBuilder.launch new file mode 100644 index 0000000000..a1a644495c --- /dev/null +++ b/OsmAnd/.externalToolBuilders/com.android.ide.eclipse.adt.ResourceManagerBuilder.launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/OsmAnd/.externalToolBuilders/org.eclipse.cdt.managedbuilder.core.genmakebuilder.launch b/OsmAnd/.externalToolBuilders/org.eclipse.cdt.managedbuilder.core.genmakebuilder.launch new file mode 100644 index 0000000000..954c6ac82b --- /dev/null +++ b/OsmAnd/.externalToolBuilders/org.eclipse.cdt.managedbuilder.core.genmakebuilder.launch @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/.gitignore b/OsmAnd/.gitignore index 3bffb9f7b3..b6567d1d18 100644 --- a/OsmAnd/.gitignore +++ b/OsmAnd/.gitignore @@ -10,6 +10,8 @@ libs/org.*.jar libs/commons-logging-commons-logging-api-1.1.jar libs/fr.univ-valenciennes-bzip2-1.0.jar libs/it.unibo.alice.tuprolog-tuprolog-3.2.1.jar +libs/commons-codec-commons-codec-1.11.jar +libs/OsmAndCore_android-0.1-SNAPSHOT.jar valgrind/ bin/ diff --git a/OsmAnd/.project b/OsmAnd/.project index 81f09b6a09..bf3e28b1a9 100644 --- a/OsmAnd/.project +++ b/OsmAnd/.project @@ -7,71 +7,33 @@ - org.eclipse.cdt.managedbuilder.core.genmakebuilder - + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, - ?children? - ?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|\|| - - - ?name? - - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.buildArguments - ${ANDROID_NDK}/ndk-build - - - org.eclipse.cdt.make.core.buildCommand - sh - - - org.eclipse.cdt.make.core.cleanBuildTarget - clean - - - org.eclipse.cdt.make.core.contents - org.eclipse.cdt.make.core.activeConfigSettings - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.enableCleanBuild - false - - - org.eclipse.cdt.make.core.enableFullBuild - false - - - org.eclipse.cdt.make.core.fullBuildTarget - V=1 - - - org.eclipse.cdt.make.core.stopOnError - true - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - false + LaunchConfigHandle + <project>/.externalToolBuilders/org.eclipse.cdt.managedbuilder.core.genmakebuilder.launch - com.android.ide.eclipse.adt.ResourceManagerBuilder + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + LaunchConfigHandle + <project>/.externalToolBuilders/com.android.ide.eclipse.adt.ResourceManagerBuilder.launch + - com.android.ide.eclipse.adt.PreCompilerBuilder + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + LaunchConfigHandle + <project>/.externalToolBuilders/com.android.ide.eclipse.adt.PreCompilerBuilder.launch + diff --git a/OsmAnd/assets/article_style.css b/OsmAnd/assets/article_style.css old mode 100644 new mode 100755 index 5562dbb38d..8c28ff57b7 --- a/OsmAnd/assets/article_style.css +++ b/OsmAnd/assets/article_style.css @@ -30,33 +30,62 @@ body { } h1 { - font-size: 3em; + font-size: 2em; color: #212121; font-family: serif; - font-weight: bold; letter-spacing: 0.03em; word-wrap: break-word; padding-top: 5%; - + font-weight: normal; } h2 { - font-size: 2em; + font-size: 1.5em; color: #454545; font-family: serif; - font-weight: bold; word-wrap: break-word; margin-top: 3%; margin-bottom: 3%; + font-weight: normal; + line-height: 1.6em; } +h2.active:after { + transform: rotate(-135deg); + -webkit-transform: rotate(-135deg); + position: absolute; + right: 1em; +} + +h2:after { + vertical-align: middle; + content: ""; + border: solid black; + border-width: 0 3px 3px 0; + margin-top: 13px; + display: inline-block; + padding: 3px; + transform: rotate(45deg); + -webkit-transform: rotate(45deg); + position: absolute; + right: 1em; +} + +/* +.mw-headline { + +} +*/ + h3 { color: #212121; - font-size: 1.5em; + font-size: 1.2em; font-family: sans-serif; word-wrap: break-word; + font-weight: bold; margin-top: 3%; margin-bottom: 3%; + line-height: 1.6em; } p { @@ -84,12 +113,6 @@ li { font-size: 1.1em; } -.mw-headline { - font-family: sans-serif; - font-size: 1.1em; - line-height: 1.6em; - font-weight: bold; -} img { width: 100%; diff --git a/OsmAnd/build.gradle b/OsmAnd/build.gradle index e7a96711c7..eeff63d664 100644 --- a/OsmAnd/build.gradle +++ b/OsmAnd/build.gradle @@ -22,10 +22,18 @@ apply plugin: 'com.github.ksoichiro.eclipse.aar' def analytics = (!System.getenv("APP_FEATURES") || System.getenv("APP_FEATURES").contains("+play_market")) && getGradle().getStartParameter().getTaskRequests().toString().contains("Free") + eclipseAar { // See "Configurations" for details androidTarget = 'android-27' aarDependenciesDir = 'aarDependencies' + targetConfigurations = ['compile'] + +// cleanLibsDirectoryEnabled = true +} + +task printc { + configurations.each { if(it.isCanBeResolved()) println it.name } } android { @@ -390,47 +398,47 @@ repositories { project.logger.warn("Analytics enabled for free version: $analytics") dependencies { - compile project(path: ':OsmAnd-java', configuration: 'android') + implementation project(path: ':OsmAnd-java', configuration: 'android') if (analytics) { - compile 'com.google.firebase:firebase-core:12.0.1' - compile 'com.google.firebase:firebase-messaging:12.0.1' - compile 'com.google.firebase:firebase-iid:12.0.1' - compile 'com.google.firebase:firebase-config:12.0.1' - compile 'com.facebook.android:facebook-android-sdk:4.31.0' + implementation 'com.google.firebase:firebase-core:12.0.1' + implementation 'com.google.firebase:firebase-messaging:12.0.1' + implementation 'com.google.firebase:firebase-iid:12.0.1' + implementation 'com.google.firebase:firebase-config:12.0.1' + implementation 'com.facebook.android:facebook-android-sdk:4.31.0' } - compile 'com.android.support:multidex:1.0.1' - compile 'com.android.support:gridlayout-v7:27.1.0' - compile 'com.android.support:cardview-v7:27.1.0' - compile 'com.android.support:appcompat-v7:27.1.0' - compile 'com.android.support:design:27.1.0' - compile 'com.android.support:customtabs:27.1.0' - compile fileTree(include: ['gnu-trove-osmand.jar', 'icu4j-49_1_patched.jar'], dir: 'libs') + implementation 'com.android.support:multidex:1.0.1' + implementation 'com.android.support:gridlayout-v7:27.1.0' + implementation 'com.android.support:cardview-v7:27.1.0' + implementation 'com.android.support:appcompat-v7:27.1.0' + implementation 'com.android.support:design:27.1.0' + implementation 'com.android.support:customtabs:27.1.0' + implementation fileTree(include: ['gnu-trove-osmand.jar', 'icu4j-49_1_patched.jar'], dir: 'libs') - compile 'commons-logging:commons-logging-api:1.1' - compile 'commons-codec:commons-codec:1.11' - compile 'it.unibo.alice.tuprolog:tuprolog:3.2.1' - compile 'org.beanshell:bsh-core:2.0b4' - compile 'fr.univ-valenciennes:bzip2:1.0' - compile 'com.moparisthebest:junidecode:0.1.1' - compile 'org.immutables:gson:2.5.0' - compile 'com.vividsolutions:jts-core:1.14.0' + implementation 'commons-logging:commons-logging-api:1.1' + implementation 'commons-codec:commons-codec:1.11' + implementation 'it.unibo.alice.tuprolog:tuprolog:3.2.1' + implementation 'org.beanshell:bsh-core:2.0b4' + implementation 'fr.univ-valenciennes:bzip2:1.0' + implementation 'com.moparisthebest:junidecode:0.1.1' + implementation 'org.immutables:gson:2.5.0' + implementation 'com.vividsolutions:jts-core:1.14.0' - compile 'com.squareup.picasso:picasso:2.71828' + implementation 'com.squareup.picasso:picasso:2.71828' // size restrictions -// compile 'com.ibm.icu:icu4j:50.1' -// compile 'net.sf.trove4j:trove4j:3.0.3' +// implementation 'com.ibm.icu:icu4j:50.1' +// implementation 'net.sf.trove4j:trove4j:3.0.3' - legacyCompile "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@jar" - qtcoredebugCompile "net.osmand:OsmAndCore_androidNativeDebug:0.1-SNAPSHOT@aar" - qtcoredebugCompile "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@aar" - qtcoreCompile "net.osmand:OsmAndCore_androidNativeRelease:0.1-SNAPSHOT@aar" - qtcoreCompile "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@aar" - compile ("com.getkeepsafe.taptargetview:taptargetview:1.6.1"){ + legacyImplementation "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@jar" + qtcoredebugImplementation "net.osmand:OsmAndCore_androidNativeDebug:0.1-SNAPSHOT@aar" + qtcoredebugImplementation "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@aar" + qtcoreImplementation "net.osmand:OsmAndCore_androidNativeRelease:0.1-SNAPSHOT@aar" + qtcoreImplementation "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@aar" + implementation ("com.getkeepsafe.taptargetview:taptargetview:1.6.1"){ exclude group: 'com.android.support' } - compile 'com.github.PhilJay:MPAndroidChart:v3.0.1' - compile ("com.github.HITGIF:TextFieldBoxes:1.3.5"){ + implementation 'com.github.PhilJay:MPAndroidChart:v3.0.1' + implementation ("com.github.HITGIF:TextFieldBoxes:1.3.5"){ exclude group: 'com.android.support' } } diff --git a/OsmAnd/project.properties b/OsmAnd/project.properties index d693eb2a9f..7dabf0f209 100644 --- a/OsmAnd/project.properties +++ b/OsmAnd/project.properties @@ -34,3 +34,5 @@ android.library.reference.19=aarDependencies/android.arch.lifecycle-viewmodel-1. android.library.reference.20=aarDependencies/android.arch.lifecycle-livedata-core-1.1.0 android.library.reference.21=aarDependencies/com.android.support-transition-27.1.0 android.library.reference.22=aarDependencies/com.android.support-support-media-compat-27.1.0 +android.library.reference.23=aarDependencies/com.squareup.picasso-picasso-2.71828 +android.library.reference.24=aarDependencies/com.android.support-exifinterface-27.1.0 diff --git a/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml b/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml index 787f1b54aa..5e871cf1bc 100644 --- a/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml +++ b/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml @@ -1,14 +1,11 @@ - - @@ -26,8 +23,13 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - @@ -55,13 +57,22 @@ + + + - - - + android:layout_gravity="bottom" + android:layout_height="10dp" + android:background="@drawable/bg_contextmenu_shadow_top_light" /> + + - + + + + - + diff --git a/OsmAnd/res/layout/fragment_wikivoyage_show_images_first_time.xml b/OsmAnd/res/layout/fragment_wikivoyage_show_images_first_time.xml new file mode 100644 index 0000000000..ec891a84cb --- /dev/null +++ b/OsmAnd/res/layout/fragment_wikivoyage_show_images_first_time.xml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/wikivoyage_contents_list_item.xml b/OsmAnd/res/layout/wikivoyage_contents_list_item.xml index 5a8df25af2..068f05da69 100644 --- a/OsmAnd/res/layout/wikivoyage_contents_list_item.xml +++ b/OsmAnd/res/layout/wikivoyage_contents_list_item.xml @@ -41,6 +41,7 @@ android:layout_gravity="end" android:paddingLeft="@dimen/list_content_padding" android:paddingRight="@dimen/list_content_padding" + android:background="?attr/selectableItemBackground" android:scaleType="center" tools:src="@drawable/ic_action_arrow_up" /> diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 6c8e23e6cd..bff61aa316 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,10 +9,19 @@ 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 --> + Don\'t + Do + Only with WiFi + Download Pictures + We can download & show images in the articles and store them on device, so you will access them while offline. + You can always change the setting in Explore > Options. + Only WiFi + Select travel book + Travel book This page is only available online. Do you wish to open it in a web browser? Images cache Delete search history - Show images + Download images Travel maps Wikivoyage Article removed diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 749c5dcb44..2c12d35383 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -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.travelDbHelper = startupInit(new TravelDbHelper(app), TravelDbHelper.class); initOpeningHoursParser(); } diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index 977c15c434..320ee0c2f8 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -7,7 +7,6 @@ import android.graphics.Color; import android.graphics.Paint; import android.support.annotation.ColorInt; import android.text.TextUtils; - import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.data.LocationPoint; @@ -812,7 +811,7 @@ public class GPXUtilities { return points.isEmpty(); } - int getPointsSize() { + public int getPointsSize() { return points.size(); } @@ -1210,8 +1209,13 @@ public class GPXUtilities { public static String writeGpxFile(File fout, GPXFile file, OsmandApplication ctx) { Writer output = null; try { + fout.getParentFile().mkdirs(); output = new OutputStreamWriter(new FileOutputStream(fout), "UTF-8"); //$NON-NLS-1$ - return writeGpx(output, file, ctx); + String msg = writeGpx(output, file, ctx); + if(Algorithms.isEmpty(file.path)) { + file.path = fout.getAbsolutePath(); + } + return msg; } catch (IOException e) { log.error("Error saving gpx", e); //$NON-NLS-1$ return ctx.getString(R.string.error_occurred_saving_gpx); @@ -1286,8 +1290,10 @@ public class GPXUtilities { } serializer.endTag(null, "gpx"); //$NON-NLS-1$ - serializer.flush(); serializer.endDocument(); + serializer.flush(); + + } catch (RuntimeException e) { log.error("Error saving gpx", e); //$NON-NLS-1$ return ctx.getString(R.string.error_occurred_saving_gpx); @@ -1396,10 +1402,10 @@ public class GPXUtilities { } catch (IOException e) { } return file; - } catch (FileNotFoundException e) { + } catch (IOException e) { GPXFile res = new GPXFile(); res.path = f.getAbsolutePath(); - log.error("Error reading gpx", e); //$NON-NLS-1$ + log.error("Error reading gpx " + res.path, e); //$NON-NLS-1$ res.warning = ctx.getString(R.string.error_reading_gpx); return res; } finally { diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 137752ec5f..456d1ae47b 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -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.TravelArticle; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -497,6 +498,26 @@ public class MapMarkersHelper { } return res; } + + @NonNull + public List getGroupsForSavedArticlesTravelBook() { + List res = new ArrayList<>(); + TravelDbHelper travelDbHelper = ctx.getTravelDbHelper(); + if(travelDbHelper.getSelectedTravelBook() != null) { + List 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())); + if (!isGroupSynced(group.getId())) { + group.disabled = true; + createHeaderInGroup(group); + res.add(group); + } + } + } + return res; + } @Nullable public MapMarker getMapMarker(WptPt wptPt) { diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index f1ba71a69a..48b0755ec8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -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() { diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index b686d58f9d..5f01e9c314 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -717,7 +717,8 @@ public class OsmandSettings { public final CommonPreference SHOW_LINES_TO_FIRST_MARKERS = new BooleanPreference("show_lines_to_first_markers", false).makeProfile(); public final CommonPreference SHOW_ARROWS_TO_FIRST_MARKERS = new BooleanPreference("show_arrows_to_first_markers", false).makeProfile(); - public final CommonPreference WIKIVOYAGE_SHOW_IMAGES = new BooleanPreference("wikivoyage_show_images", false); + public final CommonPreference WIKIVOYAGE_SHOW_IMAGES_ASKED = new BooleanPreference("wikivoyage_show_images_asked", false).makeGlobal(); + public final CommonPreference WIKIVOYAGE_SHOW_IMAGES = new EnumIntPreference<>("wikivoyage_show_imgs", WikivoyageShowImages.OFF, WikivoyageShowImages.values()).makeGlobal(); public final CommonPreference SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile(); @@ -3310,4 +3311,17 @@ public class OsmandSettings { SECOND, EMPTY } + + public enum WikivoyageShowImages { + ON(R.string.shared_string_on), + OFF(R.string.shared_string_off), + WIFI(R.string.shared_string_wifi_only); + + public final int name; + + WikivoyageShowImages(int name) { + this.name = name; + } + } + } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index e748cbcc61..4680db276b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -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 adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) { - getMyApplication().getWikivoyageDbHelper().initTravelBooks(); + getMyApplication().getTravelDbHelper().initTravelBooks(); MapActivity.clearPrevActivityIntent(); WikivoyageExploreDialogFragment.showInstance(mapActivity.getSupportFragmentManager()); return true; diff --git a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java index b4309e66e7..e042761017 100644 --- a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java @@ -72,11 +72,13 @@ public class TrackActivity extends TabActivity { finish(); return; } - file = null; + if (intent.hasExtra(TRACK_FILE_NAME)) { + file = new File(intent.getStringExtra(TRACK_FILE_NAME)); + } + ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { - if (intent.hasExtra(TRACK_FILE_NAME)) { - file = new File(intent.getStringExtra(TRACK_FILE_NAME)); + if(file != null) { String fn = file.getName().replace(".gpx", "").replace("/", " ").replace("_", " "); actionBar.setTitle(fn); } else { diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 6ca1f973c3..d187857aee 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -250,7 +250,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra return nightMode ? R.drawable.bg_bottom_sheet_sides_landscape_dark : R.drawable.bg_bottom_sheet_sides_landscape_light; } - protected boolean isNightMode() { + private boolean isNightMode() { if (usedOnMap) { return getMyApplication().getDaynightHelper().isNightModeForMapControls(); } diff --git a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java index 4bc30fe322..190452c22a 100644 --- a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java @@ -17,6 +17,7 @@ import android.view.View; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmAndLocationSimulation; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.actions.AppModeDialog; @@ -70,10 +71,13 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { @Override public boolean onPreferenceClick(Preference preference) { getMyApplication().getAppInitializer().resetFirstTimeRun(); - getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.set(false); - getMyApplication().getSettings().MAPILLARY_FIRST_DIALOG_SHOWN.set(false); - getMyApplication().getSettings().WEBGL_SUPPORTED.set(true); - getMyApplication().getSettings().METRIC_SYSTEM_CHANGED_MANUALLY.set(false); + OsmandSettings settings = getMyApplication().getSettings(); + settings.FIRST_MAP_IS_DOWNLOADED.set(false); + settings.MAPILLARY_FIRST_DIALOG_SHOWN.set(false); + settings.WEBGL_SUPPORTED.set(true); + settings.METRIC_SYSTEM_CHANGED_MANUALLY.set(false); + settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.set(false); + getMyApplication().showToastMessage(R.string.shared_string_ok); return true; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 2feadfacc0..cf7f07199d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -93,6 +93,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter 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()) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index abeaa4c08c..8903632d87 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -449,14 +449,18 @@ public class TrackPointFragment extends OsmandExpandableListFragment { }); if (!MenuItemCompat.isActionViewExpanded(mi)) { - final MapMarkersHelper markersHelper = app.getMapMarkersHelper(); - final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(getGpxDataItem().getFile()); - final boolean synced = markersHelper.isGroupSynced(markersGr.getId()); + createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER); - createMenuItem(menu, SELECT_MAP_MARKERS_ID, synced ? R.string.remove_from_map_markers : R.string.shared_string_add_to_map_markers, R.drawable.ic_action_flag_dark, - R.drawable.ic_action_flag_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER); + if (getGpx().path != null) { + final MapMarkersHelper markersHelper = app.getMapMarkersHelper(); + final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(new File(getGpx().path)); + final boolean synced = markersHelper.isGroupSynced(markersGr.getId()); + createMenuItem(menu, SELECT_MAP_MARKERS_ID, synced ? R.string.remove_from_map_markers + : R.string.shared_string_add_to_map_markers, R.drawable.ic_action_flag_dark, + R.drawable.ic_action_flag_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER); + } createMenuItem(menu, SELECT_FAVORITES_ID, R.string.shared_string_add_to_favorites, R.drawable.ic_action_fav_dark, R.drawable.ic_action_fav_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER); createMenuItem(menu, DELETE_ID, R.string.shared_string_delete, R.drawable.ic_action_delete_dark, diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java new file mode 100644 index 0000000000..5377bb69c0 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java @@ -0,0 +1,66 @@ +package net.osmand.plus.wikivoyage; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings.WikivoyageShowImages; +import net.osmand.plus.R; +import net.osmand.plus.base.BottomSheetDialogFragment; + +public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragment { + public static final String TAG = WikivoyageShowPicturesDialogFragment.class.getSimpleName(); + + public static final int SHOW_PICTURES_CHANGED = 1; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + View view = inflater.inflate(R.layout.fragment_wikivoyage_show_images_first_time, container, false); + view.findViewById(R.id.button_no).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.OFF); + } + sendResult(); + dismiss(); + } + }); + view.findViewById(R.id.button_wifi).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.WIFI); + } + sendResult(); + dismiss(); + } + }); + view.findViewById(R.id.button_yes).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.ON); + } + sendResult(); + dismiss(); + } + }); + + return view; + } + + private void sendResult() { + Fragment fragment = getTargetFragment(); + if (fragment != null) { + fragment.onActivityResult(getTargetRequestCode(), SHOW_PICTURES_CHANGED, null); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageUtils.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageUtils.java new file mode 100644 index 0000000000..70f500d176 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageUtils.java @@ -0,0 +1,24 @@ +package net.osmand.plus.wikivoyage; + +import com.squareup.picasso.NetworkPolicy; +import com.squareup.picasso.RequestCreator; + +import net.osmand.plus.OsmandSettings; + +public class WikivoyageUtils { + + public static void setupNetworkPolicy(OsmandSettings settings, RequestCreator rc) { + switch (settings.WIKIVOYAGE_SHOW_IMAGES.get()) { + case ON: + break; + case OFF: + rc.networkPolicy(NetworkPolicy.OFFLINE); + break; + case WIFI: + if (!settings.isWifiConnected()) { + rc.networkPolicy(NetworkPolicy.OFFLINE); + } + break; + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/CustomWebViewClient.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java similarity index 88% rename from OsmAnd/src/net/osmand/plus/wikivoyage/data/CustomWebViewClient.java rename to OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java index e26bf7cf53..e1b8c6a042 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/CustomWebViewClient.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java @@ -1,4 +1,4 @@ -package net.osmand.plus.wikivoyage.data; +package net.osmand.plus.wikivoyage; import android.content.Context; @@ -22,7 +22,7 @@ import java.net.URLDecoder; * Custom WebView client to handle the internal links. */ -public class CustomWebViewClient extends WebViewClient { +public class WikivoyageWebViewClient extends WebViewClient { private OsmandApplication app; private FragmentManager mFragmentManager; @@ -31,7 +31,7 @@ public class CustomWebViewClient extends WebViewClient { private static final String PAGE_PREFIX = "https://"; private static final String WEB_DOMAIN = ".wikivoyage.com/wiki/"; - public CustomWebViewClient(FragmentActivity context, FragmentManager fm) { + public WikivoyageWebViewClient(FragmentActivity context, FragmentManager fm) { app = (OsmandApplication) context.getApplication(); mFragmentManager = fm; mContext = context; @@ -48,7 +48,7 @@ public class CustomWebViewClient 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); @@ -63,6 +63,7 @@ public class CustomWebViewClient extends WebViewClient { private void warnAboutExternalLoad(final String url) { AlertDialog.Builder builder = new AlertDialog.Builder(mContext); + builder.setTitle(url); builder.setMessage(R.string.online_webpage_warning); builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java index b5a52f0c55..f705450861 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java @@ -29,6 +29,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag public static final String CONTENTS_JSON_KEY = "contents_json"; public static final String CONTENTS_LINK_KEY = "contents_link"; + public static final String CONTENTS_TITLE_KEY = "title"; public static final int REQUEST_LINK_CODE = 0; @@ -70,19 +71,23 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - String link = contentItem.getSubItems().get(groupPosition).getSubItems().get(childPosition).getLink(); - sendResult(link); + WikivoyageContentItem wikivoyageContentItem = contentItem.getSubItems().get(groupPosition); + String link = wikivoyageContentItem.getSubItems().get(childPosition).getLink(); + String name = wikivoyageContentItem.getLink().substring(1); + sendResults(link, name); dismiss(); - return false; + return true; } }); expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { - String link = contentItem.getSubItems().get(groupPosition).getLink(); - sendResult(link); + WikivoyageContentItem wikivoyageContentItem = contentItem.getSubItems().get(groupPosition); + String link = wikivoyageContentItem.getLink(); + String name = wikivoyageContentItem.getLink().substring(1); + sendResults(link, name); dismiss(); - return false; + return true; } }); LinearLayout container = new LinearLayout(getContext()); @@ -91,9 +96,10 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag items.add(new SimpleBottomSheetItem.Builder().setCustomView(container).create()); } - private void sendResult(String link) { + private void sendResults(String link, String name) { Intent intent = new Intent(); intent.putExtra(CONTENTS_LINK_KEY, link); + intent.putExtra(CONTENTS_TITLE_KEY, name); Fragment fragment = getTargetFragment(); if (fragment != null) { fragment.onActivityResult(getTargetRequestCode(), REQUEST_LINK_CODE, intent); @@ -155,7 +161,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag } TextView txtListChild = (TextView) convertView.findViewById(R.id.item_label); txtListChild.setText(childText); - txtListChild.setTextColor(getResolvedColor(nightMode + txtListChild.setTextColor(ContextCompat.getColor(context, nightMode ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light)); txtListChild.setCompoundDrawablesWithIntrinsicBounds(itemChildIcon, null, null, null); @@ -202,7 +208,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag } TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label); lblListHeader.setText(headerTitle); - lblListHeader.setTextColor(getResolvedColor(isNightMode() ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light)); + lblListHeader.setTextColor(ContextCompat.getColor(context, nightMode ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light)); lblListHeader.setCompoundDrawablesWithIntrinsicBounds(itemGroupIcon, null, null, null); adjustIndicator(getMyApplication(), groupPosition, isExpanded, convertView, !nightMode); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index dc929bca03..c4bd9066c6 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -8,6 +8,7 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v7.widget.PopupMenu; import android.support.v7.widget.Toolbar; @@ -23,12 +24,19 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.IndexConstants; +import net.osmand.plus.GPXUtilities; +import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandSettings.WikivoyageShowImages; import net.osmand.plus.R; +import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment; -import net.osmand.plus.wikivoyage.data.CustomWebViewClient; -import net.osmand.plus.wikivoyage.data.WikivoyageArticle; -import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper; +import net.osmand.plus.wikivoyage.WikivoyageShowPicturesDialogFragment; +import net.osmand.plus.wikivoyage.WikivoyageWebViewClient; +import net.osmand.plus.wikivoyage.data.TravelArticle; +import net.osmand.plus.wikivoyage.data.TravelDbHelper; +import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import net.osmand.util.Algorithms; import java.io.File; @@ -48,19 +56,58 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen "\n" + "\n" + "\n" + - "\n" + ""; - private static final String FOOTER_INNER = ""; + "\n"; + private static final String FOOTER_INNER = "" + + ""; private long cityId = NO_VALUE; private ArrayList langs; private String selectedLang; - private WikivoyageArticle article; + private TravelArticle article; + private TextView trackButton; private TextView selectedLangTv; private TextView saveBtn; private WebView contentWebView; + private TextView articleToolbarText; + + @SuppressLint("SetJavaScriptEnabled") @Nullable @Override @@ -77,7 +124,8 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen final View mainView = inflate(R.layout.fragment_wikivoyage_article_dialog, container); setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar)); - + + articleToolbarText = (TextView) mainView.findViewById(R.id.article_toolbar_text); ColorStateList selectedLangColorStateList = AndroidUtils.createPressedColorStateList( getContext(), nightMode, R.color.icon_color, R.color.wikivoyage_active_light, @@ -112,18 +160,45 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen WikivoyageArticleContentsFragment fragment = new WikivoyageArticleContentsFragment(); fragment.setUsedOnMap(false); fragment.setArguments(args); - fragment.setTargetFragment(WikivoyageArticleDialogFragment.this, 0); + fragment.setTargetFragment(WikivoyageArticleDialogFragment.this, WikivoyageArticleContentsFragment.REQUEST_LINK_CODE); fragment.show(fm, WikivoyageArticleContentsFragment.TAG); } }); + + + trackButton = (TextView) mainView.findViewById(R.id.gpx_button); + trackButton.setCompoundDrawablesWithIntrinsicBounds( + getActiveIcon(R.drawable.ic_action_track_16), null, null, null + ); + trackButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FragmentManager fm = getFragmentManager(); + if (article == null || fm == null) { + return; + } + final GPXFile gpx = article.getGpxFile(); + TravelDbHelper dbHelper = getMyApplication().getTravelDbHelper(); + File file = getMyApplication().getAppPath(IndexConstants.GPX_TRAVEL_DIR + dbHelper.getGPXName(article)); + + GPXUtilities.writeGpxFile(file, gpx, getMyApplication()); + Bundle args = new Bundle(); + args.putString(WikivoyageArticleContentsFragment.CONTENTS_JSON_KEY, article.getContentsJson()); + Intent newIntent = new Intent(getActivity(), getMyApplication().getAppCustomization().getTrackActivity()); + newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, gpx.path); + // newIntent.putExtra(TrackActivity.OPEN_POINTS_TAB, true); + newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(newIntent); + } + }); saveBtn = (TextView) mainView.findViewById(R.id.save_button); - boolean showImages = getSettings().WIKIVOYAGE_SHOW_IMAGES.get(); contentWebView = (WebView) mainView.findViewById(R.id.content_web_view); - contentWebView.getSettings().setJavaScriptEnabled(true); - contentWebView.getSettings().setCacheMode(showImages ? WebSettings.LOAD_DEFAULT : WebSettings.LOAD_CACHE_ONLY); - contentWebView.setWebViewClient(new CustomWebViewClient(getActivity(), getFragmentManager())); + WebSettings webSettings = contentWebView.getSettings(); + webSettings.setJavaScriptEnabled(true); + updateWebSettings(); + contentWebView.setWebViewClient(new WikivoyageWebViewClient(getActivity(), getFragmentManager())); return mainView; } @@ -144,7 +219,27 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen super.onActivityResult(requestCode, resultCode, data); if (requestCode == WikivoyageArticleContentsFragment.REQUEST_LINK_CODE) { String link = data.getStringExtra(WikivoyageArticleContentsFragment.CONTENTS_LINK_KEY); - moveToAnchor(link); + String title = data.getStringExtra(WikivoyageArticleContentsFragment.CONTENTS_TITLE_KEY); + moveToAnchor(link, title); + } else if (requestCode == WikivoyageShowPicturesDialogFragment.SHOW_PICTURES_CHANGED) { + updateWebSettings(); + populateArticle(); + } + } + + @Override + public void onResume() { + super.onResume(); + OsmandSettings settings = getMyApplication().getSettings(); + if (!settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.get()) { + FragmentActivity activity = getActivity(); + FragmentManager fm = getFragmentManager(); + if (activity != null && fm != null) { + WikivoyageShowPicturesDialogFragment fragment = new WikivoyageShowPicturesDialogFragment(); + fragment.setTargetFragment(this, WikivoyageShowPicturesDialogFragment.SHOW_PICTURES_CHANGED); + fragment.show(fm, WikivoyageShowPicturesDialogFragment.TAG); + settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.set(true); + } } } @@ -153,9 +248,26 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen return nightMode ? R.color.status_bar_wikivoyage_article_dark : R.color.status_bar_wikivoyage_article_light; } + private void updateWebSettings() { + WikivoyageShowImages showImages = getSettings().WIKIVOYAGE_SHOW_IMAGES.get(); + WebSettings webSettings = contentWebView.getSettings(); + switch (showImages) { + case ON: + webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); + break; + case OFF: + webSettings.setCacheMode(WebSettings.LOAD_CACHE_ONLY); + break; + case WIFI: + webSettings.setCacheMode(getMyApplication().getSettings().isWifiConnected() ? + WebSettings.LOAD_DEFAULT : WebSettings.LOAD_CACHE_ONLY); + break; + } + } + private void updateSaveButton() { if (article != null) { - final WikivoyageLocalDataHelper helper = WikivoyageLocalDataHelper.getInstance(getMyApplication()); + 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)); @@ -213,30 +325,35 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen if (selectedLang == null) { selectedLang = langs.get(0); } - - article = getMyApplication().getWikivoyageDbHelper().getArticle(cityId, selectedLang); + articleToolbarText.setText(""); + article = getMyApplication().getTravelDbHelper().getArticle(cityId, selectedLang); if (article == null) { return; } + articleToolbarText.setText(article.getTitle()); + if(article.getGpxFile() != null) { + trackButton.setText(getString(R.string.points) + " (" + article.getGpxFile().getPointsSize() +")"); + } - WikivoyageLocalDataHelper.getInstance(getMyApplication()).addToHistory(article); + TravelLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper(); + ldh.addToHistory(article); updateSaveButton(); selectedLangTv.setText(Algorithms.capitalizeFirstLetter(selectedLang)); contentWebView.loadDataWithBaseURL(getBaseUrl(), createHtmlContent(article), "text/html", "UTF-8", null); } - private void moveToAnchor(String id) { - contentWebView.loadUrl("javascript:scrollAnchor(\"" + id + "\")"); + private void moveToAnchor(String id, String title) { + contentWebView.loadUrl("javascript:scrollAnchor(\"" + id + "\", \"" + title.trim() + "\")"); } @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("
"); } sb.append("
\n"); @@ -270,7 +387,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen @NonNull FragmentManager fm, long cityId, @Nullable String selectedLang) { - ArrayList langs = app.getWikivoyageDbHelper().getArticleLangs(cityId); + ArrayList langs = app.getTravelDbHelper().getArticleLangs(cityId); return showInstance(fm, cityId, langs, selectedLang); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageArticle.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java similarity index 98% rename from OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageArticle.java rename to OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java index 492021bfe7..14b2e9e482 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageArticle.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java @@ -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-"; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java similarity index 84% rename from OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java rename to OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index 659f8fea6a..532d807787 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -7,12 +7,16 @@ import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; import net.osmand.IndexConstants; import net.osmand.OsmAndCollator; +import net.osmand.PlatformUtil; +import net.osmand.plus.GPXUtilities; +import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.util.Algorithms; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -21,10 +25,14 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +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(TravelDbHelper.class); + private static final String ARTICLES_TABLE_NAME = "wikivoyage_articles"; private static final String ARTICLES_COL_ID = "article_id"; private static final String ARTICLES_COL_TITLE = "title"; @@ -67,16 +75,32 @@ public class WikivoyageDbHelper { private File selectedTravelBook = null; private List existingTravelBooks = new ArrayList<>(); private Collator collator; + private TravelLocalDataHelper localDataHelper; + 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) { + initTravelBooks(); + } + } + + public TravelLocalDataHelper getLocalDataHelper() { + initTravelBooks(); + return localDataHelper; } public void initTravelBooks() { + if(initialized) { + return; + } + initialized = true; File[] possibleFiles = application.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles(); String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get(); existingTravelBooks.clear(); + localDataHelper = new TravelLocalDataHelper(application); if (possibleFiles != null) { for (File f : possibleFiles) { if (f.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) { @@ -108,7 +132,17 @@ public class WikivoyageDbHelper { return connection; } - public void closeConnection() { + 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.refreshCachedData(); + } + } + + private void closeConnection() { if (connection != null) { connection.close(); connection = null; @@ -209,8 +243,8 @@ public class WikivoyageDbHelper { } @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 " @@ -263,41 +297,49 @@ public class WikivoyageDbHelper { } while (cursor.moveToNext()); } cursor.close(); - } return res; } @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); try { res.content = Algorithms.gzipToString(cursor.getBlob(2)); } catch (IOException e) { - e.printStackTrace(); + LOG.error(e.getMessage(), e); } res.isPartOf = cursor.getString(3); res.lat = cursor.getDouble(4); res.lon = cursor.getDouble(5); res.imageTitle = cursor.getString(6); - byte[] gpxFileBlob = cursor.getBlob(7); res.cityId = cursor.getLong(8); res.originalId = cursor.getLong(9); res.lang = cursor.getString(10); res.contentsJson = cursor.getString(11); res.aggregatedPartOf = cursor.getString(12); - + try { + String gpxContent = Algorithms.gzipToString(cursor.getBlob(7)); + res.gpxFile = GPXUtilities.loadGPXFile(application, new ByteArrayInputStream(gpxContent.getBytes("UTF-8"))); + } catch (IOException e) { + LOG.error(e.getMessage(), e); + } + return res; } public String formatTravelBookName(File tb) { - if(tb == null) { + if (tb == null) { return application.getString(R.string.shared_string_none); } String nm = tb.getName(); return nm.substring(0, nm.indexOf('.')).replace('_', ' '); } + + public String getGPXName(TravelArticle article) { + return article.getTitle().replace('/', '_').replace('\'', '_').replace('\"', '_') + ".gpx"; + } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java similarity index 87% rename from OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageLocalDataHelper.java rename to OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index 60184f4f67..86f1762493 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -14,16 +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 static WikivoyageLocalDataHelper instance; - private WikivoyageLocalDataDbHelper dbHelper; private TLongObjectHashMap historyMap; - private List savedArticles; + private List savedArticles; private Listener listener; @@ -31,17 +29,14 @@ public class WikivoyageLocalDataHelper { this.listener = listener; } - private WikivoyageLocalDataHelper(OsmandApplication app) { + TravelLocalDataHelper(OsmandApplication app) { dbHelper = new WikivoyageLocalDataDbHelper(app); - historyMap = dbHelper.getAllHistoryMap(); - savedArticles = dbHelper.getSavedArticles(); + refreshCachedData(); } - public static WikivoyageLocalDataHelper getInstance(OsmandApplication app) { - if (instance == null) { - instance = new WikivoyageLocalDataHelper(app); - } - return instance; + public void refreshCachedData() { + historyMap = dbHelper.getAllHistoryMap(); + savedArticles = dbHelper.getSavedArticles(); } public List getAllHistory() { @@ -65,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()); } @@ -95,13 +90,13 @@ public class WikivoyageLocalDataHelper { } @NonNull - public List getSavedArticles() { + public List 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; @@ -114,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); @@ -122,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); @@ -131,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; } @@ -142,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; } @@ -244,7 +239,6 @@ public class WikivoyageLocalDataHelper { conn.execSQL(BOOKMARKS_TABLE_CREATE); } - @SuppressWarnings("unused") private void onUpgrade(SQLiteConnection conn, int oldVersion, int newVersion) { if (oldVersion < 2) { conn.execSQL(BOOKMARKS_TABLE_CREATE); @@ -252,9 +246,11 @@ 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"); - Object[] args = new Object[]{context.getWikivoyageDbHelper().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); + 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); + } } } @@ -344,8 +340,8 @@ public class WikivoyageLocalDataHelper { } @NonNull - List getSavedArticles() { - List res = new ArrayList<>(); + List getSavedArticles() { + List res = new ArrayList<>(); SQLiteConnection conn = openConnection(true); if (conn != null) { try { @@ -357,6 +353,7 @@ public class WikivoyageLocalDataHelper { res.add(readSavedArticle(cursor)); } while (cursor.moveToNext()); } + cursor.close(); } finally { conn.close(); } @@ -364,7 +361,7 @@ public class WikivoyageLocalDataHelper { return res; } - void addSavedArticle(WikivoyageArticle article) { + void addSavedArticle(TravelArticle article) { SQLiteConnection conn = openConnection(false); if (conn != null) { try { @@ -378,7 +375,7 @@ public class WikivoyageLocalDataHelper { } } - void removeSavedArticle(WikivoyageArticle article) { + void removeSavedArticle(TravelArticle article) { SQLiteConnection conn = openConnection(false); if (conn != null) { try { @@ -406,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); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageJsonParser.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageJsonParser.java index 533cb511dc..db40a2ee7c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageJsonParser.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageJsonParser.java @@ -1,6 +1,7 @@ package net.osmand.plus.wikivoyage.data; import android.support.annotation.Nullable; +import android.util.Log; import org.json.JSONArray; import org.json.JSONException; @@ -11,6 +12,8 @@ import java.util.List; public class WikivoyageJsonParser { + private static final String TAG = WikivoyageJsonParser.class.getSimpleName(); + private static final String HEADERS = "headers"; private static final String SUBHEADERS = "subheaders"; private static final String LINK = "link"; @@ -25,7 +28,7 @@ public class WikivoyageJsonParser { reader = new JSONObject(contentsJson); jArray = reader.getJSONObject(HEADERS); } catch (JSONException e) { - e.printStackTrace(); + Log.e(TAG, e.getMessage(), e); return null; } @@ -37,22 +40,23 @@ public class WikivoyageJsonParser { WikivoyageContentItem headerItem = new WikivoyageContentItem(jArray.names().getString(i), link, topContentItem); topContentItem.subItems.add(headerItem); - JSONArray subheaders = header.getJSONArray(SUBHEADERS); + JSONObject subheaders = header.getJSONObject(SUBHEADERS); + JSONArray subNames = subheaders.names(); List subheaderNames = null; for (int j = 0; j < subheaders.length(); j++) { - JSONObject subheader = subheaders.getJSONObject(j); - JSONObject subheaderLink = subheader.getJSONObject(subheader.keys().next()); + String title = subNames.get(j).toString(); + JSONObject subheaderLink = subheaders.getJSONObject(title); if (subheaderNames == null) { subheaderNames = new ArrayList<>(); } - subheaderNames.add(subheader.keys().next()); + subheaderNames.add(title); link = subheaderLink.getString(LINK); - WikivoyageContentItem subheaderItem = new WikivoyageContentItem(subheader.names().getString(0), link, headerItem); + WikivoyageContentItem subheaderItem = new WikivoyageContentItem(title, link, headerItem); headerItem.subItems.add(subheaderItem); } } catch (JSONException e) { - e.printStackTrace(); + Log.e(TAG, e.getMessage(), e); } } return topContentItem; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java index 393d295fd5..f2d1277bf6 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java @@ -12,18 +12,19 @@ import android.widget.ImageView; import android.widget.TextView; import com.squareup.picasso.Callback; -import com.squareup.picasso.NetworkPolicy; import com.squareup.picasso.Picasso; import com.squareup.picasso.RequestCreator; import net.osmand.AndroidUtils; import net.osmand.plus.IconsCache; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.widgets.tools.CropCircleTransformation; import net.osmand.plus.widgets.tools.CropRectTransformation; -import net.osmand.plus.wikivoyage.data.WikivoyageArticle; -import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper; +import net.osmand.plus.wikivoyage.WikivoyageUtils; +import net.osmand.plus.wikivoyage.data.TravelArticle; +import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import java.util.ArrayList; import java.util.List; @@ -36,6 +37,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter items = new ArrayList<>(); @@ -50,7 +52,9 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter getItems() { List items = new ArrayList<>(); - List savedArticles = dataHelper.getSavedArticles(); + List savedArticles = dataHelper.getSavedArticles(); if (!savedArticles.isEmpty()) { Collections.reverse(savedArticles); items.add(getString(R.string.saved_articles)); @@ -121,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()); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java index c9197b8dfe..a4209ac0f2 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java @@ -1,93 +1,85 @@ package net.osmand.plus.wikivoyage.explore; -import java.io.File; -import java.util.List; - import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; -import android.content.Intent; -import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AlertDialog; -import android.support.v7.widget.AlertDialogLayout; +import android.support.v7.widget.PopupMenu; +import android.view.Gravity; +import android.view.MenuItem; import android.view.View; import android.webkit.WebView; -import android.widget.Toast; + import net.osmand.PicassoUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandSettings.WikivoyageShowImages; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; 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.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.WikivoyageLocalDataHelper; +import net.osmand.plus.wikivoyage.data.TravelDbHelper; +import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; + +import java.io.File; +import java.util.List; public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment"; - protected void selectTravelBookDialog() { - WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper(); - final List 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.setItems(ls, new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - Toast.makeText(getMyApplication(), list.get(which).getName(), Toast.LENGTH_LONG).show(); - - } - }); - builder.setNegativeButton(R.string.shared_string_dismiss, null); - builder.show(); - - } - @Override public void createMenuItems(Bundle savedInstanceState) { final OsmandApplication app = getMyApplication(); - final OsmandSettings.CommonPreference showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES; - final WikivoyageDbHelper dbHelper = app.getWikivoyageDbHelper(); + final OsmandSettings.CommonPreference showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES; + final TravelDbHelper dbHelper = app.getTravelDbHelper(); + 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() - .setDescription(dbHelper.formatTravelBookName(dbHelper.getSelectedTravelBook())) - .setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light) - .setTitle("Travel book") // TODO think & externalize - .setLayoutId(R.layout.bottom_sheet_item_with_right_descr) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - selectTravelBookDialog(); - dismiss(); - } - }) - .create(); + .setDescription(dbHelper.formatTravelBookName(dbHelper.getSelectedTravelBook())) + .setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light) + .setTitle(getString(R.string.shared_string_travel_book)) + .setLayoutId(R.layout.bottom_sheet_item_with_right_descr) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + selectTravelBookDialog(); + dismiss(); + } + }) + .create(); items.add(selectTravelBook); - } - BaseBottomSheetItem showImagesItem = new BottomSheetItemWithCompoundButton.Builder() - .setChecked(showImagesPref.get()) + BaseBottomSheetItem showImagesItem = new BottomSheetItemWithDescription.Builder() + .setDescription(getString(showImagesPref.get().name)) + .setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light) .setIcon(getContentIcon(R.drawable.ic_type_img)) - .setTitle(getString(R.string.show_images)) - .setLayoutId(R.layout.bottom_sheet_item_with_switch) + .setTitle(getString(R.string.download_images)) + .setLayoutId(R.layout.bottom_sheet_item_with_right_descr) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - showImagesPref.set(!showImagesPref.get()); - dismiss(); + + final PopupMenu popup = new PopupMenu(v.getContext(), v, Gravity.END); + for (final WikivoyageShowImages showImages : WikivoyageShowImages.values()) { + MenuItem item = popup.getMenu().add(getString(showImages.name)); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + showImagesPref.set(showImages); + dismiss(); + return true; + } + }); + } + + popup.show(); } }) .create(); @@ -118,7 +110,8 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - WikivoyageLocalDataHelper.getInstance(app).clearHistory(); + TravelLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper(); + ldh.clearHistory(); dismiss(); } }) @@ -126,5 +119,23 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD items.add(clearHistoryItem); } - + protected void selectTravelBookDialog() { + final TravelDbHelper dbHelper = getMyApplication().getTravelDbHelper(); + final List 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(); + } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java index 300af389b0..8811b3c203 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java @@ -19,7 +19,8 @@ import com.squareup.picasso.RequestCreator; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.widgets.tools.CropCircleTransformation; -import net.osmand.plus.wikivoyage.data.WikivoyageArticle; +import net.osmand.plus.wikivoyage.WikivoyageUtils; +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; @@ -76,10 +77,8 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter items) { if (items == null || items.isEmpty()) { - adapter.setHistoryItems(WikivoyageLocalDataHelper - .getInstance(getMyApplication()).getAllHistory()); + TravelLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper(); + adapter.setHistoryItems(ldh.getAllHistory()); } else { adapter.setItems(items); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchHelper.java index c5359c0e5d..147cfbd91e 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchHelper.java @@ -42,7 +42,7 @@ public class WikivoyageSearchHelper { } if (!isCancelled()) { - List results = application.getWikivoyageDbHelper().search(query); + List results = application.getTravelDbHelper().search(query); if (!isCancelled()) { rm.publish(results); } diff --git a/OsmAndCore-sample/build.gradle b/OsmAndCore-sample/build.gradle index f525174904..6ed7085f94 100644 --- a/OsmAndCore-sample/build.gradle +++ b/OsmAndCore-sample/build.gradle @@ -118,18 +118,18 @@ repositories { } dependencies { - compile project(path: ':OsmAnd-java', configuration: 'android') + implementation project(path: ':OsmAnd-java', configuration: 'android') - compile 'com.android.support:multidex:1.0.1' - compile 'com.android.support:appcompat-v7:27.1.0' - compile 'com.android.support:design:27.1.0' - compile 'commons-logging:commons-logging-api:1.1' - compile 'com.moparisthebest:junidecode:0.1.1' + implementation 'com.android.support:multidex:1.0.1' + implementation 'com.android.support:appcompat-v7:27.1.0' + implementation 'com.android.support:design:27.1.0' + implementation 'commons-logging:commons-logging-api:1.1' + implementation 'com.moparisthebest:junidecode:0.1.1' - compile fileTree(include: ['gnu-trove-osmand.jar', 'icu4j-49_1_patched.jar'], dir: 'libs') + implementation fileTree(include: ['gnu-trove-osmand.jar', 'icu4j-49_1_patched.jar'], dir: 'libs') - compile "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@aar" - debugCompile "net.osmand:OsmAndCore_androidNativeRelease:0.1-SNAPSHOT@aar" - nativeDebugCompile "net.osmand:OsmAndCore_androidNativeDebug:0.1-SNAPSHOT@aar" - releaseCompile "net.osmand:OsmAndCore_androidNativeRelease:0.1-SNAPSHOT@aar" + implementation "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@aar" + debugImplementation "net.osmand:OsmAndCore_androidNativeRelease:0.1-SNAPSHOT@aar" + nativeDebugImplementation "net.osmand:OsmAndCore_androidNativeDebug:0.1-SNAPSHOT@aar" + releaseImplementation "net.osmand:OsmAndCore_androidNativeRelease:0.1-SNAPSHOT@aar" } diff --git a/OsmAndCore-sample/project.properties b/OsmAndCore-sample/project.properties index 18f58d43e3..7a2e361782 100644 --- a/OsmAndCore-sample/project.properties +++ b/OsmAndCore-sample/project.properties @@ -14,3 +14,7 @@ android.library.reference.12=aarDependencies/com.android.support-transition-27.1 android.library.reference.13=aarDependencies/com.android.support-recyclerview-v7-27.1.0 android.library.reference.14=aarDependencies/net.osmand-OsmAndCore_android-0.1-SNAPSHOT android.library.reference.15=aarDependencies/net.osmand-OsmAndCore_androidNativeRelease-0.1-SNAPSHOT +android.library.reference.16=aarDependencies/com.android.support-multidex-1.0.1 +android.library.reference.17=aarDependencies/android.arch.lifecycle-viewmodel-1.1.0 +android.library.reference.18=aarDependencies/android.arch.lifecycle-livedata-core-1.1.0 +android.library.reference.19=aarDependencies/android.arch.core-runtime-1.1.0 diff --git a/build.gradle b/build.gradle index 825da98acf..a96af76236 100644 --- a/build.gradle +++ b/build.gradle @@ -13,9 +13,10 @@ buildscript { classpath 'com.github.ksoichiro:gradle-eclipse-aar-plugin:0.3.1' } } -apply plugin: 'com.github.ksoichiro.eclipse.aar' +apply plugin: 'com.github.ksoichiro.eclipse.aar' allprojects { + repositories { mavenCentral() maven {