Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-04-15 19:00:44 +02:00
commit 4b991ff1cb
42 changed files with 858 additions and 340 deletions

View file

@ -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$

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="com.android.ide.eclipse.adt.PreCompilerBuilder"/>
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="com.android.ide.eclipse.adt.ResourceManagerBuilder"/>
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="org.eclipse.cdt.managedbuilder.core.genmakebuilder"/>
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS">
<mapEntry key="?children?" value="?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|\||"/>
<mapEntry key="?name?" value=""/>
<mapEntry key="org.eclipse.cdt.make.core.append_environment" value="true"/>
<mapEntry key="org.eclipse.cdt.make.core.buildArguments" value="${ANDROID_NDK}/ndk-build"/>
<mapEntry key="org.eclipse.cdt.make.core.buildCommand" value="sh"/>
<mapEntry key="org.eclipse.cdt.make.core.cleanBuildTarget" value="clean"/>
<mapEntry key="org.eclipse.cdt.make.core.contents" value="org.eclipse.cdt.make.core.activeConfigSettings"/>
<mapEntry key="org.eclipse.cdt.make.core.enableAutoBuild" value="false"/>
<mapEntry key="org.eclipse.cdt.make.core.enableCleanBuild" value="false"/>
<mapEntry key="org.eclipse.cdt.make.core.enableFullBuild" value="false"/>
<mapEntry key="org.eclipse.cdt.make.core.fullBuildTarget" value="V=1"/>
<mapEntry key="org.eclipse.cdt.make.core.stopOnError" value="true"/>
<mapEntry key="org.eclipse.cdt.make.core.useDefaultBuildCmd" value="false"/>
</mapAttribute>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>

2
OsmAnd/.gitignore vendored
View file

@ -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/

View file

@ -7,71 +7,33 @@
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers></triggers>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>?children?</key>
<value>?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|\||</value>
</dictionary>
<dictionary>
<key>?name?</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.append_environment</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildArguments</key>
<value>${ANDROID_NDK}/ndk-build</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildCommand</key>
<value>sh</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
<value>clean</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.contents</key>
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
<value>V=1</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.stopOnError</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
<value>false</value>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/org.eclipse.cdt.managedbuilder.core.genmakebuilder.launch</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/com.android.ide.eclipse.adt.ResourceManagerBuilder.launch</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/com.android.ide.eclipse.adt.PreCompilerBuilder.launch</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>

47
OsmAnd/assets/article_style.css Normal file → Executable file
View file

@ -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%;

View file

@ -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'
}
}

View file

@ -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

View file

@ -1,14 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="?attr/wikivoyage_bg_color"
android:orientation="vertical">
@ -26,8 +23,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/article_toolbar_text"
android:layout_width="0dp"
android:gravity="center_vertical"
android:textSize="@dimen/dialog_header_text_size"
android:ellipsize="end"
osmand:typeface="@string/font_roboto_medium"
android:layout_height="match_parent"
android:layout_weight="1"/>
@ -55,13 +57,22 @@
</android.support.v7.widget.Toolbar>
<FrameLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
<WebView
android:id="@+id/content_web_view"
android:id="@+id/content_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
android:layout_gravity="bottom"
android:layout_height="10dp"
android:background="@drawable/bg_contextmenu_shadow_top_light" />
</FrameLayout>
<LinearLayout
android:id="@+id/bottom_bar"
android:layout_width="match_parent"
@ -69,10 +80,7 @@
android:layout_gravity="bottom|center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@drawable/bg_contextmenu_shadow_top_light" />
<LinearLayout
android:layout_width="match_parent"
@ -84,7 +92,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="0.5"
android:layout_weight="0.33"
android:background="?attr/selectableItemBackground"
android:drawablePadding="@dimen/bottom_sheet_content_padding_small"
android:ellipsize="end"
@ -102,13 +110,38 @@
tools:drawableLeft="@drawable/ic_action_list_header"
tools:drawableTint="?attr/wikivoyage_active_color"
tools:ignore="UnusedAttribute" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/gpx_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="0.33"
android:background="?attr/selectableItemBackground"
android:drawablePadding="@dimen/bottom_sheet_content_padding_small"
android:ellipsize="end"
android:gravity="center_vertical"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1"
android:paddingBottom="@dimen/context_menu_padding_margin_tiny"
android:paddingLeft="@dimen/bottom_sheet_content_margin"
android:paddingRight="@dimen/bottom_sheet_content_padding_small"
android:paddingTop="@dimen/context_menu_padding_margin_tiny"
android:text="@string/points"
android:textColor="?attr/wikivoyage_active_color"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:drawableLeft="@drawable/ic_action_track_16"
tools:drawableTint="?attr/wikivoyage_active_color"
tools:ignore="UnusedAttribute" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/save_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|end"
android:layout_weight="1"
android:layout_weight="0.34"
android:background="?attr/selectableItemBackground"
android:drawablePadding="@dimen/bottom_sheet_content_padding_small"
android:ellipsize="end"
@ -131,4 +164,4 @@
</LinearLayout>
</FrameLayout>
</LinearLayout>

View file

@ -0,0 +1,109 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_gravity="bottom"
android:background="?attr/bottom_menu_view_bg"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_weight="1"
android:paddingTop="22dp"
android:paddingLeft="@dimen/list_content_padding"
android:paddingStart="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:text="@string/wikivoyage_download_pics"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
android:textSize="@dimen/dialog_header_text_size"/>
</LinearLayout>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_marginBottom="@dimen/dialog_content_margin"
android:layout_marginTop="@dimen/list_header_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingStart="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:text="@string/wikivoyage_download_pics_descr"
android:textSize="16sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/list_header_padding"
android:paddingStart="@dimen/list_header_padding"
android:paddingRight="@dimen/list_header_padding"
android:paddingEnd="@dimen/list_header_padding"
android:paddingBottom="@dimen/list_header_padding"
android:orientation="horizontal">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_no"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/ctx_menu_controller_bg"
android:gravity="center"
android:padding="@dimen/context_menu_button_padding_x"
android:layout_marginRight="@dimen/list_header_padding"
android:layout_marginEnd="@dimen/list_header_padding"
osmand:typeface="@string/font_roboto_regular"
android:textSize="@dimen/default_list_text_size"
android:textColor="?attr/ctx_menu_controller_text_color"
android:text="@string/shared_string_dont"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_wifi"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/ctx_menu_controller_bg"
android:gravity="center"
android:padding="@dimen/context_menu_button_padding_x"
android:layout_marginRight="@dimen/list_header_padding"
android:layout_marginEnd="@dimen/list_header_padding"
osmand:typeface="@string/font_roboto_regular"
android:textSize="@dimen/default_list_text_size"
android:textColor="?attr/ctx_menu_controller_text_color"
android:text="@string/shared_string_only_with_wifi"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_yes"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/ctx_menu_controller_bg"
android:gravity="center"
android:padding="@dimen/context_menu_button_padding_x"
osmand:typeface="@string/font_roboto_regular"
android:textSize="@dimen/default_list_text_size"
android:textColor="?attr/ctx_menu_controller_text_color"
android:text="@string/shared_string_do"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -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" />

View file

@ -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
-->
<string name="shared_string_dont">Don\'t</string>
<string name="shared_string_do">Do</string>
<string name="shared_string_only_with_wifi">Only with WiFi</string>
<string name="wikivoyage_download_pics">Download Pictures</string>
<string name="wikivoyage_download_pics_descr">We can download &amp; 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.</string>
<string name="shared_string_wifi_only">Only WiFi</string>
<string name="select_travel_book">Select travel book</string>
<string name="shared_string_travel_book">Travel book</string>
<string name="online_webpage_warning">This page is only available online. Do you wish to open it in a web browser?</string>
<string name="images_cache">Images cache</string>
<string name="delete_search_history">Delete search history</string>
<string name="show_images">Show images</string>
<string name="download_images">Download images</string>
<string name="download_maps_travel">Travel maps</string>
<string name="shared_string_wikivoyage">Wikivoyage</string>
<string name="article_removed">Article removed</string>

View file

@ -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();
}

View file

@ -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 {

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.TravelArticle;
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<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()));
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

@ -717,7 +717,8 @@ public class OsmandSettings {
public final CommonPreference<Boolean> SHOW_LINES_TO_FIRST_MARKERS = new BooleanPreference("show_lines_to_first_markers", false).makeProfile();
public final CommonPreference<Boolean> SHOW_ARROWS_TO_FIRST_MARKERS = new BooleanPreference("show_arrows_to_first_markers", false).makeProfile();
public final CommonPreference<Boolean> WIKIVOYAGE_SHOW_IMAGES = new BooleanPreference("wikivoyage_show_images", false);
public final CommonPreference<Boolean> WIKIVOYAGE_SHOW_IMAGES_ASKED = new BooleanPreference("wikivoyage_show_images_asked", false).makeGlobal();
public final CommonPreference<WikivoyageShowImages> WIKIVOYAGE_SHOW_IMAGES = new EnumIntPreference<>("wikivoyage_show_imgs", WikivoyageShowImages.OFF, WikivoyageShowImages.values()).makeGlobal();
public final CommonPreference<Boolean> 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;
}
}
}

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

@ -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 {

View file

@ -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();
}

View file

@ -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;
}

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

@ -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,

View file

@ -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);
}
}
}

View file

@ -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;
}
}
}

View file

@ -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

View file

@ -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);

View file

@ -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
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n" +
"<meta http-equiv=\"cleartype\" content=\"on\" />\n" +
"<link href=\"article_style.css\" type=\"text/css\" rel=\"stylesheet\"/>\n" +
"</head><body>\n" + "<script>" + "function scrollAnchor(id) {" +
"window.location.hash = id;}</script>";
private static final String FOOTER_INNER = "</div></body></html>";
"</head><body>\n";
private static final String FOOTER_INNER = "<script>var coll = document.getElementsByTagName(\"H2\");" +
"var i;" +
"for (i = 0; i < coll.length; i++) {" +
" coll[i].addEventListener(\"click\", function() {" +
" this.classList.toggle(\"active\");" +
" var content = this.nextElementSibling;" +
" if (content.style.display === \"block\") {" +
" content.style.display = \"none\";" +
" } else {" +
" content.style.display = \"block\";" +
" }" +
" });" +
"}" + "function scrollAnchor(id, title) {" +
"openContent(title);" +
"window.location.hash = id;}\n" +
"function openContent(id) {\n" +
" var doc = document.getElementById(id).parentElement;\n" +
" doc.classList.toggle(\"active\");\n" +
" var content = doc.nextElementSibling;\n" +
" content.style.display = \"block\";\n" +
" collapseActive(doc);" +
"}" +
"function collapseActive(doc) {" +
" var coll = document.getElementsByTagName(\"H2\");" +
" var i;" +
" for (i = 0; i < coll.length; i++) {" +
" var item = coll[i];" +
" if (item != doc && item.classList.contains(\"active\")) {" +
" item.classList.toggle(\"active\");" +
" var content = item.nextElementSibling;" +
" if (content.style.display === \"block\") {" +
" content.style.display = \"none\";" +
" }" +
" }" +
" }" +
"}</script>"
+ "</body></html>";
private long cityId = NO_VALUE;
private ArrayList<String> 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("<div class=\"title-image\" style=\"background-image: url(").append(url).append(")\"></div>");
}
sb.append("<div class=\"main\">\n");
@ -270,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

@ -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

@ -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<File> 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";
}
}

View file

@ -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<WikivoyageSearchHistoryItem> historyMap;
private List<WikivoyageArticle> savedArticles;
private List<TravelArticle> 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<WikivoyageSearchHistoryItem> 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<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;
@ -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<WikivoyageArticle> getSavedArticles() {
List<WikivoyageArticle> res = new ArrayList<>();
List<TravelArticle> getSavedArticles() {
List<TravelArticle> 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);

View file

@ -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<String> 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;

View file

@ -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<RecyclerView.Vi
private static final boolean USE_ALTERNATIVE_CARD = false;
private final OsmandApplication app;
private final OsmandSettings settings;
private final List<Object> items = new ArrayList<>();
@ -50,7 +52,9 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
SavedArticlesRvAdapter(OsmandApplication app) {
this.app = app;
int colorId = app.getSettings().isLightContent()
this.settings = app.getSettings();
int colorId = settings.isLightContent()
? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark;
IconsCache ic = app.getIconsCache();
readIcon = ic.getIcon(R.drawable.ic_action_read_article, colorId);
@ -76,13 +80,11 @@ 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));
if (!app.getSettings().WIKIVOYAGE_SHOW_IMAGES.get()) {
rc.networkPolicy(NetworkPolicy.OFFLINE);
}
.load(TravelArticle.getImageUrl(article.getImageTitle(), false));
WikivoyageUtils.setupNetworkPolicy(settings, rc);
rc.transform(USE_ALTERNATIVE_CARD ? new CropRectTransformation() : new CropCircleTransformation())
.into(holder.icon, new Callback() {
@Override
@ -172,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);
}
}
}
@ -187,14 +189,15 @@ 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;
WikivoyageLocalDataHelper.getInstance(app).removeArticleFromSaved(article);
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() {
@Override
public void onClick(View view) {
WikivoyageLocalDataHelper.getInstance(app).restoreSavedArticle(article);
ldh.restoreSavedArticle(article);
}
});
AndroidUtils.setSnackbarTextColor(snackbar, R.color.wikivoyage_active_dark);
@ -215,6 +218,6 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
}
interface Listener {
void openArticle(WikivoyageArticle article);
void openArticle(TravelArticle article);
}
}

View file

@ -11,20 +11,25 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndFragment;
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;
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 {
private WikivoyageLocalDataHelper dataHelper;
protected static final Log LOG = PlatformUtil.getLog(SavedArticlesTabFragment.class);
private TravelLocalDataHelper dataHelper;
private SavedArticlesRvAdapter adapter;
@ -32,14 +37,14 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Wiki
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
dataHelper = WikivoyageLocalDataHelper.getInstance(app);
dataHelper = app.getTravelDbHelper().getLocalDataHelper();
final View mainView = inflater.inflate(R.layout.fragment_saved_articles_tab, container, false);
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());
@ -79,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));
@ -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());
}

View file

@ -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<File> list = dbHelper.getExistingTravelBooks();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
String[] ls = new String[list.size()];
for (int i = 0; i < ls.length; i++) {
ls[i] = dbHelper.formatTravelBookName(list.get(i));
}
builder.setTitle("Select travel book"); // TODO externalize
builder.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<Boolean> showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES;
final WikivoyageDbHelper dbHelper = app.getWikivoyageDbHelper();
final OsmandSettings.CommonPreference<WikivoyageShowImages> 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<File> 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();
}
}

View file

@ -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<RecyclerView
if (item instanceof WikivoyageSearchResult) {
WikivoyageSearchResult searchRes = (WikivoyageSearchResult) item;
RequestCreator rc = Picasso.get()
.load(WikivoyageArticle.getImageUrl(searchRes.getImageTitle(), true));
if (!app.getSettings().WIKIVOYAGE_SHOW_IMAGES.get()) {
rc.networkPolicy(NetworkPolicy.OFFLINE);
}
.load(TravelArticle.getImageUrl(searchRes.getImageTitle(), true));
WikivoyageUtils.setupNetworkPolicy(app.getSettings(), rc);
rc.transform(new CropCircleTransformation())
.placeholder(placeholder)
.into(holder.icon);

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,8 +147,8 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
private void setAdapterItems(@Nullable List<WikivoyageSearchResult> items) {
if (items == null || items.isEmpty()) {
adapter.setHistoryItems(WikivoyageLocalDataHelper
.getInstance(getMyApplication()).getAllHistory());
TravelLocalDataHelper 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);
}

View file

@ -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"
}

View file

@ -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

View file

@ -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 {