Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-03-14 13:57:06 +01:00
commit 397bcd676c
8 changed files with 88 additions and 17 deletions

View file

@ -9,6 +9,7 @@
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="full_version_thanks">Thank you for purchasing full version of OsmAnd!</string>
<string name="routing_attr_relief_smoothness_factor_hills_name">Hills</string>
<string name="routing_attr_relief_smoothness_factor_plains_name">Plains</string>
<string name="routing_attr_relief_smoothness_factor_more_plains_name">More plains</string>

View file

@ -73,6 +73,7 @@ public class OsmandApplication extends MultiDexApplication {
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandApplication.class);
public static final String SHOW_PLUS_VERSION_PARAM = "show_plus_version";
public static final String SHOW_PLUS_VERSION_INAPP_PARAM = "show_plus_version_inapp";
final AppInitializer appInitializer = new AppInitializer(this);
OsmandSettings osmandSettings = null;

View file

@ -914,6 +914,7 @@ 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<Boolean> FULL_VERSION_PURCHASED = new BooleanPreference("billing_full_version_purchased", false).makeGlobal();
public final OsmandPreference<Integer> DISCOUNT_ID = new IntPreference("discount_id", 0).makeGlobal();
public final OsmandPreference<Integer> DISCOUNT_SHOW_NUMBER_OF_STARTS = new IntPreference("number_of_starts_on_discount_show", 0).makeGlobal();

View file

@ -1,11 +1,9 @@
package net.osmand.plus.download;
import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StatFs;
@ -185,7 +183,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
inAppHelper = new InAppHelper(getMyApplication(), true);
inAppHelper.addListener(this);
visibleBanner.setUpdatingPrices(true);
inAppHelper.start(true);
inAppHelper.start(false);
}
final Intent intent = getIntent();
@ -196,11 +194,23 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Pass on the activity result to the helper for handling
if (inAppHelper == null || !inAppHelper.onActivityResultHandled(requestCode, resultCode, data)) {
// not handled, so handle it ourselves (here's where you'd
// perform any handling of activity results not related to in-app
// billing...
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (inAppHelper != null) {
inAppHelper.removeListener(this);
inAppHelper.stop();
}
}
@ -291,6 +301,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
@Override
public void onItemPurchased(String sku) {
visibleBanner.setUpdatingPrices(false);
}
@Override
@ -347,7 +358,8 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
}
private static boolean shouldShowFreeVersionBanner(OsmandApplication application) {
return (Version.isFreeVersion(application) && !application.getSettings().LIVE_UPDATES_PURCHASED.get())
return (Version.isFreeVersion(application) && !application.getSettings().LIVE_UPDATES_PURCHASED.get()
&& !application.getSettings().FULL_VERSION_PURCHASED.get())
|| application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get();
}
@ -380,8 +392,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
collapseBanner();
} else {
ctx.getMyApplication().logEvent(ctx, "click_free_dialog");
new FreeVersionDialogFragment().show(ctx.getSupportFragmentManager(), "dialog");
// expandBanner();
new FreeVersionDialogFragment().show(ctx.getSupportFragmentManager(), FreeVersionDialogFragment.TAG);
}
}
};
@ -438,12 +449,11 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
@Override
public void onClick(View v) {
ctx.getMyApplication().logEvent(ctx, "click_buy_plus");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(
ctx.getMyApplication()) + "net.osmand.plus"));
try {
ctx.startActivity(intent);
} catch (ActivityNotFoundException e) {
LOG.error("ActivityNotFoundException", e);
ctx.inAppHelper.purchaseFullVersion(ctx);
DialogFragment f = (DialogFragment) ctx.getSupportFragmentManager()
.findFragmentByTag(FreeVersionDialogFragment.TAG);
if (f != null) {
f.dismiss();
}
}
});
@ -489,6 +499,9 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
public void updateFreeVersionBanner() {
if (!shouldShowFreeVersionBanner(ctx.getMyApplication())) {
if (freeVersionBanner.getVisibility() == View.VISIBLE) {
freeVersionBanner.setVisibility(View.GONE);
}
return;
}
setMinimizedFreeVersionBanner(false);

View file

@ -574,8 +574,11 @@ public class DownloadIndexesThread {
}
private boolean validateNotExceedsFreeLimit(IndexItem item) {
boolean exceed = Version.isFreeVersion(app) && !app.getSettings().LIVE_UPDATES_PURCHASED.get() &&
DownloadActivityType.isCountedInDownloads(item) && downloads.get() >= DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
boolean exceed = Version.isFreeVersion(app)
&& !app.getSettings().LIVE_UPDATES_PURCHASED.get()
&& !app.getSettings().FULL_VERSION_PURCHASED.get()
&& DownloadActivityType.isCountedInDownloads(item)
&& downloads.get() >= DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
if(exceed) {
String breakDownloadMessage = app.getString(R.string.free_version_message,
DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");

View file

@ -154,7 +154,8 @@ public class DownloadValidationManager {
}
protected void downloadFilesCheck_1_FreeVersion(FragmentActivity context, IndexItem[] items) {
if (Version.isFreeVersion(getMyApplication()) && !app.getSettings().LIVE_UPDATES_PURCHASED.get()) {
if (Version.isFreeVersion(getMyApplication()) && !app.getSettings().LIVE_UPDATES_PURCHASED.get()
&& !app.getSettings().FULL_VERSION_PURCHASED.get()) {
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS) {
if (context instanceof FragmentActivity) {

View file

@ -13,9 +13,11 @@ import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivity.FreeVersionDialog;
import static net.osmand.plus.OsmandApplication.SHOW_PLUS_VERSION_INAPP_PARAM;
import static net.osmand.plus.OsmandApplication.SHOW_PLUS_VERSION_PARAM;
public class FreeVersionDialogFragment extends DialogFragment {
public static final String TAG = "FreeVersionDialogFragment";
private FreeVersionDialog dialog;
@NonNull
@ -28,7 +30,7 @@ public class FreeVersionDialogFragment extends DialogFragment {
builder.setNegativeButton(R.string.later, null);
View view = getActivity().getLayoutInflater().inflate(R.layout.free_version_banner, null);
boolean hidePlus = !app.getRemoteBoolean(SHOW_PLUS_VERSION_PARAM, false);
boolean hidePlus = !app.getRemoteBoolean(SHOW_PLUS_VERSION_INAPP_PARAM, true);
view.findViewById(R.id.osmLiveLayoutTopDivider).setVisibility(hidePlus ? View.GONE : View.VISIBLE);
view.findViewById(R.id.fullVersionLayout).setVisibility(hidePlus ? View.GONE : View.VISIBLE);
builder.setView(view);

View file

@ -36,6 +36,7 @@ public class InAppHelper {
boolean mDebugLog = false;
private static boolean mSubscribedToLiveUpdates = false;
private static boolean mFullVersionPurchased = false;
private static String mLiveUpdatesPrice;
private static long lastValidationCheckTime;
private static String mFullVersionPrice;
@ -79,6 +80,10 @@ public class InAppHelper {
return mSubscribedToLiveUpdates;
}
public static boolean isFullVersionPurchased() {
return mFullVersionPurchased;
}
public static String getLiveUpdatesPrice() {
return mLiveUpdatesPrice;
}
@ -108,7 +113,9 @@ public class InAppHelper {
isDeveloperVersion = Version.isDeveloperVersion(ctx);
if (isDeveloperVersion) {
mSubscribedToLiveUpdates = true;
mFullVersionPurchased = true;
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
ctx.getSettings().FULL_VERSION_PURCHASED.set(true);
}
}
@ -214,6 +221,13 @@ public class InAppHelper {
if (mSubscribedToLiveUpdates) {
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
}
Purchase fullVersionPurchase = inventory.getPurchase(SKU_FULL_VERSION_PRICE);
mFullVersionPurchased = isDeveloperVersion || (fullVersionPurchase != null && fullVersionPurchase.getPurchaseState() == 0);
if (mFullVersionPurchased) {
ctx.getSettings().FULL_VERSION_PURCHASED.set(true);
}
lastValidationCheckTime = System.currentTimeMillis();
logDebug("User " + (mSubscribedToLiveUpdates ? "HAS" : "DOES NOT HAVE")
+ " live updates purchased.");
@ -270,9 +284,26 @@ public class InAppHelper {
}
};
public void purchaseFullVersion(final Activity activity) {
if (mHelper == null || !mHelper.subscriptionsSupported()) {
complain("Subscriptions not supported on your device yet. Sorry!");
notifyError("Subscriptions not supported on your device yet. Sorry!");
if (stopAfterResult) {
stop();
}
return;
}
logDebug("Launching purchase flow for full version");
if (mHelper != null) {
mHelper.launchPurchaseFlow(activity,
SKU_FULL_VERSION_PRICE, RC_REQUEST, mPurchaseFinishedListener);
}
}
public void purchaseLiveUpdates(final Activity activity, final String email, final String userName,
final String countryDownloadName, final boolean hideUserName) {
if (!mHelper.subscriptionsSupported()) {
if (mHelper == null || !mHelper.subscriptionsSupported()) {
complain("Subscriptions not supported on your device yet. Sorry!");
notifyError("Subscriptions not supported on your device yet. Sorry!");
if (stopAfterResult) {
@ -420,6 +451,24 @@ public class InAppHelper {
}
});
}
if (purchase.getSku().equals(SKU_FULL_VERSION_PRICE)) {
// bought full version
logDebug("Full version purchased.");
sendToken(purchase.getToken(), new OnRequestResultListener() {
@Override
public void onResult(String result) {
showToast(ctx.getString(R.string.full_version_thanks));
mFullVersionPurchased = true;
ctx.getSettings().FULL_VERSION_PURCHASED.set(true);
notifyDismissProgress();
notifyItemPurchased(SKU_FULL_VERSION_PRICE);
if (stopAfterResult) {
stop();
}
}
});
}
}
};