Bug fix in campaigns (#2119)

* Bug fix in campaigns

* remove hardcoded reference to camapign at index 0
This commit is contained in:
Ashish Kumar 2018-12-19 17:36:51 +05:30 committed by Josephine Lim
parent 46db38b8e9
commit 4425c36713

View file

@ -73,21 +73,23 @@ public class CampaignsPresenter implements BasePresenter {
} }
return date1.compareTo(date2); return date1.compareTo(date2);
}); });
Date campaignEndDate = null; Date campaignEndDate, campaignStartDate;
Date currentDate = new Date();
try { try {
campaignEndDate = dateFormat.parse(campaigns.get(0).getEndDate()); for (Campaign aCampaign : campaigns) {
campaignEndDate = dateFormat.parse(aCampaign.getEndDate());
campaignStartDate =
dateFormat.parse(aCampaign.getStartDate());
if (campaignEndDate.compareTo(currentDate) >= 0
&& campaignStartDate.compareTo(currentDate) <= 0) {
campaign = aCampaign;
break;
}
}
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (campaignEndDate == null) { view.showCampaigns(campaign);
view.showCampaigns(null);
} else if (campaignEndDate.compareTo(new Date()) > 0) {
campaign = campaigns.get(0);
view.showCampaigns(campaign);
} else {
Log.e(TAG, "The campaigns has already finished");
view.showCampaigns(null);
}
} }
@Override public void onError(Throwable e) { @Override public void onError(Throwable e) {