Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-05-04 23:29:39 +02:00
commit ac25fee1cb
7 changed files with 30 additions and 22 deletions

View file

@ -175,23 +175,26 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In
}
@Override
public void onItemPurchased(String sku) {
public void onItemPurchased(String sku, boolean active) {
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);
if (!active) {
OsmLiveRestartBottomSheetDialogFragment fragment = new OsmLiveRestartBottomSheetDialogFragment();
fragment.setUsedOnMap(this instanceof MapActivity);
fragment.show(getSupportFragmentManager(), OsmLiveRestartBottomSheetDialogFragment.TAG);
}
}
onInAppPurchaseItemPurchased(sku);
fireInAppPurchaseItemPurchasedOnFragments(getSupportFragmentManager(), sku);
fireInAppPurchaseItemPurchasedOnFragments(getSupportFragmentManager(), sku, active);
}
public void fireInAppPurchaseItemPurchasedOnFragments(@NonNull FragmentManager fragmentManager, String sku) {
public void fireInAppPurchaseItemPurchasedOnFragments(@NonNull FragmentManager fragmentManager,
String sku, boolean active) {
List<Fragment> fragments = fragmentManager.getFragments();
for (Fragment f : fragments) {
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).onItemPurchased(sku);
((InAppPurchaseListener) f).onItemPurchased(sku, active);
}
}
}

View file

@ -4,7 +4,6 @@ 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;
import android.support.annotation.ColorRes;
@ -39,8 +38,6 @@ import net.osmand.plus.base.BaseOsmAndDialogFragment;
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.OsmLiveActivity;
import net.osmand.plus.liveupdates.SubscriptionFragment;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.widgets.TextViewEx;
@ -84,6 +81,9 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
}
public boolean isFeaturePurchased(OsmandApplication ctx) {
if (InAppPurchaseHelper.isSubscribedToLiveUpdates(ctx)) {
return true;
}
switch (this) {
case DAILY_MAP_UPDATES:
case DONATION_TO_OSM:
@ -447,7 +447,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
}
@Override
public void onItemPurchased(String sku) {
public void onItemPurchased(String sku, boolean active) {
}
@Override

View file

@ -169,7 +169,7 @@ public class OsmLiveCancelledDialog extends BaseOsmAndDialogFragment implements
}
@Override
public void onItemPurchased(String sku) {
public void onItemPurchased(String sku, boolean active) {
}
@Override

View file

@ -345,7 +345,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
}
@Override
public void onItemPurchased(String sku) {
public void onItemPurchased(String sku, boolean active) {
getMyApplication().getDownloadThread().runReloadIndexFilesSilent();
}

View file

@ -97,7 +97,7 @@ public class InAppPurchaseHelper {
void onGetItems();
void onItemPurchased(String sku);
void onItemPurchased(String sku, boolean active);
void showProgress(InAppPurchaseTaskType taskType);
@ -604,11 +604,16 @@ public class InAppPurchaseHelper {
sendToken(purchase.getToken(), new OnRequestResultListener() {
@Override
public void onResult(String result) {
boolean active = ctx.getSettings().LIVE_UPDATES_PURCHASED.get();
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
ctx.getSettings().getCustomRenderBooleanProperty("depthContours").set(true);
ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_TIME.set(0L);
ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_FIRST_DLG_SHOWN.set(false);
ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_SECOND_DLG_SHOWN.set(false);
notifyDismissProgress(InAppPurchaseTaskType.PURCHASE_LIVE_UPDATES);
notifyItemPurchased(SKU_LIVE_UPDATES);
notifyItemPurchased(SKU_LIVE_UPDATES, active);
stop(true);
}
});
@ -620,7 +625,7 @@ public class InAppPurchaseHelper {
ctx.getSettings().FULL_VERSION_PURCHASED.set(true);
notifyDismissProgress(InAppPurchaseTaskType.PURCHASE_FULL_VERSION);
notifyItemPurchased(SKU_FULL_VERSION_PRICE);
notifyItemPurchased(SKU_FULL_VERSION_PRICE, false);
stop(true);
} else if (purchase.getSku().equals(SKU_DEPTH_CONTOURS)) {
@ -631,7 +636,7 @@ public class InAppPurchaseHelper {
ctx.getSettings().getCustomRenderBooleanProperty("depthContours").set(true);
notifyDismissProgress(InAppPurchaseTaskType.PURCHASE_DEPTH_CONTOURS);
notifyItemPurchased(SKU_DEPTH_CONTOURS);
notifyItemPurchased(SKU_DEPTH_CONTOURS, false);
stop(true);
} else {
@ -748,9 +753,9 @@ public class InAppPurchaseHelper {
}
}
private void notifyItemPurchased(String sku) {
private void notifyItemPurchased(String sku, boolean active) {
if (uiActivity != null) {
uiActivity.onItemPurchased(sku);
uiActivity.onItemPurchased(sku, active);
}
}

View file

@ -715,7 +715,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
}
@Override
public void onItemPurchased(String sku) {
public void onItemPurchased(String sku, boolean active) {
InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper();
if (purchaseHelper != null && purchaseHelper.getSkuLiveUpdates().equals(sku)) {
updateSubscriptionHeader();
@ -723,7 +723,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
OsmandInAppPurchaseActivity activity = getInAppPurchaseActivity();
if (activity != null) {
activity.fireInAppPurchaseItemPurchasedOnFragments(getChildFragmentManager(), sku);
activity.fireInAppPurchaseItemPurchasedOnFragments(getChildFragmentManager(), sku, active);
}
}

View file

@ -355,7 +355,7 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
}
@Override
public void onItemPurchased(String sku) {
public void onItemPurchased(String sku, boolean active) {
dismiss();
}