Search in sources :

Example 1 with InAppPurchases

use of net.osmand.plus.inapp.InAppPurchases in project Osmand by osmandapp.

the class DiscountHelper method openUrl.

public static void openUrl(final MapActivity mapActivity, String url) {
    if (url.startsWith(INAPP_PREFIX)) {
        OsmandApplication app = mapActivity.getMyApplication();
        InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
        if (purchaseHelper != null) {
            InAppPurchase fullVersion = purchaseHelper.getFullVersion();
            if (fullVersion != null && url.contains(fullVersion.getSku())) {
                app.logEvent("in_app_purchase_redirect");
                try {
                    purchaseHelper.purchaseFullVersion(mapActivity);
                } catch (UnsupportedOperationException e) {
                    LOG.error("purchaseFullVersion is not supported", e);
                }
            } else {
                InAppPurchases purchases = purchaseHelper.getInAppPurchases();
                for (InAppPurchase p : purchaseHelper.getSubscriptions().getAllSubscriptions()) {
                    if (url.contains(p.getSku())) {
                        if (purchases.isMapsSubscription(p)) {
                            MapsPlusPlanFragment.showInstance(mapActivity, p.getSku());
                        } else if (purchases.isOsmAndProSubscription(p)) {
                            OsmAndProPlanFragment.showInstance(mapActivity, p.getSku());
                        } else {
                            ChoosePlanFragment.showDefaultInstance(mapActivity);
                        }
                        break;
                    }
                }
            }
        }
    } else if (url.startsWith(SEARCH_QUERY_PREFIX)) {
        String query = url.substring(SEARCH_QUERY_PREFIX.length());
        if (!query.isEmpty()) {
            mapActivity.showQuickSearch(query);
        }
    } else if (url.startsWith(SHOW_POI_PREFIX)) {
        String names = url.substring(SHOW_POI_PREFIX.length());
        if (!names.isEmpty()) {
            OsmandApplication app = mapActivity.getMyApplication();
            MapPoiTypes poiTypes = app.getPoiTypes();
            Map<PoiCategory, LinkedHashSet<String>> acceptedTypes = new LinkedHashMap<>();
            for (String name : names.split(",")) {
                AbstractPoiType abstractType = poiTypes.getAnyPoiTypeByKey(name);
                if (abstractType instanceof PoiCategory) {
                    acceptedTypes.put((PoiCategory) abstractType, null);
                } else if (abstractType instanceof PoiType) {
                    PoiType type = (PoiType) abstractType;
                    PoiCategory category = type.getCategory();
                    LinkedHashSet<String> set = acceptedTypes.get(category);
                    if (set == null) {
                        set = new LinkedHashSet<>();
                        acceptedTypes.put(category, set);
                    }
                    set.add(type.getKeyName());
                }
            }
            if (!acceptedTypes.isEmpty()) {
                PoiUIFilter filter = new PoiUIFilter("", null, acceptedTypes, app);
                filter.setName(filter.getTypesName());
                showPoiFilter(mapActivity, filter);
            }
        }
    } else if (url.equals(OPEN_ACTIVITY)) {
        if (mData != null && mData.activityJson != null) {
            openActivity(mapActivity, mData.activityJson);
        }
    } else if (url.startsWith(SHOW_CHOOSE_PLAN_PREFIX)) {
        String planType = url.substring(SHOW_CHOOSE_PLAN_PREFIX.length()).trim();
        showDialogForPlanType(mapActivity, planType);
    } else {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        AndroidUtils.startActivityIfSafe(mapActivity, intent);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OsmandApplication(net.osmand.plus.OsmandApplication) InAppPurchase(net.osmand.plus.inapp.InAppPurchases.InAppPurchase) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) InAppPurchases(net.osmand.plus.inapp.InAppPurchases) Intent(android.content.Intent) AbstractPoiType(net.osmand.osm.AbstractPoiType) MapPoiTypes(net.osmand.osm.MapPoiTypes) LinkedHashMap(java.util.LinkedHashMap) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) PoiCategory(net.osmand.osm.PoiCategory) InAppPurchaseHelper(net.osmand.plus.inapp.InAppPurchaseHelper)

Example 2 with InAppPurchases

use of net.osmand.plus.inapp.InAppPurchases in project Osmand by osmandapp.

the class OsmAndProPlanFragment method getVisibleSubscriptions.

public static List<InAppSubscription> getVisibleSubscriptions(OsmandApplication app, InAppPurchaseHelper purchaseHelper) {
    InAppPurchases purchases = app.getInAppPurchaseHelper().getInAppPurchases();
    List<InAppSubscription> subscriptions = new ArrayList<>();
    List<InAppSubscription> visibleSubscriptions = purchaseHelper.getSubscriptions().getVisibleSubscriptions();
    for (InAppSubscription subscription : visibleSubscriptions) {
        if (purchases.isOsmAndProSubscription(subscription)) {
            subscriptions.add(subscription);
        }
    }
    return subscriptions;
}
Also used : ArrayList(java.util.ArrayList) InAppPurchases(net.osmand.plus.inapp.InAppPurchases) InAppSubscription(net.osmand.plus.inapp.InAppPurchases.InAppSubscription)

Example 3 with InAppPurchases

use of net.osmand.plus.inapp.InAppPurchases in project Osmand by osmandapp.

the class MapsPlusPlanFragment method getVisibleSubscriptions.

protected static List<InAppSubscription> getVisibleSubscriptions(OsmandApplication app, InAppPurchaseHelper purchaseHelper) {
    InAppPurchases purchases = app.getInAppPurchaseHelper().getInAppPurchases();
    List<InAppSubscription> subscriptions = new ArrayList<>();
    List<InAppSubscription> visibleSubscriptions = purchaseHelper.getSubscriptions().getVisibleSubscriptions();
    for (InAppSubscription subscription : visibleSubscriptions) {
        if (purchases.isMapsSubscription(subscription)) {
            subscriptions.add(subscription);
        }
    }
    return subscriptions;
}
Also used : ArrayList(java.util.ArrayList) InAppPurchases(net.osmand.plus.inapp.InAppPurchases) InAppSubscription(net.osmand.plus.inapp.InAppPurchases.InAppSubscription)

Aggregations

InAppPurchases (net.osmand.plus.inapp.InAppPurchases)3 ArrayList (java.util.ArrayList)2 InAppSubscription (net.osmand.plus.inapp.InAppPurchases.InAppSubscription)2 Intent (android.content.Intent)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 AbstractPoiType (net.osmand.osm.AbstractPoiType)1 MapPoiTypes (net.osmand.osm.MapPoiTypes)1 PoiCategory (net.osmand.osm.PoiCategory)1 PoiType (net.osmand.osm.PoiType)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 InAppPurchaseHelper (net.osmand.plus.inapp.InAppPurchaseHelper)1 InAppPurchase (net.osmand.plus.inapp.InAppPurchases.InAppPurchase)1 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)1