Advertisement
andyshon

upload/update pairs

Mar 19th, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. public void uploadExercise(final Pattern pattern) {
  2.         if (AzureServiceAdapter.getInstance().getClient() == null)
  3.             return;
  4.  
  5.         // Insert the new item
  6.         @SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>(){
  7.             @Override
  8.             protected Void doInBackground(Void... params) {
  9.                 try {
  10.                     final Pattern entity = addExerciseInTableOffline(pattern);
  11.  
  12.                     runOnUiThread(new Runnable() {
  13.                         @Override
  14.                         public void run() {
  15.                             _ExerciseId_for_pairs = entity.getId();
  16.  
  17.                             for (int i=0 ;i<items.size(); i++){
  18.                                 Pair pair = new Pair(items.get(i).getText1().trim(), items.get(i).getText2().trim());
  19.                                 pair.setExerciseId(_ExerciseId_for_pairs);
  20.  
  21.                                 uploadPair(pair);
  22.                             }
  23.  
  24.                         }
  25.                     });
  26.                 } catch (final Exception e) {
  27.                     createAndShowDialogFromTask(e, "Error4");
  28.                 }
  29.                 return null;
  30.             }
  31.         };
  32.         runAsyncTask(task);
  33.     }
  34.  
  35. public void uploadPair(final Pair pair) {
  36.         if (AzureServiceAdapter.getInstance().getClient() == null)
  37.             return;
  38.  
  39.         // Insert the new item
  40.         @SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>(){
  41.             @Override
  42.             protected Void doInBackground(Void... params) {
  43.                 try {
  44.                     addPairsInTableOffline(pair);
  45.  
  46.                     runOnUiThread(new Runnable() {
  47.                         @Override
  48.                         public void run() {
  49.                             System.out.println("Upload 1 pair done");
  50.                         }
  51.                     });
  52.                 } catch (final Exception e) {
  53.                     createAndShowDialogFromTask(e, "Error4");
  54.                 }
  55.                 return null;
  56.             }
  57.         };
  58.         runAsyncTask(task);
  59.     }
  60.  
  61.     public void addPairsInTableOffline(Pair pair) throws ExecutionException, InterruptedException {
  62.         Global_config.mPairTableOffline.insert(pair).get();
  63.         try {
  64.             sync().get();
  65.         } catch (MobileServicePushFailedException e) {
  66.             e.printStackTrace();
  67.         }
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement