Added restore purchases button. Fixes.

This commit is contained in:
Alexey Kulish 2017-03-18 14:40:09 +03:00
parent 9fcf359247
commit afdaedbf36
7 changed files with 201 additions and 13 deletions

View file

@ -37,5 +37,7 @@
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:layout_weight="1"
android:dividerHeight="0.5dp"
android:divider="?attr/ctx_menu_info_divider"
android:groupIndicator="@android:color/transparent"/>
</LinearLayout>

View file

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="16dp"
android:background="?attr/ctx_menu_info_view_bg"/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="?attr/ctx_menu_info_divider"/>
<LinearLayout
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/list_item_height"
android:paddingLeft="@dimen/list_content_padding"
android:background="@android:drawable/list_selector_background">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/favorites_icon_right_margin"
tools:src="@drawable/ic_action_reset_to_default_dark"/>
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:text="@string/restore_purchases"/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="8dp"
android:indeterminate="true"
android:visibility="gone"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="?attr/ctx_menu_info_divider"/>
<View
android:layout_width="match_parent"
android:layout_height="16dp"
android:background="?attr/ctx_menu_info_view_bg"/>
</LinearLayout>
</LinearLayout>

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="restore_purchases">Restore purchases</string>
<string name="fonts_header">Fonts for map</string>
<string name="right_side_navigation">Right-hand driving</string>
<string name="driving_region_automatic">Automatic</string>

View file

@ -111,6 +111,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
private DownloadIndexesThread downloadThread;
protected WorldRegion downloadItem;
protected String downloadTargetFileName;
private InAppHelper inAppHelper;
private boolean srtmDisabled;
@ -180,15 +181,14 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
}
});
viewPager.setCurrentItem(currentTab);
visibleBanner = new BannerAndDownloadFreeVersion(findViewById(R.id.mainLayout), this, true);
visibleBanner = new BannerAndDownloadFreeVersion(findViewById(R.id.mainLayout), this, true);
if (shouldShowFreeVersionBanner(getMyApplication())) {
inAppHelper = new InAppHelper(getMyApplication(), true);
inAppHelper.addListener(this);
visibleBanner.setUpdatingPrices(true);
inAppHelper.start(false);
}
startInAppHelper();
final Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
filter = intent.getExtras().getString(FILTER_KEY);
@ -211,6 +211,18 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
@Override
public void onDestroy() {
super.onDestroy();
stopInAppHelper();
}
public void startInAppHelper() {
stopInAppHelper();
inAppHelper = new InAppHelper(getMyApplication(), true);
inAppHelper.addListener(this);
inAppHelper.start(false);
}
public void stopInAppHelper() {
if (inAppHelper != null) {
inAppHelper.removeListener(this);
inAppHelper.stop();
@ -308,24 +320,54 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
@Override
public void onError(String error) {
visibleBanner.setUpdatingPrices(false);
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof InAppListener && f.isAdded()) {
((InAppListener) f).onError(error);
}
}
}
@Override
public void onGetItems() {
visibleBanner.setUpdatingPrices(false);
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof InAppListener && f.isAdded()) {
((InAppListener) f).onGetItems();
}
}
}
@Override
public void onItemPurchased(String sku) {
visibleBanner.setUpdatingPrices(false);
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof InAppListener && f.isAdded()) {
((InAppListener) f).onItemPurchased(sku);
}
}
}
@Override
public void showProgress() {
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof InAppListener && f.isAdded()) {
((InAppListener) f).showProgress();
}
}
}
@Override
public void dismissProgress() {
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof InAppListener && f.isAdded()) {
((InAppListener) f).dismissProgress();
}
}
}
@Override
@ -531,8 +573,8 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
freeVersionBanner.findViewById(R.id.bannerTopLayout).setOnClickListener(onCollapseListener);
}
if (InAppHelper.hasPrices() || !updatingPrices) {
if (!InAppHelper.hasPrices()) {
if (InAppHelper.hasPrices(ctx.getMyApplication()) || !updatingPrices) {
if (!InAppHelper.hasPrices(ctx.getMyApplication())) {
fullVersionButton.setText(ctx.getString(R.string.get_for, ctx.getString(R.string.full_version_price)));
osmLiveButton.setText(ctx.getString(R.string.get_for_month, ctx.getString(R.string.osm_live_default_price)));
} else {

View file

@ -16,6 +16,7 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.plus.IconsCache;
@ -31,12 +32,15 @@ import net.osmand.plus.download.DownloadResourceGroup;
import net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType;
import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.inapp.InAppHelper;
import net.osmand.plus.inapp.InAppHelper.InAppListener;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.List;
public class DownloadResourceGroupFragment extends DialogFragment implements DownloadEvents, OnChildClickListener {
public class DownloadResourceGroupFragment extends DialogFragment implements DownloadEvents,
InAppListener, OnChildClickListener {
public static final int RELOAD_ID = 0;
public static final int SEARCH_ID = 1;
public static final String TAG = "RegionDialogFragment";
@ -50,6 +54,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
private DownloadActivity activity;
private Toolbar toolbar;
private View searchView;
private View restorePurchasesView;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -103,6 +108,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
listView = (ExpandableListView) view.findViewById(android.R.id.list);
addSearchRow();
addRestorePurchasesRow();
listView.setOnChildClickListener(this);
listAdapter = new DownloadResourceGroupAdapter(activity);
listView.setAdapter(listAdapter);
@ -110,6 +116,27 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
return view;
}
private void addRestorePurchasesRow() {
if (!openAsDialog() && !InAppHelper.isInAppIntentoryRead()) {
restorePurchasesView = activity.getLayoutInflater().inflate(R.layout.restore_purchases_list_footer, null);
((ImageView) restorePurchasesView.findViewById(R.id.icon)).setImageDrawable(
getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_reset_to_default_dark));
restorePurchasesView.findViewById(R.id.button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
restorePurchasesView.findViewById(R.id.progressBar).setVisibility(View.VISIBLE);
activity.startInAppHelper();
}
});
listView.addFooterView(restorePurchasesView);
listView.setFooterDividersEnabled(false);
IndexItem worldBaseMapItem = activity.getDownloadThread().getIndexes().getWorldBaseMapItem();
if (worldBaseMapItem == null || !worldBaseMapItem.isDownloaded()) {
restorePurchasesView.findViewById(R.id.container).setVisibility(View.GONE);
}
}
}
private void addSearchRow() {
if (!openAsDialog() ) {
searchView = activity.getLayoutInflater().inflate(R.layout.simple_list_menu_item, null);
@ -124,21 +151,56 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
}
});
listView.addHeaderView(searchView);
listView.setHeaderDividersEnabled(false);
listView.setHeaderDividersEnabled(true);
IndexItem worldBaseMapItem = activity.getDownloadThread().getIndexes().getWorldBaseMapItem();
if (worldBaseMapItem == null || !worldBaseMapItem.isDownloaded()) {
title.setVisibility(View.GONE);
searchView.findViewById(R.id.title).setVisibility(View.GONE);
listView.setHeaderDividersEnabled(false);
}
}
}
private void updateSearchView() {
IndexItem worldBaseMapItem = null;
if (searchView != null && searchView.findViewById(R.id.title).getVisibility() == View.GONE) {
IndexItem worldBaseMapItem = activity.getDownloadThread().getIndexes().getWorldBaseMapItem();
worldBaseMapItem = activity.getDownloadThread().getIndexes().getWorldBaseMapItem();
if (worldBaseMapItem != null && worldBaseMapItem.isDownloaded()) {
searchView.findViewById(R.id.title).setVisibility(View.VISIBLE);
listView.setHeaderDividersEnabled(true);
}
}
if (restorePurchasesView != null && restorePurchasesView.findViewById(R.id.container).getVisibility() == View.GONE
&& !InAppHelper.isInAppIntentoryRead()) {
if (worldBaseMapItem != null && worldBaseMapItem.isDownloaded()) {
restorePurchasesView.findViewById(R.id.container).setVisibility(View.VISIBLE);
}
}
}
@Override
public void onError(String error) {
}
@Override
public void onGetItems() {
if (restorePurchasesView != null && restorePurchasesView.getVisibility() == View.VISIBLE) {
restorePurchasesView.findViewById(R.id.container).setVisibility(View.GONE);
}
}
@Override
public void onItemPurchased(String sku) {
}
@Override
public void showProgress() {
}
@Override
public void dismissProgress() {
if (restorePurchasesView != null && restorePurchasesView.getVisibility() == View.VISIBLE) {
restorePurchasesView.findViewById(R.id.progressBar).setVisibility(View.GONE);
}
}
@Override

View file

@ -10,6 +10,7 @@ import android.view.View;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivity.FreeVersionDialog;
@ -30,7 +31,7 @@ public class FreeVersionDialogFragment extends DialogFragment {
builder.setNegativeButton(R.string.later, null);
View view = getActivity().getLayoutInflater().inflate(R.layout.free_version_banner, null);
boolean hidePlus = !app.getRemoteBoolean(SHOW_PLUS_VERSION_INAPP_PARAM, true);
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);

View file

@ -119,8 +119,9 @@ public class InAppHelper {
return SKU_LIVE_UPDATES;
}
public static boolean hasPrices() {
return !Algorithms.isEmpty(mLiveUpdatesPrice) && !Algorithms.isEmpty(mFullVersionPrice);
public static boolean hasPrices(OsmandApplication app) {
return !Algorithms.isEmpty(mLiveUpdatesPrice)
&& (!Version.isFreeVersion(app) || !Algorithms.isEmpty(mFullVersionPrice));
}
public static void initialize(OsmandApplication ctx) {
@ -146,6 +147,10 @@ public class InAppHelper {
}
}
public static boolean isInAppIntentoryRead() {
return lastValidationCheckTime != 0;
}
public void exec(final @NonNull InAppRunnable runnable) {
this.stopAfterResult = true;