Merge branch 'cosmote' of https://git.warp.ly/open-source/warply_android_sdk_mav…
…en_plugin into cosmote
Showing
5 changed files
with
67 additions
and
43 deletions
1 | +package ly.warp.sdk.fragments; | ||
2 | + | ||
3 | +import android.os.Bundle; | ||
4 | + | ||
5 | +import androidx.fragment.app.Fragment; | ||
6 | + | ||
7 | +import ly.warp.sdk.io.callbacks.CallbackReceiver; | ||
8 | +import ly.warp.sdk.io.models.Consumer; | ||
9 | +import ly.warp.sdk.io.request.WarplyConsumerRequest; | ||
10 | +import ly.warp.sdk.utils.managers.WarplyManager; | ||
11 | + | ||
12 | +public class BaseFragment extends Fragment { | ||
13 | + private static Consumer mConsumer; | ||
14 | + | ||
15 | + @Override | ||
16 | + public void onCreate(Bundle savedInstanceState) { | ||
17 | + super.onCreate(savedInstanceState); | ||
18 | + | ||
19 | + new Thread(() -> { | ||
20 | + if (!Thread.currentThread().isInterrupted()) { | ||
21 | + WarplyManager.getConsumer(new WarplyConsumerRequest(), mConsumerReceiver); | ||
22 | + } | ||
23 | + }).start(); | ||
24 | + } | ||
25 | + | ||
26 | + | ||
27 | + @Override | ||
28 | + public void onDestroyView() { | ||
29 | + super.onDestroyView(); | ||
30 | + } | ||
31 | + | ||
32 | + public static Consumer getConsumer() { | ||
33 | + return mConsumer; | ||
34 | + } | ||
35 | + | ||
36 | + private final CallbackReceiver<Consumer> mConsumerReceiver = new CallbackReceiver<Consumer>() { | ||
37 | + @Override | ||
38 | + public void onSuccess(Consumer result) { | ||
39 | + mConsumer = result; | ||
40 | + Thread.currentThread().interrupt(); | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public void onFailure(int errorCode) { | ||
45 | + Thread.currentThread().interrupt(); | ||
46 | + } | ||
47 | + }; | ||
48 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -2,8 +2,6 @@ package ly.warp.sdk.fragments; | ... | @@ -2,8 +2,6 @@ package ly.warp.sdk.fragments; |
2 | 2 | ||
3 | import android.content.Intent; | 3 | import android.content.Intent; |
4 | import android.os.Bundle; | 4 | import android.os.Bundle; |
5 | -import android.os.Handler; | ||
6 | -import android.os.Looper; | ||
7 | import android.view.LayoutInflater; | 5 | import android.view.LayoutInflater; |
8 | import android.view.View; | 6 | import android.view.View; |
9 | import android.view.ViewGroup; | 7 | import android.view.ViewGroup; |
... | @@ -22,20 +20,15 @@ import org.json.JSONException; | ... | @@ -22,20 +20,15 @@ import org.json.JSONException; |
22 | import ly.warp.sdk.R; | 20 | import ly.warp.sdk.R; |
23 | import ly.warp.sdk.activities.BillPaymentActivity; | 21 | import ly.warp.sdk.activities.BillPaymentActivity; |
24 | import ly.warp.sdk.activities.CouponInfoActivity; | 22 | import ly.warp.sdk.activities.CouponInfoActivity; |
25 | -import ly.warp.sdk.io.callbacks.CallbackReceiver; | ||
26 | -import ly.warp.sdk.io.models.Consumer; | ||
27 | -import ly.warp.sdk.io.request.WarplyConsumerRequest; | ||
28 | -import ly.warp.sdk.io.request.WarplyLoginRequest; | ||
29 | -import ly.warp.sdk.utils.managers.WarplyManager; | ||
30 | -import ly.warp.sdk.views.adapters.HomeCampaignAdapter; | ||
31 | -import ly.warp.sdk.views.adapters.HomeCouponAdapter; | ||
32 | import ly.warp.sdk.activities.WarpViewActivity; | 23 | import ly.warp.sdk.activities.WarpViewActivity; |
33 | -import ly.warp.sdk.io.models.Coupon; | ||
34 | -import ly.warp.sdk.io.models.CouponList; | ||
35 | import ly.warp.sdk.io.models.Campaign; | 24 | import ly.warp.sdk.io.models.Campaign; |
36 | import ly.warp.sdk.io.models.CampaignList; | 25 | import ly.warp.sdk.io.models.CampaignList; |
26 | +import ly.warp.sdk.io.models.Coupon; | ||
27 | +import ly.warp.sdk.io.models.CouponList; | ||
28 | +import ly.warp.sdk.views.adapters.HomeCampaignAdapter; | ||
29 | +import ly.warp.sdk.views.adapters.HomeCouponAdapter; | ||
37 | 30 | ||
38 | -public class HomeFragment extends Fragment implements View.OnClickListener { | 31 | +public class HomeFragment extends BaseFragment implements View.OnClickListener { |
39 | 32 | ||
40 | private RelativeLayout mOptionOne, mOptionTwo, mOptionThree; | 33 | private RelativeLayout mOptionOne, mOptionTwo, mOptionThree; |
41 | private RecyclerView mRecyclerCampaigns, mRecyclerCoupons; | 34 | private RecyclerView mRecyclerCampaigns, mRecyclerCoupons; |
... | @@ -43,18 +36,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener { | ... | @@ -43,18 +36,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener { |
43 | private HomeCampaignAdapter mAdapterCampaigns; | 36 | private HomeCampaignAdapter mAdapterCampaigns; |
44 | private LinearLayout mLlBillPayment; | 37 | private LinearLayout mLlBillPayment; |
45 | private TextView mTvUsername; | 38 | private TextView mTvUsername; |
46 | - public static Consumer mConsumer; | ||
47 | - | ||
48 | - @Override | ||
49 | - public void onCreate(Bundle savedInstanceState) { | ||
50 | - super.onCreate(savedInstanceState); | ||
51 | - | ||
52 | - new Thread(() -> { | ||
53 | - if (!Thread.currentThread().isInterrupted()) { | ||
54 | - WarplyManager.getConsumer(new WarplyConsumerRequest(), mConsumerReceiver); | ||
55 | - } | ||
56 | - }).start(); | ||
57 | - } | ||
58 | 39 | ||
59 | @Override | 40 | @Override |
60 | public View onCreateView( | 41 | public View onCreateView( |
... | @@ -89,6 +70,9 @@ public class HomeFragment extends Fragment implements View.OnClickListener { | ... | @@ -89,6 +70,9 @@ public class HomeFragment extends Fragment implements View.OnClickListener { |
89 | mLlBillPayment.setOnClickListener(this); | 70 | mLlBillPayment.setOnClickListener(this); |
90 | 71 | ||
91 | mTvUsername = view.findViewById(R.id.welcome_user_txt); | 72 | mTvUsername = view.findViewById(R.id.welcome_user_txt); |
73 | + if (BaseFragment.getConsumer() != null) | ||
74 | + mTvUsername.setText(String.format(getResources().getString(R.string.welcome_user), | ||
75 | + BaseFragment.getConsumer().getFirstName() + " " + BaseFragment.getConsumer().getLastName())); | ||
92 | 76 | ||
93 | /********* TEST CAMPAIGNS DATA **********/ | 77 | /********* TEST CAMPAIGNS DATA **********/ |
94 | CampaignList clistCampaigns = new CampaignList(); | 78 | CampaignList clistCampaigns = new CampaignList(); |
... | @@ -156,20 +140,4 @@ public class HomeFragment extends Fragment implements View.OnClickListener { | ... | @@ -156,20 +140,4 @@ public class HomeFragment extends Fragment implements View.OnClickListener { |
156 | HomeFragment homeFragment = new HomeFragment(); | 140 | HomeFragment homeFragment = new HomeFragment(); |
157 | return homeFragment; | 141 | return homeFragment; |
158 | } | 142 | } |
159 | - | ||
160 | - private final CallbackReceiver<Consumer> mConsumerReceiver = new CallbackReceiver<Consumer>() { | ||
161 | - @Override | ||
162 | - public void onSuccess(Consumer result) { | ||
163 | - mConsumer = result; | ||
164 | - new Handler(Looper.getMainLooper()).post(() -> { | ||
165 | - mTvUsername.setText(String.format(getResources().getString(R.string.welcome_user), | ||
166 | - mConsumer.getFirstName() + " " + mConsumer.getLastName())); | ||
167 | - }); | ||
168 | - } | ||
169 | - | ||
170 | - @Override | ||
171 | - public void onFailure(int errorCode) { | ||
172 | - Thread.currentThread().interrupt(); | ||
173 | - } | ||
174 | - }; | ||
175 | } | 143 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -6,6 +6,7 @@ import android.view.LayoutInflater; | ... | @@ -6,6 +6,7 @@ import android.view.LayoutInflater; |
6 | import android.view.View; | 6 | import android.view.View; |
7 | import android.view.ViewGroup; | 7 | import android.view.ViewGroup; |
8 | import android.widget.LinearLayout; | 8 | import android.widget.LinearLayout; |
9 | +import android.widget.TextView; | ||
9 | 10 | ||
10 | import androidx.annotation.Nullable; | 11 | import androidx.annotation.Nullable; |
11 | import androidx.constraintlayout.widget.ConstraintLayout; | 12 | import androidx.constraintlayout.widget.ConstraintLayout; |
... | @@ -22,7 +23,7 @@ import ly.warp.sdk.io.models.Campaign; | ... | @@ -22,7 +23,7 @@ import ly.warp.sdk.io.models.Campaign; |
22 | import ly.warp.sdk.io.models.CampaignList; | 23 | import ly.warp.sdk.io.models.CampaignList; |
23 | import ly.warp.sdk.views.adapters.ProfileCampaignAdapter; | 24 | import ly.warp.sdk.views.adapters.ProfileCampaignAdapter; |
24 | 25 | ||
25 | -public class LoyaltyFragment extends Fragment implements View.OnClickListener { | 26 | +public class LoyaltyFragment extends BaseFragment implements View.OnClickListener { |
26 | 27 | ||
27 | // =========================================================== | 28 | // =========================================================== |
28 | // Constants | 29 | // Constants |
... | @@ -36,6 +37,7 @@ public class LoyaltyFragment extends Fragment implements View.OnClickListener { | ... | @@ -36,6 +37,7 @@ public class LoyaltyFragment extends Fragment implements View.OnClickListener { |
36 | private ProfileCampaignAdapter mAdapterDeals, mAdapterGifts, mAdapterMore; | 37 | private ProfileCampaignAdapter mAdapterDeals, mAdapterGifts, mAdapterMore; |
37 | private LinearLayout mLlMoreDeals, mLlMoreGifts, mLlMore; | 38 | private LinearLayout mLlMoreDeals, mLlMoreGifts, mLlMore; |
38 | private ConstraintLayout mClRewardsWallet; | 39 | private ConstraintLayout mClRewardsWallet; |
40 | + private TextView mTvUsername; | ||
39 | 41 | ||
40 | // =========================================================== | 42 | // =========================================================== |
41 | // Methods for/from SuperClass/Interfaces | 43 | // Methods for/from SuperClass/Interfaces |
... | @@ -63,6 +65,11 @@ public class LoyaltyFragment extends Fragment implements View.OnClickListener { | ... | @@ -63,6 +65,11 @@ public class LoyaltyFragment extends Fragment implements View.OnClickListener { |
63 | mClRewardsWallet = view.findViewById(R.id.cl_rewards_wallet); | 65 | mClRewardsWallet = view.findViewById(R.id.cl_rewards_wallet); |
64 | mClRewardsWallet.setOnClickListener(this); | 66 | mClRewardsWallet.setOnClickListener(this); |
65 | 67 | ||
68 | + mTvUsername = view.findViewById(R.id.tv_name); | ||
69 | + if (BaseFragment.getConsumer() != null) | ||
70 | + mTvUsername.setText(String.format(getResources().getString(R.string.cos_profile_name), | ||
71 | + BaseFragment.getConsumer().getFirstName() + " " + BaseFragment.getConsumer().getLastName())); | ||
72 | + | ||
66 | mLlMoreDeals = view.findViewById(R.id.ll_more); | 73 | mLlMoreDeals = view.findViewById(R.id.ll_more); |
67 | mLlMoreDeals.setOnClickListener(this); | 74 | mLlMoreDeals.setOnClickListener(this); |
68 | mLlMoreGifts = view.findViewById(R.id.ll_more2); | 75 | mLlMoreGifts = view.findViewById(R.id.ll_more2); | ... | ... |
... | @@ -4,6 +4,7 @@ | ... | @@ -4,6 +4,7 @@ |
4 | xmlns:app="http://schemas.android.com/apk/res-auto" | 4 | xmlns:app="http://schemas.android.com/apk/res-auto" |
5 | android:layout_width="match_parent" | 5 | android:layout_width="match_parent" |
6 | android:layout_height="match_parent" | 6 | android:layout_height="match_parent" |
7 | + xmlns:tools="http://schemas.android.com/tools" | ||
7 | android:background="@android:color/white"> | 8 | android:background="@android:color/white"> |
8 | 9 | ||
9 | <LinearLayout | 10 | <LinearLayout |
... | @@ -32,7 +33,7 @@ | ... | @@ -32,7 +33,7 @@ |
32 | android:layout_height="wrap_content" | 33 | android:layout_height="wrap_content" |
33 | android:layout_marginStart="8dp" | 34 | android:layout_marginStart="8dp" |
34 | android:layout_marginTop="6dp" | 35 | android:layout_marginTop="6dp" |
35 | - android:text="@string/cos_profile_name" | 36 | + tools:text="Test Name" |
36 | android:maxLines="1" | 37 | android:maxLines="1" |
37 | android:textColor="@color/grey" | 38 | android:textColor="@color/grey" |
38 | app:layout_constraintLeft_toRightOf="@+id/iv_profile_photo" | 39 | app:layout_constraintLeft_toRightOf="@+id/iv_profile_photo" | ... | ... |
... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
7 | 7 | ||
8 | <string name="cos_profile_tab">Profile</string> | 8 | <string name="cos_profile_tab">Profile</string> |
9 | <string name="welcome_user">Γεία σου %1$s !</string> | 9 | <string name="welcome_user">Γεία σου %1$s !</string> |
10 | - <string name="cos_profile_name">Γιώργος</string> | 10 | + <string name="cos_profile_name">%1$s</string> |
11 | <string name="cos_profile_type">Traveller</string> | 11 | <string name="cos_profile_type">Traveller</string> |
12 | <string name="header_add">Προσθήκη</string> | 12 | <string name="header_add">Προσθήκη</string> |
13 | <string name="cos_profile_reward">My reward wallet</string> | 13 | <string name="cos_profile_reward">My reward wallet</string> | ... | ... |
-
Please register or login to post a comment