Fix purchases

This commit is contained in:
Alexey Kulish 2017-04-18 15:26:26 +03:00
parent c8a26f52fa
commit fb03d8b959
8 changed files with 44 additions and 20 deletions

View file

@ -126,6 +126,11 @@ android {
dimension "version" dimension "version"
applicationId "net.osmand" applicationId "net.osmand"
} }
freeres {
dimension "version"
applicationId "net.osmand"
resConfig "en"
}
full { full {
dimension "version" dimension "version"
applicationId "net.osmand.plus" applicationId "net.osmand.plus"

View file

@ -99,7 +99,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/list_content_padding" android:layout_marginTop="@dimen/list_content_padding"
android:orientation="horizontal" android:orientation="horizontal"
android:visibility="gone"> android:visibility="visible">
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
android:layout_width="54dp" android:layout_width="54dp"
@ -149,7 +149,7 @@
android:paddingTop="4dp" android:paddingTop="4dp"
android:textColor="@color/color_white" android:textColor="@color/color_white"
android:visibility="visible" android:visibility="visible"
tools:text="GET FOR E5"/> tools:text="GET FOR 5 EUR"/>
</LinearLayout> </LinearLayout>
@ -162,7 +162,7 @@
android:layout_marginLeft="54dp" android:layout_marginLeft="54dp"
android:layout_marginTop="@dimen/list_content_padding" android:layout_marginTop="@dimen/list_content_padding"
android:background="@color/dashboard_divider_dark" android:background="@color/dashboard_divider_dark"
android:visibility="gone"/> android:visibility="visible"/>
<LinearLayout <LinearLayout
android:id="@+id/osmLiveLayout" android:id="@+id/osmLiveLayout"
@ -219,7 +219,7 @@
android:paddingRight="14dp" android:paddingRight="14dp"
android:paddingTop="4dp" android:paddingTop="4dp"
android:textColor="@color/color_white" android:textColor="@color/color_white"
tools:text="GET FOR 1,5E PER MONTH"/> tools:text="GET FOR 1,5 EUR PER MONTH"/>
</LinearLayout> </LinearLayout>

View file

@ -74,7 +74,6 @@ public class OsmandApplication extends MultiDexApplication {
public static final String EXCEPTION_PATH = "exception.log"; //$NON-NLS-1$ public static final String EXCEPTION_PATH = "exception.log"; //$NON-NLS-1$
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandApplication.class); 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"; public static final String SHOW_PLUS_VERSION_INAPP_PARAM = "show_plus_version_inapp";
final AppInitializer appInitializer = new AppInitializer(this); final AppInitializer appInitializer = new AppInitializer(this);
@ -841,7 +840,7 @@ public class OsmandApplication extends MultiDexApplication {
Object inst = mm.invoke(null); Object inst = mm.invoke(null);
Method log = cl.getMethod("setDefaults", Map.class); Method log = cl.getMethod("setDefaults", Map.class);
Map<String, Object> defaults = new HashMap<>(); Map<String, Object> defaults = new HashMap<>();
defaults.put(SHOW_PLUS_VERSION_PARAM, Boolean.FALSE); defaults.put(SHOW_PLUS_VERSION_INAPP_PARAM, Boolean.TRUE);
log.invoke(inst, defaults); log.invoke(inst, defaults);
} }
} catch (Exception e) { } catch (Exception e) {

View file

@ -1,10 +1,12 @@
package net.osmand.plus.download; package net.osmand.plus.download;
import android.Manifest; import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.StatFs; import android.os.StatFs;
@ -77,6 +79,8 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import static net.osmand.plus.OsmandApplication.SHOW_PLUS_VERSION_INAPP_PARAM;
public class DownloadActivity extends AbstractDownloadActivity implements DownloadEvents, public class DownloadActivity extends AbstractDownloadActivity implements DownloadEvents,
OnRequestPermissionsResultCallback, InAppListener { OnRequestPermissionsResultCallback, InAppListener {
private static final Log LOG = PlatformUtil.getLog(DownloadActivity.class); private static final Log LOG = PlatformUtil.getLog(DownloadActivity.class);
@ -231,13 +235,29 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
} }
public void purchaseFullVersion() { public void purchaseFullVersion() {
OsmandApplication app = getMyApplication();
if (Version.isFreeVersion(app)) {
if (app.getRemoteBoolean(SHOW_PLUS_VERSION_INAPP_PARAM, true)) {
if (inAppHelper != null) { if (inAppHelper != null) {
app.logEvent(this, "in_app_purchase_redirect");
inAppHelper.purchaseFullVersion(this); inAppHelper.purchaseFullVersion(this);
} }
} else {
app.logEvent(this, "paid_version_redirect");
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(Version.marketPrefix(app) + "net.osmand.plus"));
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
LOG.error("ActivityNotFoundException", e);
}
}
}
} }
public void purchaseDepthContours() { public void purchaseDepthContours() {
if (inAppHelper != null) { if (inAppHelper != null) {
getMyApplication().logEvent(this, "depth_contours_purchase_redirect");
inAppHelper.purchaseDepthContours(this); inAppHelper.purchaseDepthContours(this);
} }
} }
@ -533,8 +553,13 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
fullVersionButton.setOnClickListener(new OnClickListener() { fullVersionButton.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
ctx.getMyApplication().logEvent(ctx, "click_buy_plus"); OsmandApplication app = ctx.getMyApplication();
ctx.inAppHelper.purchaseFullVersion(ctx); if (app.getRemoteBoolean(SHOW_PLUS_VERSION_INAPP_PARAM, true)) {
app.logEvent(ctx, "in_app_purchase_redirect_from_banner");
} else {
app.logEvent(ctx, "paid_version_redirect_from_banner");
}
ctx.purchaseFullVersion();
DialogFragment f = (DialogFragment) ctx.getSupportFragmentManager() DialogFragment f = (DialogFragment) ctx.getSupportFragmentManager()
.findFragmentByTag(FreeVersionDialogFragment.TAG); .findFragmentByTag(FreeVersionDialogFragment.TAG);
if (f != null) { if (f != null) {

View file

@ -15,7 +15,6 @@ import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivity.FreeVersionDialog; 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_INAPP_PARAM;
import static net.osmand.plus.OsmandApplication.SHOW_PLUS_VERSION_PARAM;
public class FreeVersionDialogFragment extends DialogFragment { public class FreeVersionDialogFragment extends DialogFragment {
public static final String TAG = "FreeVersionDialogFragment"; public static final String TAG = "FreeVersionDialogFragment";
@ -30,10 +29,6 @@ public class FreeVersionDialogFragment extends DialogFragment {
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.OsmandDarkTheme)); AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.OsmandDarkTheme));
builder.setNegativeButton(R.string.later, null); builder.setNegativeButton(R.string.later, null);
View view = getActivity().getLayoutInflater().inflate(R.layout.free_version_banner, null); View view = getActivity().getLayoutInflater().inflate(R.layout.free_version_banner, null);
boolean hidePlus = !Version.isFreeVersion(app) || !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); builder.setView(view);
dialog = new DownloadActivity.FreeVersionDialog(view, getDownloadActivity(), true); dialog = new DownloadActivity.FreeVersionDialog(view, getDownloadActivity(), true);

View file

@ -331,11 +331,10 @@ public class ItemViewHolder {
public void onClick(View v) { public void onClick(View v) {
switch (clickAction) { switch (clickAction) {
case ASK_FOR_FULL_VERSION_PURCHASE: case ASK_FOR_FULL_VERSION_PURCHASE:
context.getMyApplication().logEvent(context, "click_buy_plus_inapp"); context.getMyApplication().logEvent(context, "in_app_purchase_show_from_wiki_context_menu");
context.purchaseFullVersion(); context.purchaseFullVersion();
break; break;
case ASK_FOR_DEPTH_CONTOURS_PURCHASE: case ASK_FOR_DEPTH_CONTOURS_PURCHASE:
context.getMyApplication().logEvent(context, "click_buy_depth_contours_inapp");
context.purchaseDepthContours(); context.purchaseDepthContours();
break; break;
case ASK_FOR_SEAMARKS_PLUGIN: case ASK_FOR_SEAMARKS_PLUGIN:

View file

@ -213,6 +213,7 @@ public class DiscountHelper {
mapActivity.execInAppTask(new InAppHelper.InAppRunnable() { mapActivity.execInAppTask(new InAppHelper.InAppRunnable() {
@Override @Override
public void run(InAppHelper helper) { public void run(InAppHelper helper) {
mapActivity.getMyApplication().logEvent(mapActivity, "in_app_purchase_redirect");
helper.purchaseFullVersion(mapActivity); helper.purchaseFullVersion(mapActivity);
} }
}); });

View file

@ -130,7 +130,7 @@ public abstract class OsmandNotification {
Notification notification = notificationBuilder.build(); Notification notification = notificationBuilder.build();
setupNotification(notification); setupNotification(notification);
if (top) { if (top) {
notificationManager.cancel(getOsmandNotificationId()); removeNotification();
notificationManager.notify(TOP_NOTIFICATION_SERVICE_ID, notification); notificationManager.notify(TOP_NOTIFICATION_SERVICE_ID, notification);
Builder wearNotificationBuilder = buildNotification(true); Builder wearNotificationBuilder = buildNotification(true);
@ -144,10 +144,10 @@ public abstract class OsmandNotification {
} }
return true; return true;
} else { } else {
notificationManager.cancel(getOsmandNotificationId()); removeNotification();
} }
} else { } else {
notificationManager.cancel(getOsmandNotificationId()); removeNotification();
} }
return false; return false;
} }