Santosh Bhandary
4 years ago
2 changed files with 237 additions and 225 deletions
-
116app/src/main/java/com/swifttech/remit/android/features/notice/model/NoticeDTO.java
-
346app/src/main/java/com/swifttech/remit/android/features/notice/presenter/NoticeViewModel.java
@ -1,52 +1,64 @@ |
|||
package com.swifttech.remit.android.features.notice.model; |
|||
|
|||
import com.google.gson.annotations.Expose; |
|||
import com.google.gson.annotations.SerializedName; |
|||
|
|||
public class NoticeDTO { |
|||
|
|||
@SerializedName("rowId") |
|||
@Expose |
|||
private String rowId; |
|||
@SerializedName("title") |
|||
@Expose |
|||
private String title; |
|||
@SerializedName("createDate") |
|||
@Expose |
|||
private String createDate; |
|||
@SerializedName("isRead") |
|||
@Expose |
|||
private String isRead; |
|||
|
|||
public String getRowId() { |
|||
return rowId; |
|||
} |
|||
|
|||
public void setRowId(String rowId) { |
|||
this.rowId = rowId; |
|||
} |
|||
|
|||
public String getTitle() { |
|||
return title; |
|||
} |
|||
|
|||
public void setTitle(String title) { |
|||
this.title = title; |
|||
} |
|||
|
|||
public String getCreateDate() { |
|||
return createDate; |
|||
} |
|||
|
|||
public void setCreateDate(String createDate) { |
|||
this.createDate = createDate; |
|||
} |
|||
|
|||
public String getIsRead() { |
|||
return isRead; |
|||
} |
|||
|
|||
public void setIsRead(String isRead) { |
|||
this.isRead = isRead; |
|||
} |
|||
} |
|||
package com.swifttech.remit.android.features.notice.model; |
|||
|
|||
import com.google.gson.annotations.Expose; |
|||
import com.google.gson.annotations.SerializedName; |
|||
|
|||
public class NoticeDTO { |
|||
|
|||
@SerializedName("rowId") |
|||
@Expose |
|||
private String rowId; |
|||
@SerializedName("title") |
|||
@Expose |
|||
private String title; |
|||
@SerializedName("createDate") |
|||
@Expose |
|||
private String createDate; |
|||
@SerializedName("isRead")// 0 => Not Read, 1=> Read, |
|||
@Expose |
|||
private String isRead; |
|||
|
|||
@SerializedName("type")//0 => General Notice, 1=> Txn Notice |
|||
@Expose |
|||
private String type; |
|||
|
|||
@SerializedName("extra")//If type==1, then extra will have Txn id |
|||
@Expose |
|||
private String extra; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
public String getRowId() { |
|||
return rowId; |
|||
} |
|||
|
|||
public void setRowId(String rowId) { |
|||
this.rowId = rowId; |
|||
} |
|||
|
|||
public String getTitle() { |
|||
return title; |
|||
} |
|||
|
|||
public void setTitle(String title) { |
|||
this.title = title; |
|||
} |
|||
|
|||
public String getCreateDate() { |
|||
return createDate; |
|||
} |
|||
|
|||
public void setCreateDate(String createDate) { |
|||
this.createDate = createDate; |
|||
} |
|||
|
|||
public String getIsRead() { |
|||
return isRead; |
|||
} |
|||
|
|||
public void setIsRead(String isRead) { |
|||
this.isRead = isRead; |
|||
} |
|||
} |
@ -1,173 +1,173 @@ |
|||
package com.swifttech.remit.android.features.notice.presenter; |
|||
|
|||
import androidx.lifecycle.LiveData; |
|||
import androidx.lifecycle.MutableLiveData; |
|||
|
|||
import com.google.gson.reflect.TypeToken; |
|||
import com.swifttech.remit.android.base.BaseViewModel; |
|||
import com.swifttech.remit.android.common.customwidgets.CustomAlertDialog; |
|||
import com.swifttech.remit.android.features.notice.model.NoticeDTO; |
|||
import com.swifttech.remit.android.features.notice.model.NoticeDetailDTO; |
|||
import com.swifttech.remit.android.utils.Constants; |
|||
import com.swifttech.remit.android.utils.https.GenericApiObserverResponseV2; |
|||
import com.swifttech.remit.android.utils.https.GenericResponseDataModel; |
|||
|
|||
import java.lang.reflect.Type; |
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers; |
|||
import io.reactivex.disposables.CompositeDisposable; |
|||
import io.reactivex.schedulers.Schedulers; |
|||
|
|||
public class NoticeViewModel extends BaseViewModel implements NoticePresenterInterface { |
|||
|
|||
|
|||
private final NoticeViewContractInterface view; |
|||
private final NoticeGatewayInterface gateway; |
|||
private final CompositeDisposable compositeDisposable; |
|||
|
|||
MutableLiveData<List<NoticeDTO>> noticeListLiveData; |
|||
MutableLiveData<NoticeDetailDTO> noticeDetailLiveData; |
|||
|
|||
public NoticeViewModel(NoticePresenterInterface.NoticeViewContractInterface view, NoticeGatewayInterface gatewayInterface) { |
|||
this.view = view; |
|||
this.gateway = gatewayInterface; |
|||
noticeListLiveData = new MutableLiveData<>(); |
|||
noticeDetailLiveData = new MutableLiveData<>(); |
|||
this.compositeDisposable = new CompositeDisposable(); |
|||
} |
|||
|
|||
@Override |
|||
public void onViewReady() { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void onViewNotReady() { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void fetchNoticeListLiveData() { |
|||
this.compositeDisposable.add( |
|||
this.gateway.getNoticeList(gateway.getAuth(), gateway.getUserIDNumber()) |
|||
.doOnSubscribe(subs -> view.showProgressBar(true, "")) |
|||
.subscribeOn(Schedulers.io()) |
|||
.observeOn(AndroidSchedulers.mainThread()) |
|||
.doFinally(() -> view.showProgressBar(false, "")) |
|||
.subscribeWith(new NoticeListObserver()) |
|||
); |
|||
} |
|||
|
|||
@Override |
|||
public void fetchNoticeDetail(NoticeDTO selectedNotice) { |
|||
this.compositeDisposable.add( |
|||
this.gateway.getNoticeDetail(gateway.getAuth(), selectedNotice.getRowId()) |
|||
.doOnSubscribe(subs -> view.showProgressBar(true, "")) |
|||
.subscribeOn(Schedulers.io()) |
|||
.observeOn(AndroidSchedulers.mainThread()) |
|||
.doFinally(() -> view.showProgressBar(false, "")) |
|||
.subscribeWith(new NoticeDetailObserver()) |
|||
); |
|||
} |
|||
|
|||
@Override |
|||
public LiveData<List<NoticeDTO>> getNoticeListLiveData() { |
|||
return noticeListLiveData; |
|||
} |
|||
|
|||
@Override |
|||
public LiveData<NoticeDetailDTO> getNoticeDetailLiveData() { |
|||
return noticeDetailLiveData; |
|||
} |
|||
|
|||
public class NoticeListObserver extends GenericApiObserverResponseV2<List<NoticeDTO>> { |
|||
|
|||
@Override |
|||
protected Type getDataType() { |
|||
return TypeToken.getParameterized(List.class, NoticeDTO.class).getType(); |
|||
} |
|||
|
|||
@Override |
|||
protected void onSuccess(GenericResponseDataModel<List<NoticeDTO>> t) { |
|||
if (t.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) { |
|||
if (t.getData() != null && t.getData().size() > 0) { |
|||
view.lazyInitViews(); |
|||
sortNoticeList(t.getData()); |
|||
} else |
|||
view.showPopUpMessage("You don't have any notification at the moment.", CustomAlertDialog.AlertType.FAILED, alertType -> view.exitView()); |
|||
|
|||
} else { |
|||
view.showPopUpMessage(t.getMsg(), CustomAlertDialog.AlertType.FAILED, alertType -> view.exitView()); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void onFailed(String message) { |
|||
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, alertType -> view.exitView()); |
|||
} |
|||
|
|||
@Override |
|||
protected void onConnectionNotEstablished(String message) { |
|||
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, alertType -> view.exitView()); |
|||
|
|||
} |
|||
|
|||
@Override |
|||
protected void unauthorizedAccess(String message) { |
|||
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, alertType -> view.logout()); |
|||
|
|||
} |
|||
} |
|||
|
|||
private void sortNoticeList(List<NoticeDTO> data) { |
|||
// DateFormat df = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a"); |
|||
// Collections.sort(data, (o1, o2) -> { |
|||
// try { |
|||
// return df.parse(o1.getCreateDate()).compareTo(df.parse(o2.getCreateDate())); |
|||
// } catch (Exception pe) { |
|||
// Collections.reverse(data); |
|||
// } |
|||
// return 0; |
|||
// }); |
|||
if (data != null) |
|||
Collections.reverse(data); |
|||
noticeListLiveData.setValue(data); |
|||
|
|||
} |
|||
|
|||
public class NoticeDetailObserver extends GenericApiObserverResponseV2<NoticeDetailDTO> { |
|||
@Override |
|||
protected Type getDataType() { |
|||
return TypeToken.getParameterized(NoticeDetailDTO.class).getType(); |
|||
} |
|||
|
|||
@Override |
|||
protected void onSuccess(GenericResponseDataModel<NoticeDetailDTO> t) { |
|||
if (t.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) { |
|||
noticeDetailLiveData.setValue(t.getData()); |
|||
view.showDetailScreen(); |
|||
} else { |
|||
view.showPopUpMessage(t.getMsg(), CustomAlertDialog.AlertType.FAILED, null); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void onFailed(String message) { |
|||
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, null); |
|||
} |
|||
|
|||
@Override |
|||
protected void onConnectionNotEstablished(String message) { |
|||
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, null); |
|||
} |
|||
|
|||
@Override |
|||
protected void unauthorizedAccess(String message) { |
|||
gateway.clearAllUserData(); |
|||
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, alertType -> view.logout()); |
|||
} |
|||
} |
|||
|
|||
} |
|||
package com.swifttech.remit.android.features.notice.presenter; |
|||
|
|||
import androidx.lifecycle.LiveData; |
|||
import androidx.lifecycle.MutableLiveData; |
|||
|
|||
import com.google.gson.reflect.TypeToken; |
|||
import com.swifttech.remit.android.base.BaseViewModel; |
|||
import com.swifttech.remit.android.common.customwidgets.CustomAlertDialog; |
|||
import com.swifttech.remit.android.features.notice.model.NoticeDTO; |
|||
import com.swifttech.remit.android.features.notice.model.NoticeDetailDTO; |
|||
import com.swifttech.remit.android.utils.Constants; |
|||
import com.swifttech.remit.android.utils.https.GenericApiObserverResponseV2; |
|||
import com.swifttech.remit.android.utils.https.GenericResponseDataModel; |
|||
|
|||
import java.lang.reflect.Type; |
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers; |
|||
import io.reactivex.disposables.CompositeDisposable; |
|||
import io.reactivex.schedulers.Schedulers; |
|||
|
|||
public class NoticeViewModel extends BaseViewModel implements NoticePresenterInterface { |
|||
|
|||
|
|||
private final NoticeViewContractInterface view; |
|||
private final NoticeGatewayInterface gateway; |
|||
private final CompositeDisposable compositeDisposable; |
|||
|
|||
MutableLiveData<List<NoticeDTO>> noticeListLiveData; |
|||
MutableLiveData<NoticeDetailDTO> noticeDetailLiveData; |
|||
|
|||
public NoticeViewModel(NoticePresenterInterface.NoticeViewContractInterface view, NoticeGatewayInterface gatewayInterface) { |
|||
this.view = view; |
|||
this.gateway = gatewayInterface; |
|||
noticeListLiveData = new MutableLiveData<>(); |
|||
noticeDetailLiveData = new MutableLiveData<>(); |
|||
this.compositeDisposable = new CompositeDisposable(); |
|||
} |
|||
|
|||
@Override |
|||
public void onViewReady() { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void onViewNotReady() { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void fetchNoticeListLiveData() { |
|||
this.compositeDisposable.add( |
|||
this.gateway.getNoticeList(gateway.getAuth(), gateway.getUserIDNumber()) |
|||
.doOnSubscribe(subs -> view.showProgressBar(true, "")) |
|||
.subscribeOn(Schedulers.io()) |
|||
.observeOn(AndroidSchedulers.mainThread()) |
|||
.doFinally(() -> view.showProgressBar(false, "")) |
|||
.subscribeWith(new NoticeListObserver()) |
|||
); |
|||
} |
|||
|
|||
@Override |
|||
public void fetchNoticeDetail(NoticeDTO selectedNotice) { |
|||
this.compositeDisposable.add( |
|||
this.gateway.getNoticeDetail(gateway.getAuth(), selectedNotice.getRowId()) |
|||
.doOnSubscribe(subs -> view.showProgressBar(true, "")) |
|||
.subscribeOn(Schedulers.io()) |
|||
.observeOn(AndroidSchedulers.mainThread()) |
|||
.doFinally(() -> view.showProgressBar(false, "")) |
|||
.subscribeWith(new NoticeDetailObserver()) |
|||
); |
|||
} |
|||
|
|||
@Override |
|||
public LiveData<List<NoticeDTO>> getNoticeListLiveData() { |
|||
return noticeListLiveData; |
|||
} |
|||
|
|||
@Override |
|||
public LiveData<NoticeDetailDTO> getNoticeDetailLiveData() { |
|||
return noticeDetailLiveData; |
|||
} |
|||
|
|||
public class NoticeListObserver extends GenericApiObserverResponseV2<List<NoticeDTO>> { |
|||
|
|||
@Override |
|||
protected Type getDataType() { |
|||
return TypeToken.getParameterized(List.class, NoticeDTO.class).getType(); |
|||
} |
|||
|
|||
@Override |
|||
protected void onSuccess(GenericResponseDataModel<List<NoticeDTO>> t) { |
|||
if (t.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) { |
|||
if (t.getData() != null && t.getData().size() > 0) { |
|||
view.lazyInitViews(); |
|||
sortNoticeList(t.getData()); |
|||
} else |
|||
view.showPopUpMessage("You don't have any notification at the moment.", CustomAlertDialog.AlertType.FAILED, alertType -> view.exitView()); |
|||
|
|||
} else { |
|||
view.showPopUpMessage(t.getMsg(), CustomAlertDialog.AlertType.FAILED, alertType -> view.exitView()); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void onFailed(String message) { |
|||
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, alertType -> view.exitView()); |
|||
} |
|||
|
|||
@Override |
|||
protected void onConnectionNotEstablished(String message) { |
|||
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, alertType -> view.exitView()); |
|||
|
|||
} |
|||
|
|||
@Override |
|||
protected void unauthorizedAccess(String message) { |
|||
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, alertType -> view.logout()); |
|||
|
|||
} |
|||
} |
|||
|
|||
private void sortNoticeList(List<NoticeDTO> data) { |
|||
// DateFormat df = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a"); |
|||
// Collections.sort(data, (o1, o2) -> { |
|||
// try { |
|||
// return df.parse(o1.getCreateDate()).compareTo(df.parse(o2.getCreateDate())); |
|||
// } catch (Exception pe) { |
|||
// Collections.reverse(data); |
|||
// } |
|||
// return 0; |
|||
// }); |
|||
if (data != null) |
|||
Collections.reverse(data); |
|||
noticeListLiveData.setValue(data); |
|||
|
|||
} |
|||
|
|||
public class NoticeDetailObserver extends GenericApiObserverResponseV2<NoticeDetailDTO> { |
|||
@Override |
|||
protected Type getDataType() { |
|||
return TypeToken.getParameterized(NoticeDetailDTO.class).getType(); |
|||
} |
|||
|
|||
@Override |
|||
protected void onSuccess(GenericResponseDataModel<NoticeDetailDTO> t) { |
|||
if (t.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) { |
|||
noticeDetailLiveData.setValue(t.getData()); |
|||
view.showDetailScreen(); |
|||
} else { |
|||
view.showPopUpMessage(t.getMsg(), CustomAlertDialog.AlertType.FAILED, null); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void onFailed(String message) { |
|||
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, null); |
|||
} |
|||
|
|||
@Override |
|||
protected void onConnectionNotEstablished(String message) { |
|||
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, null); |
|||
} |
|||
|
|||
@Override |
|||
protected void unauthorizedAccess(String message) { |
|||
gateway.clearAllUserData(); |
|||
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, alertType -> view.logout()); |
|||
} |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue