aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/GitAsyncTask.java
blob: cc8938fb2d36451c673f742bd626d3b7f881ee1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.zeapo.pwdstore;

import android.app.Activity;
import android.os.AsyncTask;
import android.util.Log;

import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.GitCommand;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.TransportException;


public class GitAsyncTask extends AsyncTask<GitCommand, Integer, Integer> {
    private Activity activity;
    private boolean finishOnEnd;
    public GitAsyncTask(Activity activity, boolean finishOnEnd) {
        this.activity = activity;
        this.finishOnEnd = finishOnEnd;
    }
    @Override
    protected Integer doInBackground(GitCommand... cmd) {
        int count = cmd.length;
        Integer totalSize = 0;
        for (int i = 0; i < count; i++) {
            try {
                cmd[i].call();
            } catch (JGitInternalException e) {
                e.printStackTrace();
                return -99;
            } catch (InvalidRemoteException e) {
                e.printStackTrace();
                return -1;
            } catch (TransportException e) {
                e.printStackTrace();
                return -2;
            } catch (Exception e) {
                e.printStackTrace();
            }
            totalSize++;
        }
        return totalSize;
    }

    protected void onPostExecute(Integer result) {
        Log.i("GIT_ASYNC", result + "");
        if (finishOnEnd) {
            this.activity.finish();
        }
    }
}