1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
package com.mapswithme.maps.purchase;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.mapswithme.maps.PrivateVariables;
import com.mapswithme.maps.R;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.statistics.Statistics;
enum AdsRemovalPaymentState
{
NONE
{
@Override
void activate(@NonNull AdsRemovalPurchaseDialog dialog)
{
throw new UnsupportedOperationException("This state can't be used!");
}
},
LOADING
{
@Override
void activate(@NonNull AdsRemovalPurchaseDialog dialog)
{
View view = getDialogViewOrThrow(dialog);
UiUtils.hide(view, R.id.title, R.id.image, R.id.pay_button_container, R.id.explanation,
R.id.explanation_items);
View progressLayout = view.findViewById(R.id.progress_layout);
TextView message = progressLayout.findViewById(R.id.message);
message.setText(R.string.purchase_loading);
UiUtils.show(progressLayout);
dialog.queryPurchaseDetails();
}
},
PRICE_SELECTION
{
@Override
void activate(@NonNull AdsRemovalPurchaseDialog dialog)
{
View view = getDialogViewOrThrow(dialog);
UiUtils.hide(view, R.id.progress_layout, R.id.explanation_items);
UiUtils.show(view, R.id.title, R.id.image, R.id.pay_button_container, R.id.explanation);
TextView title = view.findViewById(R.id.title);
title.setText(R.string.remove_ads_title);
View image = view.findViewById(R.id.image);
alignPayButtonBelow(view, image == null ? R.id.title : R.id.image);
dialog.updatePaymentButtons();
Statistics.INSTANCE.trackPurchasePreviewShow(PrivateVariables.adsRemovalServerId(),
PrivateVariables.adsRemovalVendor(),
PrivateVariables.adsRemovalYearlyProductId());
}
},
EXPLANATION
{
@Override
void activate(@NonNull AdsRemovalPurchaseDialog dialog)
{
View view = getDialogViewOrThrow(dialog);
UiUtils.hide(view, R.id.image, R.id.explanation, R.id.progress_layout);
UiUtils.show(view, R.id.title, R.id.explanation_items, R.id.pay_button_container);
TextView title = view.findViewById(R.id.title);
title.setText(R.string.why_support);
alignPayButtonBelow(view, R.id.explanation_items);
dialog.updatePaymentButtons();
}
},
VALIDATION
{
@Override
void activate(@NonNull AdsRemovalPurchaseDialog dialog)
{
View view = getDialogViewOrThrow(dialog);
UiUtils.hide(view, R.id.title, R.id.image, R.id.pay_button_container, R.id.explanation,
R.id.explanation_items);
View progressLayout = view.findViewById(R.id.progress_layout);
TextView message = progressLayout.findViewById(R.id.message);
message.setText(R.string.please_wait);
UiUtils.show(progressLayout);
}
},
PAYMENT_FAILURE
{
@Override
void activate(@NonNull AdsRemovalPurchaseDialog dialog)
{
PurchaseUtils.showPaymentFailureDialog(dialog, name());
}
},
PRODUCT_DETAILS_FAILURE
{
@Override
void activate(@NonNull AdsRemovalPurchaseDialog dialog)
{
PurchaseUtils.showProductDetailsFailureDialog(dialog, name());
}
},
VALIDATION_FINISH
{
@Override
void activate(@NonNull AdsRemovalPurchaseDialog dialog)
{
dialog.finishValidation();
}
};
private static void alignPayButtonBelow(@NonNull View view, @IdRes int anchor)
{
View payButton = view.findViewById(R.id.pay_button_container);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) payButton.getLayoutParams();
params.addRule(RelativeLayout.BELOW, anchor);
}
@NonNull
private static View getDialogViewOrThrow(@NonNull DialogFragment dialog)
{
View view = dialog.getView();
if (view == null)
throw new IllegalStateException("Before call this method make sure that the dialog exists");
return view;
}
abstract void activate(@NonNull AdsRemovalPurchaseDialog dialog);
}
|