Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void uploadExercise(final Pattern pattern) {
- if (AzureServiceAdapter.getInstance().getClient() == null)
- return;
- // Insert the new item
- @SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>(){
- @Override
- protected Void doInBackground(Void... params) {
- try {
- final Pattern entity = addExerciseInTableOffline(pattern);
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- _ExerciseId_for_pairs = entity.getId();
- for (int i=0 ;i<items.size(); i++){
- Pair pair = new Pair(items.get(i).getText1().trim(), items.get(i).getText2().trim());
- pair.setExerciseId(_ExerciseId_for_pairs);
- uploadPair(pair);
- }
- }
- });
- } catch (final Exception e) {
- createAndShowDialogFromTask(e, "Error4");
- }
- return null;
- }
- };
- runAsyncTask(task);
- }
- public void uploadPair(final Pair pair) {
- if (AzureServiceAdapter.getInstance().getClient() == null)
- return;
- // Insert the new item
- @SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>(){
- @Override
- protected Void doInBackground(Void... params) {
- try {
- addPairsInTableOffline(pair);
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- System.out.println("Upload 1 pair done");
- }
- });
- } catch (final Exception e) {
- createAndShowDialogFromTask(e, "Error4");
- }
- return null;
- }
- };
- runAsyncTask(task);
- }
- public void addPairsInTableOffline(Pair pair) throws ExecutionException, InterruptedException {
- Global_config.mPairTableOffline.insert(pair).get();
- try {
- sync().get();
- } catch (MobileServicePushFailedException e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement