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);
}
}
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);
}
}
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);
}
}
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;
}
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();
}
}
Aggregations