mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-06-30 21:04:16 +00:00
add project adins
This commit is contained in:
parent
ad06ac5505
commit
f8f85d679d
5299 changed files with 625430 additions and 0 deletions
|
@ -0,0 +1,704 @@
|
|||
package com.adins.mss.base.todolist.todayplanrepository;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.PlanTask;
|
||||
import com.adins.mss.dao.TaskH;
|
||||
import com.adins.mss.dao.Timeline;
|
||||
import com.adins.mss.dao.TimelineType;
|
||||
import com.adins.mss.foundation.db.dataaccess.PlanTaskDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.TaskDDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.TaskHDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.TimelineTypeDataAccess;
|
||||
import com.adins.mss.foundation.dialog.DialogManager;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class TodayPlanRepository implements Comparator<PlanTask> {
|
||||
|
||||
private List<PlanTask> currentPlans;
|
||||
private IPlanTaskDataSource dataSource;
|
||||
private List<PlanTaskRepoListener> listeners;
|
||||
private Context context;
|
||||
private int lastPlanSequenceNo;
|
||||
private boolean isStartVisit;
|
||||
private boolean needSync;//used for check if current plans has changed from last start visit
|
||||
private String[] lastOffChangePlanInfo;
|
||||
private boolean hasDeletedPlanTask;
|
||||
|
||||
@Override
|
||||
public int compare(PlanTask o1, PlanTask o2) {
|
||||
return o1.getSequence() - o2.getSequence();
|
||||
}
|
||||
|
||||
public interface PlanTaskRepoListener{
|
||||
void onRepoChange(List<PlanTask> plans);
|
||||
void onError(String errMsg);
|
||||
}
|
||||
|
||||
public TodayPlanRepository(Context context) {
|
||||
this.context = context;
|
||||
this.dataSource = new PlanTaskDataSource(context);
|
||||
isStartVisit = dataSource.getStartVisitOnlineStatus();
|
||||
needSync = dataSource.getNeedSyncStatus();
|
||||
lastOffChangePlanInfo = dataSource.getLastOfflineChangePlan();
|
||||
}
|
||||
|
||||
public void addListener(PlanTaskRepoListener listener){
|
||||
if(listeners == null){
|
||||
listeners = new ArrayList<>();
|
||||
}
|
||||
if(listeners.contains(listener)){
|
||||
return;//has added to list of listeners
|
||||
}
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(PlanTaskRepoListener listener){
|
||||
if(listeners == null){
|
||||
return;
|
||||
}
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
public int getLastPlanSequenceNo() {
|
||||
return lastPlanSequenceNo;
|
||||
}
|
||||
|
||||
public void updateLastPlanSequenceNo(){
|
||||
lastPlanSequenceNo = dataSource.getLastSequenceNo();
|
||||
}
|
||||
|
||||
public int getLastPlansCount() {
|
||||
return currentPlans.size();
|
||||
}
|
||||
|
||||
public void updateLastPlansCount(){
|
||||
lastPlanSequenceNo = dataSource.getTotalPlanFromStart();
|
||||
}
|
||||
|
||||
public boolean isStartVisit() {
|
||||
return isStartVisit;
|
||||
}
|
||||
|
||||
public boolean isHasDeletedPlanTask() {
|
||||
return hasDeletedPlanTask;
|
||||
}
|
||||
|
||||
public void setHasDeletedPlanTask(boolean hasDeletedPlanTask) {
|
||||
this.hasDeletedPlanTask = hasDeletedPlanTask;
|
||||
}
|
||||
|
||||
public void setStartVisit(boolean startVisit) {
|
||||
isStartVisit = startVisit;
|
||||
dataSource.saveStartVisitOnlineStatus(isStartVisit);
|
||||
}
|
||||
|
||||
public boolean isNeedSync() {
|
||||
return needSync;
|
||||
}
|
||||
|
||||
public void setNeedSync(boolean needSync) {
|
||||
this.needSync = needSync;
|
||||
dataSource.saveNeedSyncStatus(needSync);
|
||||
}
|
||||
|
||||
public String[] getLastOffChangePlanInfo() {
|
||||
return lastOffChangePlanInfo;
|
||||
}
|
||||
|
||||
public void setLastOffChangePlanInfo(String[] lastOffChangePlanInfo) {
|
||||
this.lastOffChangePlanInfo = lastOffChangePlanInfo;
|
||||
if(lastOffChangePlanInfo == null)
|
||||
dataSource.saveLastChangePlanOffline(null,null);
|
||||
else{
|
||||
dataSource.saveLastChangePlanOffline(lastOffChangePlanInfo[0],lastOffChangePlanInfo[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyChange(List<PlanTask> planTasks){
|
||||
if(listeners != null && !listeners.isEmpty()){
|
||||
for (PlanTaskRepoListener listener:listeners){
|
||||
if(listener == null)
|
||||
continue;
|
||||
listener.onRepoChange(planTasks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void applyChange(String message){
|
||||
if(listeners != null && !listeners.isEmpty()){
|
||||
for (PlanTaskRepoListener listener:listeners){
|
||||
if(listener == null)
|
||||
continue;
|
||||
listener.onError(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void decideStartedPlan(){
|
||||
for (PlanTask planTask:currentPlans) {
|
||||
if(planTask.getPlan_status().equals(PlanTaskDataAccess.STATUS_STARTED)){
|
||||
Global.setPlanStarted(true);
|
||||
Global.setCurrentPlanTask(planTask.getUuid_task_h());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadPlans(){
|
||||
dataSource.loadPlans(new IPlanTaskDataSource.Result<List<PlanTask>>() {
|
||||
@Override
|
||||
public void onResult(List<PlanTask> result) {
|
||||
if(result == null)
|
||||
return;
|
||||
|
||||
lastPlanSequenceNo = dataSource.getLastSequenceNo();
|
||||
currentPlans = result;
|
||||
decideStartedPlan();
|
||||
applyChange(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
applyChange(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updatePlan(final List<PlanTask> planTasks){
|
||||
dataSource.updatePlanStatus(planTasks, new IPlanTaskDataSource.Result<List<PlanTask>>() {
|
||||
@Override
|
||||
public void onResult(List<PlanTask> result) {
|
||||
//if plan status is finish -> decide next plan
|
||||
if(result != null){
|
||||
currentPlans = result;//update cached result
|
||||
for (PlanTask planTask:currentPlans) {
|
||||
if(planTask.getPlan_status().equals(PlanTaskDataAccess.STATUS_STARTED)){
|
||||
Global.setPlanStarted(true);
|
||||
Global.setCurrentPlanTask(planTask.getUuid_task_h());
|
||||
break;
|
||||
}
|
||||
}
|
||||
applyChange(result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
applyChange(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updatePlanByTaskH(TaskH taskH,String planStatus){
|
||||
if(taskH == null){
|
||||
return;
|
||||
}
|
||||
|
||||
if(planStatus.equals(PlanTaskDataAccess.STATUS_FINISH)){
|
||||
List<PlanTask> updatedPlans = new ArrayList<>();
|
||||
|
||||
//update previous finish plan status to finish
|
||||
PlanTask updatedPlan = getPlanTaskByTaskH(taskH.getTask_id());
|
||||
updatedPlan.setPlan_status(PlanTaskDataAccess.STATUS_FINISH);
|
||||
updatedPlans.add(updatedPlan);
|
||||
dataSource.updatePlanStatus(updatedPlans);//update plan
|
||||
|
||||
if(!Global.getCurrentPlanTask().equals(updatedPlan.getUuid_task_h())){//jika plan aktif bukan plan yang berubah.
|
||||
//no need decide next plan, remove plan from view
|
||||
currentPlans.remove(updatedPlan);
|
||||
updatePlanViewSequence();
|
||||
return;
|
||||
}
|
||||
|
||||
//if updated plan is active plan, decide next plan and remove current plan from view
|
||||
PlanTask nextPlan = decideNextPlan(updatedPlan);
|
||||
if(nextPlan != null){
|
||||
nextPlan.setPlan_status(PlanTaskDataAccess.STATUS_STARTED);
|
||||
Global.setCurrentPlanTask(nextPlan.getUuid_task_h());
|
||||
updatedPlans.add(nextPlan);
|
||||
}else {
|
||||
Global.setCurrentPlanTask(null);
|
||||
}
|
||||
|
||||
//update plan view sequence
|
||||
updatePlanViewSequence();
|
||||
}
|
||||
else {
|
||||
PlanTask updatedPlan = getPlanTaskByTaskH(taskH.getTask_id());
|
||||
updatedPlan.setPlan_status(planStatus);
|
||||
List<PlanTask> updatedPlans = new ArrayList<>();
|
||||
updatedPlans.add(updatedPlan);
|
||||
updatePlan(updatedPlans);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeTaskhFromPlan(String oldUuidTaskH,String newUuidTaskH){
|
||||
PlanTask oldCurrentPlan = getPlanTaskByTaskH(oldUuidTaskH);
|
||||
//create new copied plan for new task id
|
||||
PlanTask newChangedIdPlan = new PlanTask(Tool.getUUID());
|
||||
newChangedIdPlan.setPlan_crt_date(oldCurrentPlan.getPlan_crt_date());
|
||||
newChangedIdPlan.setPlan_start_date(oldCurrentPlan.getPlan_start_date());
|
||||
newChangedIdPlan.setUuid_task_h(newUuidTaskH);
|
||||
newChangedIdPlan.setPlan_status(oldCurrentPlan.getPlan_status());
|
||||
newChangedIdPlan.setSequence(oldCurrentPlan.getSequence());
|
||||
newChangedIdPlan.setUuid_user(oldCurrentPlan.getUuid_user());
|
||||
newChangedIdPlan.setView_sequence(oldCurrentPlan.getView_sequence());
|
||||
|
||||
//remove old plan and add new plan
|
||||
int planIdx = currentPlans.indexOf(oldCurrentPlan);
|
||||
currentPlans.remove(oldCurrentPlan);
|
||||
oldCurrentPlan.setPlan_status(PlanTaskDataAccess.STATUS_FINISH);//change old plan status to finish
|
||||
currentPlans.add(planIdx,newChangedIdPlan);
|
||||
|
||||
if(Global.getCurrentPlanTask().equals(oldUuidTaskH)){
|
||||
Global.setCurrentPlanTask(newUuidTaskH);
|
||||
}
|
||||
|
||||
//update plan data
|
||||
List<PlanTask> changedPlans = new ArrayList<>();
|
||||
changedPlans.add(newChangedIdPlan);
|
||||
changedPlans.add(oldCurrentPlan);
|
||||
PlanTaskDataAccess.addUpdatePlans(context,changedPlans);
|
||||
|
||||
loadPlans();//refresh today plan view
|
||||
}
|
||||
|
||||
public PlanTask decideNextPlan(PlanTask currentPlan){
|
||||
PlanTask nextPlan = null;
|
||||
|
||||
currentPlans.remove(currentPlan);
|
||||
if(currentPlans.isEmpty())
|
||||
return null;
|
||||
List<PlanTask> sortedPlanTaskAcend = new ArrayList<>(currentPlans);
|
||||
//sort by lowest sequence
|
||||
Collections.sort(sortedPlanTaskAcend,this);
|
||||
nextPlan = sortedPlanTaskAcend.get(0);
|
||||
int nextPlanIdx = currentPlans.indexOf(nextPlan);
|
||||
currentPlans.remove(nextPlanIdx);
|
||||
currentPlans.add(0,nextPlan);
|
||||
|
||||
return nextPlan;
|
||||
}
|
||||
|
||||
public String nextPlanBeforeSubmit(String uuidCurrentPlan){
|
||||
if(uuidCurrentPlan == null || uuidCurrentPlan.equals(""))
|
||||
return null;
|
||||
|
||||
if (null != Global.getCurrentPlanTask() && !Global.getCurrentPlanTask().equals(uuidCurrentPlan)) {
|
||||
return Global.getCurrentPlanTask();
|
||||
}
|
||||
|
||||
PlanTask currentPlan = getPlanTaskByTaskH(uuidCurrentPlan);
|
||||
if(currentPlan == null)
|
||||
return null;
|
||||
|
||||
if(currentPlans.isEmpty())
|
||||
return null;
|
||||
|
||||
List<PlanTask> sortedPlanTaskAcend = new ArrayList<>(currentPlans);
|
||||
//exclude current plan
|
||||
sortedPlanTaskAcend.remove(currentPlan);
|
||||
if(sortedPlanTaskAcend.isEmpty()){
|
||||
return null;
|
||||
}
|
||||
|
||||
//sort by lowest sequence
|
||||
Collections.sort(sortedPlanTaskAcend,this);
|
||||
PlanTask nextPlan = sortedPlanTaskAcend.get(0);
|
||||
|
||||
return nextPlan.getUuid_task_h();
|
||||
}
|
||||
|
||||
public PlanTask getPlanTaskByTaskH(String uuidTaskh){
|
||||
PlanTask result = null;
|
||||
if(currentPlans != null && !currentPlans.isEmpty()){
|
||||
for(PlanTask planTask:currentPlans){
|
||||
if(planTask.getUuid_task_h().equals(uuidTaskh)){
|
||||
result = planTask;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void startVisit(List<PlanTask> planTasks, IPlanTaskDataSource.Result<ResponseStartVisit> callback){
|
||||
RequestStartVisit requestStartVisit = new RequestStartVisit();
|
||||
requestStartVisit.setIsStartVisit(this.isStartVisit);
|
||||
List<PlanTaskSequence> activityList = new ArrayList<>();
|
||||
for(PlanTask planTask:planTasks){
|
||||
if(planTask == null)
|
||||
continue;
|
||||
PlanTaskSequence activity = new PlanTaskSequence(planTask.getUuid_task_h()
|
||||
,String.valueOf(planTask.getSequence()));
|
||||
activityList.add(activity);
|
||||
}
|
||||
requestStartVisit.setActivityList(activityList);
|
||||
requestStartVisit.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
dataSource.startVisit(requestStartVisit,callback);
|
||||
}
|
||||
|
||||
public boolean isAllowChangePlan(){
|
||||
List<PlanTask> result = PlanTaskDataAccess.findPlanByTaskH(context,Global.getCurrentPlanTask());
|
||||
if(result.isEmpty()){
|
||||
return false;
|
||||
}
|
||||
|
||||
PlanTask currentPlan = result.get(0);
|
||||
if(currentPlan == null)
|
||||
return false;
|
||||
|
||||
TaskH currentPlantaskH = TaskHDataAccess.getOneHeader(context,currentPlan.getUuid_task_h());
|
||||
if(currentPlantaskH == null && !hasDeletedPlanTask){//task is manualy deleted but plan still exist
|
||||
return false;
|
||||
}
|
||||
else if(currentPlantaskH == null){
|
||||
return true;
|
||||
}
|
||||
|
||||
//only allow if current plan taskh status is not failed draft task
|
||||
//check if current plan is failed draft task
|
||||
if(currentPlantaskH.getStatus().equals(TaskHDataAccess.STATUS_SEND_SAVEDRAFT)){
|
||||
List<Timeline> timelines = currentPlantaskH.getTimelineList();
|
||||
if(!timelines.isEmpty()){
|
||||
TimelineType timelineType = timelines.get(timelines.size() - 1).getTimelineType();
|
||||
if(timelineType != null){
|
||||
TimelineType typeFailedDraft = TimelineTypeDataAccess.getTimelineTypebyType(context, Global.TIMELINE_TYPE_FAILEDDRAFT);
|
||||
if(typeFailedDraft.getTimeline_type().equals(timelineType.getTimeline_type())){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check for pending submit
|
||||
if(currentPlantaskH.getStatus().equals(TaskHDataAccess.STATUS_SEND_FAILED)){
|
||||
//check if task coll result is paid/collected
|
||||
String uuidUser = GlobalData.getSharedGlobalData().getUser().getUuid_user();
|
||||
boolean isTaskPaid = TaskDDataAccess.isTaskPaid(context,uuidUser,currentPlantaskH.getUuid_task_h());
|
||||
if(isTaskPaid){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void changePlan(final String oldPlanUuidTaskh, final String newPlanUuidTaskh, final IPlanTaskDataSource.Result<Boolean> callback){
|
||||
if(callback == null)
|
||||
return;
|
||||
|
||||
RequestChangePlan requestChangePlan = new RequestChangePlan(newPlanUuidTaskh,oldPlanUuidTaskh);
|
||||
requestChangePlan.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
|
||||
dataSource.changePlan(requestChangePlan, new IPlanTaskDataSource.Result<ResponseChangePlan>() {
|
||||
@Override
|
||||
public void onResult(ResponseChangePlan result) {
|
||||
if(result != null){
|
||||
//reset last changeplan offline info
|
||||
lastOffChangePlanInfo = null;
|
||||
dataSource.saveLastChangePlanOffline(null,null);
|
||||
|
||||
List<PlanTask> oldPlanResult = PlanTaskDataAccess.findPlanByTaskH(context,oldPlanUuidTaskh);
|
||||
PlanTask oldPlan = oldPlanResult.isEmpty()?null:oldPlanResult.get(0);
|
||||
PlanTask newPlan = getPlanTaskByTaskH(newPlanUuidTaskh);
|
||||
if(newPlan == null){//if null, then it is change plan from revisit
|
||||
List<PlanTask> searchedPlans = PlanTaskDataAccess.findPlanByTaskH(context,newPlanUuidTaskh);
|
||||
if(searchedPlans.isEmpty()){
|
||||
return;
|
||||
}
|
||||
newPlan = searchedPlans.get(0);
|
||||
newPlan.setPlan_status(PlanTaskDataAccess.STATUS_STARTED);
|
||||
currentPlans.add(0,newPlan);//just add to top
|
||||
}
|
||||
else {
|
||||
//move new plan to top
|
||||
newPlan.setPlan_status(PlanTaskDataAccess.STATUS_STARTED);
|
||||
currentPlans.remove(newPlan);
|
||||
currentPlans.add(0,newPlan);
|
||||
}
|
||||
|
||||
if(oldPlan!=null){
|
||||
oldPlan.setPlan_status(PlanTaskDataAccess.STATUS_PLANNED);
|
||||
PlanTaskDataAccess.updatePlan(context,oldPlan);
|
||||
TaskH oldTaskh = TaskHDataAccess.getOneUnsentTaskHeader(context,oldPlan.getUuid_task_h());
|
||||
if(hasDeletedPlanTask || (oldTaskh != null && oldTaskh.getStatus().equals(TaskHDataAccess.STATUS_SEND_SAVEDRAFT))){//move old plan to bottom if draft task
|
||||
currentPlans.remove(oldPlan);
|
||||
currentPlans.add(oldPlan);
|
||||
}
|
||||
}
|
||||
|
||||
updatePlanViewSequence();
|
||||
Global.setCurrentPlanTask(newPlan.getUuid_task_h());
|
||||
callback.onResult(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
if(GlobalData.isRequireRelogin() || "Plan Not Approved Yet.".equals(error)) {
|
||||
callback.onError(error);
|
||||
return;
|
||||
}
|
||||
if(error.equals("Offline")){
|
||||
//save offline changeplan info
|
||||
lastOffChangePlanInfo = new String[]{oldPlanUuidTaskh,newPlanUuidTaskh};
|
||||
dataSource.saveLastChangePlanOffline(oldPlanUuidTaskh,newPlanUuidTaskh);
|
||||
|
||||
PlanTask oldPlan = getPlanTaskByTaskH(Global.getCurrentPlanTask());
|
||||
PlanTask newPlan = getPlanTaskByTaskH(newPlanUuidTaskh);
|
||||
if(newPlan == null){//if null, then it is change plan from revisit
|
||||
List<PlanTask> searchedPlans = PlanTaskDataAccess.findPlanByTaskH(context,newPlanUuidTaskh);
|
||||
if(searchedPlans.isEmpty()){
|
||||
return;
|
||||
}
|
||||
newPlan = searchedPlans.get(0);
|
||||
currentPlans.add(0,newPlan);//just add to top
|
||||
}
|
||||
else {
|
||||
//move new plan to top
|
||||
currentPlans.remove(newPlan);
|
||||
currentPlans.add(0,newPlan);
|
||||
}
|
||||
|
||||
if(oldPlan != null)
|
||||
oldPlan.setPlan_status(PlanTaskDataAccess.STATUS_PLANNED);
|
||||
|
||||
if(newPlan != null)
|
||||
newPlan.setPlan_status(PlanTaskDataAccess.STATUS_STARTED);
|
||||
|
||||
//move old plan to bottom if draft task
|
||||
if(oldPlan!=null){
|
||||
TaskH oldTaskh = TaskHDataAccess.getOneUnsentTaskHeader(context,oldPlan.getUuid_task_h());
|
||||
if(oldTaskh.getStatus().equals(TaskHDataAccess.STATUS_SEND_SAVEDRAFT)){
|
||||
currentPlans.remove(oldPlan);
|
||||
currentPlans.add(oldPlan);
|
||||
}
|
||||
}
|
||||
|
||||
updatePlanViewSequence();
|
||||
|
||||
if(newPlan != null){
|
||||
Global.setCurrentPlanTask(newPlan.getUuid_task_h());
|
||||
}
|
||||
callback.onResult(true);
|
||||
return;
|
||||
}
|
||||
|
||||
callback.onResult(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updatePlanViewSequence(){
|
||||
if(currentPlans == null || currentPlans.isEmpty()){
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i=0; i<currentPlans.size(); i++){
|
||||
PlanTask tempPlan = currentPlans.get(i);
|
||||
tempPlan.setView_sequence(i+1);//set new view sequence
|
||||
}
|
||||
updatePlan(currentPlans);
|
||||
}
|
||||
|
||||
public List<PlanTask> getCachedPlans(){
|
||||
return currentPlans;
|
||||
}
|
||||
|
||||
public void generatePlansFromTaskList(final List<TaskH> taskList){
|
||||
if(taskList == null || taskList.isEmpty())
|
||||
return;
|
||||
|
||||
//check if has plan before
|
||||
dataSource.loadPlans(new IPlanTaskDataSource.Result<List<PlanTask>>() {
|
||||
@Override
|
||||
public void onResult(List<PlanTask> result) {
|
||||
//check each sequence of taskh
|
||||
List<PlanTask> generatedPlans = new ArrayList<>();
|
||||
for(TaskH taskH: taskList){
|
||||
Integer seqNo = taskH.getSeq_no();
|
||||
//if 0 then dont generate plan
|
||||
if(seqNo == null || seqNo == 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
//if not 0 then generate plan and set status as planned
|
||||
String uuidUser = GlobalData.getSharedGlobalData().getUser().getUuid_user();
|
||||
PlanTask planTask = new PlanTask();
|
||||
planTask.setUuid_plan_task(Tool.getUUID());
|
||||
planTask.setUuid_user(uuidUser);
|
||||
planTask.setUuid_task_h(taskH.getUuid_task_h());
|
||||
planTask.setPlan_crt_date(new Date());
|
||||
planTask.setPlan_start_date(new Date());
|
||||
planTask.setPlan_status(PlanTaskDataAccess.STATUS_PLANNED);
|
||||
planTask.setSequence(seqNo);
|
||||
|
||||
//add to plan list
|
||||
generatedPlans.add(planTask);
|
||||
}
|
||||
|
||||
if (generatedPlans.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//if has, return
|
||||
if (result != null && !result.isEmpty()) {
|
||||
PlanTaskDataAccess.removeAllPlans(context, GlobalData.getSharedGlobalData().getUser().getUuid_user());
|
||||
}
|
||||
|
||||
//sort plan list ascending by seqNo
|
||||
Collections.sort(generatedPlans,TodayPlanRepository.this);
|
||||
|
||||
for(int i=0; i<generatedPlans.size(); i++){
|
||||
PlanTask sortedPlan = generatedPlans.get(i);
|
||||
//set each plan view sequence
|
||||
sortedPlan.setView_sequence(i+1);
|
||||
if(i==0){
|
||||
sortedPlan.setPlan_status(PlanTaskDataAccess.STATUS_STARTED);
|
||||
Global.setCurrentPlanTask(sortedPlan.getUuid_task_h());
|
||||
}
|
||||
}
|
||||
|
||||
//add all plans to db
|
||||
currentPlans = generatedPlans;
|
||||
//set start visit to true
|
||||
setStartVisit(true);
|
||||
PlanTaskDataAccess.addUpdatePlans(context,generatedPlans);
|
||||
lastPlanSequenceNo = dataSource.getLastSequenceNo();
|
||||
Global.setPlanStarted(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
//EMPTY
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void changePlanRevisit(String revisitUuidTaskh){
|
||||
PlanTask oldPlan = getPlanTaskByTaskH(Global.getCurrentPlanTask());
|
||||
PlanTask newPlan = getPlanTaskByTaskH(revisitUuidTaskh);
|
||||
if(newPlan == null){//if null, then it is change plan from revisit
|
||||
List<PlanTask> searchedPlans = PlanTaskDataAccess.findPlanByTaskH(context,revisitUuidTaskh);
|
||||
if(searchedPlans.isEmpty()){
|
||||
return;
|
||||
}
|
||||
newPlan = searchedPlans.get(0);
|
||||
currentPlans.add(0,newPlan);//just add to top
|
||||
}
|
||||
else {
|
||||
//move new plan to top
|
||||
currentPlans.remove(newPlan);
|
||||
currentPlans.add(0,newPlan);
|
||||
}
|
||||
|
||||
if(oldPlan != null)
|
||||
oldPlan.setPlan_status(PlanTaskDataAccess.STATUS_PLANNED);
|
||||
|
||||
if(newPlan != null)
|
||||
newPlan.setPlan_status(PlanTaskDataAccess.STATUS_STARTED);
|
||||
|
||||
//move old plan to bottom if draft task
|
||||
if(oldPlan!=null){
|
||||
TaskH oldTaskh = TaskHDataAccess.getOneUnsentTaskHeader(context,oldPlan.getUuid_task_h());
|
||||
if(oldTaskh.getStatus().equals(TaskHDataAccess.STATUS_SEND_SAVEDRAFT)){
|
||||
currentPlans.remove(oldPlan);
|
||||
currentPlans.add(oldPlan);
|
||||
}
|
||||
}
|
||||
|
||||
updatePlanViewSequence();
|
||||
|
||||
if(newPlan != null){
|
||||
Global.setCurrentPlanTask(newPlan.getUuid_task_h());
|
||||
}
|
||||
}
|
||||
|
||||
private PlanTask getPlanWithUnsentTaskh(){
|
||||
PlanTask result = null;
|
||||
TaskH taskH;
|
||||
for(PlanTask plan:currentPlans){
|
||||
if(plan == null){
|
||||
continue;
|
||||
}
|
||||
taskH = TaskHDataAccess.getOneUnsentTaskHeader(context,plan.getUuid_task_h());
|
||||
if(taskH != null){
|
||||
return plan;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void checkPlanAfterSync(){
|
||||
//getCurrent plans
|
||||
dataSource.loadPlans(new IPlanTaskDataSource.Result<List<PlanTask>>() {
|
||||
@Override
|
||||
public void onResult(List<PlanTask> result) {
|
||||
currentPlans = result;
|
||||
if(result.isEmpty()){
|
||||
Global.setCurrentPlanTask(null);
|
||||
return;
|
||||
}
|
||||
PlanTask startedPlan = null;
|
||||
for (PlanTask plan:currentPlans) {
|
||||
if(plan != null && PlanTaskDataAccess.STATUS_STARTED.equals(plan.getPlan_status())){
|
||||
startedPlan = plan;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(startedPlan == null){
|
||||
Global.setCurrentPlanTask(null);
|
||||
return;
|
||||
}
|
||||
|
||||
TaskH planTaskh = TaskHDataAccess.getOneUnsentTaskHeader(context,startedPlan.getUuid_task_h());
|
||||
if(planTaskh != null){
|
||||
Global.setPlanStarted(true);
|
||||
Global.setCurrentPlanTask(startedPlan.getUuid_task_h());
|
||||
return;
|
||||
}
|
||||
|
||||
final PlanTask newPlan = getPlanWithUnsentTaskh();
|
||||
if(newPlan == null){
|
||||
Global.setCurrentPlanTask(null);
|
||||
return;
|
||||
}
|
||||
|
||||
changePlan(startedPlan.getUuid_task_h(), newPlan.getUuid_task_h(), new IPlanTaskDataSource.Result<Boolean>() {
|
||||
@Override
|
||||
public void onResult(Boolean result) {
|
||||
Global.setPlanStarted(true);
|
||||
Global.setCurrentPlanTask(newPlan.getUuid_task_h());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
if(GlobalData.isRequireRelogin()){
|
||||
DialogManager.showForceExitAlert(context,context.getString(R.string.msgLogout));
|
||||
return;
|
||||
}
|
||||
Toast.makeText(context, context.getString(R.string.error_change_plan), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
Toast.makeText(context, "Error", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/activity_lookup_criteria"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label"
|
||||
android:padding="@dimen/padding_small"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/select_answer"/>
|
||||
<ScrollView
|
||||
android:layout_below="@+id/label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/tableCriteriaLayout">
|
||||
</TableLayout>
|
||||
</ScrollView>
|
||||
</RelativeLayout>
|
|
@ -0,0 +1,891 @@
|
|||
package com.adins.mss.foundation.dialog;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.provider.Settings;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.NewMainActivity;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.authentication.Authentication;
|
||||
import com.adins.mss.base.commons.CommonImpl;
|
||||
import com.adins.mss.base.commons.SecondHelper;
|
||||
import com.adins.mss.base.commons.SubmitResult;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.dynamicform.DynamicFormActivity;
|
||||
import com.adins.mss.base.util.ByteFormatter;
|
||||
import com.adins.mss.base.util.SecondFormatter;
|
||||
import com.adins.mss.base.util.UserSession;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.Contact;
|
||||
import com.adins.mss.dao.Scheme;
|
||||
import com.adins.mss.dao.TaskH;
|
||||
import com.adins.mss.foundation.db.dataaccess.GeneralParameterDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.SchemeDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.TaskDDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.TaskHDataAccess;
|
||||
import com.adins.mss.foundation.formatter.Formatter;
|
||||
import com.adins.mss.foundation.location.LocationTrackingManager;
|
||||
import com.adins.mss.foundation.security.storepreferences.ObscuredSharedPreferences;
|
||||
import com.github.jjobes.slidedatetimepicker.SlideDateTimeListener;
|
||||
import com.github.jjobes.slidedatetimepicker.SlideDateTimePicker;
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.GoogleApiAvailability;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class DialogManager {
|
||||
public static final int TYPE_ERROR = 0;
|
||||
public static final int TYPE_INFO = 1;
|
||||
public static final int TYPE_WARNING = 2;
|
||||
public static final int TYPE_SUCCESS = 3;
|
||||
static final int REQUEST_CODE_RECOVER_PLAY_SERVICES = 1001;
|
||||
private static final String OK_LABEL = "OK";
|
||||
private static boolean isForceLogoutDialogShowing;
|
||||
/**
|
||||
* To check gps enabled and create an alert to force user to enable gps
|
||||
*
|
||||
* @param activity
|
||||
* @author bong.rk
|
||||
*/
|
||||
public static NiftyDialogBuilder ndb;
|
||||
public static NiftyDialogBuilder ndb2;
|
||||
private static String TAG = "DIALOG_MANAGER";
|
||||
private static SlideDateTimeListener dtmListener = new SlideDateTimeListener() {
|
||||
|
||||
@Override
|
||||
public void onDateTimeSet(Date date) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(date.getTime());
|
||||
cal.set(cal.SECOND, 0);
|
||||
SimpleDateFormat mFormatter = new SimpleDateFormat(Global.DATE_TIME_STR_FORMAT);
|
||||
String result = mFormatter.format(cal);
|
||||
DynamicFormActivity.setTxtInFocusText(result);
|
||||
}
|
||||
|
||||
// Optional cancel listener
|
||||
@Override
|
||||
public void onDateTimeCancel() {
|
||||
//EMPTY
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* @param dialogType TYPE_ERROR, TYPE_INFO, TYPE_WARNING
|
||||
* @param message
|
||||
* @param title, you can set empty string
|
||||
*/
|
||||
|
||||
public static void showAlert(Context context, int dialogType, String message, String title) {
|
||||
final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
|
||||
|
||||
String frontText = null;
|
||||
|
||||
switch (dialogType) {
|
||||
case TYPE_ERROR:
|
||||
frontText = "ERROR";
|
||||
break;
|
||||
case TYPE_INFO:
|
||||
frontText = "INFO";
|
||||
break;
|
||||
case TYPE_WARNING:
|
||||
frontText = "WARNING";
|
||||
break;
|
||||
case TYPE_SUCCESS:
|
||||
frontText = "SUCCESS";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
alertDialog.setTitle(title);
|
||||
alertDialog.setMessage(frontText + ": " + message);
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, OK_LABEL, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
// ** dikasih try, soalnya kadang saat lg mau nampilin,
|
||||
// orang yang megang hp nya pencet back or home,
|
||||
// so kalo dialog nya tampil dy bakal eror karena layar nya berganti.
|
||||
// 17 feb 2012
|
||||
try {
|
||||
alertDialog.show();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
if (Global.IS_DEV)
|
||||
Log.i(TAG, "Show Dialog " + e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void showAlertNotif(Context context, String message, String title) {
|
||||
final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(context);
|
||||
dialogBuilder.withTitle(title)
|
||||
.withMessage(message)
|
||||
.withButton1Text(OK_LABEL)
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
dialogBuilder.dismiss();
|
||||
}
|
||||
})
|
||||
.isCancelable(true)
|
||||
.isCancelableOnTouchOutside(true)
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showAlert(Context context, int type, String message,
|
||||
DialogInterface.OnClickListener listener, String title) {
|
||||
final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
|
||||
|
||||
String frontText = null;
|
||||
|
||||
switch (type) {
|
||||
case TYPE_ERROR:
|
||||
frontText = "ERROR";
|
||||
break;
|
||||
case TYPE_INFO:
|
||||
frontText = "INFO";
|
||||
break;
|
||||
case TYPE_WARNING:
|
||||
frontText = "WARNING";
|
||||
break;
|
||||
case TYPE_SUCCESS:
|
||||
frontText = "SUCCESS";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
alertDialog.setTitle(title);
|
||||
alertDialog.setMessage(frontText + ": " + message);
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, OK_LABEL, listener);
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
public static void showOptimizeDialog(final Context activity) {
|
||||
try {
|
||||
ndb = NiftyDialogBuilder.getInstance(activity);
|
||||
ndb.withTitle(activity.getString(R.string.optimize_battery))
|
||||
.withMessage(activity.getString(R.string.optimize_battery_alert))
|
||||
|
||||
.withButton1Text(activity.getString(R.string.btnYes))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ndb.dismiss();
|
||||
Intent settingsIntent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
|
||||
activity.startActivity(settingsIntent);
|
||||
}
|
||||
});
|
||||
ndb.isCancelable(true);
|
||||
ndb.show();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void showImageDialog(Context context, Bitmap image) {
|
||||
NiftyDialogBuilder_PL pl = NiftyDialogBuilder_PL.getInstance(context);
|
||||
pl.withNoTitle().withNoMessage().withTransparentBackground().withImageView(image).show();
|
||||
}
|
||||
|
||||
public static void showExitAlertQuestion(final Activity activity, String message) {
|
||||
final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(activity);
|
||||
dialogBuilder.withTitle(activity.getString(R.string.btnExit))
|
||||
.withMessage(message)
|
||||
.withButton1Text(activity.getString(R.string.btnYes))
|
||||
.withButton2Text(activity.getString(R.string.btnNo))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
dialogBuilder.dismiss();
|
||||
activity.finish();
|
||||
GlobalData.getSharedGlobalData().setDoingTask(false);
|
||||
}
|
||||
})
|
||||
.setButton2Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialogBuilder.dismiss();
|
||||
}
|
||||
})
|
||||
.isCancelable(false)
|
||||
.isCancelableOnTouchOutside(true)
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showExitAlert(final Activity activity, String message) {
|
||||
if (Global.isIsUploading()) {
|
||||
//param, jika masih uoloading gak boleh exit
|
||||
final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(activity);
|
||||
dialogBuilder.withTitle(activity.getString(R.string.btnExit))
|
||||
.withMessage(activity.getString(R.string.msgStillUploading))
|
||||
.withButton1Text(OK_LABEL)
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
dialogBuilder.dismiss();
|
||||
}
|
||||
})
|
||||
.isCancelable(false)
|
||||
.isCancelableOnTouchOutside(true)
|
||||
.show();
|
||||
} else {
|
||||
final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(activity);
|
||||
dialogBuilder.withTitle(activity.getString(R.string.btnExit))
|
||||
.withMessage(message)
|
||||
.withButton1Text(activity.getString(R.string.btnYes))
|
||||
.withButton2Text(activity.getString(R.string.btnNo))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
dialogBuilder.dismiss();
|
||||
if (NewMainActivity.AutoSendLocationHistoryService != null) {
|
||||
activity.stopService(NewMainActivity.AutoSendLocationHistoryService);
|
||||
}
|
||||
if (NewMainActivity.RunNotificationService != null)
|
||||
activity.stopService(NewMainActivity.RunNotificationService);
|
||||
try {
|
||||
Formatter.clearFormatter();
|
||||
CommonImpl.clearFormatter();
|
||||
UserSession.clear();
|
||||
|
||||
ObscuredSharedPreferences sharedPref = ObscuredSharedPreferences.getPrefs(activity,
|
||||
"GlobalData", Context.MODE_PRIVATE);
|
||||
|
||||
ObscuredSharedPreferences.Editor sharedPrefEditor = sharedPref.edit();
|
||||
sharedPrefEditor.remove("HAS_LOGGED");
|
||||
sharedPrefEditor.commit();
|
||||
Authentication.setAsNonFreshInstall(LocationTrackingManager.getContextLocation());
|
||||
activity.sendBroadcast(new Intent(activity.getString(R.string.action_user_logout)));
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
activity.finish();
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.exit(0);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
})
|
||||
.setButton2Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialogBuilder.dismiss();
|
||||
}
|
||||
})
|
||||
.isCancelable(false)
|
||||
.isCancelableOnTouchOutside(true)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void showForceExitAlert(final Context context, String message) {
|
||||
if(!(context instanceof Activity)){
|
||||
//cannot show dialog if context is not activity.
|
||||
return;
|
||||
}
|
||||
|
||||
Activity activity = (Activity)context;
|
||||
if(activity.isFinishing() || activity.isDestroyed())
|
||||
return;
|
||||
|
||||
if(isForceLogoutDialogShowing){
|
||||
return;
|
||||
}
|
||||
|
||||
final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(context);
|
||||
dialogBuilder.withTitle(context.getString(R.string.btnExit))
|
||||
.withMessage(message)
|
||||
.withButton1Text(context.getString(R.string.btnYes))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
isForceLogoutDialogShowing = false;
|
||||
String application = GlobalData.getSharedGlobalData().getAuditData().getApplication();
|
||||
if (!Global.APPLICATION_ORDER.equals(application) && NewMainActivity.AutoSendLocationHistoryService != null) {
|
||||
context.stopService(NewMainActivity.AutoSendLocationHistoryService);
|
||||
}
|
||||
if (NewMainActivity.RunNotificationService != null)
|
||||
context.stopService(NewMainActivity.RunNotificationService);
|
||||
try {
|
||||
UserSession.clear();
|
||||
|
||||
ObscuredSharedPreferences sharedPref = ObscuredSharedPreferences.getPrefs(context,
|
||||
"GlobalData", Context.MODE_PRIVATE);
|
||||
|
||||
ObscuredSharedPreferences.Editor sharedPrefEditor = sharedPref.edit();
|
||||
sharedPrefEditor.remove("HAS_LOGGED");
|
||||
sharedPrefEditor.commit();
|
||||
Authentication.setAsNonFreshInstall(context);
|
||||
|
||||
((Activity)context).finishAffinity();
|
||||
dialogBuilder.dismiss();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.exit(0);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
})
|
||||
.isCancelable(false)
|
||||
.isCancelableOnTouchOutside(false)
|
||||
.show();
|
||||
isForceLogoutDialogShowing = true;
|
||||
}
|
||||
|
||||
public static void showForceExitAlert(final Activity activity, String message) {
|
||||
if(activity.isFinishing() || activity.isDestroyed())
|
||||
return;
|
||||
|
||||
if(isForceLogoutDialogShowing){
|
||||
return;
|
||||
}
|
||||
|
||||
final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(activity);
|
||||
dialogBuilder.withTitle(activity.getString(R.string.btnExit))
|
||||
.withMessage(message)
|
||||
.withButton1Text(activity.getString(R.string.btnYes))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
dialogBuilder.dismiss();
|
||||
isForceLogoutDialogShowing = false;
|
||||
String application = GlobalData.getSharedGlobalData().getAuditData().getApplication();
|
||||
if (!Global.APPLICATION_ORDER.equals(application) && NewMainActivity.AutoSendLocationHistoryService != null) {
|
||||
activity.stopService(NewMainActivity.AutoSendLocationHistoryService);
|
||||
}
|
||||
if (NewMainActivity.RunNotificationService != null)
|
||||
activity.stopService(NewMainActivity.RunNotificationService);
|
||||
try {
|
||||
UserSession.clear();
|
||||
|
||||
ObscuredSharedPreferences sharedPref = ObscuredSharedPreferences.getPrefs(activity,
|
||||
"GlobalData", Context.MODE_PRIVATE);
|
||||
|
||||
ObscuredSharedPreferences.Editor sharedPrefEditor = sharedPref.edit();
|
||||
sharedPrefEditor.remove("HAS_LOGGED");
|
||||
sharedPrefEditor.commit();
|
||||
Authentication.setAsNonFreshInstall(LocationTrackingManager.getContextLocation());
|
||||
|
||||
activity.sendBroadcast(new Intent(activity.getString(R.string.action_user_logout)));
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
|
||||
activity.finishAffinity();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.exit(0);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
})
|
||||
.isCancelable(false)
|
||||
.isCancelableOnTouchOutside(false)
|
||||
.show();
|
||||
isForceLogoutDialogShowing = true;
|
||||
}
|
||||
|
||||
public static void showForceSyncronize(final NewMainActivity activity) {
|
||||
final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(activity);
|
||||
dialogBuilder.withTitle(activity.getString(R.string.sync_dialog))
|
||||
.withMessage(R.string.sync_dialog_message)
|
||||
.withButton1Text(activity.getString(R.string.btnYes))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
dialogBuilder.dismiss();
|
||||
activity.gotoSynchronize();
|
||||
}
|
||||
})
|
||||
.isCancelable(false)
|
||||
.isCancelableOnTouchOutside(false)
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showDateTimePicker(FragmentActivity activity) {
|
||||
new SlideDateTimePicker.Builder(activity.getSupportFragmentManager())
|
||||
.setListener(dtmListener)
|
||||
.setInitialDate(new Date())
|
||||
.setIs24HourTime(true)
|
||||
.build()
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showGPSAlert(final Context activity) {
|
||||
LocationManager lm = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
|
||||
try {
|
||||
if (lm.getProvider(LocationManager.GPS_PROVIDER) != null) {
|
||||
final boolean gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
||||
if (!gpsEnabled) {
|
||||
closeGPSAlert();
|
||||
ndb = NiftyDialogBuilder.getInstance(activity);
|
||||
ndb.withTitle(activity.getString(R.string.gps_unable))
|
||||
.withMessage(activity.getString(R.string.gps_warning))
|
||||
.withButton1Text(activity.getString(R.string.gps_button))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ndb.dismiss();
|
||||
Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||
activity.startActivity(settingsIntent);
|
||||
|
||||
}
|
||||
});
|
||||
ndb.isCancelable(false);
|
||||
ndb.show();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (lm.getProvider(LocationManager.GPS_PROVIDER) != null) {
|
||||
final boolean gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
||||
|
||||
new LocationListener() {
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
boolean isMock;
|
||||
if (android.os.Build.VERSION.SDK_INT >= 18) {
|
||||
isMock = location.isFromMockProvider();
|
||||
} else {
|
||||
isMock = Settings.Secure.getString(LocationTrackingManager.getContextLocation().getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");
|
||||
}
|
||||
showMockDialog(gpsEnabled, isMock, activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) {
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) {
|
||||
//EMPTY
|
||||
}
|
||||
};
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void showMockDialog(Boolean gpsEnabled, Boolean isMock, final Context activity) {
|
||||
if (gpsEnabled && isMock) {
|
||||
closeGPSAlert();
|
||||
ndb = NiftyDialogBuilder.getInstance(activity);
|
||||
ndb.withTitle(activity.getString(R.string.mock_location))
|
||||
.withMessage(activity.getString(R.string.mock_location_alert))
|
||||
|
||||
.withButton1Text(activity.getString(R.string.dev_option))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ndb.dismiss();
|
||||
Intent settingsIntent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
|
||||
activity.startActivity(settingsIntent);
|
||||
|
||||
}
|
||||
});
|
||||
ndb.isCancelable(false);
|
||||
ndb.show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void showMockDialog(final Context activity) {
|
||||
try {
|
||||
closeGPSAlert();
|
||||
ndb = NiftyDialogBuilder.getInstance(activity);
|
||||
ndb.withTitle(activity.getString(R.string.mock_location))
|
||||
.withMessage(activity.getString(R.string.mock_location_alert))
|
||||
|
||||
.withButton1Text(activity.getString(R.string.dev_option))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ndb.dismiss();
|
||||
Intent settingsIntent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
|
||||
activity.startActivity(settingsIntent);
|
||||
|
||||
}
|
||||
});
|
||||
ndb.isCancelable(false);
|
||||
ndb.show();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeGPSAlert() {
|
||||
if (ndb != null)
|
||||
ndb.dismiss();
|
||||
}
|
||||
|
||||
public static boolean checkPlayServices(Activity activity) {
|
||||
int status = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity);
|
||||
if (status != ConnectionResult.SUCCESS) {
|
||||
if (GoogleApiAvailability.getInstance().isUserResolvableError(status)) {
|
||||
Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog(activity, status,
|
||||
REQUEST_CODE_RECOVER_PLAY_SERVICES);
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
} else {
|
||||
Toast.makeText(activity, activity.getString(R.string.device_not_supported),
|
||||
Toast.LENGTH_LONG).show();
|
||||
activity.finish();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void uninstallAPK(Context context) {
|
||||
String packageName = context.getPackageName();
|
||||
Uri packageURI = Uri.parse("package:" + packageName);
|
||||
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
|
||||
uninstallIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(uninstallIntent);
|
||||
}
|
||||
|
||||
public static void UninstallerHandler(final FragmentActivity activity) {
|
||||
String message = activity.getString(R.string.inactive_user, GlobalData.getSharedGlobalData().getUser().getFullname());
|
||||
final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(activity);
|
||||
dialogBuilder.withTitle(activity.getString(R.string.warning_capital))
|
||||
.withMessage(message)
|
||||
.withButton1Text("Uninstall")
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
dialogBuilder.dismiss();
|
||||
String packageName = activity.getPackageName();
|
||||
Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
|
||||
intent.setData(Uri.parse("package:" + packageName));
|
||||
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
|
||||
activity.startActivityForResult(intent, 1);
|
||||
activity.sendBroadcast(new Intent(activity.getString(R.string.action_user_logout)));
|
||||
}
|
||||
})
|
||||
.isCancelable(false)
|
||||
.isCancelableOnTouchOutside(false)
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void UninstallerHandler(final Activity activity) {
|
||||
String message = activity.getString(R.string.inactive_user, GlobalData.getSharedGlobalData().getUser().getFullname());
|
||||
final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(activity);
|
||||
dialogBuilder.withTitle(activity.getString(R.string.warning_capital))
|
||||
.withMessage(message)
|
||||
.withButton1Text("Uninstall")
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
dialogBuilder.dismiss();
|
||||
String packageName = activity.getPackageName();
|
||||
Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
|
||||
intent.setData(Uri.parse("package:" + packageName));
|
||||
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
|
||||
activity.startActivityForResult(intent, 1);
|
||||
activity.sendBroadcast(new Intent(activity.getString(R.string.action_user_logout)));
|
||||
}
|
||||
})
|
||||
.isCancelable(false)
|
||||
.isCancelableOnTouchOutside(false)
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showRootAlert(final Activity activity, final Context context) {
|
||||
try {
|
||||
ndb2 = NiftyDialogBuilder.getInstance(activity);
|
||||
ndb2.withTitle(activity.getResources().getString(R.string.device_rooted))
|
||||
.withMessage(activity.getResources().getString(R.string.device_rooted_uninstall))
|
||||
.withButton1Text(activity.getResources().getString(R.string.uninstall_apk))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ndb2.dismiss();
|
||||
uninstallAPK(context);
|
||||
}
|
||||
});
|
||||
ndb2.isCancelable(false);
|
||||
ndb2.show();
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isTimeAutomatic(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
return Settings.Global.getInt(context.getContentResolver(), Settings.Global.AUTO_TIME, 0) == 1;
|
||||
} else {
|
||||
return android.provider.Settings.System.getInt(context.getContentResolver(), android.provider.Settings.System.AUTO_TIME, 0) == 1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void showTimeProviderAlert(final Activity activity) {
|
||||
try {
|
||||
if (!isTimeAutomatic(activity)) {
|
||||
closeGPSAlert();
|
||||
ndb = NiftyDialogBuilder.getInstance(activity);
|
||||
ndb.withTitle(activity.getString(R.string.time_unable))
|
||||
.withMessage(activity.getString(R.string.time_warning))
|
||||
.withButton1Text(activity.getString(R.string.time_button))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ndb.dismiss();
|
||||
Intent settingsIntent = new Intent(Settings.ACTION_DATE_SETTINGS);
|
||||
activity.startActivity(settingsIntent);
|
||||
|
||||
}
|
||||
});
|
||||
ndb.isCancelable(false);
|
||||
ndb.show();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void showTurnOffDevMode(final Context context) {
|
||||
try {
|
||||
ndb = NiftyDialogBuilder.getInstance(context);
|
||||
ndb.withTitle(context.getString(R.string.title_developer_mode))
|
||||
.withMessage(context.getString(R.string.text_turn_off_dev_mode))
|
||||
.withButton1Text(context.getString(R.string.btnSetting))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ndb.dismiss();
|
||||
Intent setting = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
|
||||
context.startActivity(setting);
|
||||
}
|
||||
});
|
||||
ndb.isCancelable(false);
|
||||
ndb.isCancelableOnTouchOutside(false);
|
||||
ndb.show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void showAskForDownloadDialog(final Activity activity) {
|
||||
final NiftyDialogBuilder builder = NiftyDialogBuilder.getInstance(activity);
|
||||
builder.withTitle(activity.getString(R.string.get_services))
|
||||
.withMessage(activity.getString(R.string.get_services_message))
|
||||
.withButton1Text(activity.getString(R.string.get_services))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
builder.dismiss();
|
||||
Intent download = new Intent(Intent.ACTION_VIEW, Uri.parse(activity.getString(R.string.download_services)));
|
||||
activity.startActivity(download);
|
||||
}
|
||||
|
||||
}).show();
|
||||
}
|
||||
|
||||
public static void submitResult(final Activity activity, final SubmitResult submitResult) {
|
||||
String msgResult = submitResult.getResult();
|
||||
|
||||
final androidx.appcompat.app.AlertDialog dialog = new androidx.appcompat.app.AlertDialog.Builder(activity)
|
||||
.setView(R.layout.new_dialog_send_result)
|
||||
.create();
|
||||
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
|
||||
wmlp.windowAnimations = R.style.DialogAnimation2;
|
||||
dialog.show();
|
||||
|
||||
ImageView icon = (ImageView) dialog.findViewById(R.id.imgHeader);
|
||||
Button btnOK = (Button) dialog.findViewById(R.id.btnOK);
|
||||
Button btnPrint = (Button) dialog.findViewById(R.id.btnPrintPage);
|
||||
TextView txtResult = (TextView) dialog.findViewById(R.id.txtResult);
|
||||
TextView txtTime = (TextView) dialog.findViewById(R.id.txtTimeSent);
|
||||
TextView txtSize = (TextView) dialog.findViewById(R.id.txtDataSize);
|
||||
|
||||
Scheme scheme = SchemeDataAccess.getOne(activity, submitResult.getTaskH().getUuid_scheme());
|
||||
if (scheme != null) {
|
||||
String uuidUser = GlobalData.getSharedGlobalData().getUser().getUuid_user();
|
||||
boolean isTaskPaid = TaskDDataAccess.isTaskPaid(activity, uuidUser, submitResult.getTaskH().getUuid_task_h());
|
||||
boolean isRVinFront = GeneralParameterDataAccess.isRvInFrontEnable(activity, uuidUser);
|
||||
if (isRVinFront) {
|
||||
btnPrint.setVisibility(View.GONE);
|
||||
} else if (!scheme.getIs_printable().equals("1") || !isTaskPaid) {
|
||||
btnPrint.setVisibility(View.GONE);
|
||||
} else {
|
||||
btnPrint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
if (msgResult != null) {
|
||||
if (msgResult.equalsIgnoreCase("Success")) {
|
||||
String time = submitResult.getTaskH().getSubmit_duration();
|
||||
String size = submitResult.getTaskH().getSubmit_size();
|
||||
|
||||
String seconds = SecondFormatter.secondsToString(Long.parseLong(time));
|
||||
String mTime = activity.getString(com.adins.mss.base.R.string.time) + seconds;
|
||||
|
||||
String bytes = ByteFormatter.formatByteSize(Long.parseLong(size));
|
||||
String mSize = activity.getString(com.adins.mss.base.R.string.size) + bytes;
|
||||
|
||||
txtTime.setText(mTime);
|
||||
txtSize.setText(mSize);
|
||||
} else {
|
||||
icon.setImageDrawable(activity.getResources().getDrawable(R.drawable.ic_failed));
|
||||
txtResult.setText(submitResult.getTaskH().getMessage());
|
||||
txtTime.setVisibility(View.GONE);
|
||||
txtSize.setVisibility(View.GONE);
|
||||
btnPrint.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
icon.setImageDrawable(activity.getResources().getDrawable(R.drawable.ic_failed));
|
||||
txtResult.setText(activity.getString(R.string.message_sending_failed));
|
||||
txtTime.setVisibility(View.GONE);
|
||||
txtSize.setVisibility(View.GONE);
|
||||
btnPrint.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
btnOK.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dialog.dismiss();
|
||||
|
||||
Message msg = new Message();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(NewMainActivity.KEY_ACTION, NewMainActivity.ACTION_TIMELINE);
|
||||
msg.setData(bundle);
|
||||
|
||||
NewMainActivity.submitHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
|
||||
btnPrint.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final TaskH taskH = TaskHDataAccess.getOneTaskHeader(activity, submitResult.getTaskId());
|
||||
if (taskH.getRv_number() != null && !taskH.getRv_number().isEmpty()) {
|
||||
Toast.makeText(activity, R.string.cantPrint, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
SecondHelper.Companion.doPrint(activity, submitResult.getTaskId(), "log");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void showDetailContact(final Activity activity, final Contact contact) {
|
||||
final androidx.appcompat.app.AlertDialog dialog = new androidx.appcompat.app.AlertDialog.Builder(activity, R.style.Dialog_NoTitle)
|
||||
.setView(R.layout.dialog_contact_detail)
|
||||
.create();
|
||||
dialog.setCancelable(true);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
|
||||
wmlp.gravity = Gravity.BOTTOM;
|
||||
wmlp.windowAnimations = R.style.DialogAnimation;
|
||||
dialog.show();
|
||||
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
TextView contactName = (TextView) dialog.findViewById(R.id.txtName);
|
||||
TextView contactDept = (TextView) dialog.findViewById(R.id.txtDepartment);
|
||||
TextView contactPhone = (TextView) dialog.findViewById(R.id.txtPhone);
|
||||
TextView contactEmail = (TextView) dialog.findViewById(R.id.txtEmail);
|
||||
ImageButton btnCall = (ImageButton) dialog.findViewById(R.id.btnCall);
|
||||
|
||||
contactName.setText(contact.getContact_name());
|
||||
contactDept.setText(contact.getContact_dept());
|
||||
contactPhone.setText(contact.getContact_phone());
|
||||
contactEmail.setText(contact.getContact_email());
|
||||
|
||||
btnCall.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(Intent.ACTION_CALL);
|
||||
intent.setData(Uri.parse("tel:" + contact.getContact_phone()));
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
public static void showTaskRejected(Activity activity, String result){
|
||||
final androidx.appcompat.app.AlertDialog dialog = new androidx.appcompat.app.AlertDialog.Builder(activity)
|
||||
.setView(R.layout.dialog_reject_success)
|
||||
.create();
|
||||
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
|
||||
wmlp.windowAnimations = R.style.DialogAnimation2;
|
||||
dialog.show();
|
||||
|
||||
TextView textMessage = dialog.findViewById(R.id.txtResult);
|
||||
Button btnOK = (Button) dialog.findViewById(R.id.btnOK);
|
||||
|
||||
textMessage.setText(result);
|
||||
|
||||
btnOK.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/fragmentRoot">
|
||||
|
||||
</FrameLayout>
|
|
@ -0,0 +1,122 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#dfdfdf"
|
||||
android:padding="5dp">
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/tableRow1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/contract_number"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/divider_colon"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_no_kontrak"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="2"
|
||||
android:textColor="@android:color/black"
|
||||
android:text="@string/divider_dash"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/tableRow2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@android:color/black"
|
||||
android:text="@string/customer_name"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@android:color/black"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/divider_colon"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_customer_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@android:color/black"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="2"
|
||||
android:text="@string/divider_dash"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:visibility="gone"
|
||||
android:id="@+id/tableRow3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@android:color/black"
|
||||
android:text="@string/lkp_number"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView8"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:textColor="@android:color/black"
|
||||
android:text="@string/divider_colon"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_no_lkp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@android:color/black"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="5"
|
||||
android:text="@string/divider_dash"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,26 @@
|
|||
package com.adins.mss.base.receipt;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
|
||||
/**
|
||||
* Created by Loise on 12/04/2018.
|
||||
*/
|
||||
|
||||
/**
|
||||
* interface untuk menggambar pada canvas
|
||||
*/
|
||||
public interface IDrawItem {
|
||||
/**
|
||||
* Menggambar pada canvas
|
||||
* @param canvas objek canvas yang akan digambar
|
||||
* @param x lokasi menggambar pada sumbu x
|
||||
* @param y lokasi menggambar pada sumbu y
|
||||
*/
|
||||
void drawOnCanvas(Canvas canvas, float x, float y);
|
||||
|
||||
/**
|
||||
* mengembalikan tinggi objek
|
||||
* @return
|
||||
*/
|
||||
int getHeight();
|
||||
}
|
|
@ -0,0 +1,418 @@
|
|||
package com.adins.mss.coll.fragments;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.dynamicform.JsonRequestPdfReceiptHistory;
|
||||
import com.adins.mss.base.dynamicform.JsonResponsePdfReceiptHistory;
|
||||
import com.adins.mss.base.pdfrenderer.ViewPdfRendererFragment;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.coll.R;
|
||||
import com.adins.mss.coll.api.ReceiptHistoryApi;
|
||||
import com.adins.mss.coll.models.ReceiptHistoryResponse;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.ReceiptHistory;
|
||||
import com.adins.mss.dao.TaskH;
|
||||
import com.adins.mss.foundation.db.dataaccess.ReceiptHistoryDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.TaskHDataAccess;
|
||||
import com.adins.mss.foundation.dialog.NiftyDialogBuilder;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.http.HttpConnectionResult;
|
||||
import com.adins.mss.foundation.http.HttpCryptedConnection;
|
||||
import com.adins.mss.foundation.image.Base64;
|
||||
import com.google.firebase.perf.FirebasePerformance;
|
||||
import com.google.firebase.perf.metrics.HttpMetric;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class ReceiptHistoryFragment extends FragmentActivity {
|
||||
|
||||
public ReceiptHistoryResponse rHistoryResponse;
|
||||
private String taskId;
|
||||
private String agreementNo;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.fragment_receipt_history);
|
||||
|
||||
ACRA.getErrorReporter().putCustomData("LAST_CLASS_ACCESSED", getClass().getSimpleName());
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
taskId = bundle.getString(Global.BUND_KEY_TASK_ID);
|
||||
agreementNo = bundle.getString(Global.BUND_KEY_AGREEMENT_NO);
|
||||
|
||||
loadData();
|
||||
}
|
||||
|
||||
public void saveData(Context context, ReceiptHistoryResponse receiptHistoryResponse) {
|
||||
List<ReceiptHistory> receiptHistoryList = receiptHistoryResponse.getReceiptHistoryList();
|
||||
if (receiptHistoryList != null && receiptHistoryList.size() > 0) {
|
||||
TaskH taskH = TaskHDataAccess.getOneTaskHeader(context, taskId);
|
||||
ReceiptHistoryDataAccess.delete(context, taskH.getTask_id());
|
||||
for (ReceiptHistory receiptHistory : receiptHistoryList) {
|
||||
receiptHistory.setUuid_task_h(taskH.getTask_id());
|
||||
receiptHistory.setUuid_receipt_history(Tool.getUUID());
|
||||
receiptHistory.setAgreement_no(agreementNo);
|
||||
}
|
||||
ReceiptHistoryDataAccess.add(getApplicationContext(), receiptHistoryList);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadData() {
|
||||
new AsyncTask<Void, Void, ReceiptHistoryResponse>() {
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
progressDialog = ProgressDialog.show(ReceiptHistoryFragment.this,
|
||||
"", getString(R.string.progressWait), true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReceiptHistoryResponse doInBackground(Void... params) {
|
||||
ReceiptHistoryApi api = new ReceiptHistoryApi(ReceiptHistoryFragment.this);
|
||||
try {
|
||||
|
||||
//bong 21 mei 15 - check internet connection
|
||||
if (Tool.isInternetconnected(getApplicationContext())) {
|
||||
return api.request(agreementNo, taskId);
|
||||
}
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onPostExecute(ReceiptHistoryResponse receiptHistoryResponse) {
|
||||
super.onPostExecute(receiptHistoryResponse);
|
||||
if (progressDialog != null && progressDialog.isShowing()) {
|
||||
try {
|
||||
progressDialog.dismiss();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (receiptHistoryResponse == null) {
|
||||
TaskH taskH = TaskHDataAccess.getOneTaskHeader(getApplicationContext(), taskId);
|
||||
if (taskH != null) {
|
||||
List<ReceiptHistory> receiptHistoryList = ReceiptHistoryDataAccess.getAllByTask(getApplicationContext(), taskH.getUuid_task_h());
|
||||
if (receiptHistoryList != null) {
|
||||
TableLayout table = (TableLayout) findViewById(R.id.tableHeaders);
|
||||
int index = 1;
|
||||
|
||||
for (final ReceiptHistory item : receiptHistoryList) {
|
||||
View row = LayoutInflater.from(ReceiptHistoryFragment.this).inflate(R.layout.view_row_receipt_history, table, false);
|
||||
TextView contractNumber = (TextView) row.findViewById(R.id.contractNumber);
|
||||
TextView receiptNumber = (TextView) row.findViewById(R.id.receiptNumber);
|
||||
TextView paymentDate = (TextView) row.findViewById(R.id.paymentDate);
|
||||
TextView file = (TextView) row.findViewById(R.id.file);
|
||||
row.setTag(item);
|
||||
|
||||
contractNumber.setText(item.getAgreement_no());
|
||||
receiptNumber.setText(item.getReceipt_no());
|
||||
paymentDate.setText(item.getPayment_date() + "");
|
||||
file.setText("(download)");
|
||||
SpannableString spannableString = new SpannableString(file.getText());
|
||||
ClickableSpan clickableSpan = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
String receiptNo = item.getReceipt_no();
|
||||
if (receiptNo.contains("/")) {
|
||||
receiptNo = receiptNo.replace("/", "");
|
||||
}
|
||||
getDocumentPDF(getApplicationContext(), item.getAgreement_no(), receiptNo);
|
||||
}
|
||||
};
|
||||
spannableString.setSpan(clickableSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
file.setText(spannableString);
|
||||
file.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
file.setHighlightColor(Color.TRANSPARENT);
|
||||
if (index % 2 == 1) {
|
||||
row.setBackgroundResource(R.color.tv_gray_light);
|
||||
} else if (index % 2 == 0) {
|
||||
row.setBackgroundResource(R.color.tv_gray);
|
||||
}
|
||||
table.addView(row);
|
||||
}
|
||||
} else {
|
||||
NiftyDialogBuilder.getInstance(ReceiptHistoryFragment.this)
|
||||
.withMessage(getString(R.string.no_data_found_offline))
|
||||
.withTitle(getString(R.string.no_data_found_offline))
|
||||
.withIcon(android.R.drawable.ic_dialog_alert)
|
||||
.withButton1Text(getString(R.string.btnClose))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//finish();
|
||||
NiftyDialogBuilder.getInstance(ReceiptHistoryFragment.this).dismiss();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
}
|
||||
} else if (receiptHistoryResponse.getStatus().getCode() != 0) {
|
||||
NiftyDialogBuilder.getInstance(ReceiptHistoryFragment.this)
|
||||
.withMessage(receiptHistoryResponse.getStatus().getMessage())
|
||||
.withTitle(getString(R.string.server_error))
|
||||
.withButton1Text(getString(R.string.btnClose))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
return;
|
||||
} else if (!receiptHistoryResponse.getStatusCode().equalsIgnoreCase("00")) {
|
||||
NiftyDialogBuilder.getInstance(ReceiptHistoryFragment.this)
|
||||
.withMessage(receiptHistoryResponse.getMessage())
|
||||
.withTitle(getString(R.string.message))
|
||||
.withButton1Text(getString(R.string.btnClose))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
return;
|
||||
} else {
|
||||
rHistoryResponse = receiptHistoryResponse;
|
||||
saveData(getApplicationContext(), rHistoryResponse);
|
||||
|
||||
TableLayout table = (TableLayout) findViewById(R.id.tableHeaders);
|
||||
int index = 1;
|
||||
|
||||
for (final ReceiptHistory item : receiptHistoryResponse.getReceiptHistoryList()) {
|
||||
View row = LayoutInflater.from(ReceiptHistoryFragment.this).inflate(R.layout.view_row_receipt_history, table, false);
|
||||
TextView contractNumber = (TextView) row.findViewById(R.id.contractNumber);
|
||||
TextView receiptNumber = (TextView) row.findViewById(R.id.receiptNumber);
|
||||
TextView paymentDate = (TextView) row.findViewById(R.id.paymentDate);
|
||||
TextView file = (TextView) row.findViewById(R.id.file);
|
||||
row.setTag(item);
|
||||
|
||||
contractNumber.setText(rHistoryResponse.getAgreementNo());
|
||||
receiptNumber.setText(item.getReceipt_no());
|
||||
paymentDate.setText(item.getPayment_date() + "");
|
||||
file.setText("(download)");
|
||||
SpannableString spannableString = new SpannableString(file.getText());
|
||||
ClickableSpan clickableSpan = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
String receiptNo = item.getReceipt_no();
|
||||
if (receiptNo.contains("/")) {
|
||||
receiptNo = receiptNo.replace("/", "");
|
||||
}
|
||||
getDocumentPDF(getApplicationContext(), item.getAgreement_no(), receiptNo);
|
||||
}
|
||||
};
|
||||
spannableString.setSpan(clickableSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
file.setText(spannableString);
|
||||
file.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
file.setHighlightColor(Color.TRANSPARENT);
|
||||
if (index % 2 == 1) {
|
||||
row.setBackgroundResource(R.color.tv_gray_light);
|
||||
} else if (index % 2 == 0) {
|
||||
row.setBackgroundResource(R.color.tv_gray);
|
||||
}
|
||||
table.addView(row);
|
||||
}
|
||||
if (receiptHistoryResponse.getReceiptHistoryList().size() == 0) {
|
||||
NiftyDialogBuilder.getInstance(ReceiptHistoryFragment.this)
|
||||
.withMessage(R.string.no_data_from_server)
|
||||
.withTitle(getString(R.string.info_capital))
|
||||
.withButton1Text(getString(R.string.btnClose))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private void getDocumentPDF(final Context context, final String agreementNo, final String receiptNo) {
|
||||
new AsyncTask<Void, Void, JsonResponsePdfReceiptHistory>() {
|
||||
private ProgressDialog progressDialog;
|
||||
private String fileLocation;
|
||||
private String message;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
progressDialog = ProgressDialog.show(ReceiptHistoryFragment.this,
|
||||
"", getString(R.string.progressWait), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonResponsePdfReceiptHistory doInBackground(Void... arg0) {
|
||||
String fileName = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/bafmcspdf" + "/" + agreementNo + "_" + receiptNo + ".pdf";
|
||||
File fileOpen = new File(fileName);
|
||||
if (fileOpen.exists()) {
|
||||
fileLocation = fileName;
|
||||
JsonResponsePdfReceiptHistory responsePdfReceiptHistory = new JsonResponsePdfReceiptHistory();
|
||||
JsonResponsePdfReceiptHistory.Status status = new JsonResponsePdfReceiptHistory.Status();
|
||||
status.setCode(0);
|
||||
responsePdfReceiptHistory.setStatusCode("00");
|
||||
responsePdfReceiptHistory.setStatus(status);
|
||||
return responsePdfReceiptHistory;
|
||||
} else {
|
||||
try {
|
||||
if (Tool.isInternetconnected(context)) {
|
||||
JsonRequestPdfReceiptHistory requestPdfDocument = new JsonRequestPdfReceiptHistory();
|
||||
requestPdfDocument.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
requestPdfDocument.addImeiAndroidIdToUnstructured();
|
||||
requestPdfDocument.setAgreementNo(agreementNo);
|
||||
requestPdfDocument.setInvoiceNo(receiptNo);
|
||||
|
||||
String json = GsonHelper.toJson(requestPdfDocument);
|
||||
String url = GlobalData.getSharedGlobalData().getURL_GET_RECEIPT_HISTORY_PDF();
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(context, encrypt, decrypt);
|
||||
HttpConnectionResult serverResult = null;
|
||||
// Firebase Performance Trace Network Request
|
||||
HttpMetric networkMetric = FirebasePerformance.getInstance().newHttpMetric(
|
||||
url, FirebasePerformance.HttpMethod.POST);
|
||||
Utility.metricStart(networkMetric, json);
|
||||
|
||||
try {
|
||||
serverResult = httpConn.requestToServer(url, json, Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
Utility.metricStop(networkMetric, serverResult);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (null != serverResult) {
|
||||
if (serverResult.isOK()) {
|
||||
JsonResponsePdfReceiptHistory responsePdfReceiptHistory = GsonHelper.fromJson(serverResult.getResult(), JsonResponsePdfReceiptHistory.class);
|
||||
if (responsePdfReceiptHistory.getStatus().getCode() == 0) {
|
||||
if (responsePdfReceiptHistory.getStatusCode().equals("200") || responsePdfReceiptHistory.getStatusCode().equals("00")) {
|
||||
String pathFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/bafmcspdf";
|
||||
File filePath = new File(pathFolder);
|
||||
if (!filePath.exists()) {
|
||||
filePath.mkdirs();
|
||||
}
|
||||
|
||||
String uriString = filePath.getAbsolutePath() + "/" + agreementNo + "_" + receiptNo + ".pdf";
|
||||
fileLocation = uriString;
|
||||
|
||||
try {
|
||||
File file = new File(uriString);
|
||||
byte[] pdfBytes = Base64.decode(responsePdfReceiptHistory.getPdf());
|
||||
FileOutputStream os = new FileOutputStream(file);
|
||||
os.write(pdfBytes);
|
||||
os.flush();
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
message = "Error decoding pdf file!";
|
||||
}
|
||||
return responsePdfReceiptHistory;
|
||||
} else {
|
||||
message = responsePdfReceiptHistory.getMessage();
|
||||
}
|
||||
return responsePdfReceiptHistory;
|
||||
} else {
|
||||
message = responsePdfReceiptHistory.getStatus().getMessage();
|
||||
}
|
||||
} else {
|
||||
message = serverResult.getResult();
|
||||
}
|
||||
} else {
|
||||
message = "Failed to get result from Server";
|
||||
}
|
||||
} else {
|
||||
message = context.getString(com.adins.mss.base.R.string.no_internet_connection);
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
if (Global.IS_DEV) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.e("Info", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(JsonResponsePdfReceiptHistory result) {
|
||||
super.onPostExecute(result);
|
||||
if (progressDialog != null && progressDialog.isShowing()) {
|
||||
try {
|
||||
progressDialog.dismiss();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (result != null && (result.getStatusCode().equals("200") || result.getStatusCode().equals("00"))) {
|
||||
try {
|
||||
Intent intent = new Intent(context, ViewPdfRendererFragment.class);
|
||||
Bundle extras = new Bundle();
|
||||
extras.putString("FILE_LOC", fileLocation);
|
||||
intent.putExtras(extras);
|
||||
|
||||
startActivity(intent);
|
||||
} catch (Exception ex) {
|
||||
if (Global.IS_DEV) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else if (result != null && !(result.getStatusCode().equals("200") || result.getStatusCode().equals("00"))) {
|
||||
final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(context);
|
||||
dialogBuilder.withTitle(context.getString(com.adins.mss.base.R.string.info_capital))
|
||||
.isCancelableOnTouchOutside(false)
|
||||
.withMessage(result.getMessage())
|
||||
.withButton1Text(context.getString(com.adins.mss.base.R.string.btnOk))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialogBuilder.dismiss();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
} else if (!TextUtils.isEmpty(message)) {
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(context, context.getString(com.adins.mss.base.R.string.msgErrorParsingJson), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid
|
||||
android:color="@color/gradient_start" />
|
||||
<corners
|
||||
android:radius="10dp" />
|
||||
</shape>
|
|
@ -0,0 +1,140 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg_grayscale"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonSend"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="45dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="@drawable/button_background"
|
||||
android:text="@string/btnSend"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="@color/fontColorWhite" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="46dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/deposit_report"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@android:color/black" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/transferAsBank"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtTransferTo"
|
||||
style="@style/FieldLabel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_transfer_to_pc" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatSpinner
|
||||
android:id="@+id/spinnerBankAccount"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
android:background="@drawable/dropdown_background"
|
||||
android:padding="5dp"
|
||||
android:spinnerMode="dropdown" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/spinnerBankAccount"
|
||||
android:layout_alignEnd="@+id/spinnerBankAccount"
|
||||
android:layout_alignBottom="@+id/spinnerBankAccount"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:tint="@color/colorMC"
|
||||
app:srcCompat="@drawable/ic_expand" />
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtTransactionCode"
|
||||
style="@style/FieldLabel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/label_transactioncode" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editKodeTransaksi"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtBuktiTransfer"
|
||||
style="@style/FieldLabel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_transfer_evidence_pc" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageBukti"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="120dp"
|
||||
android:layout_gravity="center"
|
||||
android:background="#EEE" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonSelectPhoto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/button_background"
|
||||
android:text="@string/take_a_photo"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="@color/fontColorWhite" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/transferAsCashier"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtCashierName"
|
||||
style="@style/FieldLabel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_cashier_name_2" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editNamaKasir"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
|
@ -0,0 +1,268 @@
|
|||
package com.adins.mss.base.dynamicform.form.questions.viewholder;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.adins.mss.base.AppContext;
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.dynamicform.DynamicFormActivity;
|
||||
import com.adins.mss.base.dynamicform.JsonRequestLuOnlineView;
|
||||
import com.adins.mss.base.dynamicform.JsonResponseLuOnlineView;
|
||||
import com.adins.mss.base.dynamicform.form.models.PhotoDocumentBean;
|
||||
import com.adins.mss.base.dynamicform.form.questions.ImageViewerActivity;
|
||||
import com.adins.mss.base.dynamicform.form.view.DynamicQuestionView;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.TaskH;
|
||||
import com.adins.mss.foundation.db.dataaccess.TaskHDataAccess;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.http.AuditDataType;
|
||||
import com.adins.mss.foundation.http.HttpConnectionResult;
|
||||
import com.adins.mss.foundation.http.HttpCryptedConnection;
|
||||
import com.adins.mss.foundation.image.Base64;
|
||||
import com.adins.mss.foundation.image.Utils;
|
||||
import com.adins.mss.foundation.questiongenerator.QuestionBean;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LuOnlineQuestionViewHolder extends RecyclerView.ViewHolder {
|
||||
private final TextView mQuestionLabel;
|
||||
private final Button btnView;
|
||||
private final ImageView imgPhotos;
|
||||
private final Activity mActivity;
|
||||
private QuestionBean bean;
|
||||
|
||||
public LuOnlineQuestionViewHolder(View itemView, Activity activity) {
|
||||
super(itemView);
|
||||
mQuestionLabel = (TextView) itemView.findViewById(R.id.questionTextLabel);
|
||||
btnView = (Button) itemView.findViewById(R.id.btnView);
|
||||
imgPhotos = (ImageView) itemView.findViewById(R.id.imgPhotoLuOnlineAnswer);
|
||||
mActivity = activity;
|
||||
}
|
||||
|
||||
public void bind(final QuestionBean item, int number) {
|
||||
bean = item;
|
||||
String qLabel = number + ". " + bean.getQuestion_label();
|
||||
mQuestionLabel.setText(qLabel);
|
||||
|
||||
String taskId = DynamicQuestionView.header.getTask_id();
|
||||
TaskH taskH = TaskHDataAccess.getOneTaskHeader(mActivity, taskId);
|
||||
final String agreementNo = taskH.getAppl_no();
|
||||
|
||||
// Keep Data for not happen moving to Other Question because do Scrolling
|
||||
final LinearLayout layoutListDocument = (LinearLayout) itemView.findViewById(R.id.layoutListDocument);
|
||||
if (bean.getListImgByteArray() != null) {
|
||||
// To avoid trigger many times add photos on 'layoutListDocument'
|
||||
layoutListDocument.removeAllViews();
|
||||
|
||||
// Show all list document have been saved on QuestionBean
|
||||
if (bean.getListImgByteArray().size() > 0) {
|
||||
ArrayList<byte[]> beanListLuDocKeep = bean.getListImgByteArray();
|
||||
for (int index = 0; index < beanListLuDocKeep.size(); index++) {
|
||||
ImageView imgView = new ImageView(mActivity);
|
||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(200, 200);
|
||||
|
||||
final byte[] imageByteArray = beanListLuDocKeep.get(index);
|
||||
final Bitmap bitmap = BitmapFactory.decodeByteArray(imageByteArray, 0, imageByteArray.length);
|
||||
|
||||
layoutParams.setMargins(2, 8, 2, 8);
|
||||
layoutParams.gravity = Gravity.CENTER;
|
||||
imgView.setLayoutParams(layoutParams);
|
||||
imgView.setImageBitmap(bitmap);
|
||||
layoutListDocument.addView(imgView);
|
||||
|
||||
imgView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Global.isViewer = !DynamicFormActivity.allowImageEdit;
|
||||
Bundle extras = new Bundle();
|
||||
extras.putByteArray(ImageViewerActivity.BUND_KEY_IMAGE, imageByteArray);
|
||||
extras.putInt(ImageViewerActivity.BUND_KEY_IMAGE_QUALITY, Utils.picQuality);
|
||||
extras.putBoolean(ImageViewerActivity.BUND_KEY_IMAGE_ISVIEWER, Global.isViewer);
|
||||
Intent intent = new Intent(mActivity, ImageViewerActivity.class);
|
||||
intent.putExtras(extras);
|
||||
mActivity.startActivityForResult(intent, Global.REQUEST_EDIT_IMAGE);
|
||||
}
|
||||
});
|
||||
}
|
||||
layoutListDocument.setVisibility(View.VISIBLE);
|
||||
btnView.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
layoutListDocument.setVisibility(View.GONE);
|
||||
btnView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
btnView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
GetViewLuOnline getViewLuOnline = new GetViewLuOnline(mActivity, bean, layoutListDocument, btnView, agreementNo, bean.getIdentifier_name());
|
||||
getViewLuOnline.execute();
|
||||
}
|
||||
});
|
||||
|
||||
imgPhotos.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Global.isViewer = true;
|
||||
Bundle extras = new Bundle();
|
||||
extras.putByteArray(ImageViewerActivity.BUND_KEY_IMAGE, bean.getImgAnswer());
|
||||
extras.putInt(ImageViewerActivity.BUND_KEY_IMAGE_QUALITY, Utils.picQuality);
|
||||
extras.putBoolean(ImageViewerActivity.BUND_KEY_IMAGE_ISVIEWER, Global.isViewer);
|
||||
Intent intent = new Intent(mActivity, ImageViewerActivity.class);
|
||||
intent.putExtras(extras);
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static class GetViewLuOnline extends AsyncTask<Void, Void, JsonResponseLuOnlineView> {
|
||||
private ProgressDialog progressDialog;
|
||||
private final Activity activity;
|
||||
private final QuestionBean bean;
|
||||
private final LinearLayout mLayout;
|
||||
private final Button btnView;
|
||||
private final String agrNo;
|
||||
private final String refId;
|
||||
private String errorMessage = "";
|
||||
|
||||
public GetViewLuOnline(Activity activity, QuestionBean bean, LinearLayout mLayout, Button btnView, String argNo, String refId) {
|
||||
this.activity = activity;
|
||||
this.bean = bean;
|
||||
this.mLayout = mLayout;
|
||||
this.btnView = btnView;
|
||||
this.agrNo = argNo;
|
||||
this.refId = refId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
progressDialog = ProgressDialog.show(activity, "", activity.getString(R.string.please_wait_rv_mobile), true);
|
||||
progressDialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonResponseLuOnlineView doInBackground(Void... voids) {
|
||||
if (Tool.isInternetconnected(activity)) {
|
||||
JsonRequestLuOnlineView request = new JsonRequestLuOnlineView();
|
||||
AuditDataType auditData = GlobalData.getSharedGlobalData().getAuditData();
|
||||
request.setAudit(auditData);
|
||||
request.addImeiAndroidIdToUnstructured();
|
||||
request.setAgrNo(agrNo);
|
||||
request.setRefId(refId);
|
||||
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(activity, encrypt, decrypt);
|
||||
String url = GlobalData.getSharedGlobalData().getURL_GET_LU_ONLINE();
|
||||
HttpConnectionResult serverResult;
|
||||
|
||||
try {
|
||||
String json = GsonHelper.toJson(request);
|
||||
serverResult = httpConn.requestToServer(url, json, Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
if (serverResult != null) {
|
||||
try {
|
||||
String result = serverResult.getResult();
|
||||
return GsonHelper.fromJson(result, JsonResponseLuOnlineView.class);
|
||||
} catch (Exception e) {
|
||||
errorMessage = activity.getString(R.string.failed_view_lu_online);
|
||||
ACRA.getErrorReporter().putCustomData("errorGetMessageFromServer", e.getMessage());
|
||||
ACRA.getErrorReporter().putCustomData("errorGetMessageFromServer", Tool.getSystemDateTime().toLocaleString());
|
||||
ACRA.getErrorReporter().handleSilentException(new Exception("Exception saat convert json dari server"));
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
errorMessage = activity.getString(R.string.failed_view_lu_online);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errorMessage = activity.getString(R.string.failed_view_lu_online);
|
||||
ACRA.getErrorReporter().putCustomData("errorRequestToServer", e.getMessage());
|
||||
ACRA.getErrorReporter().putCustomData("errorRequestToServer", Tool.getSystemDateTime().toLocaleString());
|
||||
ACRA.getErrorReporter().handleSilentException(new Exception("Exception saat request ke server"));
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
errorMessage = AppContext.getAppContext().getString(R.string.no_internet_connection);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(JsonResponseLuOnlineView result) {
|
||||
super.onPostExecute(result);
|
||||
|
||||
if (progressDialog != null && progressDialog.isShowing()) {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
|
||||
if (errorMessage.equals("")) {
|
||||
if (result != null) {
|
||||
if (result.getStatus().getCode() == 200) {
|
||||
List<PhotoDocumentBean> listLuDoc = result.getData();
|
||||
ArrayList<byte[]> beanListLuDoc = new ArrayList<>();
|
||||
mLayout.removeAllViews();
|
||||
for (int index = 0; index < listLuDoc.size(); index++) {
|
||||
ImageView imgView = new ImageView(activity);
|
||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(200, 200);
|
||||
|
||||
final byte[] imageByteArray = Base64.decode(result.getData().get(index).getContent());
|
||||
final Bitmap bitmap = BitmapFactory.decodeByteArray(imageByteArray, 0, imageByteArray.length);
|
||||
|
||||
layoutParams.setMargins(2, 8, 2, 8);
|
||||
layoutParams.gravity = Gravity.CENTER;
|
||||
imgView.setLayoutParams(layoutParams);
|
||||
imgView.setImageBitmap(bitmap);
|
||||
mLayout.addView(imgView);
|
||||
beanListLuDoc.add(imageByteArray);
|
||||
|
||||
imgView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Global.isViewer = true;
|
||||
Bundle extras = new Bundle();
|
||||
extras.putByteArray(ImageViewerActivity.BUND_KEY_IMAGE, imageByteArray);
|
||||
extras.putInt(ImageViewerActivity.BUND_KEY_IMAGE_QUALITY, Utils.picQuality);
|
||||
extras.putBoolean(ImageViewerActivity.BUND_KEY_IMAGE_ISVIEWER, Global.isViewer);
|
||||
Intent intent = new Intent(activity, ImageViewerActivity.class);
|
||||
intent.putExtras(extras);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
bean.setListImgByteArray(beanListLuDoc);
|
||||
mLayout.setVisibility(View.VISIBLE);
|
||||
btnView.setVisibility(View.GONE);
|
||||
} else {
|
||||
Toast.makeText(activity, result.getStatus().getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(activity, errorMessage, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(activity, errorMessage, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue