Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BookmarkSubscriptionPaymentState.java « purchase « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f5a7226edd75e2b660789f6daec9888d6376b624 (plain)
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
129
130
131
132
133
134
135
136
137
138
package com.mapswithme.maps.purchase;

import androidx.annotation.NonNull;

import com.mapswithme.maps.R;
import com.mapswithme.util.ConnectionState;
import com.mapswithme.util.NetworkPolicy;
import com.mapswithme.util.UiUtils;

public enum  BookmarkSubscriptionPaymentState
{
  NONE
      {
        @Override
        void activate(@NonNull BookmarkSubscriptionFragment fragment)
        {
          UiUtils.hide(fragment.getViewOrThrow(), R.id.root_screen_progress, R.id.content_view);
        }
      },
  PRODUCT_DETAILS_LOADING
      {
        @Override
        void activate(@NonNull BookmarkSubscriptionFragment fragment)
        {
          showProgress(fragment);
          fragment.queryProductDetails();
        }
      },
  PRODUCT_DETAILS_FAILURE
      {
        @Override
        void activate(@NonNull BookmarkSubscriptionFragment fragment)
        {
          PurchaseUtils.showProductDetailsFailureDialog(fragment, name());
        }
      },
  PAYMENT_FAILURE
      {
        @Override
        void activate(@NonNull BookmarkSubscriptionFragment fragment)
        {
          PurchaseUtils.showPaymentFailureDialog(fragment, name());
        }
      },
  PRICE_SELECTION
      {
        @Override
        void activate(@NonNull BookmarkSubscriptionFragment fragment)
        {
          hideProgress(fragment);
          fragment.updatePaymentButtons();
        }
      },
  VALIDATION
      {
        @Override
        void activate(@NonNull BookmarkSubscriptionFragment fragment)
        {
          showButtonProgress(fragment);
        }
      },
  VALIDATION_FINISH
      {
        @Override
        void activate(@NonNull BookmarkSubscriptionFragment fragment)
        {
          hideButtonProgress(fragment);
          fragment.finishValidation();
        }
      },
  PINGING
      {
        @Override
        void activate(@NonNull BookmarkSubscriptionFragment fragment)
        {
          showButtonProgress(fragment);
        }
      },
  PINGING_FINISH
      {
        @Override
        void activate(@NonNull BookmarkSubscriptionFragment fragment)
        {
          BookmarkSubscriptionPaymentState.hideButtonProgress(fragment);
          fragment.finishPinging();
        }
      },

  CHECK_NETWORK_CONNECTION
      {
        @Override
        void activate(@NonNull BookmarkSubscriptionFragment fragment)
        {
          if (ConnectionState.isConnected())
            NetworkPolicy.checkNetworkPolicy(fragment.requireFragmentManager(),
                                             policy -> onNetworkPolicyResult(policy, fragment), true);
          else
            PurchaseUtils.showNoConnectionDialog(fragment);

        }

        private void onNetworkPolicyResult(@NonNull NetworkPolicy policy,
                                           @NonNull BookmarkSubscriptionFragment fragment)
        {
          if (policy.canUseNetwork())
            fragment.onNetworkCheckPassed();
          else
            fragment.requireActivity().finish();
        }
      }
  ;

  private static void showProgress(@NonNull BookmarkSubscriptionFragment fragment)
  {
    UiUtils.show(fragment.getViewOrThrow(), R.id.root_screen_progress);
    UiUtils.hide(fragment.getViewOrThrow(), R.id.content_view);
  }

  private static void hideProgress(@NonNull BookmarkSubscriptionFragment fragment)
  {
    UiUtils.hide(fragment.getViewOrThrow(), R.id.root_screen_progress);
    UiUtils.show(fragment.getViewOrThrow(), R.id.content_view);
  }

  private static void showButtonProgress(@NonNull BookmarkSubscriptionFragment fragment)
  {
    UiUtils.hide(fragment.getViewOrThrow(), R.id.continue_btn);
    UiUtils.show(fragment.getViewOrThrow(), R.id.progress);
  }

  private static void hideButtonProgress(@NonNull BookmarkSubscriptionFragment fragment)
  {
    UiUtils.hide(fragment.getViewOrThrow(), R.id.progress);
    UiUtils.show(fragment.getViewOrThrow(), R.id.continue_btn);
  }

  abstract void activate(@NonNull BookmarkSubscriptionFragment fragment);
}