Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-04-30 14:05:41 +02:00
commit 64ffeadffa
23 changed files with 160 additions and 103 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View file

@ -7,15 +7,16 @@
android:background="?attr/bottom_menu_view_bg"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingStart="@dimen/list_content_padding"
android:src="@drawable/img_help_wikivoyage_show_image"
android:contentDescription="@string/wikivoyage_download_pics" />
<TextView
android:id="@+id/title"
@ -26,20 +27,17 @@
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginTop="@dimen/bottom_sheet_icon_margin"
android:layout_marginTop="@dimen/list_content_padding"
android:textSize="@dimen/empty_state_text_size"
android:textColor="?attr/wikivoyage_primary_text_color"
android:text="@string/wikivoyage_download_pics" />
</LinearLayout>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_marginBottom="@dimen/dialog_content_margin"
android:layout_marginTop="@dimen/list_header_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingStart="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
@ -136,6 +134,4 @@
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -19,6 +19,7 @@ import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper;
public class SecondSplashScreenFragment extends Fragment {
public static final String TAG = "SecondSplashScreenFragment";
@ -99,15 +100,15 @@ public class SecondSplashScreenFragment extends Fragment {
logoLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
ImageView text = new ImageView(activity);
if (Version.isFreeVersion(app)) {
if (settings.LIVE_UPDATES_PURCHASED.get()) {
if (InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) {
text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand_osmlive));
} else if (settings.FULL_VERSION_PURCHASED.get()) {
} else if (InAppPurchaseHelper.isFullVersionPurchased(app)) {
text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand_inapp));
} else {
text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand));
}
} else if (Version.isPaidVersion(app) || Version.isDeveloperVersion(app)) {
if (settings.LIVE_UPDATES_PURCHASED.get()) {
if (InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) {
text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand_plus_osmlive));
} else {
text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand_plus));

View file

@ -878,8 +878,8 @@ public class OsmandApplication extends MultiDexApplication {
try {
if (Version.isGooglePlayEnabled(this) && Version.isFreeVersion(this)
&& !osmandSettings.DO_NOT_SEND_ANONYMOUS_APP_USAGE.get()
&& !osmandSettings.FULL_VERSION_PURCHASED.get()
&& !osmandSettings.LIVE_UPDATES_PURCHASED.get()) {
&& !InAppPurchaseHelper.isFullVersionPurchased(this)
&& !InAppPurchaseHelper.isSubscribedToLiveUpdates(this)) {
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

@ -965,6 +965,9 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> BILLING_HIDE_USER_NAME = new BooleanPreference("billing_hide_user_name", false).makeGlobal();
public final OsmandPreference<Boolean> BILLING_PURCHASE_TOKEN_SENT = new BooleanPreference("billing_purchase_token_sent", false).makeGlobal();
public final OsmandPreference<Boolean> LIVE_UPDATES_PURCHASED = new BooleanPreference("billing_live_updates_purchased", false).makeGlobal();
public final OsmandPreference<Long> LIVE_UPDATES_PURCHASE_CANCELLED_TIME = new LongPreference("live_updates_purchase_cancelled_time", 0).makeGlobal();
public final OsmandPreference<Boolean> LIVE_UPDATES_PURCHASE_CANCELLED_FIRST_DLG_SHOWN = new BooleanPreference("live_updates_purchase_cancelled_first_dlg_shown", false).makeGlobal();
public final OsmandPreference<Boolean> LIVE_UPDATES_PURCHASE_CANCELLED_SECOND_DLG_SHOWN = new BooleanPreference("live_updates_purchase_cancelled_second_dlg_shown", false).makeGlobal();
public final OsmandPreference<Boolean> FULL_VERSION_PURCHASED = new BooleanPreference("billing_full_version_purchased", false).makeGlobal();
public final OsmandPreference<Boolean> DEPTH_CONTOURS_PURCHASED = new BooleanPreference("billing_sea_depth_purchased", false).makeGlobal();
public final OsmandPreference<Boolean> EMAIL_SUBSCRIBED = new BooleanPreference("email_subscribed", false).makeGlobal();
@ -974,8 +977,6 @@ public class OsmandSettings {
public final OsmandPreference<Integer> DISCOUNT_TOTAL_SHOW = new IntPreference("discount_total_show", 0).makeGlobal();
public final OsmandPreference<Long> DISCOUNT_SHOW_DATETIME_MS = new LongPreference("show_discount_datetime_ms", 0).makeGlobal();
public final OsmandPreference<Boolean> TRAVEL_ARTICLES_PURCHASED = new BooleanPreference("travel_articles_purchased", false).makeGlobal();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<String> USER_OSM_BUG_NAME =
new StringPreference("user_osm_bug_name", "NoName/OsmAnd").makeGlobal();

View file

@ -6,6 +6,8 @@ import java.net.URLEncoder;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import net.osmand.plus.inapp.InAppPurchaseHelper;
public class Version {
private final String appVersion;
@ -121,14 +123,18 @@ public class Version {
public static boolean isPaidVersion(OsmandApplication ctx) {
return !isFreeVersion(ctx)
|| ctx.getSettings().FULL_VERSION_PURCHASED.get()
|| ctx.getSettings().LIVE_UPDATES_PURCHASED.get();
|| InAppPurchaseHelper.isFullVersionPurchased(ctx)
|| InAppPurchaseHelper.isSubscribedToLiveUpdates(ctx);
}
public static boolean isDeveloperVersion(OsmandApplication ctx){
return getAppName(ctx).contains("~") || ctx.getPackageName().equals(FREE_DEV_VERSION_NAME);
}
public static boolean isDeveloperBuild(OsmandApplication ctx){
return getAppName(ctx).contains("~");
}
public static String getVersionForTracker(OsmandApplication ctx) {
String v = Version.getAppName(ctx);
if(Version.isProductionVersion(ctx)){

View file

@ -48,6 +48,7 @@ import net.osmand.plus.dashboard.DashChooseAppDirFragment.ChooseAppDirFragment;
import net.osmand.plus.dashboard.DashChooseAppDirFragment.MoveFilesToDifferentDirectory;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.render.RenderingRulesStorage;
@ -495,8 +496,10 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
misc.addPreference(createCheckBoxPreference(settings.DO_NOT_USE_ANIMATIONS, R.string.do_not_use_animations, R.string.do_not_use_animations_descr));
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));
if (Version.isGooglePlayEnabled(getMyApplication()) && Version.isFreeVersion(getMyApplication())
&& !settings.FULL_VERSION_PURCHASED.get() && !settings.LIVE_UPDATES_PURCHASED.get()) {
OsmandApplication app = getMyApplication();
if (Version.isGooglePlayEnabled(getMyApplication()) && Version.isFreeVersion(app)
&& !InAppPurchaseHelper.isFullVersionPurchased(app)
&& !InAppPurchaseHelper.isSubscribedToLiveUpdates(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

@ -3,6 +3,7 @@ package net.osmand.plus.chooseplan;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
@ -31,6 +32,7 @@ import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.inapp.InAppPurchaseHelper;
@ -56,7 +58,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
private View planTypeCardButton;
public interface ChoosePlanDialogListener {
void onChoosePlanDialogDismissed();
void onChoosePlanDialogDismiss();
}
public enum OsmAndFeature {
@ -88,11 +90,10 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
case WIKIPEDIA_OFFLINE:
case UNLOCK_ALL_FEATURES:
case DONATION_TO_OSM:
case WIKIVOYAGE_OFFLINE:
return false;
case SEA_DEPTH_MAPS:
return ctx.getSettings().DEPTH_CONTOURS_PURCHASED.get();
case WIKIVOYAGE_OFFLINE:
return ctx.getSettings().TRAVEL_ARTICLES_PURCHASED.get();
return InAppPurchaseHelper.isDepthContoursPurchased(ctx);
case CONTOUR_LINES_HILLSHADE_MAPS:
return OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null;
}
@ -198,11 +199,11 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
}
@Override
public void dismiss() {
super.dismiss();
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
Activity activity = getActivity();
if (activity != null && activity instanceof ChoosePlanDialogListener) {
((ChoosePlanDialogListener) activity).onChoosePlanDialogDismissed();
((ChoosePlanDialogListener) activity).onChoosePlanDialogDismiss();
}
}

View file

@ -58,6 +58,7 @@ import net.osmand.plus.download.ui.DownloadResourceGroupFragment;
import net.osmand.plus.download.ui.LocalIndexesFragment;
import net.osmand.plus.download.ui.UpdatesIndexFragment;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
@ -403,8 +404,8 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
}
public static boolean shouldShowFreeVersionBanner(OsmandApplication application) {
return (Version.isFreeVersion(application) && !application.getSettings().LIVE_UPDATES_PURCHASED.get()
&& !application.getSettings().FULL_VERSION_PURCHASED.get())
return (Version.isFreeVersion(application) && !InAppPurchaseHelper.isSubscribedToLiveUpdates(application)
&& !InAppPurchaseHelper.isFullVersionPurchased(application))
|| application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get();
}

View file

@ -32,6 +32,7 @@ import net.osmand.plus.Version;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.helpers.DatabaseHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.util.Algorithms;
@ -563,8 +564,8 @@ public class DownloadIndexesThread {
private boolean validateNotExceedsFreeLimit(IndexItem item) {
boolean exceed = Version.isFreeVersion(app)
&& !app.getSettings().LIVE_UPDATES_PURCHASED.get()
&& !app.getSettings().FULL_VERSION_PURCHASED.get()
&& !InAppPurchaseHelper.isSubscribedToLiveUpdates(app)
&& !InAppPurchaseHelper.isFullVersionPurchased(app)
&& DownloadActivityType.isCountedInDownloads(item)
&& downloads.get() >= DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
if(exceed) {

View file

@ -12,6 +12,7 @@ import net.osmand.map.OsmandRegions;
import net.osmand.map.WorldRegion;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
@ -75,23 +76,26 @@ public class DownloadResources extends DownloadResourceGroup {
@Nullable
public IndexItem getWikivoyageItem(@NonNull String fileName) {
String groupId = DownloadResourceGroupType.TRAVEL_GROUP.getDefaultId() + "#" +
DownloadResourceGroupType.WIKIVOYAGE_MAPS.getDefaultId() + "#" +
DownloadResourceGroupType.WIKIVOYAGE_HEADER.getDefaultId();
DownloadResourceGroup wikivoyageHeader = getSubGroupById(groupId);
if (wikivoyageHeader != null) {
List<IndexItem> items = wikivoyageHeader.getIndividualResources();
if (items != null) {
for (IndexItem ii : items) {
if (ii.getFileName().equals(fileName)) {
return ii;
}
List<IndexItem> items = getWikivoyageItems();
if (items != null) {
for (IndexItem ii : items) {
if (ii.getFileName().equals(fileName)) {
return ii;
}
}
}
return null;
}
@Nullable
public List<IndexItem> getWikivoyageItems() {
String groupId = DownloadResourceGroupType.TRAVEL_GROUP.getDefaultId() + "#" +
DownloadResourceGroupType.WIKIVOYAGE_MAPS.getDefaultId() + "#" +
DownloadResourceGroupType.WIKIVOYAGE_HEADER.getDefaultId();
DownloadResourceGroup header = getSubGroupById(groupId);
return header == null ? null : header.getIndividualResources();
}
public IndexItem getIndexItem(String fileName) {
IndexItem res = null;
if (rawResources == null) {
@ -321,7 +325,7 @@ public class DownloadResources extends DownloadResourceGroup {
continue;
}
if (ii.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE) {
if (app.getSettings().DEPTH_CONTOURS_PURCHASED.get() || nauticalMaps.size() == 0) {
if (InAppPurchaseHelper.isDepthContoursPurchased(app) || nauticalMaps.size() == 0) {
nauticalMaps.addItem(ii);
}
continue;

View file

@ -17,6 +17,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import java.io.File;
import java.text.MessageFormat;
@ -154,8 +155,8 @@ public class DownloadValidationManager {
}
protected void downloadFilesCheck_1_FreeVersion(FragmentActivity context, IndexItem[] items) {
if (Version.isFreeVersion(getMyApplication()) && !app.getSettings().LIVE_UPDATES_PURCHASED.get()
&& !app.getSettings().FULL_VERSION_PURCHASED.get()) {
if (Version.isFreeVersion(getMyApplication()) && !InAppPurchaseHelper.isSubscribedToLiveUpdates(app)
&& !InAppPurchaseHelper.isFullVersionPurchased(app)) {
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS) {
if (context instanceof FragmentActivity) {

View file

@ -32,6 +32,7 @@ import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.util.Algorithms;
import java.io.File;
@ -129,7 +130,7 @@ public class ItemViewHolder {
nauticalPluginDisabled = context.isNauticalPluginDisabled();
freeVersion = context.isFreeVersion();
srtmNeedsInstallation = context.isSrtmNeedsInstallation();
depthContoursPurchased = context.getMyApplication().getSettings().DEPTH_CONTOURS_PURCHASED.get();
depthContoursPurchased = InAppPurchaseHelper.isDepthContoursPurchased(context.getMyApplication());
}
public void bindIndexItem(final IndexItem indexItem) {
@ -314,10 +315,10 @@ public class ItemViewHolder {
}
} else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE && freeVersion
&& !context.getMyApplication().getSettings().FULL_VERSION_PURCHASED.get()) {
&& !InAppPurchaseHelper.isFullVersionPurchased(context.getMyApplication())) {
clickAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE;
} else if (indexItem.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE
&& !context.getMyApplication().getSettings().DEPTH_CONTOURS_PURCHASED.get()) {
&& !InAppPurchaseHelper.isDepthContoursPurchased(context.getMyApplication())) {
clickAction = RightButtonAction.ASK_FOR_DEPTH_CONTOURS_PURCHASE;
}
return clickAction;

View file

@ -56,6 +56,7 @@ import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.resources.IncrementalChangesManager;
import net.osmand.util.Algorithms;
@ -469,7 +470,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
if (operation == DELETE_OPERATION) {
File f = new File(info.getPathToData());
successfull = Algorithms.removeAllFiles(f);
if (getMyApplication().getSettings().LIVE_UPDATES_PURCHASED.get()) {
if (InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) {
String fileNameWithoutExtension =
Algorithms.getFileNameWithoutExtension(f);
IncrementalChangesManager changesManager =

View file

@ -26,6 +26,7 @@ import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.util.Algorithms;
import java.util.Comparator;
@ -92,7 +93,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download
getMyApplication().getResourceManager().getOsmandRegions();
OsmandSettings settings = getMyApplication().getSettings();
listAdapter = new UpdateIndexAdapter(a, R.layout.download_index_list_item, indexItems,
!settings.LIVE_UPDATES_PURCHASED.get() || settings.SHOULD_SHOW_FREE_VERSION_BANNER.get());
!InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication()) || settings.SHOULD_SHOW_FREE_VERSION_BANNER.get());
listAdapter.sort(new Comparator<IndexItem>() {
@Override
public int compare(IndexItem indexItem, IndexItem indexItem2) {

View file

@ -121,8 +121,16 @@ public class InAppPurchaseHelper {
return activeTask;
}
public boolean isSubscribedToLiveUpdates() {
return ctx.getSettings().LIVE_UPDATES_PURCHASED.get();
public static boolean isSubscribedToLiveUpdates(@NonNull OsmandApplication ctx) {
return Version.isDeveloperBuild(ctx) || ctx.getSettings().LIVE_UPDATES_PURCHASED.get();
}
public static boolean isFullVersionPurchased(@NonNull OsmandApplication ctx) {
return Version.isDeveloperBuild(ctx) || ctx.getSettings().FULL_VERSION_PURCHASED.get();
}
public static boolean isDepthContoursPurchased(@NonNull OsmandApplication ctx) {
return Version.isDeveloperBuild(ctx) || ctx.getSettings().DEPTH_CONTOURS_PURCHASED.get();
}
public String getLiveUpdatesPrice() {
@ -176,12 +184,7 @@ public class InAppPurchaseHelper {
public InAppPurchaseHelper(OsmandApplication ctx) {
this.ctx = ctx;
this.isDeveloperVersion = Version.isDeveloperVersion(ctx);
if (this.isDeveloperVersion) {
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
ctx.getSettings().FULL_VERSION_PURCHASED.set(true);
ctx.getSettings().DEPTH_CONTOURS_PURCHASED.set(true);
}
isDeveloperVersion = Version.isDeveloperVersion(ctx);
initialize();
}
@ -192,11 +195,11 @@ public class InAppPurchaseHelper {
public boolean isPurchased(String inAppSku) {
OsmandSettings settings = ctx.getSettings();
if (inAppSku.equals(SKU_FULL_VERSION_PRICE)) {
return settings.FULL_VERSION_PURCHASED.get();
return isFullVersionPurchased(ctx);
} else if (inAppSku.equals(SKU_LIVE_UPDATES_FULL) || inAppSku.equals(SKU_LIVE_UPDATES_FREE)) {
return settings.LIVE_UPDATES_PURCHASED.get();
return isSubscribedToLiveUpdates(ctx);
} else if (inAppSku.equals(SKU_DEPTH_CONTOURS_FULL) || inAppSku.equals(SKU_DEPTH_CONTOURS_FREE)) {
return settings.DEPTH_CONTOURS_PURCHASED.get();
return isDepthContoursPurchased(ctx);
}
return false;
}
@ -252,7 +255,7 @@ public class InAppPurchaseHelper {
}
public boolean needRequestInventory() {
return (ctx.getSettings().LIVE_UPDATES_PURCHASED.get() && !ctx.getSettings().BILLING_PURCHASE_TOKEN_SENT.get())
return (isSubscribedToLiveUpdates(ctx) && !ctx.getSettings().BILLING_PURCHASE_TOKEN_SENT.get())
|| System.currentTimeMillis() - lastValidationCheckTime > PURCHASE_VALIDATION_PERIOD_MSEC;
}
@ -355,7 +358,9 @@ public class InAppPurchaseHelper {
// Do we have the live updates?
Purchase liveUpdatesPurchase = inventory.getPurchase(SKU_LIVE_UPDATES);
boolean subscribedToLiveUpdates = (liveUpdatesPurchase != null && liveUpdatesPurchase.getPurchaseState() == 0);
//subscribedToLiveUpdates = false;
if (!subscribedToLiveUpdates && ctx.getSettings().LIVE_UPDATES_PURCHASED.get()) {
ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_TIME.set(System.currentTimeMillis());
}
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(subscribedToLiveUpdates);
Purchase fullVersionPurchase = inventory.getPurchase(SKU_FULL_VERSION_PRICE);

View file

@ -130,8 +130,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper();
if (!processing && purchaseHelper != null && purchaseHelper.isSubscribedToLiveUpdates()) {
if (!processing && InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) {
final FragmentManager fragmentManager = getChildFragmentManager();
LiveUpdatesSettingsDialogFragment
.createInstance(adapter.getChild(groupPosition, childPosition).getFileName())
@ -153,8 +152,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper();
if (position == 0 && !processing && purchaseHelper != null && purchaseHelper.isSubscribedToLiveUpdates()) {
if (position == 0 && !processing && InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) {
SubscriptionFragment subscriptionFragment = new SubscriptionFragment();
subscriptionFragment.setEditMode(true);
subscriptionFragment.show(getChildFragmentManager(), SubscriptionFragment.TAG);
@ -174,7 +172,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
if (getActivity() instanceof OsmLiveActivity) {
View subscriptionBanner = subscriptionHeader.findViewById(R.id.subscription_banner);
View subscriptionInfo = subscriptionHeader.findViewById(R.id.subscription_info);
if (getSettings().LIVE_UPDATES_PURCHASED.get()) {
if (InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) {
ImageView statusIcon = (ImageView) subscriptionHeader.findViewById(R.id.statusIcon);
TextView statusTextView = (TextView) subscriptionHeader.findViewById(R.id.statusTextView);
TextView regionNameHeaderTextView = (TextView) subscriptionHeader.findViewById(R.id.regionHeaderTextView);
@ -267,7 +265,9 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
@SuppressWarnings("deprecation")
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (getSettings().LIVE_UPDATES_PURCHASED.get() && !Version.isDeveloperVersion(getMyApplication())) {
if (InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())
&& !Version.isDeveloperVersion(getMyApplication())) {
ActionBar actionBar = getMyActivity().getSupportActionBar();
if (actionBar != null) {
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
@ -404,8 +404,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper();
if (purchaseHelper != null && purchaseHelper.isSubscribedToLiveUpdates()) {
if (InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) {
switchOnLiveUpdates(settings);
} else {
liveUpdatesSwitch.setChecked(false);
@ -606,8 +605,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
descriptionTextView.setText(context.getString(R.string.last_map_change, lastCheckString));
}
InAppPurchaseHelper purchaseHelper = fragment.getInAppPurchaseHelper();
if (!fragment.isProcessing() && purchaseHelper != null && purchaseHelper.isSubscribedToLiveUpdates()) {
if (!fragment.isProcessing() && InAppPurchaseHelper.isSubscribedToLiveUpdates(context)) {
final View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -708,8 +706,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
@Override
public void onGetItems() {
InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper();
if (purchaseHelper != null && !purchaseHelper.isSubscribedToLiveUpdates()) {
if (!InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) {
getSettings().IS_LIVE_UPDATES_ON.set(false);
adapter.enableLiveUpdates(false);
}

View file

@ -21,6 +21,7 @@ import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment.ChoosePlanDialogListener;
import net.osmand.plus.download.AbstractDownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import org.apache.commons.logging.Log;
@ -35,12 +36,10 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
private final static Log LOG = PlatformUtil.getLog(OsmLiveActivity.class);
public final static String OPEN_SUBSCRIPTION_INTENT_PARAM = "open_subscription_intent_param";
public final static String SHOW_SETTINGS_ONLY_INTENT_PARAM = "show_settings_only_intent_param";
public final static String CHOOSE_PLAN_DIALOG_DISMISSED_KEY = "choose_plan_dialog_dismissed_key";
private LiveUpdatesFragmentPagerAdapter pagerAdapter;
private boolean openSubscription;
private boolean showSettingOnly;
private boolean choosePlanDialogDismissed;
private GetLastUpdateDateTask getLastUpdateDateTask;
private static final String URL = "https://osmand.net/api/osmlive_status";
@ -57,7 +56,6 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
} else if (savedInstanceState != null) {
openSubscription = savedInstanceState.getBoolean(OPEN_SUBSCRIPTION_INTENT_PARAM, false);
showSettingOnly = savedInstanceState.getBoolean(SHOW_SETTINGS_ONLY_INTENT_PARAM, false);
choosePlanDialogDismissed = savedInstanceState.getBoolean(CHOOSE_PLAN_DIALOG_DISMISSED_KEY, false);
}
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
@ -89,8 +87,7 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
@Override
protected void onResume() {
super.onResume();
if (!getMyApplication().getSettings().LIVE_UPDATES_PURCHASED.get() && showSettingOnly
&& !choosePlanDialogDismissed) {
if (!InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication()) && showSettingOnly) {
ChoosePlanDialogFragment.showOsmLiveInstance(getSupportFragmentManager());
}
}
@ -114,12 +111,11 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
super.onSaveInstanceState(outState);
outState.putBoolean(OPEN_SUBSCRIPTION_INTENT_PARAM, openSubscription);
outState.putBoolean(SHOW_SETTINGS_ONLY_INTENT_PARAM, showSettingOnly);
outState.putBoolean(CHOOSE_PLAN_DIALOG_DISMISSED_KEY, choosePlanDialogDismissed);
}
@Override
public void onChoosePlanDialogDismissed() {
choosePlanDialogDismissed = true;
public void onChoosePlanDialogDismiss() {
finish();
}
public boolean isShowSettingOnly() {

View file

@ -36,6 +36,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.plus.resources.AsyncLoadingThread.MapLoadRequest;
@ -581,7 +582,7 @@ 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) || context.getSettings().FULL_VERSION_PURCHASED.get()) {
if (!Version.isFreeVersion(context) || InAppPurchaseHelper.isFullVersionPurchased(context)) {
collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
}
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
@ -618,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 && !context.getSettings().FULL_VERSION_PURCHASED.get())) {
if (mapReader == null || (Version.isFreeVersion(context) && wikiMap && !InAppPurchaseHelper.isFullVersionPurchased(context))) {
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
} else {
if (mapReader.isBasemap()) {

View file

@ -22,7 +22,7 @@ public class TravelLocalDataHelper {
private WikivoyageLocalDataDbHelper dbHelper;
private TLongObjectHashMap<WikivoyageSearchHistoryItem> historyMap;
private List<TravelArticle> savedArticles;
private List<TravelArticle> savedArticles = new ArrayList<>();
private Listener listener;
@ -114,7 +114,7 @@ public class TravelLocalDataHelper {
savedArticles.add(article);
dbHelper.addSavedArticle(article);
notifySavedUpdated();
}
}
}
public void removeArticleFromSaved(@NonNull TravelArticle article) {

View file

@ -1,5 +1,7 @@
package net.osmand.plus.wikivoyage.explore;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -10,7 +12,6 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -38,7 +39,6 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
private ExploreRvAdapter adapter = new ExploreRvAdapter();
private StartEditingTravelCard startEditingTravelCard;
private TravelDownloadUpdateCard downloadUpdateCard;
private boolean nightMode;
@ -67,7 +67,6 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
final List<BaseTravelCard> items = new ArrayList<>();
final OsmandApplication app = getMyApplication();
startEditingTravelCard = new StartEditingTravelCard(app, nightMode);
addOpenBetaTravelCard(items, nightMode);
if (app.getTravelDbHelper().getSelectedTravelBook() != null) {
items.add(new HeaderTravelCard(app, nightMode, getString(R.string.popular_destinations)));
@ -80,7 +79,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
}
}
}
items.add(startEditingTravelCard);
items.add(new StartEditingTravelCard(app, nightMode));
adapter.setItems(items);
checkToAddDownloadTravelCard();
@ -150,17 +149,21 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
boolean outdated = indexItem != null && indexItem.isOutdated();
File selectedTravelBook = app.getTravelDbHelper().getSelectedTravelBook();
if (selectedTravelBook == null || outdated) {
boolean showOtherMaps = false;
if (selectedTravelBook == null) {
List<IndexItem> items = app.getDownloadThread().getIndexes().getWikivoyageItems();
showOtherMaps = items != null && items.size() > 1;
}
downloadUpdateCard = new TravelDownloadUpdateCard(app, nightMode, !outdated);
downloadUpdateCard.setShowOtherMapsBtn(showOtherMaps);
downloadUpdateCard.setLoadingInProgress(loadingInProgress);
downloadUpdateCard.setListener(new TravelDownloadUpdateCard.ClickListener() {
@Override
public void onPrimaryButtonClick() {
if (app.getSettings().isInternetConnectionAvailable()) {
if (indexItem != null) {
new DownloadValidationManager(app).startDownload(getMyActivity(), indexItem);
downloadUpdateCard.setLoadingInProgress(true);
adapter.updateDownloadUpdateCard();
} else {
Toast.makeText(app, app.getString(R.string.no_index_file_to_download), Toast.LENGTH_SHORT).show();
}
}
@ -172,6 +175,14 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
adapter.updateDownloadUpdateCard();
} else if (!downloadUpdateCard.isDownload()) {
removeDownloadUpdateCard();
} else if (downloadUpdateCard.isShowOtherMapsBtn()) {
Activity activity = getActivity();
if (activity != null) {
Intent newIntent = new Intent(activity,
getMyApplication().getAppCustomization().getDownloadActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
activity.startActivity(newIntent);
}
}
}
});

View file

@ -3,6 +3,7 @@ package net.osmand.plus.wikivoyage.explore.travelcards;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.View;
@ -21,6 +22,7 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
public static final int TYPE = 50;
private boolean download;
private boolean showOtherMapsBtn;
private boolean loadingInProgress;
private int progress;
@ -35,6 +37,14 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
return download;
}
public boolean isShowOtherMapsBtn() {
return showOtherMapsBtn;
}
public void setShowOtherMapsBtn(boolean showOtherMapsBtn) {
this.showOtherMapsBtn = showOtherMapsBtn;
}
public boolean isLoadingInProgress() {
return loadingInProgress;
}
@ -97,6 +107,10 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
return app.getString(download ? R.string.download_file : R.string.update_is_available);
}
private boolean isInternetAvailable() {
return app.getSettings().isInternetConnectionAvailable();
}
private Drawable getIcon() {
int id = download ? R.drawable.travel_card_download_icon : R.drawable.travel_card_update_icon;
return ContextCompat.getDrawable(app, id);
@ -104,6 +118,9 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
@NonNull
private String getDescription() {
if (!isInternetAvailable()) {
return app.getString(R.string.no_index_file_to_download);
}
return app.getString(download ? R.string.travel_card_download_descr : R.string.travel_card_update_descr);
}
@ -131,9 +148,9 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
* @return true if button is visible, false otherwise.
*/
private boolean updateSecondaryButton(DownloadUpdateVH vh) {
if (loadingInProgress || !download) {
if (loadingInProgress || !download || showOtherMapsBtn) {
vh.secondaryBtnContainer.setVisibility(View.VISIBLE);
vh.secondaryBtn.setText(loadingInProgress ? R.string.shared_string_cancel : R.string.later);
vh.secondaryBtn.setText(getSecondaryBtnTextId());
vh.secondaryBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -148,12 +165,24 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
return false;
}
@StringRes
private int getSecondaryBtnTextId() {
if (loadingInProgress) {
return R.string.shared_string_cancel;
}
if (!download) {
return R.string.later;
}
return R.string.download_select_map_types;
}
/**
* @return true if button is visible, false otherwise.
*/
private boolean updatePrimaryButton(DownloadUpdateVH vh) {
if (!loadingInProgress) {
vh.primaryBtnContainer.setVisibility(View.VISIBLE);
vh.primaryButton.setEnabled(isInternetAvailable());
vh.primaryButton.setText(download ? R.string.shared_string_download : R.string.shared_string_update);
vh.primaryButton.setOnClickListener(new View.OnClickListener() {
@Override