forked from organicmaps/organicmaps
[android] Implemented 'purchase info is loading' state in dialog
This commit is contained in:
parent
af6a048f9a
commit
68c99a5819
6 changed files with 222 additions and 3 deletions
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:fillViewport="true">
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/ads_removal_dialog_min_height"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:id="@+id/progress_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="invisible"
|
||||
tools:visibility="visible">
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_base_plus"
|
||||
android:gravity="center"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:textSize="@dimen/text_size_body_2"
|
||||
android:text="@string/purchase_loading"/>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
36
android/res/layout/fragment_ads_removal_purchase_dialog.xml
Normal file
36
android/res/layout/fragment_ads_removal_purchase_dialog.xml
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:fillViewport="true">
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/ads_removal_dialog_min_height"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:id="@+id/progress_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="invisible"
|
||||
tools:visibility="visible">
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_base_plus"
|
||||
android:gravity="center"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:textSize="@dimen/text_size_body_2"
|
||||
android:text="@string/purchase_loading"/>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
|
@ -24,4 +24,7 @@
|
|||
<dimen name="permissions_title_note_margin">@dimen/margin_half</dimen>
|
||||
<dimen name="permissions_items_margin">@dimen/margin_half</dimen>
|
||||
<dimen name="info_page_image_size">200dp</dimen>
|
||||
|
||||
<!-- Purchases-->
|
||||
<dimen name="ads_removal_dialog_min_height">360dp</dimen>
|
||||
</resources>
|
||||
|
|
|
@ -251,4 +251,7 @@
|
|||
<dimen name="dp_0">0dp</dimen>
|
||||
<dimen name="toggle_map_layer_frame_height">98dp</dimen>
|
||||
<dimen name="focal_radius">44dp</dimen>
|
||||
|
||||
<!-- Purchases-->
|
||||
<dimen name="ads_removal_dialog_min_height">508dp</dimen>
|
||||
</resources>
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.ThemeUtils;
|
||||
|
@ -73,7 +74,16 @@ public class BaseMwmDialogFragment extends DialogFragment
|
|||
{
|
||||
Context context = getContext();
|
||||
if (context == null)
|
||||
throw new IllegalStateException("Before call this method make sure that the context exist");
|
||||
throw new IllegalStateException("Before call this method make sure that the context exists");
|
||||
return (Application) context.getApplicationContext();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected View getViewOrThrow()
|
||||
{
|
||||
View view = getView();
|
||||
if (view == null)
|
||||
throw new IllegalStateException("Before call this method make sure that the view exists");
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,159 @@
|
|||
package com.mapswithme.maps.purchase;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AdsRemovalPurchaseDialog extends BaseMwmDialogFragment
|
||||
{
|
||||
private final static Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.BILLING);
|
||||
private final static String TAG = AdsRemovalPurchaseDialog.class.getSimpleName();
|
||||
private final static String EXTRA_CURRENT_STATE = "extra_current_state";
|
||||
@Nullable
|
||||
private List<SkuDetails> mDetails;
|
||||
@NonNull
|
||||
private State mState = State.NONE;
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private PurchaseController<AdsRemovalPurchaseCallback> mController;
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
LOGGER.d(TAG, "onCreate savedInstanceState = " + savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context)
|
||||
{
|
||||
super.onAttach(context);
|
||||
LOGGER.d(TAG, "onAttach");
|
||||
mController = ((AdsRemovalPurchaseControllerProvider) context).getAdsRemovalPurchaseController();
|
||||
mController.addCallback(new PurchaseCallback());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
LOGGER.d(TAG, "onCreateView savedInstanceState = " + savedInstanceState + "this " + this);
|
||||
View view = inflater.inflate(R.layout.fragment_ads_removal_purchase_dialog, container, false);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
LOGGER.d(TAG, "onViewCreated savedInstanceState = " + savedInstanceState);
|
||||
if (savedInstanceState != null)
|
||||
{
|
||||
State savedState = State.values()[savedInstanceState.getInt(EXTRA_CURRENT_STATE)];
|
||||
activateState(savedState);
|
||||
}
|
||||
else
|
||||
{
|
||||
activateState(State.LOADING);
|
||||
mController.queryPurchaseDetails();
|
||||
}
|
||||
}
|
||||
|
||||
private void activateState(@NonNull State state)
|
||||
{
|
||||
mState = state;
|
||||
mState.activate(getViewOrThrow());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState)
|
||||
{
|
||||
super.onSaveInstanceState(outState);
|
||||
LOGGER.d(TAG, "onSaveInstanceState");
|
||||
outState.putInt(EXTRA_CURRENT_STATE, mState.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach()
|
||||
{
|
||||
LOGGER.d(TAG, "onDetach");
|
||||
super.onDetach();
|
||||
mController = null;
|
||||
mController.removeCallback();
|
||||
}
|
||||
|
||||
// UI implementation is coming soon.
|
||||
public enum State
|
||||
{
|
||||
NONE
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull View view)
|
||||
{
|
||||
throw new UnsupportedOperationException("This state can't be used!");
|
||||
}
|
||||
},
|
||||
LOADING
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull View view)
|
||||
{
|
||||
UiUtils.show(view, R.id.progress_layout);
|
||||
}
|
||||
},
|
||||
PRICE_SELECTION
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull View view)
|
||||
{
|
||||
UiUtils.hide(view, R.id.progress_layout);
|
||||
}
|
||||
},
|
||||
EXPLANATION
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull View view)
|
||||
{
|
||||
|
||||
}
|
||||
},
|
||||
ERROR
|
||||
{
|
||||
@Override
|
||||
void activate(@NonNull View view)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
abstract void activate(@NonNull View view);
|
||||
}
|
||||
|
||||
private class PurchaseCallback implements AdsRemovalPurchaseCallback
|
||||
{
|
||||
@Override
|
||||
public void onProductDetailsLoaded(@NonNull List<SkuDetails> details)
|
||||
{
|
||||
mDetails = Collections.unmodifiableList(details);
|
||||
activateState(State.PRICE_SELECTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure()
|
||||
{
|
||||
// Coming soon.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue