Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.56 KB | None | 0 0
  1. package dmspro.ngaim.orderentry.screens.login;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.text.TextUtils;
  8. import android.view.View;
  9. import android.view.inputmethod.EditorInfo;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.TextView;
  13.  
  14. import java.io.File;
  15. import java.util.ArrayList;
  16. import java.util.Locale;
  17.  
  18. import dmspro.ngaim.orderentry.BuildConfig;
  19. import dmspro.ngaim.orderentry.R;
  20. import dmspro.ngaim.orderentry.base.BaseAppCompatActivity;
  21. import dmspro.ngaim.orderentry.base.SingleClick;
  22. import dmspro.ngaim.orderentry.database.DatabaseHelper;
  23. import dmspro.ngaim.orderentry.database.entitites.DMSAimDistributorStockAvailableEntity;
  24. import dmspro.ngaim.orderentry.database.entitites.DMSAimFileSyncEntity;
  25. import dmspro.ngaim.orderentry.database.entitites.DMSAimUserEntity;
  26. import dmspro.ngaim.orderentry.model.DMSAimFileSyncModel;
  27. import dmspro.ngaim.orderentry.model.DMSAimParameterModel;
  28. import dmspro.ngaim.orderentry.model.DMSAimUserModel;
  29. import dmspro.ngaim.orderentry.network.AuthenticateTask;
  30. import dmspro.ngaim.orderentry.network.sync.DistributorStockAvailableDownloader;
  31. import dmspro.ngaim.orderentry.network.sync.SyncTask;
  32. import dmspro.ngaim.orderentry.network.sync.Uploader;
  33. import dmspro.ngaim.orderentry.screens.login.supportingapps.SupportingAppsActivity;
  34. import dmspro.ngaim.orderentry.service.GPSOnlineFunction;
  35. import dmspro.ngaim.orderentry.service.servicelocation.LocationTrackingHelper;
  36. import dmspro.ngaim.orderentry.ui.activity.FileSyncActivity;
  37. import dmspro.ngaim.orderentry.screens.dashboard.MainMRCActivity;
  38. import dmspro.ngaim.orderentry.ui.dialog.DialogDownloadAPK;
  39. import dmspro.ngaim.orderentry.ui.dialog.LoadingDialog;
  40. import dmspro.ngaim.orderentry.ui.dialog.OneButtonDialog;
  41. import dmspro.ngaim.orderentry.ui.dialog.TwoButtonDialog;
  42. import dmspro.ngaim.orderentry.uploadimages.IOnUploaderCallback;
  43. import dmspro.ngaim.orderentry.uploadimages.ImageScanner;
  44. import dmspro.ngaim.orderentry.util.Config;
  45. import dmspro.ngaim.orderentry.util.HardwareUtils;
  46. import dmspro.ngaim.orderentry.util.LauncherUtil;
  47. import dmspro.ngaim.orderentry.util.NGPrefUtils;
  48. import dmspro.ngaim.orderentry.util.Utils;
  49. import dmspro.ngaim.orderentry.util.autoupdateapk.UpdateAPI;
  50. import dmspro.ngaim.orderentry.util.autoupdateapk.UpdateAPKUtils;
  51. import dmspro.ngaim.orderentry.util.autoupdateapk.VersionInfo;
  52.  
  53. public class LoginActivity extends BaseAppCompatActivity implements SingleClick.SingleClickListener {
  54.     private TextView tvUrl;
  55.     private EditText edtUsername;
  56.     private EditText edtPassword;
  57.     private EditText edtUrl;
  58.     private Button btnLogin;
  59.     private Button btnSync;
  60.     private Button btnApps;
  61.  
  62.     private String savedUsername;
  63.     private String savedPassword;
  64.     private String savedUrl;
  65.  
  66.     @Override
  67.     protected void onCreate(Bundle savedInstanceState) {
  68.         super.onCreate(savedInstanceState);
  69.         setContentView(R.layout.activity_mrc_login);
  70.         DatabaseHelper.getInstance(); // do not delete this line
  71.         LocationTrackingHelper.getInstance(this).start();
  72.  
  73.         /*NGPrefUtils.saveUserName("AGI01");//SM000001
  74.         NGPrefUtils.savePassword("1234");
  75.         NGPrefUtils.saveUrl("192.168.10.14:8099");*/
  76.         Bundle bundle = getIntent().getExtras();
  77.         if (bundle != null && bundle.getBoolean(Config.BUNDLE_CLOSE_APPLICATION)) finish();
  78.         loadPref();
  79.         initView();
  80.     }
  81.  
  82.     private void loadPref() {
  83.         savedUsername = NGPrefUtils.getUserName();
  84.         savedPassword = NGPrefUtils.getPassword();
  85.         savedUrl = NGPrefUtils.getUrl();
  86.     }
  87.  
  88.     private void initView() {
  89.  
  90.         TextView tvVersion = findViewById(R.id.tv_version);
  91.         btnLogin = findViewById(R.id.btn_login);
  92.         edtUsername = findViewById(R.id.ed_user_name);
  93.         edtPassword = findViewById(R.id.ed_password);
  94.         edtUrl = findViewById(R.id.ed_url);
  95.         btnSync = findViewById(R.id.btn_sync);
  96.         tvUrl = findViewById(R.id.tv_url);
  97.         btnApps = findViewById(R.id.btn_apps);
  98.  
  99.         edtUsername.setText(savedUsername);
  100.         edtPassword.setText(savedPassword);
  101.         edtUrl.setText(savedUrl);
  102.         tvVersion.setText(getString(R.string.p_version, Utils.getAppVersionName(this)));
  103.  
  104.         SingleClick singleClick = getSingleClick(this);
  105.         btnSync.setOnClickListener(singleClick);
  106.         btnLogin.setOnClickListener(singleClick);
  107.         btnApps.setOnClickListener(singleClick);
  108.         initUrlField();
  109.     }
  110.  
  111.     private void initUrlField() {
  112.         // IMPORTANT: IGNORE THE WARNINGS
  113.  
  114.         if (edtUrl.getText().toString().trim().isEmpty()
  115.                 || BuildConfig.FORCE_URL) {
  116.             edtUrl.setText(BuildConfig.BASE_URL);
  117.         }
  118.         if (BuildConfig.HIDE_URL) {
  119.             edtUrl.setVisibility(View.GONE);
  120.             tvUrl.setVisibility(View.GONE);
  121.             edtPassword.setImeOptions(EditorInfo.IME_ACTION_DONE);
  122.         }
  123.     }
  124.  
  125.     @Override
  126.     public void onClick(View v) {
  127.         int id = v.getId();
  128.         switch (id) {
  129.             case R.id.btn_login:
  130.             case R.id.btn_sync:
  131.                 String newUserName = edtUsername.getText().toString()
  132.                         .replaceAll("\\s", "").trim().toUpperCase(Locale.getDefault());
  133.                 edtUsername.setText(newUserName);
  134.                 String newPassword = edtPassword.getText().toString();
  135.                 String newUrl = edtUrl.getText().toString().replaceAll("\\s", "").trim();
  136.  
  137.                 // if username, password or url changed, run settings process
  138.                 if (!newUserName.equals(savedUsername) || !newUrl.equals(savedUrl) || !newPassword.equals(savedPassword)) {
  139.                     if (!dmspro.ngaim.orderentry.uploadimages.Uploader.isUploadImageRunning()) {
  140.                         executeSettings(newUserName, newUrl);
  141.                     } else {
  142.                         String msg = getResources().getString(R.string.network_error_upload_image_running_in_other_thread_setting);
  143.                         OneButtonDialog dateError = new OneButtonDialog(this);
  144.                         dateError.setAlertContent(msg);
  145.                         dateError.show();
  146.                     }
  147.                 } else {
  148.                     // if SR tap button Sync or
  149.                     // if SR tap button Login but hasn't sync today
  150.                     // proceed syncing
  151.                     if (id == R.id.btn_sync || !DMSAimUserModel.checkSyncDate()) {
  152.                         startLocation(this, false);
  153.                     } else {
  154.                         afterSyncComplete(this);
  155.                     }
  156.                 }
  157.                 break;
  158.             case R.id.btn_apps:
  159.                 SupportingAppsActivity.launch(this);
  160.                 break;
  161.         }
  162.     }
  163.  
  164.     public void startLocation(final Context context, final boolean lastUpload) {
  165.         final LoadingDialog dialog = new LoadingDialog(context, context.getString(R.string.alert_synchronizing));
  166.         dialog.show();
  167.         new GPSOnlineFunction(context).startGetLocation(new GPSOnlineFunction.OnStartGetLocationListener() {
  168.             @Override
  169.             public void onGettingLocation(long millsTime) {
  170.                 dialog.setLoadingMessage(context.getString(R.string.alert_obtaining_location) + String.valueOf(millsTime / 1000) + "s");
  171.             }
  172.  
  173.             @Override
  174.             public void onLocationIsHWGPS(double latitude, double longitude, double accuracy, long mills_total_time_get_location) {
  175.                 sendOrderToServer(context, dialog, latitude, longitude, lastUpload);
  176.             }
  177.  
  178.             @Override
  179.             public void onLocationIsAGPS(double latitude, double longitude, double accuracy, long mills_total_time_get_location) {
  180.                 sendOrderToServer(context, dialog, latitude, longitude, lastUpload);
  181.             }
  182.  
  183.             @Override
  184.             public void onLocationIsError(long mills_total_time_get_location) {
  185.                 sendOrderToServer(context, dialog, 0.0, 0.0, lastUpload);
  186.             }
  187.         });
  188.     }
  189.  
  190.     private void uploadImage(final Context context, final LoadingDialog loading, final double lat, final double lng, final boolean lastUpload) {
  191.         //final LoadingDialog loading = new LoadingDialog(this);
  192.         if (!loading.isShowing()) loading.show();
  193.         loading.setLoadingMessage(context.getString(R.string.uploading_data));
  194.  
  195.         ImageScanner.uploadImageLacked(context, new ImageScanner.IOnUploadImageLackedListener() {
  196.  
  197.             @Override
  198.             public void onUploading(int count) {
  199.                 loading.setLoadingMessage(context.getString(R.string.remained) + " " + count + " " + context.getString(R.string.image));
  200.             }
  201.  
  202.             @Override
  203.             public void onFailed(IOnUploaderCallback.UploaderEnum error) {
  204.                 loading.dismiss();
  205.                 if (lastUpload) {
  206.                     onSave();
  207.                 } else {
  208.                     String msg;
  209.                     if (error == IOnUploaderCallback.UploaderEnum.AlreadyRunning) {
  210.  
  211.                         msg = context.getResources().getString(R.string.network_error_upload_image_running_in_other_thread_login);
  212.                     } else {
  213.                         msg = dmspro.ngaim.orderentry.uploadimages.Uploader.getUploadImageError(context, error);
  214.                     }
  215.                     OneButtonDialog dialogerrroruser = new OneButtonDialog(context, null);
  216.                     dialogerrroruser.setAlertContent(msg);
  217.                     dialogerrroruser.setCancelable(false);
  218.                     if (context instanceof Activity) {
  219.                         Activity act = ((Activity) context);
  220.                         if (!act.isFinishing()) {
  221.                             dialogerrroruser.show();
  222.                         }
  223.                     }
  224.                 }
  225.             }
  226.  
  227.             @Override
  228.             public void onCompleted() {
  229.                 if (lastUpload) {
  230.                     loading.dismiss();
  231.                     onSave();
  232.                 } else {
  233.                     updateApK(context, loading, lat, lng);
  234.                 }
  235.             }
  236.         });
  237.  
  238.     }
  239.  
  240.     private void sendOrderToServer(final Context context, final LoadingDialog d, final double lat, final double lng, final boolean lastUpload) {
  241.         d.setLoadingMessage(context.getString(R.string.alert_uploading));
  242.         Uploader.uploadData(Uploader.SYNC_MIDDLE_DAY, lat, lng, new Uploader.OnUploadListener() {
  243.             @Override
  244.             public void onSuccess() {
  245.                 uploadImage(context, d, lat, lng, lastUpload);
  246.             }
  247.  
  248.             @Override
  249.             public void onError(String error) {
  250.                 d.dismiss();
  251.                 if (lastUpload) {
  252.                     onSave();
  253.                 } else {
  254.                     OneButtonDialog dialog = new OneButtonDialog(context, null);
  255.                     dialog.setAlertContent(error);
  256.                     dialog.show();
  257.                 }
  258.             }
  259.         },false);
  260.     }
  261.  
  262.     public void sync(final Context context, final LoadingDialog dialog, final double latitude, final double longitude) {
  263.         dialog.setLoadingMessage(context.getString(R.string.alert_synchronizing));
  264.         boolean isFirstSync = !DMSAimUserModel.checkSyncDate();
  265.         new SyncTask(isFirstSync, latitude, longitude, new SyncTask.SyncCallBack() {
  266.             @Override
  267.             public void onFinished(SyncTask.SyncResult result) {
  268.                 if (result == SyncTask.SyncResult.Success) {
  269.                     if (DMSAimUserModel.checkSyncDate()) {
  270.                         getDistributorStock(context, dialog);
  271.                     } else {
  272.                         dialog.dismiss();
  273.                         OneButtonDialog dateError = new OneButtonDialog(context);
  274.                         dateError.setAlertContent(R.string.alert_sync_check_date_error);
  275.                         dateError.show();
  276.                     }
  277.  
  278.  
  279.                 } else {
  280.                     final TwoButtonDialog error = new TwoButtonDialog(context, new TwoButtonDialog.IAlertConfirm() {
  281.                         @Override
  282.                         public void accept() {
  283.                             dialog.dismiss();
  284.                         }
  285.                     }, new TwoButtonDialog.IAlertConfirm() {
  286.                         @Override
  287.                         public void accept() {
  288.                             sync(context, dialog, latitude, longitude);
  289.                         }
  290.                     });
  291.  
  292.                     //error.setAlertContent(context.getString(R.string.alert_sync_error));
  293.                     error.setAlertContent(SyncTask.getDownloadError(context, result));
  294.                     error.setAlertLeftBtnText(context.getString(R.string.alert_button_exit));
  295.                     error.setAlertRightBtnText(context.getString(R.string.alert_button_retry));
  296.                     error.show();
  297.                 }
  298.             }
  299.         }).execute();
  300.     }
  301.  
  302.  
  303.     public void updateApK(final Context context, final LoadingDialog dialog, final double latitude, final double longitude) {
  304.         UpdateAPKUtils.checkVersion(context, NGPrefUtils.getUrlUpdateAPK(), new UpdateAPI.IOnCheckVersionListener() {
  305.             @Override
  306.             public void onChecked(VersionInfo newInfo, VersionInfo oldInfo, UpdateAPI updateAPI) {
  307.                 if (newInfo != null && oldInfo != null) {
  308.                     double newInfoVersionCode = 0;
  309.                     try {
  310.                         newInfoVersionCode = Double.parseDouble(newInfo.getVersionCode());
  311.                     } catch (NumberFormatException e) {
  312.                         e.printStackTrace();
  313.                     }
  314.                     double oldinfoVersionCode = 0;
  315.                     try {
  316.                         oldinfoVersionCode = Double.parseDouble(oldInfo.getVersionCode());
  317.                     } catch (NumberFormatException e) {
  318.                         e.printStackTrace();
  319.                     }
  320.  
  321.                     if (newInfoVersionCode > oldinfoVersionCode) {
  322.                         dialog.dismiss();
  323.                         DialogDownloadAPK d = new DialogDownloadAPK(context, newInfo);
  324.                         if (context instanceof Activity) {
  325.                             if (!((Activity) context).isFinishing()) {
  326.                                 d.show();
  327.                             }
  328.                         }
  329.                         return;
  330.                     } else {
  331.                         // khong co version moi
  332.                         sync(context, dialog, latitude, longitude);
  333.                     }
  334.  
  335.  
  336.                 } else {
  337.                     dialog.dismiss();
  338.                     OneButtonDialog dialog = new OneButtonDialog(context, new OneButtonDialog.IAlertConfirm() {
  339.                         @Override
  340.                         public void accept() {
  341.                             if (context instanceof Activity) {
  342.                                 ((Activity) context).finish();
  343.                             }
  344.                         }
  345.                     });
  346.                     dialog.setAlertContent(context.getString(R.string.error_checking_update));
  347.                     dialog.show();
  348.                 }
  349.             }
  350.         });
  351.     }
  352.  
  353.     public static boolean isAllFileDownloaded() {
  354.         boolean allFileDownloaded = true;
  355.         ArrayList<DMSAimFileSyncEntity> fileSyncEntities = checkSum(DMSAimFileSyncModel.getAlls());
  356.         if (fileSyncEntities.size() > 0) {
  357.             allFileDownloaded = false;
  358.         }
  359.         return allFileDownloaded;
  360.     }
  361.  
  362.     public static void downloadFile(final Context context) {
  363.         OneButtonDialog downloadDialog = new OneButtonDialog(context, new OneButtonDialog.IAlertConfirm() {
  364.             @Override
  365.             public void accept() {
  366.                 Intent intent = new Intent(context, FileSyncActivity.class);
  367.                 Bundle b = new Bundle();
  368.                 b.putBoolean(FileSyncActivity.BUNDLE_AUTO_DOWNLOAD, true);
  369.                 intent.putExtras(b);
  370.                 if (context instanceof Activity && !((Activity) context).isFinishing()) {
  371.                     context.startActivity(intent);
  372.                 }
  373.  
  374.             }
  375.         });
  376.         downloadDialog.setAlertContent(R.string.file_is_not_downloaded);
  377.         downloadDialog.show();
  378.     }
  379.  
  380.     private static ArrayList<DMSAimFileSyncEntity> checkSum(ArrayList<DMSAimFileSyncEntity> allEntities) {
  381.         ArrayList<DMSAimFileSyncEntity> results = new ArrayList<DMSAimFileSyncEntity>();
  382.         for (DMSAimFileSyncEntity e : allEntities) {
  383.  
  384.             // kiem tra file da ton tai hay chua
  385.             File f = new File(e.getSaveTo());
  386.             if (f.exists()) {
  387.                 // check md5
  388.                 String md5 = Utils.fileToMD5(e.getSaveTo());
  389.                 if (md5 != null) {
  390.                     if (!md5.equalsIgnoreCase(e.getMD5CheckSum())) {
  391.                         results.add(e);
  392.  
  393.                         // // xoa
  394.                         File file = new File(e.getSaveTo());
  395.                         file.delete();
  396.                     }
  397.                 }
  398.  
  399.             } else
  400.                 results.add(e);
  401.         }
  402.         return results;
  403.     }
  404.  
  405.     public static void afterSyncComplete(Context context) {
  406.  
  407.         boolean install = false;
  408.         boolean launcherEnable = DMSAimParameterModel.isLauncherEnabled();
  409.  
  410.         if (launcherEnable) {
  411.             int currentVersion = LauncherUtil.getCurrentVersionCode(context);
  412.             int newVersion = DMSAimParameterModel.getLauncherVersionCode();
  413.             String url = DMSAimParameterModel.getLauncherUrl();
  414.             if (newVersion > currentVersion && url != null && !url.trim().equals("")) {
  415.                 VersionInfo newInfo = new VersionInfo();
  416.                 newInfo.setAppName(Config.LAUNCHER_APP_NAME);
  417.                 newInfo.setApkUrl(url);
  418.                 newInfo.setPackageName(Config.LAUNCHER_PACKAGE_NAME);
  419.                 DialogDownloadAPK d = new DialogDownloadAPK(context, newInfo);
  420.                 d.setCloseDialogWhenInstall(true);
  421.                 if (context instanceof Activity) {
  422.                     if (!((Activity) context).isFinishing()) {
  423.                         d.show();
  424.                     }
  425.                 }
  426.                 install = true;
  427.             }
  428.         }
  429.         if (!install) {
  430.             lastCheck(context);
  431.         }
  432.     }
  433.  
  434.     public static void lastCheck(Context context) {
  435.         LauncherUtil.sendBroadCast(context);
  436.         if (Utils.checkStateDevice(context, true) == null) {
  437.             Intent intent = new Intent(context, MainMRCActivity.class);
  438.             context.startActivity(intent);
  439.         }
  440.     }
  441.  
  442.     public static void deleteUploadedFiles(final Context context, final LoadingDialog dialog) {
  443.         ImageScanner.deleteFiles(context, new ImageScanner.IOnDeleteListener() {
  444.             @Override
  445.             public void onDeleting(int total) {
  446.                 dialog.setLoadingMessage(R.string.dialog_deleting_uploaded_files);
  447.             }
  448.  
  449.             @Override
  450.             public void onCompleted() {
  451.                 dialog.dismiss();
  452.                 if (!isAllFileDownloaded()) {
  453.                     downloadFile(context);
  454.                     return;
  455.                 }
  456.                 afterSyncComplete(context);
  457.             }
  458.         });
  459.     }
  460.  
  461.  
  462.     private void executeSettings(String newUserName, String newUrl) {
  463.         String newPass = edtPassword.getText().toString();
  464.  
  465.         if (newUserName.isEmpty() || newUrl.isEmpty()) {
  466.             String msg;
  467.             if (newUserName.isEmpty()) {
  468.                 msg = getString(R.string.setting_alert_username_can_not_blank);
  469.             } else {
  470.                 msg = getString(R.string.setting_alert_url_can_not_blank);
  471.             }
  472.             OneButtonDialog dialog = new OneButtonDialog(this);
  473.             dialog.setAlertContent(msg);
  474.             dialog.show();
  475.         } else if (!newUserName.equals(savedUsername) || !newUrl.equals(savedUrl)) { //User  changed
  476.             DMSAimUserEntity user = DMSAimUserModel.getUser();
  477.             if (user == null) {
  478.                 onSave();
  479.             } else {
  480.                 // re-save data when exists data in db but not in pref
  481.                 if (savedUsername.isEmpty()) {
  482.                     NGPrefUtils.saveUserName(user.getUserName());
  483.                 }
  484.                 if (NGPrefUtils.getToken().isEmpty()) {
  485.                     NGPrefUtils.saveToken(Config.TEMP_TOKEN);
  486.                 }
  487.                 if (savedUrl.isEmpty()) {
  488.                     NGPrefUtils.saveUrl(BuildConfig.BASE_URL);
  489.                 }
  490.                 startLocation(this, true);
  491.             }
  492.         } else {
  493.             NGPrefUtils.savePassword(newPass);
  494.             startLocation(this, false);
  495.         }
  496.     }
  497.  
  498.     public void onSave() {
  499.         DatabaseHelper.deleteAllTables();
  500.         NGPrefUtils.saveToken(Config.EMPTY_TEXT);
  501.         NGPrefUtils.saveUserName(edtUsername.getText().toString().replaceAll("\\s", "").trim());
  502.         NGPrefUtils.savePassword(edtPassword.getText().toString().replaceAll("\\s", ""));
  503.         NGPrefUtils.saveUrl(edtUrl.getText().toString().replaceAll("\\s", "").trim());
  504.  
  505.         if (TextUtils.isEmpty(NGPrefUtils.getToken())) {
  506.             authenticate();
  507.         }
  508.     }
  509.  
  510.     private void authenticate() {
  511.         String userName = NGPrefUtils.getUserName();
  512.         final LoadingDialog dialog = new LoadingDialog(this, getString(R.string.alert_authenticating));
  513.         dialog.show();
  514.         new AuthenticateTask(HardwareUtils.getUID(this), userName, new AuthenticateTask.AuthenticateBack() {
  515.             @Override
  516.             public void onFinished(AuthenticateTask.AuthenticateResult result, String token) {
  517.                 if (!isDestroyed()) dialog.dismiss();
  518.                 if (result == AuthenticateTask.AuthenticateResult.Success) {
  519.                     NGPrefUtils.saveToken(token);
  520.                     startLocation(LoginActivity.this, false);
  521.                 } else {
  522.                     NGPrefUtils.saveUrl(Config.EMPTY_TEXT);
  523.                     NGPrefUtils.savePassword(Config.EMPTY_TEXT);
  524.                     NGPrefUtils.saveUserName(Config.EMPTY_TEXT);
  525.                     NGPrefUtils.saveToken(Config.EMPTY_TEXT);
  526.  
  527.                     OneButtonDialog dialog = new OneButtonDialog(LoginActivity.this);
  528.                     dialog.setAlertContent(AuthenticateTask.getAuthenticateError(LoginActivity.this, result));
  529.                     dialog.setAlertBtnText(R.string.dialog_btn_accept);
  530.                     dialog.show();
  531.                 }
  532.                 loadPref();
  533.             }
  534.         }).execute();
  535.  
  536.     }
  537.  
  538.     public static void getDistributorStock(final Context context, final LoadingDialog dialog) {
  539.         dialog.setLoadingMessage(R.string.msg_downloading_distributor_stock);
  540.         new DistributorStockAvailableDownloader().download(new DistributorStockAvailableDownloader.IDistributorStockDownloadResultListener() {
  541.             @Override
  542.             public void onSuccess() {
  543.                 deleteUploadedFiles(context,dialog);
  544.             }
  545.  
  546.             @Override
  547.             public void onFail() {
  548.                 dialog.dismiss();
  549.                 TwoButtonDialog retryDialog = new TwoButtonDialog(context, new TwoButtonDialog.IAlertConfirm() {
  550.                     @Override
  551.                     public void accept() {
  552.                         LoadingDialog dialog = new LoadingDialog(context, context.getString(R.string.alert_synchronizing));
  553.                         dialog.show();
  554.                         deleteUploadedFiles(context,dialog);
  555.                     }
  556.                 }, new TwoButtonDialog.IAlertConfirm() {
  557.                     @Override
  558.                     public void accept() {
  559.                         LoadingDialog dialog = new LoadingDialog(context);
  560.                         dialog.show();
  561.                         // Do chỉ delete lúc đồng bộ nên phải tự delete lúc retry
  562.                         DatabaseHelper.getInstance().delete(DMSAimDistributorStockAvailableEntity.TABLE_NAME, null, null);
  563.                         getDistributorStock(context, dialog);
  564.                     }
  565.                 });
  566.                 retryDialog.setAlertContent(R.string.msg_retry_get_distributor_stock);
  567.                 retryDialog.setAlertLeftBtnText(context.getString(R.string.skip));
  568.                 retryDialog.setAlertRightBtnText(context.getString(R.string.alert_button_retry));
  569.                 retryDialog.show();
  570.             }
  571.         });
  572.     }
  573. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement