Panagiotis Triantafyllou

get inbox

......@@ -4,13 +4,21 @@ import android.os.Bundle;
import androidx.fragment.app.Fragment;
import java.util.ArrayList;
import java.util.HashMap;
import ly.warp.sdk.Warply;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.Campaign;
import ly.warp.sdk.io.models.CampaignList;
import ly.warp.sdk.io.models.Consumer;
import ly.warp.sdk.io.request.WarplyConsumerRequest;
import ly.warp.sdk.io.request.WarplyInboxRequest;
import ly.warp.sdk.utils.managers.WarplyManager;
public class BaseFragment extends Fragment {
private static Consumer mConsumer;
private static HashMap mUniqueCampaignList = new HashMap<String, CampaignList>();
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -21,6 +29,12 @@ public class BaseFragment extends Fragment {
WarplyManager.getConsumer(new WarplyConsumerRequest(), mConsumerReceiver);
}
}).start();
new Thread(() -> {
if (!Thread.currentThread().isInterrupted()) {
Warply.getInbox(new WarplyInboxRequest().setUseCache(false), mInboxReceiver);
}
}).start();
}
......@@ -45,4 +59,30 @@ public class BaseFragment extends Fragment {
Thread.currentThread().interrupt();
}
};
private final CallbackReceiver<CampaignList> mInboxReceiver =
new CallbackReceiver<CampaignList>() {
@Override
public void onSuccess(CampaignList result) {
for (Campaign campaign : result) {
if (mUniqueCampaignList.containsKey(campaign.getOfferCategory().trim())) {
CampaignList tempCampaignList = (CampaignList) mUniqueCampaignList.get(campaign.getOfferCategory().trim());
tempCampaignList.add(campaign);
mUniqueCampaignList.put(campaign.getOfferCategory().trim(), tempCampaignList);
} else {
CampaignList tempCampaignList = new CampaignList();
tempCampaignList.add(campaign);
mUniqueCampaignList.put(campaign.getOfferCategory().trim(), tempCampaignList);
}
}
Thread.currentThread().interrupt();
}
@Override
public void onFailure(int errorCode) {
Thread.currentThread().interrupt();
}
};
}
\ No newline at end of file
......