Add UI of support region setting
This commit is contained in:
parent
3e4153a5cb
commit
03f0f19cae
7 changed files with 192 additions and 55 deletions
|
@ -1,6 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/bg_color"
|
||||
|
@ -32,6 +34,70 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/support_region_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingEnd="@dimen/content_padding">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/setting_list_item_group_height"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="@dimen/map_widget_height"
|
||||
android:layout_marginRight="@dimen/map_widget_height"
|
||||
app:srcCompat="@drawable/ic_world_globe_dark"
|
||||
app:tint="?attr/default_icon_color" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginTop="@dimen/content_padding_small"
|
||||
android:layout_marginBottom="@dimen/content_padding_small"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/support_region_header"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
osmand:typeface="@string/font_roboto_regular"
|
||||
tools:text="@string/osm_live_support_region"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/support_region"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
android:text="@string/osm_live_support_region"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_regular"
|
||||
tools:text="@string/clear_updates_proposition_message"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
app:srcCompat="@drawable/ic_action_settings"
|
||||
app:tint="?attr/default_icon_color" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/simple_divider_item" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/report_container"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -198,6 +198,18 @@ public abstract class InAppPurchaseHelper {
|
|||
isDeveloperVersion = Version.isDeveloperVersion(ctx);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<InAppSubscription> getEverMadeSubscriptions() {
|
||||
List<InAppSubscription> subscriptions = new ArrayList<>();
|
||||
for (InAppSubscription subscription : getLiveUpdates().getVisibleSubscriptions()) {
|
||||
SubscriptionState state = subscription.getState();
|
||||
if (state != null && !SubscriptionState.UNDEFINED.equals(state)) {
|
||||
subscriptions.add(subscription);
|
||||
}
|
||||
}
|
||||
return subscriptions;
|
||||
}
|
||||
|
||||
public abstract void isInAppPurchaseSupported(@NonNull final Activity activity, @Nullable final InAppPurchaseInitCallback callback);
|
||||
|
||||
public boolean hasInventory() {
|
||||
|
|
|
@ -35,6 +35,8 @@ import java.util.List;
|
|||
|
||||
public class CountrySelectionFragment extends BaseOsmAndDialogFragment {
|
||||
|
||||
public static final String TAG = CountrySelectionFragment.class.getSimpleName();
|
||||
|
||||
private List<CountryItem> countryItems = new ArrayList<>();
|
||||
private OnFragmentInteractionListener mListener;
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener;
|
|||
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType;
|
||||
import net.osmand.plus.inapp.InAppPurchases.InAppSubscription;
|
||||
import net.osmand.plus.resources.IncrementalChangesManager;
|
||||
import net.osmand.plus.settings.fragments.PurchasesFragment;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -181,28 +182,9 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
|
|||
statusTextView.setText(getString(R.string.osm_live_active));
|
||||
statusIcon.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_done));
|
||||
|
||||
regionNameHeaderTextView.setText(R.string.osm_live_support_region);
|
||||
String countryName = app.getSettings().BILLING_USER_COUNTRY.get();
|
||||
InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper();
|
||||
if (purchaseHelper != null) {
|
||||
InAppSubscription monthlyPurchased = purchaseHelper.getPurchasedMonthlyLiveUpdates();
|
||||
if (monthlyPurchased != null && monthlyPurchased.isDonationSupported()) {
|
||||
if (Algorithms.isEmpty(countryName)) {
|
||||
if (app.getSettings().BILLING_USER_COUNTRY_DOWNLOAD_NAME.get().equals(OsmandSettings.BILLING_USER_DONATION_NONE_PARAMETER)) {
|
||||
regionNameHeaderTextView.setText(R.string.default_buttons_support);
|
||||
countryName = getString(R.string.osmand_team);
|
||||
} else {
|
||||
countryName = getString(R.string.shared_string_world);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
regionNameHeaderTextView.setText(R.string.default_buttons_support);
|
||||
countryName = getString(R.string.osmand_team);
|
||||
}
|
||||
} else {
|
||||
regionNameHeaderTextView.setText(R.string.default_buttons_support);
|
||||
countryName = getString(R.string.osmand_team);
|
||||
}
|
||||
String countryName = PurchasesFragment.getSupportRegionName(app, getInAppPurchaseHelper());
|
||||
String header = PurchasesFragment.getSupportRegionHeader(app, countryName);
|
||||
regionNameHeaderTextView.setText(header);
|
||||
regionNameTextView.setText(countryName);
|
||||
|
||||
View subscriptionsButton = subscriptionHeader.findViewById(R.id.button_subscriptions);
|
||||
|
|
|
@ -177,7 +177,7 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
|
|||
CountrySelectionFragment countryCountrySelectionFragment =
|
||||
countrySelectionFragment;
|
||||
countryCountrySelectionFragment
|
||||
.show(getChildFragmentManager(), "CountriesSearchSelectionFragment");
|
||||
.show(getChildFragmentManager(), CountrySelectionFragment.TAG);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -21,11 +21,6 @@ import android.widget.ImageView;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
|
@ -39,21 +34,37 @@ import net.osmand.plus.base.BaseOsmAndFragment;
|
|||
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
|
||||
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener;
|
||||
import net.osmand.plus.inapp.InAppPurchases.InAppSubscription;
|
||||
import net.osmand.plus.liveupdates.CountrySelectionFragment;
|
||||
import net.osmand.plus.liveupdates.CountrySelectionFragment.CountryItem;
|
||||
import net.osmand.plus.liveupdates.CountrySelectionFragment.OnFragmentInteractionListener;
|
||||
import net.osmand.plus.liveupdates.LiveUpdatesFragmentNew;
|
||||
import net.osmand.plus.liveupdates.OsmLiveActivity;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
public class PurchasesFragment extends BaseOsmAndFragment implements InAppPurchaseListener {
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
public class PurchasesFragment extends BaseOsmAndFragment implements InAppPurchaseListener, OnFragmentInteractionListener {
|
||||
|
||||
public static final String TAG = PurchasesFragment.class.getName();
|
||||
public static final String KEY_IS_SUBSCRIBER = "action_is_new";
|
||||
private static final String PLAY_STORE_SUBSCRIPTION_URL = "https://play.google.com/store/account/subscriptions";
|
||||
private static final String PLAY_STORE_SUBSCRIPTION_DEEPLINK_URL = "https://play.google.com/store/account/subscriptions?sku=%s&package=%s";
|
||||
|
||||
private OsmandApplication app;
|
||||
private Context context;
|
||||
private InAppPurchaseHelper purchaseHelper;
|
||||
|
||||
private View mainView;
|
||||
private SubscriptionsCard subscriptionsCard;
|
||||
private Context context;
|
||||
private OsmandApplication app;
|
||||
|
||||
private CountrySelectionFragment countrySelectionFragment = new CountrySelectionFragment();
|
||||
|
||||
private String url;
|
||||
private Boolean isSubscriber;
|
||||
|
||||
|
@ -79,20 +90,14 @@ public class PurchasesFragment extends BaseOsmAndFragment implements InAppPurcha
|
|||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
app = getMyApplication();
|
||||
context = requireContext();
|
||||
purchaseHelper = getInAppPurchaseHelper();
|
||||
isSubscriber = Version.isPaidVersion(app);
|
||||
final MapActivity mapActivity = (MapActivity) getActivity();
|
||||
final boolean nightMode = !getMyApplication().getSettings().isLightContent();
|
||||
final MapActivity mapActivity = getMapActivity();
|
||||
final boolean nightMode = !app.getSettings().isLightContent();
|
||||
LayoutInflater themedInflater = UiUtilities.getInflater(context, nightMode);
|
||||
|
||||
if (isSubscriber) {
|
||||
mainView = themedInflater.inflate(R.layout.purchases_layout, container, false);
|
||||
setSubscriptionClick(mapActivity);
|
||||
if (mapActivity != null && purchaseHelper != null) {
|
||||
ViewGroup subscriptionsCardContainer = mainView.findViewById(R.id.subscriptions_card_container);
|
||||
subscriptionsCard = new SubscriptionsCard(mapActivity, purchaseHelper);
|
||||
subscriptionsCardContainer.addView(subscriptionsCard.build(mapActivity));
|
||||
}
|
||||
} else {
|
||||
mainView = themedInflater.inflate(R.layout.empty_purchases_layout, container, false);
|
||||
LinearLayout osmandLive = mainView.findViewById(R.id.osmand_live);
|
||||
|
@ -138,6 +143,21 @@ public class PurchasesFragment extends BaseOsmAndFragment implements InAppPurcha
|
|||
return mainView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
purchaseHelper = getInAppPurchaseHelper();
|
||||
if (isSubscriber) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (getMapActivity() != null && purchaseHelper != null) {
|
||||
ViewGroup subscriptionsCardContainer = mainView.findViewById(R.id.subscriptions_card_container);
|
||||
subscriptionsCard = new SubscriptionsCard(mapActivity, purchaseHelper);
|
||||
subscriptionsCardContainer.addView(subscriptionsCard.build(mapActivity));
|
||||
}
|
||||
setupSupportRegion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
@ -189,6 +209,54 @@ public class PurchasesFragment extends BaseOsmAndFragment implements InAppPurcha
|
|||
|
||||
}
|
||||
|
||||
private void setupSupportRegion() {
|
||||
String region = getSupportRegionName(app, purchaseHelper);
|
||||
String header = getSupportRegionHeader(app, region);
|
||||
TextView supportRegionHeader = mainView.findViewById(R.id.support_region_header);
|
||||
TextView supportRegion = mainView.findViewById(R.id.support_region);
|
||||
supportRegionHeader.setText(header);
|
||||
supportRegion.setText(region);
|
||||
|
||||
View supportRegionContainer = mainView.findViewById(R.id.support_region_container);
|
||||
supportRegionContainer.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CountrySelectionFragment countryCountrySelectionFragment = countrySelectionFragment;
|
||||
countryCountrySelectionFragment.show(getChildFragmentManager(), CountrySelectionFragment.TAG);
|
||||
}
|
||||
});
|
||||
|
||||
countrySelectionFragment.initCountries(app);
|
||||
}
|
||||
|
||||
public static String getSupportRegionName(OsmandApplication app, InAppPurchaseHelper purchaseHelper) {
|
||||
OsmandSettings settings = app.getSettings();
|
||||
String countryName = settings.BILLING_USER_COUNTRY.get();
|
||||
if (purchaseHelper != null) {
|
||||
InAppSubscription monthlyPurchased = purchaseHelper.getPurchasedMonthlyLiveUpdates();
|
||||
if (monthlyPurchased != null && monthlyPurchased.isDonationSupported()) {
|
||||
if (Algorithms.isEmpty(countryName)) {
|
||||
if (OsmandSettings.BILLING_USER_DONATION_NONE_PARAMETER.equals(settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get())) {
|
||||
countryName = app.getString(R.string.osmand_team);
|
||||
} else {
|
||||
countryName = app.getString(R.string.shared_string_world);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
countryName = app.getString(R.string.osmand_team);
|
||||
}
|
||||
} else {
|
||||
countryName = app.getString(R.string.osmand_team);
|
||||
}
|
||||
return countryName;
|
||||
}
|
||||
|
||||
public static String getSupportRegionHeader(OsmandApplication app, String supportRegion) {
|
||||
return supportRegion.equals(app.getString(R.string.osmand_team)) ?
|
||||
app.getString(R.string.default_buttons_support) :
|
||||
app.getString(R.string.osm_live_support_region);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public InAppPurchaseHelper getInAppPurchaseHelper() {
|
||||
Activity activity = getActivity();
|
||||
|
@ -263,6 +331,23 @@ public class PurchasesFragment extends BaseOsmAndFragment implements InAppPurcha
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchResult(CountryItem selectedCountryItem) {
|
||||
String countryName = selectedCountryItem != null ? selectedCountryItem.getLocalName() : "";
|
||||
String countryDownloadName = selectedCountryItem != null ?
|
||||
selectedCountryItem.getDownloadName() : OsmandSettings.BILLING_USER_DONATION_WORLD_PARAMETER;
|
||||
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
TextView supportRegionHeader = mainView.findViewById(R.id.support_region_header);
|
||||
TextView supportRegion = mainView.findViewById(R.id.support_region);
|
||||
supportRegionHeader.setText(getSupportRegionHeader(app, countryName));
|
||||
supportRegion.setText(countryName);
|
||||
app.getSettings().BILLING_USER_COUNTRY.set(countryName);
|
||||
app.getSettings().BILLING_USER_COUNTRY_DOWNLOAD_NAME.set(countryDownloadName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(InAppPurchaseHelper.InAppPurchaseTaskType taskType, String error) {
|
||||
}
|
||||
|
@ -288,4 +373,8 @@ public class PurchasesFragment extends BaseOsmAndFragment implements InAppPurcha
|
|||
@Override
|
||||
public void dismissProgress(InAppPurchaseHelper.InAppPurchaseTaskType taskType) {
|
||||
}
|
||||
|
||||
private MapActivity getMapActivity() {
|
||||
return (MapActivity) getActivity();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,11 +45,11 @@ public class SubscriptionsCard extends BaseCard {
|
|||
|
||||
@Override
|
||||
protected void updateContent() {
|
||||
if (mapActivity == null) {
|
||||
if (mapActivity == null || purchaseHelper == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<InAppSubscription> subscriptions = getActiveAndCancelledSubscriptions();
|
||||
List<InAppSubscription> subscriptions = purchaseHelper.getEverMadeSubscriptions();
|
||||
if (Algorithms.isEmpty(subscriptions)) {
|
||||
return;
|
||||
}
|
||||
|
@ -162,18 +162,4 @@ public class SubscriptionsCard extends BaseCard {
|
|||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private List<InAppSubscription> getActiveAndCancelledSubscriptions() {
|
||||
List<InAppSubscription> subscriptions = new ArrayList<>();
|
||||
for (InAppSubscription subscription : purchaseHelper.getLiveUpdates().getVisibleSubscriptions()) {
|
||||
if (shouldShowSubscription(subscription)) {
|
||||
subscriptions.add(subscription);
|
||||
}
|
||||
}
|
||||
return subscriptions;
|
||||
}
|
||||
|
||||
private boolean shouldShowSubscription(InAppSubscription s) {
|
||||
return s.getState() != null && !SubscriptionState.UNDEFINED.equals(s.getState());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue