|
|
@@ -8,14 +8,17 @@ import java.util.List;
|
|
|
import io.reactivex.disposables.Disposable;
|
|
|
import kr.co.zumo.app.R;
|
|
|
import kr.co.zumo.app.lifeplus.bean.api.APIData;
|
|
|
+import kr.co.zumo.app.lifeplus.bean.api.ContentsLikeRequestBean;
|
|
|
import kr.co.zumo.app.lifeplus.bean.api.EventDetailBean;
|
|
|
import kr.co.zumo.app.lifeplus.bean.api.EventDetailResultBean;
|
|
|
import kr.co.zumo.app.lifeplus.bean.api.EventPageBean;
|
|
|
import kr.co.zumo.app.lifeplus.bean.api.ItemNoRequestBean;
|
|
|
+import kr.co.zumo.app.lifeplus.bean.api.LifeplusAPIBean;
|
|
|
import kr.co.zumo.app.lifeplus.model.CoinModel;
|
|
|
import kr.co.zumo.app.lifeplus.model.module.APIError;
|
|
|
import kr.co.zumo.app.lifeplus.model.module.APIEventDetailModule;
|
|
|
import kr.co.zumo.app.lifeplus.model.module.APIModuleListener;
|
|
|
+import kr.co.zumo.app.lifeplus.supervisor.ContentsFlagHelper;
|
|
|
import kr.co.zumo.app.lifeplus.util.ResourceUtil;
|
|
|
import kr.co.zumo.app.lifeplus.util.StringUtil;
|
|
|
import kr.co.zumo.app.lifeplus.view.Event;
|
|
|
@@ -36,10 +39,10 @@ public abstract class EventDetailModel extends CoinModel {
|
|
|
protected EventDetailBean eventDetailBean;
|
|
|
protected EventDetailBean deliveredEventDetailBean;
|
|
|
protected Disposable disposable;
|
|
|
+ private Disposable disposableLiked;
|
|
|
|
|
|
@Override
|
|
|
protected void createViewInternal() {
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@CallSuper
|
|
|
@@ -49,11 +52,14 @@ public abstract class EventDetailModel extends CoinModel {
|
|
|
disposable.dispose();
|
|
|
disposable = null;
|
|
|
}
|
|
|
+ if (null != disposableLiked) {
|
|
|
+ disposableLiked.dispose();
|
|
|
+ disposableLiked = null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void destroyViewInternal() {
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -89,6 +95,7 @@ public abstract class EventDetailModel extends CoinModel {
|
|
|
|
|
|
public void setDeliveredEventDetailBean(EventDetailBean eventDetailBean) {
|
|
|
this.deliveredEventDetailBean = eventDetailBean;
|
|
|
+ this.deliveredEventDetailBean.updateLike(ContentsFlagHelper.getInstance());
|
|
|
}
|
|
|
|
|
|
protected List<EventPageBean> eventPageBeans;
|
|
|
@@ -115,6 +122,7 @@ public abstract class EventDetailModel extends CoinModel {
|
|
|
public void onApiSuccess(EventDetailResultBean resultBean) {
|
|
|
if (null != resultBean && null != resultBean.getData()) {
|
|
|
eventDetailBean = resultBean.getData();
|
|
|
+ eventDetailBean.updateLike(ContentsFlagHelper.getInstance());
|
|
|
|
|
|
parseEventPageBean();
|
|
|
|
|
|
@@ -186,4 +194,28 @@ public abstract class EventDetailModel extends CoinModel {
|
|
|
return getEventDetailBean().isSimpleQuestion();
|
|
|
}
|
|
|
|
|
|
+ protected void updateItemLiked(boolean isChecked) {
|
|
|
+ eventDetailBean.setLiked(isChecked);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateLiked() {
|
|
|
+ EventDetailBean bean = eventDetailBean;
|
|
|
+ boolean toChecked = !bean.isLiked();
|
|
|
+ disposableLiked = ContentsFlagHelper.getInstance().updateLiked(new ContentsLikeRequestBean(getUserName(), bean.getItemNo(), APIData.valueOf(toChecked)), new APIModuleListener<LifeplusAPIBean>() {
|
|
|
+ @Override
|
|
|
+ public void onApiSuccess(LifeplusAPIBean resultBean) {
|
|
|
+ updateItemLiked(toChecked);
|
|
|
+ onResult(new Event.Builder(Event.SUCCESS).integer(Event.CONTENTS_LIKE).bool(toChecked).build());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onApiError(String errorMessage, APIError error) {
|
|
|
+ onResult(new Event.Builder(Event.ERROR).integer(Event.CONTENTS_LIKE).bool(toChecked).string(errorMessage).build());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isItemLiked() {
|
|
|
+ return eventDetailBean.isLiked();
|
|
|
+ }
|
|
|
}
|