Search in sources :

Example 1 with InAppHelper

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

the class DownloadActivity method startInAppHelper.

public void startInAppHelper() {
    stopInAppHelper();
    if (Version.isGooglePlayEnabled(getMyApplication())) {
        inAppHelper = new InAppHelper(getMyApplication(), true);
        inAppHelper.addListener(this);
        inAppHelper.start(false);
    }
}
Also used : InAppHelper(net.osmand.plus.inapp.InAppHelper)

Example 2 with InAppHelper

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

the class DiscountHelper method openUrl.

private static void openUrl(final MapActivity mapActivity, String url) {
    if (url.startsWith(INAPP_PREFIX)) {
        if (url.contains(InAppHelper.SKU_FULL_VERSION_PRICE)) {
            mapActivity.execInAppTask(new InAppHelper.InAppRunnable() {

                @Override
                public void run(InAppHelper helper) {
                    mapActivity.getMyApplication().logEvent(mapActivity, "in_app_purchase_redirect");
                    helper.purchaseFullVersion(mapActivity);
                }
            });
        } else if (url.contains(InAppHelper.SKU_LIVE_UPDATES)) {
            Intent intent = new Intent(mapActivity, OsmLiveActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            intent.putExtra(OsmLiveActivity.OPEN_SUBSCRIPTION_INTENT_PARAM, true);
            mapActivity.startActivity(intent);
        }
    } else {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        mapActivity.startActivity(intent);
    }
}
Also used : InAppHelper(net.osmand.plus.inapp.InAppHelper) Intent(android.content.Intent) OsmLiveActivity(net.osmand.plus.liveupdates.OsmLiveActivity)

Example 3 with InAppHelper

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

the class LiveUpdatesFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    InAppHelper helper = getInAppHelper();
    if (helper != null) {
        enableProgress();
        helper.addListener(this);
        helper.start(false);
    }
    if (((OsmLiveActivity) getActivity()).shouldOpenSubscription()) {
        SubscriptionFragment subscriptionFragment = new SubscriptionFragment();
        subscriptionFragment.show(getChildFragmentManager(), SubscriptionFragment.TAG);
    }
}
Also used : InAppHelper(net.osmand.plus.inapp.InAppHelper)

Example 4 with InAppHelper

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

the class SubscriptionFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    InAppHelper helper = getInAppHelper();
    if (helper != null) {
        helper.addListener(this);
    }
    String userName = settings.BILLING_USER_NAME.get();
    String email = settings.BILLING_USER_EMAIL.get();
    String countryDownloadName = settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get();
    boolean hideUserName = settings.BILLING_HIDE_USER_NAME.get();
    donation = !countryDownloadName.equals(OsmandSettings.BILLING_USER_DONATION_NONE_PARAMETER);
    if (savedInstanceState != null) {
        userName = savedInstanceState.getString(USER_NAME_ID);
        email = savedInstanceState.getString(EMAIL_ID);
        hideUserName = savedInstanceState.getBoolean(HIDE_USER_NAME_ID);
        donation = savedInstanceState.getBoolean(DONATION_ID);
        Object obj = savedInstanceState.getSerializable(COUNTRY_ITEM_ID);
        if (obj instanceof CountryItem) {
            selectedCountryItem = (CountryItem) obj;
            countryDownloadName = selectedCountryItem.getDownloadName();
        } else {
            countryDownloadName = donation ? OsmandSettings.BILLING_USER_DONATION_WORLD_PARAMETER : OsmandSettings.BILLING_USER_DONATION_NONE_PARAMETER;
        }
    }
    View view = inflater.inflate(R.layout.subscription_fragment, container, false);
    ImageButton closeButton = (ImageButton) view.findViewById(R.id.closeButton);
    if (editMode) {
        closeButton.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_mode_back));
    } else {
        closeButton.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_remove_dark));
    }
    closeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    TextView title = (TextView) view.findViewById(R.id.titleTextView);
    if (editMode) {
        title.setText(getString(R.string.osm_live_subscription_settings));
    } else {
        title.setText(getString(R.string.osm_live_subscription));
    }
    final View headerLayout = view.findViewById(R.id.headerLayout);
    final View paramsLayout = view.findViewById(R.id.paramsLayout);
    AppCompatCheckBox donationCheckbox = (AppCompatCheckBox) view.findViewById(R.id.donationCheckbox);
    donationCheckbox.setChecked(donation);
    donationCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            donation = isChecked;
            paramsLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE);
        }
    });
    headerLayout.setVisibility(View.VISIBLE);
    paramsLayout.setVisibility(donation ? View.VISIBLE : View.GONE);
    final EditText userNameEdit = (EditText) view.findViewById(R.id.userNameEdit);
    if (!Algorithms.isEmpty(userName)) {
        userNameEdit.setText(userName);
    }
    final EditText emailEdit = (EditText) view.findViewById(R.id.emailEdit);
    if (!Algorithms.isEmpty(email)) {
        emailEdit.setText(email);
    }
    countrySelectionFragment.initCountries(getMyApplication());
    if (Algorithms.isEmpty(countryDownloadName) || countryDownloadName.equals(OsmandSettings.BILLING_USER_DONATION_NONE_PARAMETER)) {
        selectedCountryItem = countrySelectionFragment.getCountryItems().get(0);
    } else {
        selectedCountryItem = countrySelectionFragment.getCountryItem(countryDownloadName);
    }
    final EditText selectCountryEdit = (EditText) view.findViewById(R.id.selectCountryEdit);
    if (selectedCountryItem != null) {
        selectCountryEdit.setText(selectedCountryItem.getLocalName());
    }
    selectCountryEdit.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                CountrySelectionFragment countryCountrySelectionFragment = countrySelectionFragment;
                countryCountrySelectionFragment.show(getChildFragmentManager(), "CountriesSearchSelectionFragment");
            }
            return false;
        }
    });
    final CheckBox hideUserNameCheckbox = (CheckBox) view.findViewById(R.id.hideUserNameCheckbox);
    hideUserNameCheckbox.setChecked(hideUserName);
    View editModeBottomView = view.findViewById(R.id.editModeBottomView);
    View purchaseCard = view.findViewById(R.id.purchaseCard);
    if (editMode) {
        editModeBottomView.setVisibility(View.VISIBLE);
        purchaseCard.setVisibility(View.GONE);
        Button saveChangesButton = (Button) view.findViewById(R.id.saveChangesButton);
        saveChangesButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                InAppHelper helper = getInAppHelper();
                if (helper != null && applySettings(userNameEdit.getText().toString().trim(), emailEdit.getText().toString().trim(), hideUserNameCheckbox.isChecked())) {
                    final Map<String, String> parameters = new HashMap<>();
                    parameters.put("visibleName", settings.BILLING_HIDE_USER_NAME.get() ? "" : settings.BILLING_USER_NAME.get());
                    parameters.put("preferredCountry", settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get());
                    parameters.put("email", settings.BILLING_USER_EMAIL.get());
                    parameters.put("cemail", prevEmail);
                    parameters.put("userid", settings.BILLING_USER_ID.get());
                    parameters.put("token", helper.getToken());
                    showProgress();
                    AndroidNetworkUtils.sendRequestAsync(getMyApplication(), "http://download.osmand.net/subscription/update.php", parameters, "Sending data...", true, true, new AndroidNetworkUtils.OnRequestResultListener() {

                        @Override
                        public void onResult(String result) {
                            dismissProgress();
                            OsmandApplication app = getMyApplication();
                            if (result != null) {
                                try {
                                    JSONObject obj = new JSONObject(result);
                                    if (!obj.has("error")) {
                                        String userId = obj.getString("userid");
                                        app.getSettings().BILLING_USER_ID.set(userId);
                                        String email = obj.getString("email");
                                        app.getSettings().BILLING_USER_EMAIL.set(email);
                                        String visibleName = obj.getString("visibleName");
                                        if (!Algorithms.isEmpty(visibleName)) {
                                            app.getSettings().BILLING_USER_NAME.set(visibleName);
                                            app.getSettings().BILLING_HIDE_USER_NAME.set(false);
                                        } else {
                                            app.getSettings().BILLING_HIDE_USER_NAME.set(true);
                                        }
                                        String preferredCountry = obj.getString("preferredCountry");
                                        app.getSettings().BILLING_USER_COUNTRY_DOWNLOAD_NAME.set(preferredCountry);
                                        Fragment parent = getParentFragment();
                                        if (parent != null && parent instanceof LiveUpdatesFragment) {
                                            ((LiveUpdatesFragment) parent).updateSubscriptionHeader();
                                        }
                                        dismiss();
                                    } else {
                                        app.showToastMessage("Error: " + obj.getString("error"));
                                    }
                                } catch (JSONException e) {
                                    app.showToastMessage(getString(R.string.shared_string_io_error));
                                }
                            } else {
                                app.showToastMessage(getString(R.string.shared_string_io_error));
                            }
                        }
                    });
                }
            }
        });
    } else {
        editModeBottomView.setVisibility(View.GONE);
        purchaseCard.setVisibility(View.VISIBLE);
        updatePrice(view);
        final Button subscribeButton = (Button) view.findViewById(R.id.subscribeButton);
        subscribeButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                InAppHelper helper = getInAppHelper();
                if (helper != null) {
                    if (applySettings(userNameEdit.getText().toString().trim(), emailEdit.getText().toString().trim(), hideUserNameCheckbox.isChecked())) {
                        helper.purchaseLiveUpdates(getActivity(), settings.BILLING_USER_EMAIL.get(), settings.BILLING_USER_NAME.get(), settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get(), settings.BILLING_HIDE_USER_NAME.get());
                    }
                }
            }
        });
    }
    setThemedDrawable((ImageView) view.findViewById(R.id.userNameIcon), R.drawable.ic_person);
    setThemedDrawable((ImageView) view.findViewById(R.id.emailIcon), R.drawable.ic_action_message);
    setThemedDrawable((ImageView) view.findViewById(R.id.countryIcon), R.drawable.ic_world_globe_dark);
    selectCountryEdit.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
    return view;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) CountryItem(net.osmand.plus.liveupdates.CountrySelectionFragment.CountryItem) BaseOsmAndDialogFragment(net.osmand.plus.base.BaseOsmAndDialogFragment) Fragment(android.support.v4.app.Fragment) ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) TextView(android.widget.TextView) EditText(android.widget.EditText) InAppHelper(net.osmand.plus.inapp.InAppHelper) JSONException(org.json.JSONException) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AppCompatCheckBox(android.support.v7.widget.AppCompatCheckBox) MotionEvent(android.view.MotionEvent) JSONObject(org.json.JSONObject) CheckBox(android.widget.CheckBox) AppCompatCheckBox(android.support.v7.widget.AppCompatCheckBox) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) CompoundButton(android.widget.CompoundButton)

Example 5 with InAppHelper

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

the class SubscriptionFragment method onDestroy.

@Override
public void onDestroy() {
    super.onDestroy();
    InAppHelper helper = getInAppHelper();
    if (helper != null) {
        helper.removeListener(this);
    }
    if (dlg != null && dlg.isShowing()) {
        dlg.hide();
    }
}
Also used : InAppHelper(net.osmand.plus.inapp.InAppHelper)

Aggregations

InAppHelper (net.osmand.plus.inapp.InAppHelper)8 Intent (android.content.Intent)2 TabLayout (android.support.design.widget.TabLayout)1 Fragment (android.support.v4.app.Fragment)1 ViewPager (android.support.v4.view.ViewPager)1 AppCompatCheckBox (android.support.v7.widget.AppCompatCheckBox)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 Button (android.widget.Button)1 CheckBox (android.widget.CheckBox)1 CompoundButton (android.widget.CompoundButton)1 EditText (android.widget.EditText)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 BaseOsmAndDialogFragment (net.osmand.plus.base.BaseOsmAndDialogFragment)1 CountryItem (net.osmand.plus.liveupdates.CountrySelectionFragment.CountryItem)1