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,687 @@
|
|||
package com.adins.mss.coll.fragments;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.depositreport.DepositReportBatchIdBean;
|
||||
import com.adins.mss.base.depositreport.DepositReportBatchIdRequest;
|
||||
import com.adins.mss.base.depositreport.DepositReportBatchIdResponse;
|
||||
import com.adins.mss.base.depositreport.DetailTaskHRequest;
|
||||
import com.adins.mss.base.depositreport.DetailTaskHResponse;
|
||||
import com.adins.mss.base.depositreport.TaskLogHelper;
|
||||
import com.adins.mss.base.tasklog.TaskLog;
|
||||
import com.adins.mss.base.todolist.ToDoList;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.coll.NewMCMainActivity;
|
||||
import com.adins.mss.coll.R;
|
||||
import com.adins.mss.coll.api.DepositReportReconcileApi;
|
||||
import com.adins.mss.coll.models.DepositReportAdapter;
|
||||
import com.adins.mss.coll.models.DepositReportReconcileResponse;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.DepositReportH;
|
||||
import com.adins.mss.dao.PrintItem;
|
||||
import com.adins.mss.dao.TaskD;
|
||||
import com.adins.mss.dao.TaskH;
|
||||
import com.adins.mss.foundation.db.dataaccess.DepositReportHDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.PrintItemDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.TaskDDataAccess;
|
||||
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.security.storepreferences.ObscuredSharedPreferences;
|
||||
import com.google.firebase.perf.FirebasePerformance;
|
||||
import com.google.firebase.perf.metrics.HttpMetric;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static com.adins.mss.base.todolist.form.PriorityTabFragment.toDoList;
|
||||
|
||||
/**
|
||||
* Created by Aditya Purwa on 2/3/2015.
|
||||
*/
|
||||
public class DepositReportPCFragment extends Fragment {
|
||||
private static Menu mainMenu;
|
||||
DepositReportAdapter adapter;
|
||||
public List<TaskH> listTaskRecap;
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
mainMenu = menu;
|
||||
// inflater.inflate(R.menu.menu_deposit_report_fragment, menu);
|
||||
try {
|
||||
menu.findItem(R.id.menuMore).setVisible(true);
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context activity) {
|
||||
setHasOptionsMenu(true);
|
||||
super.onAttach(activity);
|
||||
ACRA.getErrorReporter().putCustomData("LAST_CLASS_ACCESSED", getClass().getSimpleName());
|
||||
insertPrintItemForDeposit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
Utility.freeMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_deposit_report, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
getActivity().findViewById(com.adins.mss.base.R.id.search).setVisibility(View.GONE);
|
||||
getActivity().findViewById(com.adins.mss.base.R.id.spinner).setVisibility(View.GONE);
|
||||
getActivity().setTitle(getString(R.string.title_mn_depositreportPC));
|
||||
|
||||
Button recapitulateButton = (Button) view.findViewById(R.id.recapitulateButton);
|
||||
recapitulateButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
recapitulate();
|
||||
}
|
||||
});
|
||||
|
||||
final List<DepositReportH> reports = DepositReportHDataAccess.getAllForAllUserPC(getActivity());
|
||||
ListView list = (ListView) getView().findViewById(R.id.recapitulationList);
|
||||
adapter = new DepositReportAdapter(getActivity(), reports);
|
||||
list.setAdapter(adapter);
|
||||
|
||||
list.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
|
||||
// TODO Auto-generated method stub
|
||||
DepositReportPCDetailActivity.report = reports.get(position);
|
||||
Intent intent = new Intent(getActivity(), DepositReportPCDetailActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
if(id== R.id.menuMore){
|
||||
mainMenu.findItem(R.id.recapitulation).setVisible(true);
|
||||
mainMenu.findItem(R.id.summary).setVisible(true);
|
||||
mainMenu.findItem(R.id.mnViewMap).setVisible(false);
|
||||
}
|
||||
if (item.getItemId() == R.id.recapitulation) {
|
||||
recapitulate();
|
||||
}
|
||||
if (item.getItemId() == R.id.summary) {
|
||||
summarize();
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void summarize() {
|
||||
DepositReportSummaryFragment fragment = new DepositReportSummaryFragment();
|
||||
FragmentTransaction transaction = NewMCMainActivity.fragmentManager.beginTransaction();
|
||||
transaction.setCustomAnimations(R.anim.activity_open_translate, R.anim.activity_close_scale, R.anim.activity_open_scale, R.anim.activity_close_translate);
|
||||
transaction.replace(R.id.content_frame, fragment);
|
||||
transaction.addToBackStack(null);
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
private void recapitulate() {
|
||||
if(Tool.isInternetconnected(getActivity())) {
|
||||
initialize();
|
||||
// DepositReportRecapitulateFragment fragment = new DepositReportRecapitulateFragment();
|
||||
// FragmentTransaction transaction = MainMenuActivity.fragmentManager.beginTransaction();
|
||||
// transaction.setCustomAnimations(R.anim.activity_open_translate, R.anim.activity_close_scale, R.anim.activity_open_scale, R.anim.activity_close_translate);
|
||||
// transaction.replace(R.id.content_frame, fragment);
|
||||
// transaction.addToBackStack(null);
|
||||
// transaction.commit();
|
||||
} else {
|
||||
Toast.makeText(getActivity(), getActivity().getString(R.string.jsonParseFailed), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
loadData();
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
new AsyncTask<Void, Void, DepositReportReconcileResponse>() {
|
||||
private ProgressDialog progressDialog;
|
||||
boolean isError = false;
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
progressDialog = ProgressDialog.show(getActivity(),
|
||||
"", getString(R.string.progressWait), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DepositReportReconcileResponse doInBackground(Void... params) {
|
||||
if(Tool.isInternetconnected(getActivity())) {
|
||||
TaskLog log = new TaskLog(getActivity());
|
||||
List<TaskH> result = log.getListTaskLog();
|
||||
|
||||
List<TaskH> onlineLog = TaskLogHelper.getTaskLog(getActivity());
|
||||
if (onlineLog != null) {
|
||||
if (result == null) result = new ArrayList<>();
|
||||
List<String> uuidListTaskH = new ArrayList<>();
|
||||
|
||||
for (TaskH taskH : result) {
|
||||
uuidListTaskH.add(taskH.getUuid_task_h());
|
||||
}
|
||||
|
||||
Iterator<TaskH> iterator = onlineLog.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
TaskH taskH = iterator.next();
|
||||
|
||||
if (uuidListTaskH.contains(taskH.getUuid_task_h())) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (onlineLog.size() > 0) {
|
||||
for (TaskH taskH : onlineLog) {
|
||||
taskH.setUuid_user(GlobalData.getSharedGlobalData().getUser().getUuid_user());
|
||||
taskH.setStatus(TaskHDataAccess.STATUS_SEND_SENT);
|
||||
TaskHDataAccess.addOrReplace(getActivity(), taskH);
|
||||
result.add(taskH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null && result.size() > 0) {
|
||||
for (TaskH taskH : result) {
|
||||
List<TaskD> taskDs = TaskDDataAccess.getAll(getActivity(), taskH.getUuid_task_h(),
|
||||
TaskDDataAccess.ALL_TASK);
|
||||
if (taskDs == null || taskDs.size() == 0) {
|
||||
DetailTaskHResponse response = null;
|
||||
|
||||
DetailTaskHRequest request = new DetailTaskHRequest();
|
||||
request.setUuidTaskH(taskH.getUuid_task_h());
|
||||
request.setFlag(taskH.getFlag());
|
||||
request.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(getActivity(),
|
||||
GlobalData.getSharedGlobalData().isEncrypt(), GlobalData.getSharedGlobalData().isDecrypt());
|
||||
String url = GlobalData.getSharedGlobalData().getURL_GET_TASK_LOG();
|
||||
HttpConnectionResult serverResult;
|
||||
// Firebase Performance Trace Network Request
|
||||
HttpMetric networkMetric = FirebasePerformance.getInstance().newHttpMetric(
|
||||
url, FirebasePerformance.HttpMethod.POST);
|
||||
Utility.metricStart(networkMetric, GsonHelper.toJson(request));
|
||||
|
||||
try {
|
||||
serverResult = httpConn.requestToServer(url, GsonHelper.toJson(request),
|
||||
Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
Utility.metricStop(networkMetric, serverResult);
|
||||
|
||||
if (serverResult != null && serverResult.isOK()) {
|
||||
try {
|
||||
response = GsonHelper.fromJson(serverResult.getResult(),
|
||||
DetailTaskHResponse.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
isError = true;
|
||||
}
|
||||
} else {
|
||||
isError = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
isError = true;
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (response != null && response.getTaskDs() != null) {
|
||||
TaskDDataAccess.addOrReplace(getActivity(), response.getTaskDs());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final List<TaskD> reports = TaskDDataAccess.getTaskDTagTotal(getActivity(), GlobalData.getSharedGlobalData().getUser().getUuid_user());
|
||||
|
||||
List<String> taskId = new ArrayList<String>();
|
||||
List<String> flag = new ArrayList<String>();
|
||||
TaskH taskH;
|
||||
for (TaskD taskD : reports) {
|
||||
taskH = TaskHDataAccess.getOneHeader(getActivity(), taskD.getUuid_task_h());
|
||||
//if(taskH.getIs_reconciled() == null) {
|
||||
taskH.setIs_reconciled("0");
|
||||
TaskHDataAccess.addOrReplace(getActivity(), taskH);
|
||||
//}
|
||||
taskId.add(taskH.getTask_id());
|
||||
flag.add(taskH.getFlag());
|
||||
}
|
||||
DepositReportReconcileApi api = new DepositReportReconcileApi(getActivity());
|
||||
|
||||
try {
|
||||
return api.request(taskId, flag);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}else{
|
||||
isError = true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(DepositReportReconcileResponse depositReportReconcileResponse) {
|
||||
super.onPostExecute(depositReportReconcileResponse);
|
||||
if (progressDialog != null && progressDialog.isShowing()) {
|
||||
try {
|
||||
progressDialog.dismiss();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (isError) {
|
||||
Toast.makeText(getActivity(), getActivity().getString(R.string.jsonParseFailed), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
if (depositReportReconcileResponse == null) {
|
||||
final List<DepositReportH> reports = DepositReportHDataAccess.getAllForAllUserPC(getActivity());
|
||||
ListView list = (ListView) getView().findViewById(R.id.recapitulationList);
|
||||
adapter = new DepositReportAdapter(getActivity(), reports);
|
||||
list.setAdapter(adapter);
|
||||
|
||||
list.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
|
||||
// TODO Auto-generated method stub
|
||||
DepositReportPCDetailActivity.report = reports.get(position);
|
||||
Intent intent = new Intent(getActivity(), DepositReportPCDetailActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
} else if (depositReportReconcileResponse.getStatus().getCode() != 0) {
|
||||
NiftyDialogBuilder.getInstance(getActivity())
|
||||
.withMessage(depositReportReconcileResponse.getStatus().getMessage())
|
||||
.withTitle(getString(R.string.server_error))
|
||||
.withButton1Text(getString(R.string.btnClose))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getActivity().finish();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
return;
|
||||
} else {
|
||||
List<String> taskId = depositReportReconcileResponse.getTaskId();
|
||||
if(taskId!=null){
|
||||
for (String task : taskId) {
|
||||
TaskH taskH = TaskHDataAccess.getOneTaskHeader(getActivity(), task);
|
||||
taskH.setIs_reconciled("1");
|
||||
TaskHDataAccess.addOrReplace(getActivity(), taskH);
|
||||
}
|
||||
}
|
||||
|
||||
final List<DepositReportH> reports = DepositReportHDataAccess.getAllForAllUserPC(getActivity());
|
||||
ListView list = (ListView) getView().findViewById(R.id.recapitulationList);
|
||||
adapter = new DepositReportAdapter(getActivity(), reports);
|
||||
list.setAdapter(adapter);
|
||||
|
||||
list.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
|
||||
// TODO Auto-generated method stub
|
||||
DepositReportDetailActivity.report = reports.get(position);
|
||||
Intent intent = new Intent(getActivity(), DepositReportDetailActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
toDoList = new ToDoList(getActivity());
|
||||
listTaskRecap = toDoList.getListTaskInStatusForMultiUser(ToDoList.SEARCH_BY_ALL_SENT, "BATCHID");
|
||||
|
||||
if(listTaskRecap != null && listTaskRecap.size() >0 ){
|
||||
BatchIdTask task = new BatchIdTask();
|
||||
task.execute();
|
||||
} else {
|
||||
DepositReportPCRecapitulateFragment fragment = new DepositReportPCRecapitulateFragment();
|
||||
FragmentTransaction transaction = NewMCMainActivity.fragmentManager.beginTransaction();
|
||||
transaction.setCustomAnimations(R.anim.activity_open_translate, R.anim.activity_close_scale, R.anim.activity_open_scale, R.anim.activity_close_translate);
|
||||
transaction.replace(R.id.content_frame, fragment);
|
||||
transaction.addToBackStack(null);
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
|
||||
}
|
||||
|
||||
private class BatchIdTask extends AsyncTask<Void, Void, List<DepositReportBatchIdBean>> {
|
||||
private ProgressDialog progressDialog;
|
||||
private String errMessage, message;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
progressDialog = ProgressDialog.show(getContext(), "", getString(com.adins.mss.base.R.string.progressWait));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DepositReportBatchIdBean> doInBackground(Void... Void) {
|
||||
if (Tool.isInternetconnected(getActivity())) {
|
||||
List<String> listUuidRequest = new ArrayList<>();
|
||||
for(TaskH taskHRequest : listTaskRecap){
|
||||
listUuidRequest.add(taskHRequest.getTask_id());
|
||||
}
|
||||
|
||||
DepositReportBatchIdRequest request = new DepositReportBatchIdRequest();
|
||||
request.setListTaskID(listUuidRequest);
|
||||
request.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
|
||||
String json = GsonHelper.toJson(request);
|
||||
String url = GlobalData.getSharedGlobalData().getURL_GET_BATCHID_LIST();
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(getActivity(), 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 (serverResult != null && serverResult.isOK()) {
|
||||
try {
|
||||
String responseBody = serverResult.getResult();
|
||||
DepositReportBatchIdResponse response = GsonHelper.fromJson(responseBody, DepositReportBatchIdResponse.class);
|
||||
|
||||
if (response.getStatus().getCode() != 0) {
|
||||
message = response.getStatus().getMessage();
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
return response.getListBatchID();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (Global.IS_DEV) {
|
||||
e.printStackTrace();
|
||||
errMessage = e.getMessage();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errMessage = getString(com.adins.mss.base.R.string.server_down);
|
||||
}
|
||||
|
||||
} else {
|
||||
errMessage = getString(com.adins.mss.base.R.string.no_internet_connection);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<DepositReportBatchIdBean> batchTask) {
|
||||
super.onPostExecute(batchTask);
|
||||
progressDialog.dismiss();
|
||||
|
||||
if (batchTask != null && batchTask.size() > 0) {
|
||||
for(DepositReportBatchIdBean taskBean : batchTask){
|
||||
if("1".equalsIgnoreCase(taskBean.getFlagDeposit()) &&
|
||||
(taskBean.getBatchId() !=null && !taskBean.getBatchId().isEmpty())){
|
||||
TaskH taskH = TaskHDataAccess.getOneTaskHeader(getActivity(),taskBean.getTaskId());
|
||||
taskH.setBatch_id(taskBean.getBatchId());
|
||||
TaskHDataAccess.addOrReplace(getActivity(), taskH);
|
||||
}else if("0".equalsIgnoreCase(taskBean.getFlagDeposit())&&
|
||||
(taskBean.getBatchId() !=null && !taskBean.getBatchId().isEmpty())){
|
||||
TaskH taskH = TaskHDataAccess.getOneTaskHeader(getActivity(),taskBean.getTaskId());
|
||||
if("0".equalsIgnoreCase(taskH.getIs_reconciled())){
|
||||
taskH.setIs_reconciled("1");
|
||||
TaskHDataAccess.addOrReplace(getActivity(), taskH);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(message != null) {
|
||||
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
|
||||
} else if (errMessage != null) {
|
||||
Toast.makeText(getContext(), errMessage, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
DepositReportPCRecapitulateFragment fragment = new DepositReportPCRecapitulateFragment();
|
||||
FragmentTransaction transaction = NewMCMainActivity.fragmentManager.beginTransaction();
|
||||
transaction.setCustomAnimations(R.anim.activity_open_translate, R.anim.activity_close_scale, R.anim.activity_open_scale, R.anim.activity_close_translate);
|
||||
transaction.replace(R.id.content_frame, fragment);
|
||||
transaction.addToBackStack(null);
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(){
|
||||
super.onResume();
|
||||
try {
|
||||
if (adapter != null) {
|
||||
// loadData();
|
||||
}
|
||||
}catch (Exception e){
|
||||
if(Global.IS_DEV)
|
||||
e.printStackTrace();
|
||||
}
|
||||
getActivity().findViewById(com.adins.mss.base.R.id.search).setVisibility(View.GONE);
|
||||
getActivity().findViewById(com.adins.mss.base.R.id.spinner).setVisibility(View.GONE);
|
||||
getActivity().setTitle(getString(R.string.title_mn_depositreportPC));
|
||||
}
|
||||
|
||||
|
||||
public void insertPrintItemForDeposit(){
|
||||
ObscuredSharedPreferences sharedPref = ObscuredSharedPreferences.getPrefs(getActivity(),
|
||||
"wasInsertedDepositPrint", Context.MODE_PRIVATE);
|
||||
String isInsert = sharedPref.getString("isInsertDepositPrint", Global.FALSE_STRING);
|
||||
if(isInsert.equals(Global.FALSE_STRING)){
|
||||
ObscuredSharedPreferences.Editor sharedPrefEditor = sharedPref.edit();
|
||||
sharedPrefEditor.putString("isInsertDepositPrint", Global.TRUE_STRING);
|
||||
sharedPrefEditor.commit();
|
||||
|
||||
// PrintItemDataAccess.delete(getActivity(), "DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
|
||||
String usr_crt = GlobalData.getSharedGlobalData().getUser().getUuid_user();
|
||||
Date date = Tool.getSystemDateTime();
|
||||
|
||||
PrintItem itemLogo = new PrintItem(Tool.getUUID());
|
||||
itemLogo.setPrint_type_id(Global.PRINT_LOGO);
|
||||
itemLogo.setPrint_item_label("LOGO");
|
||||
itemLogo.setPrint_item_order(1);
|
||||
itemLogo.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemLogo);
|
||||
|
||||
PrintItem itemBranchName = new PrintItem(Tool.getUUID());
|
||||
itemBranchName.setPrint_type_id(Global.PRINT_BRANCH_NAME);
|
||||
itemBranchName.setPrint_item_label("Branch Name");
|
||||
itemBranchName.setPrint_item_order(2);
|
||||
itemBranchName.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemBranchName);
|
||||
|
||||
PrintItem itemBranchAddr = new PrintItem(Tool.getUUID());
|
||||
itemBranchAddr.setPrint_type_id(Global.PRINT_BRANCH_ADDRESS);
|
||||
itemBranchAddr.setPrint_item_label("Branch Address");
|
||||
itemBranchAddr.setPrint_item_order(2);
|
||||
itemBranchAddr.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemBranchAddr);
|
||||
|
||||
PrintItem itemNewLineE= new PrintItem(Tool.getUUID());
|
||||
itemNewLineE.setPrint_type_id(Global.PRINT_NEW_LINE);
|
||||
itemNewLineE.setPrint_item_label("999New Line");
|
||||
itemNewLineE.setPrint_item_order(3);
|
||||
itemNewLineE.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemNewLineE);
|
||||
|
||||
/*PrintItem itemNewLine1= new PrintItem(Tool.getUUID());
|
||||
itemNewLine1.setPrint_type_id(Global.PRINT_NEW_LINE);
|
||||
itemNewLine1.setPrint_item_label("998New Line");
|
||||
itemNewLine1.setPrint_item_order(4);
|
||||
itemNewLine1.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemNewLine1);*/
|
||||
|
||||
PrintItem itemTitle = new PrintItem(Tool.getUUID());
|
||||
itemTitle.setPrint_type_id(Global.PRINT_LABEL_CENTER_BOLD);
|
||||
itemTitle.setPrint_item_label("Bukti Deposit Report");
|
||||
itemTitle.setPrint_item_order(10);
|
||||
itemTitle.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemTitle);
|
||||
|
||||
/*PrintItem itemNewLine2= new PrintItem(Tool.getUUID());
|
||||
itemNewLine2.setPrint_type_id(Global.PRINT_NEW_LINE);
|
||||
itemNewLine2.setPrint_item_label("998New Line");
|
||||
itemNewLine2.setPrint_item_order(4);
|
||||
itemNewLine2.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemNewLine2);*/
|
||||
|
||||
PrintItem itemBatchId = new PrintItem(Tool.getUUID());
|
||||
itemBatchId.setPrint_type_id(Global.PRINT_ANSWER);
|
||||
itemBatchId.setPrint_item_label("Batch ID");
|
||||
itemBatchId.setPrint_item_order(11);
|
||||
itemBatchId.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemBatchId);
|
||||
|
||||
PrintItem itemCollName = new PrintItem(Tool.getUUID());
|
||||
itemCollName.setPrint_type_id(Global.PRINT_USER_NAME);
|
||||
itemCollName.setPrint_item_label("Coll Name");
|
||||
itemCollName.setPrint_item_order(12);
|
||||
itemCollName.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemCollName);
|
||||
|
||||
PrintItem itemTransferBy = new PrintItem(Tool.getUUID());
|
||||
itemTransferBy.setPrint_type_id(Global.PRINT_ANSWER);
|
||||
itemTransferBy.setPrint_item_label("Transfer By");
|
||||
itemTransferBy.setPrint_item_order(20);
|
||||
itemTransferBy.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemTransferBy);
|
||||
|
||||
PrintItem itemCashierName = new PrintItem(Tool.getUUID());
|
||||
itemCashierName.setPrint_type_id(Global.PRINT_ANSWER);
|
||||
itemCashierName.setPrint_item_label("Cashier Name");
|
||||
itemCashierName.setPrint_item_order(30);
|
||||
itemCashierName.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemCashierName);
|
||||
|
||||
PrintItem itemAccountNo = new PrintItem(Tool.getUUID());
|
||||
itemAccountNo.setPrint_type_id(Global.PRINT_ANSWER);
|
||||
itemAccountNo.setPrint_item_label("Account No");
|
||||
itemAccountNo.setPrint_item_order(30);
|
||||
itemAccountNo.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemAccountNo);
|
||||
|
||||
PrintItem itemBankName = new PrintItem(Tool.getUUID());
|
||||
itemBankName.setPrint_type_id(Global.PRINT_ANSWER);
|
||||
itemBankName.setPrint_item_label("Bank Name");
|
||||
itemBankName.setPrint_item_order(40);
|
||||
itemBankName.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemBankName);
|
||||
|
||||
PrintItem itemTransDate = new PrintItem(Tool.getUUID());
|
||||
itemTransDate.setPrint_type_id(Global.PRINT_TIMESTAMP);
|
||||
itemTransDate.setPrint_item_label("Print Date");
|
||||
itemTransDate.setPrint_item_order(42);
|
||||
itemTransDate.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemTransDate);
|
||||
|
||||
PrintItem itemNewLine3= new PrintItem(Tool.getUUID());
|
||||
itemNewLine3.setPrint_type_id(Global.PRINT_NEW_LINE);
|
||||
itemNewLine3.setPrint_item_label("999New Line");
|
||||
itemNewLine3.setPrint_item_order(45);
|
||||
itemNewLine3.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemNewLine3);
|
||||
|
||||
PrintItem itemTitleDetail = new PrintItem(Tool.getUUID());
|
||||
itemTitleDetail.setPrint_type_id(Global.PRINT_LABEL_CENTER_BOLD);
|
||||
itemTitleDetail.setPrint_item_label("Deposit Detail");
|
||||
itemTitleDetail.setPrint_item_order(50);
|
||||
itemTitleDetail.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemTitleDetail);
|
||||
|
||||
int ANO_order = 60;
|
||||
int DAM_order = 61;
|
||||
int DIV_order = 62;
|
||||
for(int i = 0 ; i<30 ; i++){
|
||||
PrintItem itemAgreementNo = new PrintItem(Tool.getUUID());
|
||||
itemAgreementNo.setPrint_type_id(Global.PRINT_ANSWER);
|
||||
itemAgreementNo.setPrint_item_label(i+"Agreement No");
|
||||
itemAgreementNo.setPrint_item_order(ANO_order);
|
||||
itemAgreementNo.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemAgreementNo);
|
||||
|
||||
PrintItem itemDepositAmt= new PrintItem(Tool.getUUID());
|
||||
itemDepositAmt.setPrint_type_id(Global.PRINT_ANSWER);
|
||||
itemDepositAmt.setPrint_item_label(i+"Deposit Amount");
|
||||
itemDepositAmt.setPrint_item_order(DAM_order);
|
||||
itemDepositAmt.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemDepositAmt);
|
||||
|
||||
PrintItem itemNewLine= new PrintItem(Tool.getUUID());
|
||||
itemNewLine.setPrint_type_id(Global.PRINT_NEW_LINE);
|
||||
itemNewLine.setPrint_item_label(i+"New Line");
|
||||
itemNewLine.setPrint_item_order(DIV_order);
|
||||
itemNewLine.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemNewLine);
|
||||
|
||||
ANO_order=ANO_order+3;
|
||||
DAM_order=DAM_order+3;
|
||||
DIV_order=DIV_order+3;
|
||||
}
|
||||
|
||||
PrintItem itemTotalAmt= new PrintItem(Tool.getUUID());
|
||||
itemTotalAmt.setPrint_type_id(Global.PRINT_ANSWER);
|
||||
itemTotalAmt.setPrint_item_label("Total");
|
||||
itemTotalAmt.setPrint_item_order(200);
|
||||
itemTotalAmt.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemTotalAmt);
|
||||
|
||||
PrintItem itemNewLineT= new PrintItem(Tool.getUUID());
|
||||
itemNewLineT.setPrint_type_id(Global.PRINT_NEW_LINE);
|
||||
itemNewLineT.setPrint_item_label("999New Line");
|
||||
itemNewLineT.setPrint_item_order(210);
|
||||
itemNewLineT.setUuid_scheme("DUMYUUIDSCHEMEFORDEPOSITREPORT");
|
||||
PrintItemDataAccess.addOrReplace(getActivity(), itemNewLineT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
package com.adins.mss.base.update;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import androidx.core.content.FileProvider;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.foundation.dialog.NiftyDialogBuilder;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
public class DownloadUpdate extends AsyncTask<String,String,String> {
|
||||
private ProgressDialog pDialog;
|
||||
private Context context;
|
||||
public DownloadUpdate(Context context ){
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Before starting background thread
|
||||
* Show Progress Bar Dialog
|
||||
*/
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
pDialog = new ProgressDialog(context);
|
||||
pDialog.setMessage(context.getString(R.string.updating_apk));
|
||||
pDialog.setIndeterminate(false);
|
||||
pDialog.setMax(0);
|
||||
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
pDialog.setProgressNumberFormat("%1d KB/%2d KB");
|
||||
pDialog.setCancelable(false);
|
||||
pDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
cancel(true);
|
||||
}
|
||||
});
|
||||
pDialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
super.onCancelled();
|
||||
File file = new File(context.getFilesDir(), "app.apk");
|
||||
if(file.exists()) {
|
||||
boolean deleteResult = file.delete();
|
||||
if(!deleteResult){
|
||||
Toast.makeText(context, "Failed to delete file", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... f_url) {
|
||||
int count;
|
||||
InputStream input = null;
|
||||
|
||||
File directory = new File(context.getFilesDir(), "app.apk");
|
||||
publishProgress("0","0",context.getString(R.string.updating_apk));
|
||||
try(OutputStream output = new FileOutputStream(directory)) {
|
||||
URL url = new URL(f_url[0]);
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.connect();
|
||||
connection.setConnectTimeout(Global.DOWNLOADUPDATECONNECTIONTIMEOUT);
|
||||
// getting file length
|
||||
int lengthOfFile = connection.getContentLength();
|
||||
input = new BufferedInputStream(url.openStream(), 8192);
|
||||
|
||||
byte data[] = new byte[1024];
|
||||
long total = 0;
|
||||
while ((count = input.read(data)) != -1) {
|
||||
total += count;
|
||||
publishProgress(""+(total / 1024), ""+lengthOfFile/1024,context.getString(R.string.updating_apk));
|
||||
|
||||
output.write(data, 0, count);
|
||||
}
|
||||
|
||||
output.flush();
|
||||
|
||||
return null;
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e("Error: ", e.getMessage());
|
||||
return "File not found! Please contact administrator";
|
||||
} catch (MalformedURLException e) {
|
||||
Log.e("Error: ", e.getMessage());
|
||||
return "Bad Url!";
|
||||
} catch (IOException e) {
|
||||
Log.e("Error: ", e.getMessage());
|
||||
return context.getString(R.string.update_failed);
|
||||
} finally {
|
||||
try {
|
||||
if(input != null)
|
||||
input.close();
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updating progress bar
|
||||
*/
|
||||
@Override
|
||||
protected void onProgressUpdate(String... progress) {
|
||||
// setting progress percentage
|
||||
pDialog.setProgress(Integer.parseInt(progress[0]));
|
||||
pDialog.setMax(Integer.parseInt(progress[1]));
|
||||
pDialog.setMessage(progress[2]);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String message) {
|
||||
// dismiss the dialog after the file was downloaded
|
||||
pDialog.dismiss();
|
||||
|
||||
File file = new File(context.getFilesDir(), "app.apk");
|
||||
if(message==null && isAPK(file)) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Uri apkURI = FileProvider.getUriForFile(
|
||||
context, context.getPackageName() + ".provider", file);
|
||||
intent.setDataAndType(apkURI, "application/vnd.android.package-archive");
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
context.startActivity(intent);
|
||||
} else{
|
||||
if(message==null){
|
||||
message = context.getString(R.string.update_failed);
|
||||
}
|
||||
if(file.exists()) {
|
||||
boolean deleteResult = file.delete();
|
||||
if(!deleteResult){
|
||||
Toast.makeText(context, "Failed to delete file", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(context);
|
||||
dialogBuilder.withTitle(context.getString(R.string.btnExit))
|
||||
.withMessage(message)
|
||||
.withButton1Text("OK")
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
dialogBuilder.dismiss();
|
||||
}
|
||||
})
|
||||
.isCancelable(false)
|
||||
.isCancelableOnTouchOutside(true)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
public static boolean isAPK(File file) {
|
||||
|
||||
ZipEntry zEntry = null;
|
||||
String dexFile = "classes.dex";
|
||||
String manifestFile = "AndroidManifest.xml";
|
||||
boolean hasDex = false;
|
||||
boolean hasManifest = false;
|
||||
|
||||
try(FileInputStream fis = new FileInputStream(file);
|
||||
ZipInputStream zipIs = new ZipInputStream(new BufferedInputStream(fis))) {
|
||||
|
||||
while ((zEntry = zipIs.getNextEntry()) != null) {
|
||||
if (zEntry.getName().equalsIgnoreCase(dexFile)) {
|
||||
hasDex = true;
|
||||
} else if (zEntry.getName().equalsIgnoreCase(manifestFile)) {
|
||||
hasManifest = true;
|
||||
}
|
||||
if (hasDex && hasManifest) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.adins.mss.base.depositreport;
|
||||
|
||||
import com.adins.mss.foundation.http.MssRequestType;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Created by angga.permadi on 8/30/2016.
|
||||
*/
|
||||
public class DetailTaskHRequest extends MssRequestType {
|
||||
|
||||
@SerializedName("uuid_task_h")
|
||||
private String uuidTaskH;
|
||||
@SerializedName("flag")
|
||||
private String flag;
|
||||
|
||||
public String getUuidTaskH() {
|
||||
return uuidTaskH;
|
||||
}
|
||||
|
||||
public void setUuidTaskH(String uuidTaskH) {
|
||||
this.uuidTaskH = uuidTaskH;
|
||||
}
|
||||
|
||||
public String getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void setFlag(String flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="14dp"
|
||||
android:height="14dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/gradient_end"
|
||||
android:pathData="M18,17L6,17v-2h12v2zM18,13L6,13v-2h12v2zM18,9L6,9L6,7h12v2zM3,22l1.5,-1.5L6,22l1.5,-1.5L9,22l1.5,-1.5L12,22l1.5,-1.5L15,22l1.5,-1.5L18,22l1.5,-1.5L21,22L21,2l-1.5,1.5L18,2l-1.5,1.5L15,2l-1.5,1.5L12,2l-1.5,1.5L9,2 7.5,3.5 6,2 4.5,3.5 3,2v20z"/>
|
||||
</vector>
|
|
@ -0,0 +1,89 @@
|
|||
package com.adins.mss.odr.products;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.dao.Product;
|
||||
import com.adins.mss.foundation.db.dataaccess.ProductDataAccess;
|
||||
import com.adins.mss.foundation.image.Utils;
|
||||
import com.adins.mss.odr.R;
|
||||
import com.adins.mss.odr.products.api.ProductDetailViewPdf;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public class ProductDetailFragment extends Fragment implements View.OnClickListener {
|
||||
|
||||
private ImageView imgProduct;
|
||||
private TextView txtProductName, txtProductDesc;
|
||||
private Button btnViewBrosure;
|
||||
private String uuidProduct;
|
||||
private Product product;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_product_detail, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setRetainInstance(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
imgProduct = (ImageView) view.findViewById(R.id.imgProdDetail);
|
||||
txtProductName = (TextView) view.findViewById(R.id.txtProdName);
|
||||
txtProductDesc = (TextView) view.findViewById(R.id.txtProdDescription);
|
||||
btnViewBrosure = (Button) view.findViewById(R.id.btnViewBrosure);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Utility.freeMemory();
|
||||
getActivity().setTitle(getString(com.adins.mss.base.R.string.header_mn_product_detail));
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
Bundle bundle = getArguments();
|
||||
uuidProduct = bundle.getString("uuidProduct");
|
||||
product = ProductDataAccess.getOne(getContext(), uuidProduct);
|
||||
|
||||
if (product.getLob_image() != null) {
|
||||
Bitmap bitmapImage = Utils.byteToBitmap(product.getLob_image());
|
||||
imgProduct.setImageBitmap(bitmapImage);
|
||||
} else {
|
||||
imgProduct.setImageResource(R.drawable.img_notavailable);
|
||||
imgProduct.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
}
|
||||
|
||||
txtProductName.setText(product.getProduct_name());
|
||||
txtProductDesc.setText(product.getProduct_desc());
|
||||
btnViewBrosure.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int button = v.getId();
|
||||
|
||||
if (button == R.id.btnViewBrosure) {
|
||||
ProductDetailViewPdf task = new ProductDetailViewPdf(getActivity(), product);
|
||||
task.execute();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,237 @@
|
|||
package com.adins.mss.base.dynamicform.form.questions;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.dynamicform.Constant;
|
||||
import com.adins.mss.base.dynamicform.form.FragmentQuestion;
|
||||
import com.adins.mss.base.dynamicform.form.models.CriteriaParameter;
|
||||
import com.adins.mss.base.dynamicform.form.models.LookupCriteriaBean;
|
||||
import com.adins.mss.base.dynamicform.form.models.LookupOnlineRequest;
|
||||
import com.adins.mss.base.dynamicform.form.models.ReviewResponse;
|
||||
import com.adins.mss.base.dynamicform.form.questions.viewholder.LookupCriteriaOnlineActivity;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.constant.Global;
|
||||
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.http.KeyValue;
|
||||
import com.adins.mss.foundation.questiongenerator.QuestionBean;
|
||||
import com.google.firebase.perf.FirebasePerformance;
|
||||
import com.google.firebase.perf.metrics.HttpMetric;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.adins.mss.base.dynamicform.form.questions.viewholder.LookupCriteriaOnlineActivity.KEY_WITH_FILTER;
|
||||
|
||||
/**
|
||||
* Created by gigin.ginanjar on 07/10/2016.
|
||||
*/
|
||||
|
||||
public class LookupAnswerTask extends AsyncTask<String, Void, String> {
|
||||
private WeakReference<Activity> activity;
|
||||
private ProgressDialog progressDialog;
|
||||
private String errMessage;
|
||||
private QuestionBean bean;
|
||||
private CriteriaParameter criteriaParameter;
|
||||
private int mode;
|
||||
|
||||
public LookupAnswerTask(Activity activity, QuestionBean bean, CriteriaParameter criteriaParameter, int mode) {
|
||||
this.activity = new WeakReference<>(activity);
|
||||
this.bean = bean;
|
||||
this.criteriaParameter = criteriaParameter;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
progressDialog = ProgressDialog.show(activity.get(), "", activity.get().getString(R.string.please_wait), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
if (Tool.isInternetconnected(activity.get())) {
|
||||
String jsonRequest = getJsonRequest();
|
||||
String url = GlobalData.getSharedGlobalData().getURL_LOOKUP_ANSWER();
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(activity.get(), encrypt, decrypt);
|
||||
HttpConnectionResult serverResult = null;
|
||||
|
||||
//Firebase Performance Trace HTTP Request
|
||||
HttpMetric networkMetric =
|
||||
FirebasePerformance.getInstance().newHttpMetric(url, FirebasePerformance.HttpMethod.POST);
|
||||
Utility.metricStart(networkMetric, jsonRequest);
|
||||
|
||||
try {
|
||||
serverResult = httpConn.requestToServer(url, jsonRequest, Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
Utility.metricStop(networkMetric, serverResult);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
errMessage = activity.get().getString(R.string.msgConnectionFailed);
|
||||
return null;
|
||||
}
|
||||
if (serverResult != null && serverResult.isOK()) {
|
||||
String body = serverResult.getResult();
|
||||
return body;
|
||||
} else {
|
||||
errMessage = activity.get().getString(R.string.connection_failed);
|
||||
}
|
||||
} else {
|
||||
errMessage = activity.get().getString(R.string.no_internet_connection);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
super.onPostExecute(result);
|
||||
if(!GlobalData.isRequireRelogin()) {
|
||||
if (progressDialog != null) {
|
||||
if (progressDialog.isShowing()) {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
progressDialog = null;
|
||||
}
|
||||
if (errMessage != null && !errMessage.isEmpty()) {
|
||||
Toast.makeText(activity.get(), errMessage, Toast.LENGTH_SHORT).show();
|
||||
} else if (result != null) {
|
||||
processingResponseServer(result);
|
||||
|
||||
}
|
||||
} else{
|
||||
Message message = new Message();
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
bundle.putInt(Global.BUND_KEY_MODE_SURVEY, mode);
|
||||
bundle.putInt(FragmentQuestion.BUND_KEY_ACTION, FragmentQuestion.SAVE_QUESTION);
|
||||
message.setData(bundle);
|
||||
FragmentQuestion.questionHandler.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingResponseServer(String result) {
|
||||
processLuOnline(result);
|
||||
}
|
||||
|
||||
private void processLuOnline(String result) {
|
||||
ReviewResponse response = GsonHelper.fromJson(result, ReviewResponse.class);
|
||||
if (response.getStatus().getCode() == 0) {
|
||||
List<KeyValue> valueList = response.getListField();
|
||||
if (valueList != null) {
|
||||
List<LookupCriteriaBean> beanList = new ArrayList<>();
|
||||
if (!valueList.isEmpty()) {
|
||||
for (KeyValue value : valueList) {
|
||||
LookupCriteriaBean bean = new LookupCriteriaBean();
|
||||
bean.setCode(value.getKey());
|
||||
bean.setValue(value.getValue());
|
||||
beanList.add(bean);
|
||||
}
|
||||
bean.setLookupCriteriaList(beanList);
|
||||
LookupCriteriaOnlineActivity.setBeanList(beanList);
|
||||
Intent intent = new Intent(activity.get(), LookupCriteriaOnlineActivity.class);
|
||||
if (criteriaParameter != null)
|
||||
intent.putExtra(KEY_WITH_FILTER, true);
|
||||
activity.get().startActivityForResult(intent, Global.REQUEST_LOOKUP_ANSWER);
|
||||
} else {
|
||||
errMessage = activity.get().getString(R.string.data_not_found);
|
||||
Toast.makeText(activity.get(), errMessage, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errMessage = response.getStatus().getMessage();
|
||||
Toast.makeText(activity.get(), errMessage, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public String getJsonRequest() {
|
||||
return getJsonRequestLuOnline();
|
||||
}
|
||||
|
||||
public String getJsonRequestLuOnline() {
|
||||
LookupOnlineRequest request = new LookupOnlineRequest();
|
||||
request.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
request.setIdentifier(bean.getIdentifier_name());
|
||||
if (bean.getChoice_filter() != null) {
|
||||
List<String> tempfilters = getFilterAnswer(bean);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String filter : tempfilters) {
|
||||
if (stringBuilder.length() > 0)
|
||||
stringBuilder.append(Global.DELIMETER_DATA_LOOKUP);
|
||||
stringBuilder.append(filter);
|
||||
}
|
||||
request.setChoiceFilter(stringBuilder.toString());
|
||||
}
|
||||
request.setUserFilter(criteriaParameter.getParameters().get(0).getAnswer());
|
||||
request.setLovGroup(bean.getLov_group());
|
||||
request.setIdentifier(bean.getIdentifier_name());
|
||||
String jsonRequest = GsonHelper.toJson(request);
|
||||
return jsonRequest;
|
||||
}
|
||||
|
||||
public List<String> getFilterAnswer(QuestionBean bean) {
|
||||
List<String> filters = new ArrayList<>();
|
||||
if (bean.getChoice_filter() != null) {
|
||||
String[] tempfilters = Tool.split(bean.getChoice_filter(), Global.DELIMETER_DATA3);
|
||||
|
||||
for (String newFilter : tempfilters) {
|
||||
int idxOfOpenBrace = newFilter.indexOf('{');
|
||||
if (idxOfOpenBrace != -1) {
|
||||
int idxOfCloseBrace = newFilter.indexOf('}');
|
||||
String tempIdentifier = newFilter.substring(idxOfOpenBrace + 1, idxOfCloseBrace).toUpperCase();
|
||||
if (tempIdentifier.contains("%")) {
|
||||
filters.add(tempIdentifier);
|
||||
} else {
|
||||
int idxOfOpenAbs = tempIdentifier.indexOf("$");
|
||||
if (idxOfOpenAbs != -1) {
|
||||
String finalIdentifier = tempIdentifier.substring(idxOfOpenAbs + 1);
|
||||
if (finalIdentifier.equals(Global.IDF_LOGIN_ID)) {
|
||||
String loginId = GlobalData.getSharedGlobalData().getUser().getLogin_id();
|
||||
int idxOfOpenAt = loginId.indexOf('@');
|
||||
if (idxOfOpenAt != -1) {
|
||||
loginId = loginId.substring(0, idxOfOpenAt);
|
||||
}
|
||||
filters.add(loginId);
|
||||
} else if (finalIdentifier.equals(Global.IDF_BRANCH_ID)) {
|
||||
String branchId = GlobalData.getSharedGlobalData().getUser().getBranch_id();
|
||||
filters.add(branchId);
|
||||
} else if (finalIdentifier.equals(Global.IDF_BRANCH_NAME)) {
|
||||
String branchName = GlobalData.getSharedGlobalData().getUser().getBranch_name();
|
||||
filters.add(branchName);
|
||||
} else if (finalIdentifier.equals(Global.IDF_UUID_USER)) {
|
||||
String uuidUser = GlobalData.getSharedGlobalData().getUser().getUuid_user();
|
||||
filters.add(uuidUser);
|
||||
} else if (finalIdentifier.equals(Global.IDF_JOB)) {
|
||||
String job = GlobalData.getSharedGlobalData().getUser().getFlag_job();
|
||||
filters.add(job);
|
||||
} else if (finalIdentifier.equals(Global.IDF_DEALER_NAME)) {
|
||||
String dealerName = GlobalData.getSharedGlobalData().getUser().getDealer_name();
|
||||
filters.add(dealerName);
|
||||
}
|
||||
} else {
|
||||
QuestionBean bean2 = Constant.getListOfQuestion().get(tempIdentifier);
|
||||
if (bean2 != null) {
|
||||
String answer = QuestionBean.getAnswer(bean2);
|
||||
filters.add(answer);
|
||||
bean2.setRelevanted(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return filters;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,336 @@
|
|||
package com.adins.mss.base.checkin;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.Address;
|
||||
import android.location.Geocoder;
|
||||
import android.location.LocationManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.checkin.activity.CheckInView;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.GeneralParameter;
|
||||
import com.adins.mss.dao.LocationInfo;
|
||||
import com.adins.mss.foundation.camerainapp.helper.Logger;
|
||||
import com.adins.mss.foundation.db.dataaccess.GeneralParameterDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.LocationInfoDataAccess;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.location.LocationTrackingManager;
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.api.GoogleApiClient;
|
||||
import com.google.android.gms.location.LocationRequest;
|
||||
import com.google.android.gms.location.LocationServices;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class CheckInManager implements
|
||||
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
|
||||
|
||||
protected static String[] address;
|
||||
static LocationTrackingManager ltm = Global.LTM;
|
||||
static LocationInfo infoCheckIn;
|
||||
private static GoogleApiClient mGoogleApiClient;
|
||||
private static CheckInLocationListener listener;
|
||||
|
||||
boolean updateLocation = true;
|
||||
private Context context;
|
||||
private LocationRequest mLocationRequest;
|
||||
|
||||
public CheckInManager(Context context) {
|
||||
this.context = context;
|
||||
listener = new CheckInLocationListener(context);
|
||||
}
|
||||
|
||||
public static void startGPSTracking(Context context) {
|
||||
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
GeneralParameter gp_distance = GeneralParameterDataAccess.getOne(context, GlobalData.getSharedGlobalData().getUser().getUuid_user(), Global.GS_DISTANCE_TRACKING);
|
||||
try {
|
||||
if (gp_distance != null) {
|
||||
int distanceTracking = Integer.parseInt(gp_distance.getGs_value());
|
||||
if (distanceTracking != 0) {
|
||||
Global.LTM = new LocationTrackingManager(tm, lm, context);
|
||||
Global.LTM.setMinimalDistanceChangeLocation(Integer.parseInt(GeneralParameterDataAccess.getOne(context, GlobalData.getSharedGlobalData().getUser().getUuid_user(), Global.GS_DISTANCE_TRACKING).getGs_value()));
|
||||
Global.LTM.setMinimalTimeChangeLocation(15);
|
||||
Global.LTM.applyLocationListener(context);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
Global.LTM= new LocationTrackingManager(tm, lm, context);
|
||||
Global.LTM.setMinimalDistanceChangeLocation(50);
|
||||
Global.LTM.setMinimalTimeChangeLocation(5);
|
||||
Global.LTM.applyLocationListener(context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for get Current Location info Of Check In
|
||||
*
|
||||
* @return Location Info
|
||||
*/
|
||||
public static LocationInfo getCurrentCheckIn() {
|
||||
return infoCheckIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets List of Locations info CheckIn from Database
|
||||
*
|
||||
* @param context
|
||||
* @param Uuid_user
|
||||
* @return all Location info in type of Check In
|
||||
*/
|
||||
|
||||
public static List<LocationInfo> getAllLocationInfoCheckInFromDB(
|
||||
Context context, String Uuid_user) {
|
||||
return LocationInfoDataAccess.getAllbyType(context, Uuid_user,
|
||||
Global.LOCATION_TYPE_CHECKIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a LocationInfo CheckIn to Data Base
|
||||
*
|
||||
* @param locationInfo
|
||||
*/
|
||||
public static void insertLocationCheckInToDB(Context context,
|
||||
LocationInfo locationInfo) {
|
||||
try {
|
||||
LocationInfoDataAccess.add(context, locationInfo);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In response to a request to stop updates, send a request to Location
|
||||
* Services
|
||||
*/
|
||||
public static void stopPeriodicUpdates() {
|
||||
try {
|
||||
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, listener);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creating google api client object
|
||||
*/
|
||||
protected synchronized void buildGoogleApiClient() {
|
||||
mGoogleApiClient = new GoogleApiClient.Builder(context)
|
||||
.addConnectionCallbacks(this)
|
||||
.addOnConnectionFailedListener(this)
|
||||
.addApi(LocationServices.API)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to Update Location (Refresh Location)
|
||||
*/
|
||||
public void updateLocationCheckin() {
|
||||
mLocationRequest = LocationRequest.create();
|
||||
|
||||
mLocationRequest.setInterval(5000);
|
||||
mLocationRequest.setFastestInterval(5000);
|
||||
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
||||
|
||||
buildGoogleApiClient();
|
||||
updateLocation = true;
|
||||
mGoogleApiClient.connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get new LocationInfo. Use in Button Refresh or etc.
|
||||
*
|
||||
* @return Location Info
|
||||
*/
|
||||
public LocationInfo getNewLocation() {
|
||||
infoCheckIn = listener.getNewLocationInfo();
|
||||
return infoCheckIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for Get Location Info Of CheckIn
|
||||
*
|
||||
* @return Location Info
|
||||
*/
|
||||
public LocationInfo getLocationInfoCheckIn() {
|
||||
Global.FLAG_LOCATION_TYPE = 1; // checkIn
|
||||
if (ltm == null) ltm = Global.LTM;
|
||||
if (Global.LTM == null) {
|
||||
try {
|
||||
startGPSTracking(context);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (ltm == null) ltm = Global.LTM;
|
||||
infoCheckIn = ltm.getCurrentLocation(Global.FLAG_LOCATION_CHECKIN);
|
||||
if (infoCheckIn == null) infoCheckIn = new LocationInfo(Tool.getUUID());
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
|
||||
return infoCheckIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for Get Latitude and longitude from LocationInfo
|
||||
*
|
||||
* @param locationInfo
|
||||
* @return LatLng
|
||||
*/
|
||||
public LatLng getLatLng(LocationInfo locationInfo) {
|
||||
double mLatitude = Double.parseDouble(locationInfo.getLatitude());
|
||||
double mLongitude = Double.parseDouble(locationInfo.getLongitude());
|
||||
LatLng latLng = new LatLng(mLatitude, mLongitude);
|
||||
|
||||
return latLng;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method For Get Address Location from Geocoder
|
||||
*
|
||||
* @param context - context of activity
|
||||
* @param locationInfo - location info
|
||||
* @return String[] - length = 2 <br/>
|
||||
* String[0] is Local of Location, ex: Kebon Jeruk <br/>
|
||||
* String[1] is Address Line of Location, ex: Jalan Kebon Jeruk Raya
|
||||
* No. 80
|
||||
*/
|
||||
public void getAddressLocation(Context context, LocationInfo locationInfo) {
|
||||
new CheckInManager.GetAddressTask().execute();
|
||||
}
|
||||
|
||||
public String[] getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionFailed(ConnectionResult arg0) {
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(Bundle arg0) {
|
||||
startPeriodicUpdates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionSuspended(int i) {
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
/**
|
||||
* In response to a request to start updates, send a request to Location
|
||||
* Services
|
||||
*/
|
||||
private void startPeriodicUpdates() {
|
||||
try {
|
||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
|
||||
&& ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
return;
|
||||
}
|
||||
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, listener);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
public class GetAddressTask extends AsyncTask<Void, Void, String[]> {
|
||||
|
||||
/**
|
||||
* Get a Geocoder instance, get the latitude and longitude look up the
|
||||
* address, and return it
|
||||
*
|
||||
* @return A string containing the address of the current location, or
|
||||
* an empty string if no address can be found, or an error
|
||||
* message
|
||||
* @params params One or more Location objects
|
||||
*/
|
||||
@Override
|
||||
protected String[] doInBackground(Void... params) {
|
||||
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
|
||||
// Get the current location from the input parameter list
|
||||
LocationInfo loc = infoCheckIn;
|
||||
double mLatitude = 0;
|
||||
double mLongitude = 0;
|
||||
try {
|
||||
mLatitude = Double.parseDouble(loc.getLatitude());
|
||||
mLongitude = Double.parseDouble(loc.getLongitude());
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
|
||||
String[] addressString = new String[2];
|
||||
// Create a list to contain the result address
|
||||
List<Address> addresses = null;
|
||||
try {
|
||||
/*
|
||||
* Return 1 address.
|
||||
*/
|
||||
addresses = geocoder.getFromLocation(mLatitude, mLongitude, 1);
|
||||
} catch (IOException e1) {
|
||||
if (Global.IS_DEV) {
|
||||
Logger.e("LocationSampleActivity",
|
||||
"IO Exception in getFromLocation()");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
addressString[0] = context.getString(R.string.address_not_found);
|
||||
addressString[1] = context.getString(R.string.address_not_found);
|
||||
return addressString;
|
||||
} catch (IllegalArgumentException e2) {
|
||||
// Error message to post in the log
|
||||
addressString[0] = context.getString(R.string.address_not_found);
|
||||
addressString[1] = context.getString(R.string.address_not_found);
|
||||
if (Global.IS_DEV) {
|
||||
Logger.e("CheckIn Manager :", addressString[1]);
|
||||
e2.printStackTrace();
|
||||
}
|
||||
return addressString;
|
||||
}
|
||||
// If the reverse geocode returned an address
|
||||
if (addresses != null && !addresses.isEmpty()) {
|
||||
// Get the first address
|
||||
Address addressLocal = addresses.get(0);
|
||||
addressString[0] = addressLocal.getLocality();
|
||||
try {
|
||||
addressString[1] = addressLocal.getAddressLine(0);
|
||||
if (addressString[1] != null && addressString[1].contains("Timed out"))
|
||||
addressString[1] = context.getString(R.string.address_not_found);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
addressString[1] = context.getString(R.string.address_not_found);
|
||||
}
|
||||
// Return the text
|
||||
return addressString;
|
||||
} else {
|
||||
addressString[0] = context.getString(R.string.address_not_found);
|
||||
addressString[1] = context.getString(R.string.lblCoord) + " " + mLatitude + ", " + mLongitude;
|
||||
return addressString;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String[] addressResult) {
|
||||
// Set activity indicator visibility to "gone"
|
||||
// Display the results of the lookup.
|
||||
CheckInView.setLocation(addressResult);
|
||||
address = addressResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue