Panagiotis Triantafyllou

fixed home

1 package ly.warp.sdk.activities; 1 package ly.warp.sdk.activities;
2 2
3 import android.os.Bundle; 3 import android.os.Bundle;
4 +import android.os.Handler;
5 +import android.os.Looper;
4 import android.view.MenuItem; 6 import android.view.MenuItem;
5 7
6 import androidx.annotation.NonNull; 8 import androidx.annotation.NonNull;
...@@ -10,6 +12,8 @@ import androidx.fragment.app.FragmentActivity; ...@@ -10,6 +12,8 @@ import androidx.fragment.app.FragmentActivity;
10 import com.google.android.material.bottomnavigation.BottomNavigationView; 12 import com.google.android.material.bottomnavigation.BottomNavigationView;
11 import com.google.android.material.navigation.NavigationBarView; 13 import com.google.android.material.navigation.NavigationBarView;
12 14
15 +import org.json.JSONException;
16 +
13 import java.util.HashMap; 17 import java.util.HashMap;
14 18
15 import ly.warp.sdk.R; 19 import ly.warp.sdk.R;
...@@ -61,19 +65,19 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation ...@@ -61,19 +65,19 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation
61 } 65 }
62 }).start(); 66 }).start();
63 67
64 - new Thread(() -> { 68 +// new Thread(() -> {
65 - if (!Thread.currentThread().isInterrupted()) { 69 +// if (!Thread.currentThread().isInterrupted()) {
66 - Warply.getInbox(new WarplyInboxRequest().setUseCache(false), mInboxReceiver); 70 +// Warply.getInbox(new WarplyInboxRequest().setUseCache(false), mInboxReceiver);
67 - } 71 +// }
68 - }).start(); 72 +// }).start();
69 - 73 +//
70 - new Thread(() -> { 74 +// new Thread(() -> {
71 - if (!Thread.currentThread().isInterrupted()) { 75 +// if (!Thread.currentThread().isInterrupted()) {
72 - WarplyManager.getUserCoupons(new WarplyUserCouponsRequest(), mUserCouponsReceiver); 76 +// WarplyManager.getUserCoupons(new WarplyUserCouponsRequest(), mUserCouponsReceiver);
73 - } 77 +// }
74 - }).start(); 78 +// }).start();
75 - 79 +
76 - initViews(); 80 +// initViews();
77 } 81 }
78 82
79 @Override 83 @Override
...@@ -145,7 +149,8 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation ...@@ -145,7 +149,8 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation
145 @Override 149 @Override
146 public void onSuccess(Consumer result) { 150 public void onSuccess(Consumer result) {
147 mConsumer = result; 151 mConsumer = result;
148 - Thread.currentThread().interrupt(); 152 +// Thread.currentThread().interrupt();
153 + Warply.getInbox(new WarplyInboxRequest().setUseCache(false), mInboxReceiver);
149 } 154 }
150 155
151 @Override 156 @Override
...@@ -154,43 +159,45 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation ...@@ -154,43 +159,45 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation
154 } 159 }
155 }; 160 };
156 161
157 - private final CallbackReceiver<CampaignList> mInboxReceiver = 162 + private final CallbackReceiver<CampaignList> mInboxReceiver = new CallbackReceiver<CampaignList>() {
158 - new CallbackReceiver<CampaignList>() { 163 + @Override
159 - @Override 164 + public void onSuccess(CampaignList result) {
160 - public void onSuccess(CampaignList result) { 165 + for (Campaign campaign : result) {
161 - for (Campaign campaign : result) { 166 + if (mUniqueCampaignList.containsKey(campaign.getOfferCategory().trim())) {
162 - if (mUniqueCampaignList.containsKey(campaign.getOfferCategory().trim())) { 167 + CampaignList tempCampaignList = (CampaignList) mUniqueCampaignList.get(campaign.getOfferCategory().trim());
163 - CampaignList tempCampaignList = (CampaignList) mUniqueCampaignList.get(campaign.getOfferCategory().trim()); 168 + tempCampaignList.add(campaign);
164 - tempCampaignList.add(campaign); 169 + mUniqueCampaignList.put(campaign.getOfferCategory().trim(), tempCampaignList);
165 - mUniqueCampaignList.put(campaign.getOfferCategory().trim(), tempCampaignList); 170 + } else {
166 - } else { 171 + CampaignList tempCampaignList = new CampaignList();
167 - CampaignList tempCampaignList = new CampaignList(); 172 + tempCampaignList.add(campaign);
168 - tempCampaignList.add(campaign); 173 + mUniqueCampaignList.put(campaign.getOfferCategory().trim(), tempCampaignList);
169 - mUniqueCampaignList.put(campaign.getOfferCategory().trim(), tempCampaignList);
170 - }
171 - }
172 -
173 - Thread.currentThread().interrupt();
174 } 174 }
175 + }
175 176
176 - @Override 177 +// Thread.currentThread().interrupt();
177 - public void onFailure(int errorCode) { 178 + WarplyManager.getUserCoupons(new WarplyUserCouponsRequest(), mUserCouponsReceiver);
178 - Thread.currentThread().interrupt(); 179 + }
179 - }
180 - };
181 -
182 - private final CallbackReceiver<CouponList> mUserCouponsReceiver =
183 - new CallbackReceiver<CouponList>() {
184 - @Override
185 - public void onSuccess(CouponList result) {
186 - mCouponList = result;
187 - Thread.currentThread().interrupt();
188 - }
189 180
190 - @Override 181 + @Override
191 - public void onFailure(int errorCode) { 182 + public void onFailure(int errorCode) {
192 - Thread.currentThread().interrupt(); 183 + Thread.currentThread().interrupt();
193 - } 184 + }
194 - }; 185 + };
186 +
187 + private final CallbackReceiver<CouponList> mUserCouponsReceiver = new CallbackReceiver<CouponList>() {
188 + @Override
189 + public void onSuccess(CouponList result) {
190 + mCouponList = result;
191 + Thread.currentThread().interrupt();
192 + new Handler(Looper.getMainLooper()).post(() -> {
193 + initViews();
194 + });
195 + }
196 +
197 + @Override
198 + public void onFailure(int errorCode) {
199 + Thread.currentThread().interrupt();
200 + }
201 + };
195 202
196 } 203 }
......