Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-05-04 20:36:17 +02:00
commit 2102882a8e
63 changed files with 1117 additions and 282 deletions

View file

@ -242,7 +242,8 @@ p {
color: var(--main-text-color-night);
}
ul, dl {
/* Lists */
ul, dl, ol {
/* font-size: var(--main-text-font-size); */
color: var(--main-text-color-day);
font-size: inherit;
@ -259,15 +260,10 @@ li {
padding-bottom: 1%;
}
.nightmode ul, .nightmode dl {
.nightmode ul, .nightmode dl, .nightmode ol {
color: #cccccc;
}
.toc {
font-size: var(--main-text-font-size);
}
img {
width: 100%;
}
@ -327,17 +323,63 @@ a.geo {
text-decoration: none;
display: inline-block;
}
td {
display: inline-block;
/* Tables */
table {
display: block;
overflow-y: scroll;
word-wrap: break-word;
color: var(--main-text-color-day);
border: 1px solid var(--divider-color-day);
background: var(--divider-color-day);
margin-left: 0% !important;
margin-right: 0% !important;
margin-bottom: 7% !important;
font-size: inherit;
}
.nightmode table {
color: var(--main-text-color-night);
border: 1px solid var(--background-color-night);
background: var(--divider-color-night) !important;
}
td, tr, th {
border: 1px solid var(--divider-color-day);
color: var(--main-text-color-night);
background: var(--divider-color-day);
}
.nightmode td, .nightmode tr, .nightmode th {
color: var(--main-text-color-night);
border: 1px solid var(--background-color-night);
background: var(--divider-color-night) !important;
}
.toc, .toc td, .toc tr {
border: 0px solid;
background: var(--background-color-day);
}
.nightmode .toc, .toc td, .toc tr {
border: 0px solid;
background: var(--background-color-night) !important;
}
.thumb-tright, .thumbinner {
width: 100% !important;
}
.thumbnailcaption {
.thumbnailcaption, thumbcaption {
padding-top: 3%;
width: 100%;
font-size: var(--main-text-font-size);
color: var(--description-text-color);
font-style: italic;
text-align: center;
}
.nightmode .thumbnailcaption, .nightmode .thumbcaption {
padding-top: 3%;
width: 100%;
font-size: var(--main-text-font-size);
@ -353,7 +395,7 @@ hr {
background-color: var(--divider-color-day);
}
.nighmode hr {
.nightmode hr {
border: none;
height: 1px;
color: var(--divider-color-night);

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<inset>
<shape android:shape="oval">
<solid android:color="@color/dialog_bg_color_light"/>
</shape>
</inset>
</item>
</layer-list>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<inset>
<shape android:shape="oval">
<solid android:color="@color/dialog_bg_color_night"/>
</shape>
</inset>
</item>
</layer-list>

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:minHeight="@dimen/bottom_sheet_descr_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
tools:text="Some long description"/>

View file

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:background="?attr/dialog_transparent_bg_color"
android:clickable="true"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/button_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="@dimen/list_content_padding">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/button_close_img"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:background="?attr/circle_dialog_bg"
android:src="@drawable/ic_action_remove_small"
android:tint="@color/icon_color"/>
</FrameLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/title_padding"
android:layout_marginTop="@dimen/list_header_padding"
android:src="@drawable/img_help_osmand_live"/>
</FrameLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/list_content_padding_large"
android:layout_marginRight="@dimen/list_content_padding_large"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/title_padding"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/purchase_cancelled_dialog_title"
android:textColor="?attr/dialog_title_color"
android:textSize="@dimen/dialog_header_text_size"
osmand:typeface="@string/font_roboto_medium"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/info_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/title_padding"
android:textColor="?attr/dialog_text_description_color"
android:textSize="@dimen/default_list_text_size"
android:lineSpacingMultiplier="@dimen/text_button_line_spacing_multiplier"
osmand:typeface="@string/font_roboto_regular"
tools:text="@string/purchase_cancelled_dialog_descr"/>
</LinearLayout>
<LinearLayout
android:id="@+id/cards_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/inapp_descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/list_content_padding_large"
android:layout_marginRight="@dimen/list_content_padding_large"
android:layout_marginTop="@dimen/list_header_padding"
android:gravity="center"
android:text="@string/osm_live_payment_desc"
android:textColor="?attr/card_description_text_color"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_padding"
android:layout_marginTop="@dimen/card_padding">
<include layout="@layout/purchase_dialog_card_button"/>
</FrameLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>

View file

@ -76,6 +76,7 @@
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="@dimen/bottom_sheet_divider_margin_start"

View file

@ -28,14 +28,13 @@
osmand:typeface="@string/font_roboto_medium"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="@dimen/text_button_line_spacing_multiplier"
android:text="@string/maps_you_need_descr"
android:textColor="@color/wikivoyage_secondary_text"
android:textSize="@dimen/travel_card_primary_text_size"
osmand:typeface="@string/font_roboto_regular"
tools:text="@string/maps_you_need_descr"/>
osmand:typeface="@string/font_roboto_regular"/>
</LinearLayout>

View file

@ -54,6 +54,15 @@
tools:text="En"
tools:textColor="?attr/wikivoyage_active_color" />
<android.support.v7.widget.AppCompatImageView
android:id="@+id/options_button"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="48dp"
android:layout_height="match_parent"
android:layout_gravity="top"
android:contentDescription="@string/shared_string_options"
tools:src="@drawable/ic_overflow_menu_white"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>

View file

@ -65,8 +65,12 @@
<attr name="primary_icon_color" format="color"/>
<attr name="light_icon_color" format="color"/>
<attr name="circle_dialog_bg" format="reference"/>
<attr name="dialog_bg_color" format="reference"/>
<attr name="dialog_transparent_bg_color" format="reference"/>
<attr name="dialog_title_color" format="reference"/>
<attr name="dialog_description_color" format="reference"/>
<attr name="dialog_text_description_color" format="reference"/>
<attr name="card_description_text_color" format="reference"/>
<attr name="wikivoyage_bg_color" format="reference"/>

View file

@ -3,6 +3,11 @@
<color name="feature_purchased_bg">#78cc5c</color>
<color name="dialog_bg_color_light">#f0f0f0</color>
<color name="dialog_bg_color_night">#17191a</color>
<color name="dialog_transparent_bg_color_light">#14f0f0f0</color>
<color name="dialog_transparent_bg_color_night">#1417191a</color>
<color name="dialog_title_color_light">#212121</color>
<color name="dialog_title_color_dark">#cccccc</color>
<color name="dialog_description_color_light">#212121</color>
@ -10,6 +15,7 @@
<color name="dialog_divider_light">#e6e6e6</color>
<color name="dialog_divider_dark">#2d3133</color>
<color name="dialog_text_description_color">#727272</color>
<color name="dialog_text_description_color_night">#808080</color>
<color name="card_description_text_color_light">#b3b3b3</color>
<color name="card_description_text_color_dark">#4d4d4d</color>
@ -432,4 +438,7 @@
<color name="wikivoyage_start_editing_card_image_background">#339966</color>
<color name="wikivoyage_open_beta_card_image_background">#008bf8</color>
<color name="wiki_webview_background_light">#ffffff</color>
<color name="wiki_webview_background_dark">#17191a</color>
</resources>

View file

@ -9,7 +9,12 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="maps_you_need_descr">You read articles: %1$s. Based on this, we suggest you download these maps:</string>
<string name="shared_string_restart">Restart</string>
<string name="show_images">Show images</string>
<string name="purchase_cancelled_dialog_title">You have cancel OsmAnd Live subscription</string>
<string name="purchase_cancelled_dialog_descr">Renew subscription to continue use the all features:</string>
<string name="maps_you_need_descr">Based on the articles you saved, we recommend you to download following maps:</string>
<string name="maps_you_need">Maps you need</string>
<string name="osmand_team">OsmAnd team</string>
<string name="popular_destinations">Popular destinations</string>
@ -669,12 +674,12 @@
<string name="osm_live_hide_user_name">Do not show my name in reports</string>
<string name="osm_live_support_region">Support region</string>
<string name="osm_live_month_cost">Month cost</string>
<string name="osm_live_month_cost_desc">Monthly payment.</string>
<string name="osm_live_month_cost_desc">Monthly payment</string>
<string name="osm_live_active">Active</string>
<string name="osm_live_not_active">Inactive</string>
<string name="osm_live_enter_email">Please enter a valid e-mail address</string>
<string name="osm_live_enter_user_name">Please enter public name</string>
<string name="osm_live_thanks">Thank you for subscribing to live updates</string>
<string name="osm_live_thanks">Thank you for supporting OsmAnd!\nTo activate all new features you need to restart OsmAnd.</string>
<string name="osm_live_region_desc">Part of your donation will be sent to OSM users who submit changes to the map in that region.</string>
<string name="osm_live_subscription_settings">Subscription settings</string>
<string name="osm_live_ask_for_purchase">Please purchase a subscription to OsmAnd Live first</string>

View file

@ -179,6 +179,7 @@
<item name="android:actionMenuTextColor">@color/color_white</item>
<item name="actionOverflowButtonStyle">@style/OverflowMenuButton</item>
<item name="circle_dialog_bg">@drawable/circle_dialog_bg_light</item>
<item name="dialog_inactive_text_color">@color/icon_color_light</item>
<item name="secondary_icon_color">@color/icon_color_light</item>
<item name="primary_icon_color">@color/icon_color</item>
@ -197,8 +198,11 @@
<item name="coordinate_input_edit_text_normal">@color/coordinate_input_edit_text_normal_light</item>
<item name="dialog_bg_color">@color/dialog_bg_color_light</item>
<item name="dialog_transparent_bg_color">@color/dialog_transparent_bg_color_light</item>
<item name="dialog_title_color">@color/dialog_title_color_light</item>
<item name="dialog_description_color">@color/dialog_description_color_light</item>
<item name="dialog_text_description_color">@color/dialog_text_description_color</item>
<item name="card_description_text_color">@color/card_description_text_color_light</item>
<item name="wikivoyage_bg_color">@color/wikivoyage_bg_light</item>
@ -405,8 +409,12 @@
<item name="coordinate_input_edit_text_normal">@color/coordinate_input_edit_text_normal_dark</item>
<item name="circle_dialog_bg">@drawable/circle_dialog_bg_night</item>
<item name="dialog_bg_color">@color/dialog_bg_color_night</item>
<item name="dialog_transparent_bg_color">@color/dialog_transparent_bg_color_night</item>
<item name="dialog_title_color">@color/dialog_title_color_dark</item>
<item name="dialog_description_color">@color/dialog_description_color_dark</item>
<item name="dialog_text_description_color">@color/dialog_text_description_color_night</item>
<item name="card_description_text_color">@color/card_description_text_color_dark</item>
<item name="wikivoyage_bg_color">@color/wikivoyage_bg_dark</item>

View file

@ -7,6 +7,7 @@ import java.util.Map;
import android.app.Activity;
import android.media.AudioManager;
import android.media.SoundPool;
import android.support.annotation.NonNull;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -29,7 +30,7 @@ public class AccessibilityPlugin extends OsmandPlugin {
}
@Override
public boolean init(final OsmandApplication app, Activity activity) {
public boolean init(@NonNull final OsmandApplication app, Activity activity) {
sounds = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
if (sounds != null) {
soundIcons.put(DIRECTION_NOTIFICATION, loadSoundIcon("sounds/direction_notification.ogg"));

View file

@ -876,10 +876,8 @@ public class OsmandApplication extends MultiDexApplication {
public void logEvent(Activity ctx, String event) {
try {
if (Version.isGooglePlayEnabled(this) && Version.isFreeVersion(this)
&& !osmandSettings.DO_NOT_SEND_ANONYMOUS_APP_USAGE.get()
&& !InAppPurchaseHelper.isFullVersionPurchased(this)
&& !InAppPurchaseHelper.isSubscribedToLiveUpdates(this)) {
if (Version.isGooglePlayEnabled(this) && !Version.isPaidVersion(this)
&& !osmandSettings.DO_NOT_SEND_ANONYMOUS_APP_USAGE.get()) {
Class<?> cl = Class.forName("com.google.firebase.analytics.FirebaseAnalytics");
Method mm = cl.getMethod("getInstance", Context.class);
Object inst = mm.invoke(null, ctx == null ? this : ctx);

View file

@ -9,6 +9,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
@ -21,6 +22,7 @@ import net.osmand.plus.activities.TabActivity.TabItem;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.mapillary.MapillaryPlugin;
@ -73,7 +75,7 @@ public abstract class OsmandPlugin {
/**
* Initialize plugin runs just after creation
*/
public boolean init(OsmandApplication app, Activity activity) {
public boolean init(@NonNull OsmandApplication app, @Nullable Activity activity) {
return true;
}
@ -127,7 +129,7 @@ public abstract class OsmandPlugin {
public void clearContextMenuRows() {
}
public static void initPlugins(OsmandApplication app) {
public static void initPlugins(@NonNull OsmandApplication app) {
OsmandSettings settings = app.getSettings();
Set<String> enabledPlugins = settings.getEnabledPlugins();
@ -136,15 +138,15 @@ public abstract class OsmandPlugin {
allPlugins.add(new OsmandRasterMapsPlugin(app));
allPlugins.add(new OsmandMonitoringPlugin(app));
checkMarketPlugin(app, new SRTMPlugin(app), true, SRTM_PLUGIN_COMPONENT_PAID, SRTM_PLUGIN_COMPONENT);
checkMarketPlugin(app, enabledPlugins, new SRTMPlugin(app), true, SRTM_PLUGIN_COMPONENT_PAID, SRTM_PLUGIN_COMPONENT);
// ? questionable - definitely not market plugin
// checkMarketPlugin(app, new TouringViewPlugin(app), false, TouringViewPlugin.COMPONENT, null);
checkMarketPlugin(app, new NauticalMapsPlugin(app), false, NauticalMapsPlugin.COMPONENT, null);
checkMarketPlugin(app, new SkiMapsPlugin(app), false, SkiMapsPlugin.COMPONENT, null);
// checkMarketPlugin(app, enabledPlugins, new TouringViewPlugin(app), false, TouringViewPlugin.COMPONENT, null);
checkMarketPlugin(app, enabledPlugins, new NauticalMapsPlugin(app), false, NauticalMapsPlugin.COMPONENT, null);
checkMarketPlugin(app, enabledPlugins, new SkiMapsPlugin(app), false, SkiMapsPlugin.COMPONENT, null);
allPlugins.add(new AudioVideoNotesPlugin(app));
checkMarketPlugin(app, new ParkingPositionPlugin(app), false, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null);
checkMarketPlugin(app, enabledPlugins, new ParkingPositionPlugin(app), false, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null);
allPlugins.add(new AccessibilityPlugin(app));
allPlugins.add(new OsmEditingPlugin(app));
allPlugins.add(new OsmandDevelopmentPlugin(app));
@ -166,28 +168,33 @@ public abstract class OsmandPlugin {
}
}
private static void checkMarketPlugin(OsmandApplication app, OsmandPlugin srtm, boolean paid, String id, String id2) {
private static void checkMarketPlugin(@NonNull OsmandApplication app, @NonNull Set<String> enabledPlugins,
@NonNull OsmandPlugin plugin, boolean paid, String id, String id2) {
boolean marketEnabled = Version.isMarketEnabled(app);
boolean pckg = isPackageInstalled(id, app) ||
isPackageInstalled(id2, app);
boolean pckg = isPackageInstalled(id, app) || isPackageInstalled(id2, app)
|| InAppPurchaseHelper.isSubscribedToLiveUpdates(app);
if ((Version.isDeveloperVersion(app) || !Version.isProductionVersion(app)) && !paid) {
// for test reasons
marketEnabled = false;
}
if (pckg || (!marketEnabled && !paid)) {
if (pckg && !app.getSettings().getPlugins().contains("-" + srtm.getId())) {
srtm.setActive(true);
if (pckg && !app.getSettings().getPlugins().contains("-" + plugin.getId())) {
plugin.setActive(true);
}
allPlugins.add(srtm);
allPlugins.add(plugin);
} else {
if (marketEnabled) {
srtm.setInstallURL(Version.getUrlWithUtmRef(app, id));
allPlugins.add(srtm);
plugin.setActive(false);
if (!app.getSettings().getPlugins().contains("-" + plugin.getId())) {
enabledPlugins.remove(plugin.getId());
}
plugin.setInstallURL(Version.getUrlWithUtmRef(app, id));
allPlugins.add(plugin);
}
}
}
public static boolean enablePlugin(Activity activity, OsmandApplication app, OsmandPlugin plugin, boolean enable) {
public static boolean enablePlugin(@Nullable Activity activity, OsmandApplication app, OsmandPlugin plugin, boolean enable) {
if (enable) {
if (!plugin.init(app, activity)) {
plugin.setActive(false);
@ -200,7 +207,7 @@ public abstract class OsmandPlugin {
plugin.setActive(false);
}
app.getSettings().enablePlugin(plugin.getId(), enable);
if (activity instanceof MapActivity) {
if (activity != null && activity instanceof MapActivity) {
final MapActivity mapActivity = (MapActivity) activity;
plugin.updateLayers(mapActivity.getMapView(), mapActivity);
mapActivity.getDashboard().refreshDashboardFragments();

View file

@ -76,6 +76,7 @@ import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.base.FailSafeFuntions;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.chooseplan.OsmLiveCancelledDialog;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dialogs.ErrorBottomSheetDialog;
import net.osmand.plus.dialogs.RateUsBottomSheetDialog;
@ -203,7 +204,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private boolean permissionGranted;
private boolean mIsDestroyed = false;
private InAppPurchaseHelper inAppPurchaseHelper;
private Timer splashScreenTimer;
private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
@ -785,9 +785,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
getSupportFragmentManager().beginTransaction()
.add(R.id.fragmentContainer, new FirstUsageWelcomeFragment(),
FirstUsageWelcomeFragment.TAG).commitAllowingStateLoss();
} else if (!isFirstScreenShowing() && XMasDialogFragment.shouldShowXmasDialog(app)) {
SecondSplashScreenFragment.SHOW = false;
new XMasDialogFragment().show(getSupportFragmentManager(), XMasDialogFragment.TAG);
} else if (!isFirstScreenShowing()) {
if (XMasDialogFragment.shouldShowXmasDialog(app)) {
SecondSplashScreenFragment.SHOW = false;
new XMasDialogFragment().show(getSupportFragmentManager(), XMasDialogFragment.TAG);
} else if (OsmLiveCancelledDialog.shouldShowDialog(app)) {
OsmLiveCancelledDialog.showInstance(getSupportFragmentManager());
}
}
FirstUsageWelcomeFragment.SHOW = false;
@ -865,6 +869,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return null;
}
public boolean isInAppPurchaseAllowed() {
return true;
}
private void dismissSecondSplashScreen() {
if (SecondSplashScreenFragment.VISIBLE) {
SecondSplashScreenFragment.VISIBLE = false;
@ -1214,9 +1222,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if (atlasMapRendererView != null) {
atlasMapRendererView.handleOnDestroy();
}
if (inAppPurchaseHelper != null) {
inAppPurchaseHelper.stop();
}
mIsDestroyed = true;
}
@ -1524,9 +1529,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (inAppPurchaseHelper != null && inAppPurchaseHelper.onActivityResultHandled(requestCode, resultCode, data)) {
return;
}
for (ActivityResultListener listener : activityResultListeners) {
if (listener.processResult(requestCode, resultCode, data)) {
removeActivityResultListener(listener);
@ -1534,6 +1536,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
}
OsmandPlugin.onMapActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
public void refreshMap() {

View file

@ -8,6 +8,8 @@ import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
@ -19,10 +21,13 @@ import net.osmand.plus.Version;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType;
import net.osmand.plus.liveupdates.OsmLiveRestartBottomSheetDialogFragment;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import org.apache.commons.logging.Log;
import java.util.List;
@SuppressLint("Registered")
public class OsmandInAppPurchaseActivity extends AppCompatActivity implements InAppPurchaseListener {
private static final Log LOG = PlatformUtil.getLog(OsmandInAppPurchaseActivity.class);
@ -64,7 +69,7 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In
deinitInAppPurchaseHelper();
if (purchaseHelper != null) {
purchaseHelper.addListener(this);
purchaseHelper.setUiActivity(this);
if (purchaseHelper.needRequestInventory()) {
purchaseHelper.requestInventory();
}
@ -73,7 +78,7 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In
private void deinitInAppPurchaseHelper() {
if (purchaseHelper != null) {
purchaseHelper.removeListener(this);
purchaseHelper.resetUiActivity(this);
purchaseHelper.stop();
}
}
@ -141,26 +146,86 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In
@Override
public void onError(InAppPurchaseTaskType taskType, String error) {
onInAppPurchaseError(taskType, error);
fireInAppPurchaseErrorOnFragments(getSupportFragmentManager(), taskType, error);
}
public void fireInAppPurchaseErrorOnFragments(@NonNull FragmentManager fragmentManager,
InAppPurchaseTaskType taskType, String error) {
List<Fragment> fragments = fragmentManager.getFragments();
for (Fragment f : fragments) {
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).onError(taskType, error);
}
}
}
@Override
public void onGetItems() {
onInAppPurchaseGetItems();
fireInAppPurchaseGetItemsOnFragments(getSupportFragmentManager());
}
public void fireInAppPurchaseGetItemsOnFragments(@NonNull FragmentManager fragmentManager) {
List<Fragment> fragments = fragmentManager.getFragments();
for (Fragment f : fragments) {
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).onGetItems();
}
}
}
@Override
public void onItemPurchased(String sku) {
if (purchaseHelper != null && purchaseHelper.getSkuLiveUpdates().equals(sku)) {
getMyApplication().logEvent(this, "live_osm_subscription_purchased");
OsmLiveRestartBottomSheetDialogFragment fragment = new OsmLiveRestartBottomSheetDialogFragment();
fragment.setUsedOnMap(this instanceof MapActivity);
fragment.show(getSupportFragmentManager(), OsmLiveRestartBottomSheetDialogFragment.TAG);
}
onInAppPurchaseItemPurchased(sku);
fireInAppPurchaseItemPurchasedOnFragments(getSupportFragmentManager(), sku);
}
public void fireInAppPurchaseItemPurchasedOnFragments(@NonNull FragmentManager fragmentManager, String sku) {
List<Fragment> fragments = fragmentManager.getFragments();
for (Fragment f : fragments) {
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).onItemPurchased(sku);
}
}
}
@Override
public void showProgress(InAppPurchaseTaskType taskType) {
showInAppPurchaseProgress(taskType);
fireInAppPurchaseShowProgressOnFragments(getSupportFragmentManager(), taskType);
}
public void fireInAppPurchaseShowProgressOnFragments(@NonNull FragmentManager fragmentManager,
InAppPurchaseTaskType taskType) {
List<Fragment> fragments = fragmentManager.getFragments();
for (Fragment f : fragments) {
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).showProgress(taskType);
}
}
}
@Override
public void dismissProgress(InAppPurchaseTaskType taskType) {
dismissInAppPurchaseProgress(taskType);
fireInAppPurchaseDismissProgressOnFragments(getSupportFragmentManager(), taskType);
}
public void fireInAppPurchaseDismissProgressOnFragments(@NonNull FragmentManager fragmentManager,
InAppPurchaseTaskType taskType) {
List<Fragment> fragments = fragmentManager.getFragments();
for (Fragment f : fragments) {
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).dismissProgress(taskType);
}
}
}
public void onInAppPurchaseError(InAppPurchaseTaskType taskType, String error) {

View file

@ -497,9 +497,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
misc.addPreference(createCheckBoxPreference(settings.MAP_EMPTY_STATE_ALLOWED, R.string.tap_on_map_to_hide_interface, R.string.tap_on_map_to_hide_interface_descr));
misc.addPreference(createCheckBoxPreference(settings.DO_NOT_SHOW_STARTUP_MESSAGES, R.string.do_not_show_startup_messages, R.string.do_not_show_startup_messages_desc));
OsmandApplication app = getMyApplication();
if (Version.isGooglePlayEnabled(getMyApplication()) && Version.isFreeVersion(app)
&& !InAppPurchaseHelper.isFullVersionPurchased(app)
&& !InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) {
if (Version.isGooglePlayEnabled(getMyApplication()) && !Version.isPaidVersion(app)) {
misc.addPreference(createCheckBoxPreference(settings.DO_NOT_SEND_ANONYMOUS_APP_USAGE, R.string.do_not_send_anonymous_app_usage, R.string.do_not_send_anonymous_app_usage_desc));
}
}

View file

@ -575,7 +575,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
@Override
public boolean init(final OsmandApplication app, Activity activity) {
public boolean init(@NonNull final OsmandApplication app, Activity activity) {
initializeRemoteControlRegistrationMethods();
AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE);
if (am != null) {

View file

@ -20,6 +20,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
public class BaseOsmAndFragment extends Fragment implements TransitionAnimator {
private IconsCache iconsCache;
@ -128,6 +129,15 @@ public class BaseOsmAndFragment extends Fragment implements TransitionAnimator {
return (OsmandActionBarActivity) getActivity();
}
protected OsmandInAppPurchaseActivity getInAppPurchaseActivity() {
Activity activity = getActivity();
if (activity instanceof OsmandInAppPurchaseActivity) {
return (OsmandInAppPurchaseActivity) getActivity();
} else {
return null;
}
}
protected IconsCache getIconsCache() {
if (iconsCache == null) {
iconsCache = getMyApplication().getIconsCache();

View file

@ -0,0 +1,12 @@
package net.osmand.plus.base.bottomsheetmenu.simpleitems;
import net.osmand.plus.R;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
public class LongDescriptionItem extends BottomSheetItemWithDescription {
public LongDescriptionItem(CharSequence description) {
this.description = description;
this.layoutId = R.layout.bottom_sheet_item_description_long;
}
}

View file

@ -3,9 +3,9 @@ package net.osmand.plus.base.bottomsheetmenu.simpleitems;
import net.osmand.plus.R;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
public class DescriptionItem extends BottomSheetItemWithDescription {
public class ShortDescriptionItem extends BottomSheetItemWithDescription {
public DescriptionItem(CharSequence description) {
public ShortDescriptionItem(CharSequence description) {
this.description = description;
this.layoutId = R.layout.bottom_sheet_item_description;
}

View file

@ -31,6 +31,7 @@ import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
@ -85,13 +86,14 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
public boolean isFeaturePurchased(OsmandApplication ctx) {
switch (this) {
case DAILY_MAP_UPDATES:
case DONATION_TO_OSM:
case UNLOCK_ALL_FEATURES:
return false;
case MONTHLY_MAP_UPDATES:
case UNLIMITED_DOWNLOADS:
case WIKIPEDIA_OFFLINE:
case UNLOCK_ALL_FEATURES:
case DONATION_TO_OSM:
case WIKIVOYAGE_OFFLINE:
return false;
return !Version.isFreeVersion(ctx) || InAppPurchaseHelper.isFullVersionPurchased(ctx);
case SEA_DEPTH_MAPS:
return InAppPurchaseHelper.isDepthContoursPurchased(ctx);
case CONTOUR_LINES_HILLSHADE_MAPS:
@ -276,9 +278,6 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
cardDescription.setText(R.string.osm_live_payment_desc);
osmLiveCardButton = cardView.findViewById(R.id.card_button);
InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
boolean requestingInventory = purchaseHelper != null && purchaseHelper.getActiveTask() == InAppPurchaseTaskType.REQUEST_INVENTORY;
setupOsmLiveCardButton(requestingInventory);
return cardView;
}
@ -288,7 +287,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
ProgressBar progressBar = (ProgressBar) osmLiveCardButton.findViewById(R.id.card_button_progress);
TextViewEx buttonTitle = (TextViewEx) osmLiveCardButton.findViewById(R.id.card_button_title);
TextViewEx buttonSubtitle = (TextViewEx) osmLiveCardButton.findViewById(R.id.card_button_subtitle);
if (!purchaseHelper.hasPrices()) {
if (purchaseHelper == null || !purchaseHelper.hasPrices()) {
buttonTitle.setText(getString(R.string.purchase_subscription_title, getString(R.string.osm_live_default_price)));
} else {
buttonTitle.setText(getString(R.string.purchase_subscription_title, purchaseHelper.getLiveUpdatesPrice()));
@ -316,16 +315,13 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
private void subscript() {
FragmentActivity ctx = getActivity();
if (ctx != null) {
if (ctx instanceof OsmLiveActivity) {
SubscriptionFragment subscriptionFragment = new SubscriptionFragment();
subscriptionFragment.show(ctx.getSupportFragmentManager(), SubscriptionFragment.TAG);
} else {
Intent intent = new Intent(ctx, OsmLiveActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra(OsmLiveActivity.OPEN_SUBSCRIPTION_INTENT_PARAM, true);
ctx.startActivity(intent);
}
if (ctx != null && purchaseHelper != null) {
OsmandSettings settings = app.getSettings();
purchaseHelper.purchaseLiveUpdates(ctx,
settings.BILLING_USER_EMAIL.get(),
settings.BILLING_USER_NAME.get(),
settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get(),
settings.BILLING_HIDE_USER_NAME.get());
}
}
@ -376,9 +372,6 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
cardDescription.setText(R.string.in_app_purchase_desc_ex);
planTypeCardButton = cardView.findViewById(R.id.card_button);
InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
boolean requestingInventory = purchaseHelper != null && purchaseHelper.getActiveTask() == InAppPurchaseTaskType.REQUEST_INVENTORY;
setupPlanTypeCardButton(requestingInventory);
return cardView;
}
@ -421,6 +414,14 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
if (mapActivity != null) {
mapActivity.disableDrawer();
}
boolean requestingInventory = purchaseHelper != null && purchaseHelper.getActiveTask() == InAppPurchaseTaskType.REQUEST_INVENTORY;
if (osmLiveCardButton != null) {
setupOsmLiveCardButton(requestingInventory);
}
if (planTypeCardButton != null) {
setupPlanTypeCardButton(requestingInventory);
}
}
@Override

View file

@ -109,8 +109,8 @@ public class ChoosePlanFreeBannerDialogFragment extends ChoosePlanDialogFragment
app.logEvent(getActivity(), "paid_version_redirect_from_banner");
}
OsmandInAppPurchaseActivity.purchaseFullVersion(activity);
dismiss();
}
dismiss();
}
});
}

View file

@ -93,6 +93,7 @@ public class ChoosePlanHillshadeSrtmDialogFragment extends ChoosePlanDialogFragm
Activity activity = getActivity();
if (activity != null) {
OsmandInAppPurchaseActivity.purchaseSrtmPlugin(activity);
dismiss();
}
}
});

View file

@ -93,6 +93,7 @@ public class ChoosePlanSeaDepthMapsDialogFragment extends ChoosePlanDialogFragme
Activity activity = getActivity();
if (activity != null) {
OsmandInAppPurchaseActivity.purchaseDepthContours(activity);
dismiss();
}
}
});

View file

@ -0,0 +1,257 @@
package net.osmand.plus.chooseplan;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.ColorRes;
import android.support.annotation.LayoutRes;
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.v4.content.ContextCompat;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ProgressBar;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment.OsmAndFeature;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType;
import net.osmand.plus.widgets.TextViewEx;
import org.apache.commons.logging.Log;
import static net.osmand.plus.inapp.InAppPurchaseHelper.SUBSCRIPTION_HOLDING_TIME_MSEC;
public class OsmLiveCancelledDialog extends BaseOsmAndDialogFragment implements InAppPurchaseListener {
public static final String TAG = OsmLiveCancelledDialog.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(OsmLiveCancelledDialog.class);
private OsmandApplication app;
private InAppPurchaseHelper purchaseHelper;
private boolean nightMode;
private View osmLiveButton;
private final OsmAndFeature[] osmLiveFeatures = {
OsmAndFeature.DAILY_MAP_UPDATES,
OsmAndFeature.UNLIMITED_DOWNLOADS,
OsmAndFeature.WIKIPEDIA_OFFLINE,
OsmAndFeature.WIKIVOYAGE_OFFLINE,
OsmAndFeature.CONTOUR_LINES_HILLSHADE_MAPS,
OsmAndFeature.SEA_DEPTH_MAPS,
OsmAndFeature.UNLOCK_ALL_FEATURES,
OsmAndFeature.DONATION_TO_OSM,
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = getMyApplication();
purchaseHelper = app.getInAppPurchaseHelper();
nightMode = isNightMode(getMapActivity() != null);
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Activity ctx = requireActivity();
int themeId = nightMode ? R.style.OsmandDarkTheme_DarkActionbar : R.style.OsmandLightTheme_DarkActionbar_LightStatusBar;
Dialog dialog = new Dialog(ctx, themeId);
Window window = dialog.getWindow();
if (window != null) {
if (!getSettings().DO_NOT_USE_ANIMATIONS.get()) {
window.getAttributes().windowAnimations = R.style.Animations_Alpha;
}
if (Build.VERSION.SDK_INT >= 21) {
window.setStatusBarColor(ContextCompat.getColor(ctx, getStatusBarColor()));
}
}
return dialog;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Context ctx = getContext();
if (ctx == null) {
return null;
}
View view = inflate(R.layout.osmlive_cancelled_dialog_fragment, container);
view.findViewById(R.id.button_close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
TextViewEx infoDescr = (TextViewEx) view.findViewById(R.id.info_description);
StringBuilder descr = new StringBuilder();
descr.append(getString(R.string.purchase_cancelled_dialog_descr));
for (OsmAndFeature feature : osmLiveFeatures) {
descr.append("\n").append("").append(feature.toHumanString(ctx));
}
infoDescr.setText(descr);
osmLiveButton = view.findViewById(R.id.card_button);
return view;
}
@Nullable
public MapActivity getMapActivity() {
Activity activity = getActivity();
if (activity != null && activity instanceof MapActivity) {
return (MapActivity) activity;
}
return null;
}
@Override
public void onResume() {
super.onResume();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.disableDrawer();
}
boolean requestingInventory = purchaseHelper != null && purchaseHelper.getActiveTask() == InAppPurchaseTaskType.REQUEST_INVENTORY;
setupOsmLiveButton(requestingInventory);
OsmandPreference<Boolean> firstTimeShown = app.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_FIRST_DLG_SHOWN;
OsmandPreference<Boolean> secondTimeShown = app.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_SECOND_DLG_SHOWN;
if (!firstTimeShown.get()) {
firstTimeShown.set(true);
} else if (!secondTimeShown.get()) {
secondTimeShown.set(true);
}
}
@Override
public void onPause() {
super.onPause();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.enableDrawer();
}
}
@ColorRes
protected int getStatusBarColor() {
return nightMode ? R.color.status_bar_wikivoyage_dark : R.color.status_bar_wikivoyage_light;
}
@Override
public void onError(InAppPurchaseTaskType taskType, String error) {
if (taskType == InAppPurchaseTaskType.REQUEST_INVENTORY) {
setupOsmLiveButton(false);
}
}
@Override
public void onGetItems() {
}
@Override
public void onItemPurchased(String sku) {
}
@Override
public void showProgress(InAppPurchaseTaskType taskType) {
if (taskType == InAppPurchaseTaskType.REQUEST_INVENTORY) {
setupOsmLiveButton(true);
}
}
@Override
public void dismissProgress(InAppPurchaseTaskType taskType) {
if (taskType == InAppPurchaseTaskType.REQUEST_INVENTORY) {
setupOsmLiveButton(false);
}
}
private void setupOsmLiveButton(boolean progress) {
if (osmLiveButton != null) {
ProgressBar progressBar = (ProgressBar) osmLiveButton.findViewById(R.id.card_button_progress);
TextViewEx buttonTitle = (TextViewEx) osmLiveButton.findViewById(R.id.card_button_title);
TextViewEx buttonSubtitle = (TextViewEx) osmLiveButton.findViewById(R.id.card_button_subtitle);
if (!purchaseHelper.hasPrices()) {
buttonTitle.setText(getString(R.string.purchase_subscription_title, getString(R.string.osm_live_default_price)));
} else {
buttonTitle.setText(getString(R.string.purchase_subscription_title, purchaseHelper.getLiveUpdatesPrice()));
}
buttonSubtitle.setText(R.string.osm_live_month_cost_desc);
if (progress) {
buttonTitle.setVisibility(View.GONE);
buttonSubtitle.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
osmLiveButton.setOnClickListener(null);
} else {
buttonTitle.setVisibility(View.VISIBLE);
buttonSubtitle.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
osmLiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
subscript();
dismiss();
}
});
}
}
}
private void subscript() {
FragmentActivity ctx = getActivity();
if (ctx != null && purchaseHelper != null) {
OsmandSettings settings = app.getSettings();
purchaseHelper.purchaseLiveUpdates(ctx,
settings.BILLING_USER_EMAIL.get(),
settings.BILLING_USER_NAME.get(),
settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get(),
settings.BILLING_HIDE_USER_NAME.get());
}
}
private View inflate(@LayoutRes int layoutId, @Nullable ViewGroup container) {
int themeRes = nightMode ? R.style.OsmandDarkTheme_DarkActionbar : R.style.OsmandLightTheme_DarkActionbar_LightStatusBar;
return LayoutInflater.from(new ContextThemeWrapper(getContext(), themeRes))
.inflate(layoutId, container, false);
}
public static boolean shouldShowDialog(OsmandApplication app) {
OsmandSettings settings = app.getSettings();
long cancelledTime = settings.LIVE_UPDATES_PURCHASE_CANCELLED_TIME.get();
boolean firstTimeShown = settings.LIVE_UPDATES_PURCHASE_CANCELLED_FIRST_DLG_SHOWN.get();
boolean secondTimeShown = settings.LIVE_UPDATES_PURCHASE_CANCELLED_SECOND_DLG_SHOWN.get();
return cancelledTime > 0
&& (!firstTimeShown
|| (System.currentTimeMillis() - cancelledTime > SUBSCRIPTION_HOLDING_TIME_MSEC
&& !secondTimeShown));
}
public static void showInstance(@NonNull FragmentManager fm) {
try {
OsmLiveCancelledDialog fragment = new OsmLiveCancelledDialog();
fragment.show(fm, OsmLiveCancelledDialog.TAG);
} catch (RuntimeException e) {
LOG.error("showInstance", e);
}
}
}

View file

@ -42,6 +42,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.activities.PluginActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
@ -90,6 +91,7 @@ public class ConfigureMapMenu {
}
public ContextMenuAdapter createListAdapter(final MapActivity ma) {
OsmandApplication app = ma.getMyApplication();
ContextMenuAdapter adapter = new ContextMenuAdapter();
adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
adapter.addItem(new ContextMenuItem.ItemBuilder()
@ -101,13 +103,14 @@ public class ConfigureMapMenu {
ma.getDashboard().updateListAdapter(createListAdapter(ma));
}
});
RenderingRulesStorage renderer = ma.getMyApplication().getRendererRegistry().getCurrentSelectedRenderer();
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
List<RenderingRuleProperty> customRules = new ArrayList<>();
boolean hasDepthContours = ma.getMyApplication().getResourceManager().hasDepthContours();
boolean useDepthContours = app.getResourceManager().hasDepthContours()
&& (InAppPurchaseHelper.isSubscribedToLiveUpdates(app) || InAppPurchaseHelper.isDepthContoursPurchased(app));
if (renderer != null) {
for (RenderingRuleProperty p : renderer.PROPS.getCustomRules()) {
if (!RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(p.getCategory())
&& (hasDepthContours || !p.getAttrName().equals("depthContours"))) {
&& (useDepthContours || !p.getAttrName().equals("depthContours"))) {
customRules.add(p);
}
}
@ -471,7 +474,8 @@ public class ConfigureMapMenu {
OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
app.getAppCustomization().prepareLayerContextMenu(activity, adapter);
boolean srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
boolean srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null
&& !InAppPurchaseHelper.isSubscribedToLiveUpdates(app);
if (srtmDisabled) {
SRTMPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
if (srtmPlugin != null) {

View file

@ -215,54 +215,26 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
@Override
public void onInAppPurchaseError(InAppPurchaseTaskType taskType, String error) {
visibleBanner.updateFreeVersionBanner();
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).onError(taskType, error);
}
}
}
@Override
public void onInAppPurchaseGetItems() {
visibleBanner.updateFreeVersionBanner();
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).onGetItems();
}
}
initAppStatusVariables();
}
@Override
public void onInAppPurchaseItemPurchased(String sku) {
visibleBanner.updateFreeVersionBanner();
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).onItemPurchased(sku);
}
}
initAppStatusVariables();
}
@Override
public void showInAppPurchaseProgress(InAppPurchaseTaskType taskType) {
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).showProgress(taskType);
}
}
}
@Override
public void dismissInAppPurchaseProgress(InAppPurchaseTaskType taskType) {
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).dismissProgress(taskType);
}
}
}
public DownloadIndexesThread getDownloadThread() {
@ -413,8 +385,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
}
public static boolean shouldShowFreeVersionBanner(OsmandApplication application) {
return (Version.isFreeVersion(application) && !InAppPurchaseHelper.isSubscribedToLiveUpdates(application)
&& !InAppPurchaseHelper.isFullVersionPurchased(application))
return !Version.isPaidVersion(application)
|| application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get();
}
@ -732,7 +703,8 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
}
public void initAppStatusVariables() {
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null
&& !InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication());
nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
freeVersion = Version.isFreeVersion(getMyApplication());
OsmandPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);

View file

@ -567,9 +567,7 @@ public class DownloadIndexesThread {
}
private boolean validateNotExceedsFreeLimit(IndexItem item) {
boolean exceed = Version.isFreeVersion(app)
&& !InAppPurchaseHelper.isSubscribedToLiveUpdates(app)
&& !InAppPurchaseHelper.isFullVersionPurchased(app)
boolean exceed = !Version.isPaidVersion(app)
&& DownloadActivityType.isCountedInDownloads(item)
&& downloads.get() >= DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
if(exceed) {

View file

@ -325,7 +325,9 @@ public class DownloadResources extends DownloadResourceGroup {
continue;
}
if (ii.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE) {
if (InAppPurchaseHelper.isDepthContoursPurchased(app) || nauticalMaps.size() == 0) {
if (InAppPurchaseHelper.isDepthContoursPurchased(app)
|| InAppPurchaseHelper.isSubscribedToLiveUpdates(app)
|| nauticalMaps.size() == 0) {
nauticalMaps.addItem(ii);
}
continue;

View file

@ -155,14 +155,12 @@ public class DownloadValidationManager {
}
protected void downloadFilesCheck_1_FreeVersion(FragmentActivity context, IndexItem[] items) {
if (Version.isFreeVersion(getMyApplication()) && !InAppPurchaseHelper.isSubscribedToLiveUpdates(app)
&& !InAppPurchaseHelper.isFullVersionPurchased(app)) {
if (!Version.isPaidVersion(app)) {
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS) {
if (context instanceof FragmentActivity) {
FragmentActivity activity = context;
if (context != null) {
new InstallPaidVersionDialogFragment()
.show(activity.getSupportFragmentManager(), InstallPaidVersionDialogFragment.TAG);
.show(context.getSupportFragmentManager(), InstallPaidVersionDialogFragment.TAG);
}
} else {
downloadFilesCheck_2_Internet(context, items);

View file

@ -347,7 +347,6 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
@Override
public void onItemPurchased(String sku) {
getMyApplication().getDownloadThread().runReloadIndexFilesSilent();
//reloadData();
}
@Override

View file

@ -21,6 +21,7 @@ import android.widget.Toast;
import net.osmand.map.WorldRegion;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
@ -50,7 +51,6 @@ public class ItemViewHolder {
private boolean srtmDisabled;
private boolean srtmNeedsInstallation;
private boolean nauticalPluginDisabled;
private boolean freeVersion;
private boolean depthContoursPurchased;
protected final DownloadActivity context;
@ -128,9 +128,9 @@ public class ItemViewHolder {
private void initAppStatusVariables() {
srtmDisabled = context.isSrtmDisabled();
nauticalPluginDisabled = context.isNauticalPluginDisabled();
freeVersion = context.isFreeVersion();
srtmNeedsInstallation = context.isSrtmNeedsInstallation();
depthContoursPurchased = InAppPurchaseHelper.isDepthContoursPurchased(context.getMyApplication());
depthContoursPurchased = InAppPurchaseHelper.isDepthContoursPurchased(context.getMyApplication())
|| InAppPurchaseHelper.isSubscribedToLiveUpdates(context.getMyApplication());
}
public void bindIndexItem(final IndexItem indexItem) {
@ -314,11 +314,10 @@ public class ItemViewHolder {
clickAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_ENABLE;
}
} else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE && freeVersion
&& !InAppPurchaseHelper.isFullVersionPurchased(context.getMyApplication())) {
} else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE
&& !Version.isPaidVersion(context.getMyApplication())) {
clickAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE;
} else if (indexItem.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE
&& !InAppPurchaseHelper.isDepthContoursPurchased(context.getMyApplication())) {
} else if (indexItem.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE && !depthContoursPurchased) {
clickAction = RightButtonAction.ASK_FOR_DEPTH_CONTOURS_PURCHASE;
}
return clickAction;

View file

@ -110,7 +110,8 @@ public class DiscountHelper {
if (url.startsWith(INAPP_PREFIX) && url.length() > INAPP_PREFIX.length()) {
String inAppSku = url.substring(INAPP_PREFIX.length());
InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
if (purchaseHelper != null && purchaseHelper.isPurchased(inAppSku)) {
if (purchaseHelper != null
&& (purchaseHelper.isPurchased(inAppSku) || InAppPurchaseHelper.isSubscribedToLiveUpdates(app))) {
return;
}
}
@ -214,7 +215,10 @@ public class DiscountHelper {
if (url.contains(InAppPurchaseHelper.SKU_FULL_VERSION_PRICE)) {
OsmandApplication app = mapActivity.getMyApplication();
app.logEvent(mapActivity, "in_app_purchase_redirect");
app.getInAppPurchaseHelper().purchaseFullVersion(mapActivity);
InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
if (purchaseHelper != null) {
purchaseHelper.purchaseFullVersion(mapActivity);
}
} else if (url.contains(InAppPurchaseHelper.SKU_LIVE_UPDATES)){
Intent intent = new Intent(mapActivity, OsmLiveActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

View file

@ -13,18 +13,13 @@ import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.provider.OpenableColumns;
import android.provider.Settings;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import net.osmand.IProgress;
@ -39,7 +34,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.myplaces.FavoritesActivity;
@ -758,7 +753,7 @@ public class ImportHelper {
text.setSpan(new ForegroundColorSpan(nameColor), 0, fileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new ForegroundColorSpan(descrColor), fileName.length() + 1, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
items.add(new DescriptionItem(text));
items.add(new ShortDescriptionItem(text));
BaseBottomSheetItem asFavoritesItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_fav_dark))

View file

@ -11,6 +11,7 @@ import net.osmand.AndroidNetworkUtils;
import net.osmand.AndroidNetworkUtils.OnRequestResultListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.inapp.util.IabHelper;
@ -36,7 +37,9 @@ import java.util.Map;
public class InAppPurchaseHelper {
// Debug tag, for logging
private static final String TAG = InAppPurchaseHelper.class.getSimpleName();
boolean mDebugLog = false;
boolean mDebugLog = true;
public static final long SUBSCRIPTION_HOLDING_TIME_MSEC = 1000 * 60;// * 60 * 24 * 3; // 3 days
private long lastValidationCheckTime;
private String liveUpdatesPrice;
@ -69,7 +72,7 @@ public class InAppPurchaseHelper {
private boolean processingTask = false;
private OsmandApplication ctx;
private List<InAppPurchaseListener> listeners = new ArrayList<>();
private InAppPurchaseListener uiActivity = null;
/* base64EncodedPublicKey should be YOUR APPLICATION'S PUBLIC KEY
* (that you got from the Google Play developer console). This is not your
@ -193,7 +196,6 @@ public class InAppPurchaseHelper {
}
public boolean isPurchased(String inAppSku) {
OsmandSettings settings = ctx.getSettings();
if (inAppSku.equals(SKU_FULL_VERSION_PRICE)) {
return isFullVersionPurchased(ctx);
} else if (inAppSku.equals(SKU_LIVE_UPDATES_FULL) || inAppSku.equals(SKU_LIVE_UPDATES_FREE)) {
@ -358,10 +360,23 @@ public class InAppPurchaseHelper {
// Do we have the live updates?
Purchase liveUpdatesPurchase = inventory.getPurchase(SKU_LIVE_UPDATES);
boolean subscribedToLiveUpdates = (liveUpdatesPurchase != null && liveUpdatesPurchase.getPurchaseState() == 0);
if (!subscribedToLiveUpdates && ctx.getSettings().LIVE_UPDATES_PURCHASED.get()) {
ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_TIME.set(System.currentTimeMillis());
OsmandPreference<Long> subscriptionCancelledTime = ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_TIME;
if (!subscribedToLiveUpdates) {
if (subscriptionCancelledTime.get() == 0) {
subscriptionCancelledTime.set(System.currentTimeMillis());
ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_FIRST_DLG_SHOWN.set(false);
ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_SECOND_DLG_SHOWN.set(false);
} else if (System.currentTimeMillis() - subscriptionCancelledTime.get() > SUBSCRIPTION_HOLDING_TIME_MSEC
&& ctx.getSettings().LIVE_UPDATES_PURCHASED.get()) {
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(false);
if (!isDepthContoursPurchased(ctx)) {
ctx.getSettings().getCustomRenderBooleanProperty("depthContours").set(false);
}
}
} else {
subscriptionCancelledTime.set(0L);
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
}
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(subscribedToLiveUpdates);
Purchase fullVersionPurchase = inventory.getPurchase(SKU_FULL_VERSION_PRICE);
boolean fullVersionPurchased = (fullVersionPurchase != null && fullVersionPurchase.getPurchaseState() == 0);
@ -589,8 +604,8 @@ public class InAppPurchaseHelper {
sendToken(purchase.getToken(), new OnRequestResultListener() {
@Override
public void onResult(String result) {
showToast(ctx.getString(R.string.osm_live_thanks));
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
ctx.getSettings().getCustomRenderBooleanProperty("depthContours").set(true);
notifyDismissProgress(InAppPurchaseTaskType.PURCHASE_LIVE_UPDATES);
notifyItemPurchased(SKU_LIVE_UPDATES);
@ -722,41 +737,44 @@ public class InAppPurchaseHelper {
}
private void notifyError(InAppPurchaseTaskType taskType, String message) {
for (InAppPurchaseListener l : listeners) {
l.onError(taskType, message);
if (uiActivity != null) {
uiActivity.onError(taskType, message);
}
}
private void notifyGetItems() {
for (InAppPurchaseListener l : listeners) {
l.onGetItems();
if (uiActivity != null) {
uiActivity.onGetItems();
}
}
private void notifyItemPurchased(String sku) {
for (InAppPurchaseListener l : listeners) {
l.onItemPurchased(sku);
if (uiActivity != null) {
uiActivity.onItemPurchased(sku);
}
}
private void notifyShowProgress(InAppPurchaseTaskType taskType) {
for (InAppPurchaseListener l : listeners) {
l.showProgress(taskType);
if (uiActivity != null) {
uiActivity.showProgress(taskType);
}
}
private void notifyDismissProgress(InAppPurchaseTaskType taskType) {
for (InAppPurchaseListener l : listeners) {
l.dismissProgress(taskType);
if (uiActivity != null) {
uiActivity.dismissProgress(taskType);
}
}
public void addListener(InAppPurchaseListener listener) {
this.listeners.add(listener);
/// UI notifications methods
public void setUiActivity(InAppPurchaseListener uiActivity) {
this.uiActivity = uiActivity;
}
public void removeListener(InAppPurchaseListener listener) {
this.listeners.remove(listener);
public void resetUiActivity(InAppPurchaseListener uiActivity) {
if (this.uiActivity == uiActivity) {
this.uiActivity = null;
}
}
private void complain(String message) {

View file

@ -37,6 +37,7 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.map.WorldRegion;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -169,7 +170,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
}
public void updateSubscriptionHeader() {
if (getActivity() instanceof OsmLiveActivity) {
if (getActivity() instanceof OsmLiveActivity && subscriptionHeader != null) {
View subscriptionBanner = subscriptionHeader.findViewById(R.id.subscription_banner);
View subscriptionInfo = subscriptionHeader.findViewById(R.id.subscription_info);
if (InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) {
@ -229,7 +230,6 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
if (purchaseHelper.getActiveTask() == InAppPurchaseTaskType.REQUEST_INVENTORY) {
enableProgress();
}
purchaseHelper.addListener(this);
}
if (((OsmLiveActivity) getActivity()).shouldOpenSubscription()) {
SubscriptionFragment subscriptionFragment = new SubscriptionFragment();
@ -245,15 +245,6 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
}
}
@Override
public void onPause() {
super.onPause();
InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper();
if (purchaseHelper != null) {
purchaseHelper.removeListener(this);
}
}
public void notifyLiveUpdatesChanged() {
if (getActivity() != null) {
if (adapter != null && getMyApplication() != null) {
@ -702,6 +693,11 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
@Override
public void onError(InAppPurchaseTaskType taskType, String error) {
disableProgress();
OsmandInAppPurchaseActivity activity = getInAppPurchaseActivity();
if (activity != null) {
activity.fireInAppPurchaseErrorOnFragments(getChildFragmentManager(), taskType, error);
}
}
@Override
@ -711,6 +707,11 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
adapter.enableLiveUpdates(false);
}
disableProgress();
OsmandInAppPurchaseActivity activity = getInAppPurchaseActivity();
if (activity != null) {
activity.fireInAppPurchaseGetItemsOnFragments(getChildFragmentManager());
}
}
@Override
@ -719,15 +720,30 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
if (purchaseHelper != null && purchaseHelper.getSkuLiveUpdates().equals(sku)) {
updateSubscriptionHeader();
}
OsmandInAppPurchaseActivity activity = getInAppPurchaseActivity();
if (activity != null) {
activity.fireInAppPurchaseItemPurchasedOnFragments(getChildFragmentManager(), sku);
}
}
@Override
public void showProgress(InAppPurchaseTaskType taskType) {
enableProgress();
OsmandInAppPurchaseActivity activity = getInAppPurchaseActivity();
if (activity != null) {
activity.fireInAppPurchaseShowProgressOnFragments(getChildFragmentManager(), taskType);
}
}
@Override
public void dismissProgress(InAppPurchaseTaskType taskType) {
disableProgress();
OsmandInAppPurchaseActivity activity = getInAppPurchaseActivity();
if (activity != null) {
activity.fireInAppPurchaseDismissProgressOnFragments(getChildFragmentManager(), taskType);
}
}
}

View file

@ -0,0 +1,46 @@
package net.osmand.plus.liveupdates;
import android.app.Activity;
import android.os.Bundle;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
public class OsmLiveRestartBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public static final String TAG = OsmLiveRestartBottomSheetDialogFragment.class.getSimpleName();
@Override
public void createMenuItems(Bundle savedInstanceState) {
items.add(new TitleItem(getString(R.string.osm_live)));
items.add(new LongDescriptionItem(getString(R.string.osm_live_thanks)));
}
@Override
protected int getDismissButtonTextId() {
return R.string.shared_string_restart;
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.later;
}
@Override
protected void onDismissButtonClickAction() {
Activity activity = getActivity();
if (activity != null && activity instanceof MapActivity) {
MapActivity.doRestart(activity);
} else {
android.os.Process.killProcess(android.os.Process.myPid());
}
}
@Override
protected void onRightBottomButtonClick() {
dismiss();
}
}

View file

@ -308,24 +308,6 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
return view;
}
@Override
public void onResume() {
super.onResume();
InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper();
if (purchaseHelper != null) {
purchaseHelper.addListener(this);
}
}
@Override
public void onPause() {
super.onPause();
InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper();
if (purchaseHelper != null) {
purchaseHelper.removeListener(this);
}
}
@Override
public void onDestroy() {
super.onDestroy();
@ -374,7 +356,6 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
@Override
public void onItemPurchased(String sku) {
getMyApplication().logEvent(getActivity(), "live_osm_subscription_purchased");
dismiss();
}

View file

@ -25,6 +25,7 @@ import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadValidationManager;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.liveupdates.LiveUpdatesHelper;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
@ -79,7 +80,8 @@ public class MapDataMenuController extends MenuController {
}
}
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null
&& !InAppPurchaseHelper.isSubscribedToLiveUpdates(app);
OsmandPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
srtmNeedsInstallation = srtmPlugin == null || srtmPlugin.needsInstallation();

View file

@ -17,7 +17,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
@ -53,7 +53,7 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
items.add(new TitleItem(getGpxName(gpxFile)));
items.add(new DescriptionItem(getString(R.string.select_waypoints_category_description)));
items.add(new ShortDescriptionItem(getString(R.string.select_waypoints_category_description)));
final BottomSheetItemWithCompoundButton[] selectAllItem = new BottomSheetItemWithCompoundButton[1];
selectAllItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()

View file

@ -7,7 +7,7 @@ import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
public class SelectionMarkersGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -24,7 +24,7 @@ public class SelectionMarkersGroupBottomSheetDialogFragment extends MenuBottomSh
public void createMenuItems(Bundle savedInstanceState) {
items.add(new TitleItem(getString(R.string.add_group)));
items.add(new DescriptionItem(getString(R.string.add_group_descr)));
items.add(new ShortDescriptionItem(getString(R.string.add_group_descr)));
BaseBottomSheetItem favoritesItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_fav_dark))

View file

@ -11,7 +11,7 @@ import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -28,7 +28,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
public void createMenuItems(Bundle savedInstanceState) {
items.add(new TitleItem(getString(R.string.shared_string_save_as_gpx)));
items.add(new DescriptionItem(getString(R.string.measurement_tool_save_as_new_track_descr)));
items.add(new ShortDescriptionItem(getString(R.string.measurement_tool_save_as_new_track_descr)));
if (Build.VERSION.SDK_INT >= 18) {
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;

View file

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import net.osmand.IndexConstants;
import net.osmand.plus.ApplicationMode;
@ -55,7 +56,7 @@ public class NauticalMapsPlugin extends OsmandPlugin {
}
@Override
public boolean init(final OsmandApplication app, final Activity activity) {
public boolean init(@NonNull final OsmandApplication app, final Activity activity) {
if(activity != null) {
addBoatProfile(true);
// called from UI

View file

@ -7,7 +7,7 @@ import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.osmedit.OsmEditsFragment.ExportTypesDef;
@ -36,7 +36,7 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo
items.add(new TitleItem(getString(R.string.shared_string_export)));
items.add(new DescriptionItem(getString(R.string.osm_edits_export_desc)));
items.add(new ShortDescriptionItem(getString(R.string.osm_edits_export_desc)));
BaseBottomSheetItem poiItem = new BottomSheetItemWithDescription.Builder()
.setDescription(String.valueOf(poiCount))

View file

@ -582,10 +582,10 @@ public class ResourceManager {
collectFiles(appPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
renameRoadsFiles(files, roadsPath);
collectFiles(roadsPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
if (!Version.isFreeVersion(context) || InAppPurchaseHelper.isFullVersionPurchased(context)) {
if (Version.isPaidVersion(context)) {
collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
}
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(context)) {
collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
}
@ -619,7 +619,7 @@ public class ResourceManager {
}
boolean wikiMap = (f.getName().contains("_wiki") || f.getName().contains(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT));
boolean srtmMap = f.getName().contains(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT);
if (mapReader == null || (Version.isFreeVersion(context) && wikiMap && !InAppPurchaseHelper.isFullVersionPurchased(context))) {
if (mapReader == null || (!Version.isPaidVersion(context) && wikiMap)) {
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
} else {
if (mapReader.isBasemap()) {

View file

@ -1,6 +1,7 @@
package net.osmand.plus.skimapsplugin;
import android.app.Activity;
import android.support.annotation.NonNull;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -45,7 +46,7 @@ public class SkiMapsPlugin extends OsmandPlugin {
}
@Override
public boolean init(final OsmandApplication app, final Activity activity) {
public boolean init(@NonNull final OsmandApplication app, final Activity activity) {
if(activity != null) {
// called from UI
previousRenderer = app.getSettings().RENDERER.get();

View file

@ -17,6 +17,7 @@ import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.DownloadValidationManager;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.render.RenderingRuleProperty;
import java.io.IOException;
@ -47,7 +48,7 @@ public class ContourLinesMenu {
final OsmandApplication app = mapActivity.getMyApplication();
final OsmandSettings settings = app.getSettings();
final SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
final boolean srtmEnabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null;
final boolean srtmEnabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(app);
final RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
final RenderingRuleProperty colorSchemeProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_SCHEME_ATTR);
@ -135,11 +136,6 @@ public class ContourLinesMenu {
});
} else if (itemId == R.string.srtm_plugin_name) {
ChoosePlanDialogFragment.showHillshadeSrtmPluginInstance(mapActivity.getSupportFragmentManager());
/*
Intent intent = new Intent(mapActivity, PluginActivity.class);
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId());
mapActivity.startActivity(intent);
*/
closeDashboard(mapActivity);
} else if (contourWidthProp != null && itemId == contourWidthName.hashCode()) {
plugin.selectPropertyValue(mapActivity, contourWidthProp, widthPref, new Runnable() {

View file

@ -16,6 +16,7 @@ import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.DownloadValidationManager;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import java.io.IOException;
import java.util.List;
@ -42,7 +43,7 @@ public class HillshadeMenu {
final OsmandApplication app = mapActivity.getMyApplication();
final OsmandSettings settings = app.getSettings();
final SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
final boolean srtmEnabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null;
final boolean srtmEnabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(app);
if (plugin == null) {
return;
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.srtmplugin;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.ArrayAdapter;
@ -19,6 +20,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.util.Algorithms;
@ -62,7 +64,11 @@ public class SRTMPlugin extends OsmandPlugin {
public int getAssetResourceName() {
return R.drawable.contour_lines;
}
@Override
public boolean needsInstallation() {
return super.needsInstallation() && !InAppPurchaseHelper.isSubscribedToLiveUpdates(app);
}
@Override
public String getDescription() {
@ -79,7 +85,7 @@ public class SRTMPlugin extends OsmandPlugin {
return "feature_articles/contour-lines-plugin.html";
}
@Override
public boolean init(final OsmandApplication app, Activity activity) {
public boolean init(@NonNull final OsmandApplication app, Activity activity) {
OsmandSettings settings = app.getSettings();
CommonPreference<String> pref = settings.getCustomRenderProperty("contourLines");
if(pref.get().equals("")) {

View file

@ -12,6 +12,7 @@ import net.osmand.core.jni.ObfsCollection;
import net.osmand.core.jni.QIODeviceLogSink;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import android.content.Context;
import android.util.DisplayMetrics;
@ -60,7 +61,7 @@ public class NativeCoreContext {
ObfsCollection obfsCollection = new ObfsCollection();
obfsCollection.addDirectory(directory.getAbsolutePath(), false);
if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) {
obfsCollection.addDirectory(app.getAppPath(IndexConstants.SRTM_INDEX_DIR).getAbsolutePath(), false);
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.wikipedia;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.net.Uri;
@ -10,6 +11,7 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.customtabs.CustomTabsIntent;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.PopupMenu;
@ -17,12 +19,12 @@ import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.AndroidUtils;
@ -30,7 +32,6 @@ import net.osmand.IndexConstants;
import net.osmand.data.Amenity;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.helpers.FileNameTranslationHelper;
@ -47,10 +48,6 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
public static final String TAG = "WikipediaDialogFragment";
private static final int MENU_ITEM_NO_ID = 0;
private static final int MENU_ITEM_SHOW_ID = 1;
private static final int MENU_ITEM_WIFI_ID = 2;
private TextView readFullArticleButton;
private Amenity amenity;
@ -75,7 +72,25 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
articleToolbarText = (TextView) mainView.findViewById(R.id.title_text_view);
ImageView options = (ImageView) mainView.findViewById(R.id.options_button);
options.setImageDrawable(getIcon(R.drawable.ic_overflow_menu_white, R.color.icon_color));
options.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = getMyApplication();
if (app != null) {
FragmentManager fm = getFragmentManager();
if (fm == null) {
return;
}
WikipediaOptionsBottomSheetDialogFragment fragment = new WikipediaOptionsBottomSheetDialogFragment();
fragment.setUsedOnMap(false);
fragment.setTargetFragment(WikipediaDialogFragment.this,
WikipediaOptionsBottomSheetDialogFragment.REQUEST_CODE);
fragment.show(fm, WikipediaOptionsBottomSheetDialogFragment.TAG);
}
}
});
ColorStateList buttonColorStateList = AndroidUtils.createPressedColorStateList(getContext(), nightMode,
R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p,
R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
@ -106,6 +121,8 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
webSettings.setJavaScriptEnabled(true);
contentWebView.setWebViewClient(new WikipediaWebViewClient(getActivity(), nightMode));
updateWebSettings();
contentWebView.setBackgroundColor(ContextCompat.getColor(getMyApplication(),
nightMode ? R.color.wiki_webview_background_dark : R.color.wiki_webview_background_light));
return mainView;
}
@ -254,37 +271,13 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
return showInstance(activity, amenity, null);
}
protected void setupToolbar(Toolbar toolbar) {
super.setupToolbar(toolbar);
toolbar.setOverflowIcon(getIcon(R.drawable.ic_overflow_menu_white, R.color.icon_color));
Menu menu = toolbar.getMenu();
MenuItem.OnMenuItemClickListener itemClickListener = new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
OsmandApplication app = getMyApplication();
if (app != null) {
int itemId = item.getItemId();
if (itemId == MENU_ITEM_SHOW_ID) {
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.ON);
return true;
} else if (itemId == MENU_ITEM_WIFI_ID) {
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.WIFI);
return true;
} else if (itemId == MENU_ITEM_NO_ID) {
app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.OFF);
return true;
}
}
return false;
}
};
MenuItem itemShow = menu.add(0, MENU_ITEM_SHOW_ID, 0, R.string.shared_string_show);
itemShow.setOnMenuItemClickListener(itemClickListener);
MenuItem itemWifi = menu.add(0, MENU_ITEM_WIFI_ID, 0, R.string.shared_string_only_with_wifi);
itemWifi.setOnMenuItemClickListener(itemClickListener);
MenuItem itemNo = menu.add(0, MENU_ITEM_NO_ID, 0, R.string.shared_string_dont);
itemNo.setOnMenuItemClickListener(itemClickListener);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == WikipediaOptionsBottomSheetDialogFragment.REQUEST_CODE
&& resultCode == WikipediaOptionsBottomSheetDialogFragment.SHOW_PICTURES_CHANGED_REQUEST_CODE) {
updateWebSettings();
populateArticle();
}
}
}

View file

@ -0,0 +1,70 @@
package net.osmand.plus.wikipedia;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.PopupMenu;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.WikiArticleShowImages;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
public class WikipediaOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public final static String TAG = "WikipediaOptionsBottomSheetDialogFragment";
public static final int REQUEST_CODE = 0;
public static final int SHOW_PICTURES_CHANGED_REQUEST_CODE = 1;
@Override
public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
final OsmandSettings.CommonPreference<WikiArticleShowImages> showImagesPref = app.getSettings().WIKI_ARTICLE_SHOW_IMAGES;
items.add(new TitleItem(getString(R.string.shared_string_options)));
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.download_images))
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu popup = new PopupMenu(v.getContext(), v, Gravity.END);
for (final WikiArticleShowImages showImages : WikiArticleShowImages.values()) {
MenuItem item = popup.getMenu().add(getString(showImages.name));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
showImagesPref.set(showImages);
sendResult();
dismiss();
return true;
}
});
}
popup.show();
}
})
.create();
items.add(showImagesItem);
}
private void sendResult() {
Fragment fragment = getTargetFragment();
if (fragment != null) {
fragment.onActivityResult(getTargetRequestCode(), SHOW_PICTURES_CHANGED_REQUEST_CODE, null);
}
}
}

View file

@ -65,7 +65,7 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
private static final String PREFIX_GEO = "geo:";
private static final String PAGE_PREFIX_HTTP = "http://";
private static final String PAGE_PREFIX_HTTPS = "https://";
private static final String WIKIVOAYAGE_DOMAIN = ".wikivoyage.com/wiki/";
private static final String WIKIVOAYAGE_DOMAIN = ".wikivoyage.org/wiki/";
private static final String WIKI_DOMAIN = ".wikipedia.org/wiki/";
private FetchWikiRegion fetchRegionTask;
private WikiArticleSearchTask articleSearchTask;
@ -80,7 +80,8 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains(WIKIVOAYAGE_DOMAIN)) {
boolean isWebPage = url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS);
if (url.contains(WIKIVOAYAGE_DOMAIN) && isWebPage) {
String lang = getLang(url);
String articleName = getArticleNameFromUrl(url, lang);
long articleId = app.getTravelDbHelper().getArticleId(articleName, lang);
@ -90,11 +91,11 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
warnAboutExternalLoad(url, context, nightMode);
}
return true;
} else if (url.contains(WIKI_DOMAIN)) {
} else if (url.contains(WIKI_DOMAIN) && isWebPage) {
String lang = getLang(url);
String articleName = getArticleNameFromUrl(url, lang);
getWikiArticle(articleName, lang, url);
} else if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) {
} else if (isWebPage) {
warnAboutExternalLoad(url, context, nightMode);
} else if (url.startsWith(PREFIX_GEO)) {
if (article != null) {

View file

@ -10,6 +10,7 @@ import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentManager.BackStackEntry;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
@ -159,6 +160,8 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme
contentWebView.addJavascriptInterface(new WikivoyageArticleWebAppInterface(), "Android");
webViewClient = new WikivoyageWebViewClient(getActivity(), getFragmentManager(), nightMode);
contentWebView.setWebViewClient(webViewClient);
contentWebView.setBackgroundColor(ContextCompat.getColor(getMyApplication(),
nightMode ? R.color.wiki_webview_background_dark : R.color.wiki_webview_background_light));
return mainView;
}
@ -253,7 +256,8 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme
for (String n : langs) {
names.put(n, FileNameTranslationHelper.getVoiceName(getContext(), n));
}
for (final Map.Entry<String, String> e : names.entrySet()) {
Map<String, String> sortedNames = AndroidUtils.sortByValue(names);
for (final Map.Entry<String, String> e : sortedNames.entrySet()) {
final String lang = e.getValue();
final String langKey = e.getKey();
MenuItem item = popup.getMenu().add(lang);

View file

@ -19,13 +19,16 @@ import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard.StartEditingTravelVH;
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard;
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard.DownloadUpdateVH;
import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard;
import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard.NeededMapsVH;
import java.util.ArrayList;
import java.util.List;
public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int DOWNLOAD_UPDATE_CARD_POSITION = 0;
private static final int FIRST_POSITION = 0;
private static final int SECOND_POSITION = 1;
private final List<BaseTravelCard> items = new ArrayList<>();
@ -48,6 +51,9 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
case HeaderTravelCard.TYPE:
return new HeaderTravelVH(inflate(parent, R.layout.wikivoyage_list_header));
case TravelNeededMapsCard.TYPE:
return new NeededMapsVH(inflate(parent, R.layout.travel_needed_maps_card));
default:
throw new RuntimeException("Unsupported view type: " + viewType);
}
@ -131,23 +137,45 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
return false;
}
public void setNeededMapsCard(TravelNeededMapsCard card) {
if (addItem(getNeededMapsCardPosition(), card)) {
notifyDataSetChanged();
}
}
private int getNeededMapsCardPosition() {
if (downloadUpdateCardExists(FIRST_POSITION)) {
return SECOND_POSITION;
}
return FIRST_POSITION;
}
public void setDownloadUpdateCard(TravelDownloadUpdateCard card) {
if (addItem(DOWNLOAD_UPDATE_CARD_POSITION, card)) {
if (addItem(getDownloadUpdateCardPosition(), card)) {
notifyDataSetChanged();
}
}
public void updateDownloadUpdateCard() {
notifyItemChanged(DOWNLOAD_UPDATE_CARD_POSITION);
int pos = getDownloadUpdateCardPosition();
if (downloadUpdateCardExists(pos)) {
notifyItemChanged(pos);
}
}
public void removeDownloadUpdateCard() {
if (items.size() > DOWNLOAD_UPDATE_CARD_POSITION) {
BaseTravelCard card = getItem(DOWNLOAD_UPDATE_CARD_POSITION);
if (card.getCardType() == TravelDownloadUpdateCard.TYPE) {
removeItem(DOWNLOAD_UPDATE_CARD_POSITION);
notifyItemRemoved(DOWNLOAD_UPDATE_CARD_POSITION);
}
int pos = getDownloadUpdateCardPosition();
if (downloadUpdateCardExists(pos)) {
removeItem(pos);
notifyItemRemoved(pos);
}
}
private int getDownloadUpdateCardPosition() {
return FIRST_POSITION;
}
private boolean downloadUpdateCardExists(int position) {
return items.size() > position && items.get(position).getCardType() == TravelDownloadUpdateCard.TYPE;
}
}

View file

@ -34,6 +34,7 @@ import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard;
import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard;
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard;
import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard;
import java.io.File;
import java.io.IOException;
@ -93,17 +94,19 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
@Override
public void downloadHasFinished() {
final OsmandApplication app = getMyApplication();
File targetFile = mainIndexItem.getTargetFile(app);
if (downloadUpdateCard != null && mainIndexItem != null && targetFile.exists()) {
downloadUpdateCard.setLoadingInProgress(false);
removeDownloadUpdateCard();
TravelDbHelper travelDbHelper = app.getTravelDbHelper();
travelDbHelper.initTravelBooks();
travelDbHelper.selectTravelBook(targetFile);
Fragment parent = getParentFragment();
if (parent != null && parent instanceof WikivoyageExploreDialogFragment) {
((WikivoyageExploreDialogFragment) parent).populateData();
if (mainIndexItem != null) {
final OsmandApplication app = getMyApplication();
File targetFile = mainIndexItem.getTargetFile(app);
if (downloadUpdateCard != null && targetFile.exists()) {
downloadUpdateCard.setLoadingInProgress(false);
removeDownloadUpdateCard();
TravelDbHelper travelDbHelper = app.getTravelDbHelper();
travelDbHelper.initTravelBooks();
travelDbHelper.selectTravelBook(targetFile);
Fragment parent = getParentFragment();
if (parent != null && parent instanceof WikivoyageExploreDialogFragment) {
((WikivoyageExploreDialogFragment) parent).populateData();
}
}
}
}
@ -153,6 +156,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
this.mainIndexItem = mainIndexItem;
this.neededIndexItems = neededIndexItems;
addDownloadUpdateCard();
addNeededMapsCard();
}
private void addDownloadUpdateCard() {
@ -209,6 +213,12 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
}
}
private void addNeededMapsCard() {
if (!neededIndexItems.isEmpty()) {
adapter.setNeededMapsCard(new TravelNeededMapsCard(getMyApplication(), nightMode, neededIndexItems));
}
}
@NonNull
private String getWikivoyageFileName() {
File selectedTravelBook = getMyApplication().getTravelDbHelper().getSelectedTravelBook();

View file

@ -128,7 +128,7 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
@NonNull
private String getFileTitle() {
return indexItem == null ? "" : indexItem.getBasename().replace("_", " ");
return indexItem == null ? "" : indexItem.getVisibleName(app, app.getRegions(), false);
}
@NonNull

View file

@ -0,0 +1,96 @@
package net.osmand.plus.wikivoyage.explore.travelcards;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.download.IndexItem;
import java.util.List;
public class TravelNeededMapsCard extends BaseTravelCard {
public static final int TYPE = 70;
private List<IndexItem> items;
private Drawable downloadIcon;
public TravelNeededMapsCard(OsmandApplication app, boolean nightMode, List<IndexItem> items) {
super(app, nightMode);
this.items = items;
downloadIcon = getActiveIcon(R.drawable.ic_action_import);
}
@Override
public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) {
if (viewHolder instanceof NeededMapsVH) {
NeededMapsVH holder = (NeededMapsVH) viewHolder;
adjustChildCount(holder.itemsContainer);
for (int i = 0; i < items.size(); i++) {
boolean lastItem = i == items.size() - 1;
IndexItem item = items.get(i);
View view = holder.itemsContainer.getChildAt(i);
((ImageView) view.findViewById(R.id.icon))
.setImageDrawable(getActiveIcon(item.getType().getIconResource()));
((TextView) view.findViewById(R.id.title)).setText(item.getVisibleName(app, app.getRegions(), false));
((TextView) view.findViewById(R.id.description)).setText(getItemDescription(item));
((ImageView) view.findViewById(R.id.icon_action)).setImageDrawable(downloadIcon);
view.findViewById(R.id.divider).setVisibility(lastItem ? View.GONE : View.VISIBLE);
}
}
}
@Override
public int getCardType() {
return TYPE;
}
private void adjustChildCount(LinearLayout itemsContainer) {
int itemsCount = items.size();
int childCount = itemsContainer.getChildCount();
if (itemsCount == childCount) {
return;
}
if (itemsCount > childCount) {
LayoutInflater inflater = LayoutInflater.from(itemsContainer.getContext());
for (int i = childCount; i < itemsCount; i++) {
inflater.inflate(R.layout.travel_needed_map_item, itemsContainer);
}
} else if (itemsCount < childCount) {
itemsContainer.removeViews(0, childCount - itemsCount);
}
}
private String getItemDescription(IndexItem item) {
return app.getString(R.string.file_size_in_mb, item.getArchiveSizeMB()) + "" + item.getType().getString(app);
}
public static class NeededMapsVH extends RecyclerView.ViewHolder {
final LinearLayout itemsContainer;
final View secondaryBtnContainer;
final TextView secondaryBtn;
final View buttonsDivider;
final View primaryBtnContainer;
final TextView primaryButton;
@SuppressWarnings("RedundantCast")
public NeededMapsVH(View itemView) {
super(itemView);
itemsContainer = (LinearLayout) itemView.findViewById(R.id.items_container);
secondaryBtnContainer = itemView.findViewById(R.id.secondary_btn_container);
secondaryBtn = (TextView) itemView.findViewById(R.id.secondary_button);
buttonsDivider = itemView.findViewById(R.id.buttons_divider);
primaryBtnContainer = itemView.findViewById(R.id.primary_btn_container);
primaryButton = (TextView) itemView.findViewById(R.id.primary_button);
}
}
}