Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 7b8ad7c

Browse files
committed
revert auto-sync and background git activity
too buggy, no time to work on it correclty
1 parent fca7f82 commit 7b8ad7c

File tree

11 files changed

+34
-98
lines changed

11 files changed

+34
-98
lines changed

app/src/main/java/com/zeapo/pwdstore/PasswordStore.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,16 @@
2323
import android.support.v7.app.AppCompatActivity;
2424
import android.support.v7.widget.SearchView;
2525
import android.text.TextUtils;
26-
import android.text.format.DateUtils;
2726
import android.util.Log;
2827
import android.view.Menu;
2928
import android.view.MenuItem;
3029
import android.view.View;
3130
import android.widget.TextView;
32-
import android.widget.Toast;
3331

3432
import com.zeapo.pwdstore.crypto.PgpHandler;
3533
import com.zeapo.pwdstore.git.GitActivity;
3634
import com.zeapo.pwdstore.git.GitAsyncTask;
3735
import com.zeapo.pwdstore.git.GitOperation;
38-
import com.zeapo.pwdstore.git.SyncOperation;
3936
import com.zeapo.pwdstore.pwgen.PRNGFixes;
4037
import com.zeapo.pwdstore.utils.PasswordItem;
4138
import com.zeapo.pwdstore.utils.PasswordRecyclerAdapter;
@@ -46,13 +43,8 @@
4643
import org.eclipse.jgit.lib.Repository;
4744

4845
import java.io.File;
49-
import java.sql.Timestamp;
50-
import java.text.ParseException;
51-
import java.text.SimpleDateFormat;
5246
import java.util.ArrayList;
53-
import java.util.Calendar;
5447
import java.util.Collections;
55-
import java.util.Date;
5648
import java.util.HashSet;
5749
import java.util.Iterator;
5850
import java.util.List;
@@ -347,20 +339,6 @@ private void checkLocalRepository() {
347339
startActivityForResult(intent, HOME);
348340
} else {
349341
checkLocalRepository(PasswordRepository.getRepositoryDirectory(getApplicationContext()));
350-
File localDir = PasswordRepository.getRepositoryDirectory(getApplicationContext());
351-
checkLocalRepository(localDir);
352-
353-
int lastSync = settings.getInt("last_sync", -1);
354-
int currentTime = (int) Calendar.getInstance().getTimeInMillis() / 1000;
355-
if (settings.getBoolean("git_auto_sync", false) && currentTime > lastSync + 3600) {
356-
Toast.makeText(getApplicationContext(), "Running git auto sync", Toast.LENGTH_LONG).show();
357-
358-
Intent intent;
359-
intent = new Intent(this, GitActivity.class);
360-
intent.putExtra("Operation", GitActivity.REQUEST_SYNC);
361-
startActivityForResult(intent, GitActivity.REQUEST_SYNC);
362-
settings.edit().putInt("last_sync", currentTime).apply();
363-
}
364342
}
365343
}
366344

@@ -567,7 +545,7 @@ private File getCurrentDir() {
567545
private void commitChange(final String message) {
568546
new GitOperation(PasswordRepository.getRepositoryDirectory(activity), activity) {
569547
@Override
570-
public void execute(boolean finishOnEnd) {
548+
public void execute() {
571549
Log.d(TAG, "Commiting with message " + message);
572550
Git git = new Git(this.repository);
573551
GitAsyncTask tasks = new GitAsyncTask(activity, finishOnEnd, true, this);
@@ -576,7 +554,7 @@ public void execute(boolean finishOnEnd) {
576554
git.commit().setAll(true).setMessage(message)
577555
);
578556
}
579-
}.execute(false);
557+
}.execute();
580558
}
581559

582560
protected void onActivityResult(int requestCode, int resultCode,

app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public CloneOperation setAuthentication(File sshKey, String username, String pas
6666
}
6767

6868
@Override
69-
public void execute(boolean finishOnEnd) {
69+
public void execute() {
7070
if (this.provider != null) {
7171
((CloneCommand) this.command).setCredentialsProvider(this.provider);
7272
}
73-
new GitAsyncTask(callingActivity, finishOnEnd, false, this).execute(this.command);
73+
new GitAsyncTask(callingActivity, true, false, this).execute(this.command);
7474
}
7575

7676
@Override

app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ public void onClick(DialogInterface dialog, int id) {
536536
try {
537537
new CloneOperation(localDir, activity)
538538
.setCommand(hostname)
539-
.executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"), true);
539+
.executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"));
540540
} catch (Exception e) {
541541
//This is what happens when jgit fails :(
542542
//TODO Handle the diffent cases of exceptions
@@ -574,7 +574,7 @@ public void onClick(DialogInterface dialog, int id) {
574574
}
575575
new CloneOperation(localDir, activity)
576576
.setCommand(hostname)
577-
.executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"), true);
577+
.executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"));
578578
} catch (Exception e) {
579579
//This is what happens when jgit fails :(
580580
//TODO Handle the diffent cases of exceptions
@@ -632,9 +632,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
632632
}
633633

634634
try {
635-
op.executeAfterAuthentication(connectionMode,
636-
settings.getString("git_remote_username", "git"),
637-
new File(getFilesDir() + "/.ssh_key"), false);
635+
op.executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"));
638636
} catch (Exception e) {
639637
e.printStackTrace();
640638
}
@@ -676,7 +674,7 @@ protected void onActivityResult(int requestCode, int resultCode,
676674
}
677675

678676
try {
679-
op.executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"), true);
677+
op.executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"));
680678
} catch (Exception e) {
681679
e.printStackTrace();
682680
}

app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
import android.app.Activity;
44
import android.app.ProgressDialog;
55
import android.os.AsyncTask;
6-
import android.support.design.widget.Snackbar;
7-
import android.text.Html;
8-
import android.text.Spanned;
96
import android.util.Log;
10-
import android.widget.Toast;
117

128
import com.zeapo.pwdstore.PasswordStore;
139
import com.zeapo.pwdstore.R;
@@ -17,43 +13,26 @@
1713
import org.eclipse.jgit.api.StatusCommand;
1814

1915

20-
public class GitAsyncTask extends AsyncTask<GitCommand, String, String> {
16+
public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
2117
private Activity activity;
22-
private boolean lockAndFinishActivity;
18+
private boolean finishOnEnd;
2319
private boolean refreshListOnEnd;
2420
private ProgressDialog dialog;
2521
private GitOperation operation;
26-
private Snackbar snack;
2722

28-
public GitAsyncTask(Activity activity, boolean lockAndFinishActivity, boolean refreshListOnEnd, GitOperation operation) {
23+
public GitAsyncTask(Activity activity, boolean finishOnEnd, boolean refreshListOnEnd, GitOperation operation) {
2924
this.activity = activity;
30-
this.lockAndFinishActivity = lockAndFinishActivity;
25+
this.finishOnEnd = finishOnEnd;
3126
this.refreshListOnEnd = refreshListOnEnd;
3227
this.operation = operation;
3328

34-
this.dialog = new ProgressDialog(this.activity);
29+
dialog = new ProgressDialog(this.activity);
3530
}
3631

3732
protected void onPreExecute() {
38-
if (lockAndFinishActivity) {
39-
final Spanned message = Html.fromHtml(String.format("Running %s", operation.getClass().getSimpleName()));
40-
this.dialog.setMessage(message);
41-
this.dialog.setCancelable(false);
42-
this.dialog.show();
43-
} else {
44-
final Spanned message = Html.fromHtml(String.format("<font color=\"#ffffff\">Running %s</font>", operation.getClass().getSimpleName()));
45-
Toast.makeText(activity.getApplicationContext(), message, Toast.LENGTH_LONG).show();
46-
}
47-
}
48-
49-
protected void onProgressUpdate(String... progress) {
50-
if (lockAndFinishActivity) {
51-
final Spanned message = Html.fromHtml(String.format("Running jgit command: <strong>%s</strong>", progress[0]));
52-
this.dialog.setMessage(message);
53-
} else {
54-
final Spanned message = Html.fromHtml(String.format("<font color=\"#ffffff\">Running jgit command: <strong>%s</strong></font>", progress[0]));
55-
Toast.makeText(activity.getApplicationContext(), message, Toast.LENGTH_LONG).show();
56-
}
33+
this.dialog.setMessage(activity.getResources().getString(R.string.running_dialog_text));
34+
this.dialog.setCancelable(false);
35+
this.dialog.show();
5736
}
5837

5938
@Override
@@ -73,8 +52,7 @@ protected String doInBackground(GitCommand... commands) {
7352
} else {
7453
command.call();
7554
}
76-
String opName = command.getClass().getSimpleName();
77-
publishProgress(opName);
55+
7856
} catch (Exception e) {
7957
e.printStackTrace();
8058
return e.getMessage() + "\nCaused by:\n" + e.getCause();
@@ -97,7 +75,7 @@ protected void onPostExecute(String result) {
9775
if (!result.isEmpty()) {
9876
this.operation.onTaskEnded(result);
9977
} else {
100-
if (lockAndFinishActivity) {
78+
if (finishOnEnd) {
10179
this.activity.setResult(Activity.RESULT_OK);
10280
this.activity.finish();
10381
}

app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,18 @@ public GitOperation setAuthentication(File sshKey, String username, String passp
7676

7777
/**
7878
* Executes the GitCommand in an async task
79-
*
80-
* @param finishOnEnd
8179
*/
82-
public abstract void execute(boolean finishOnEnd);
80+
public abstract void execute();
8381

8482
/**
8583
* Executes the GitCommand in an async task after creating the authentication
8684
*
8785
* @param connectionMode the server-connection mode
8886
* @param username the username
8987
* @param sshKey the ssh-key file
90-
* @param finishOnEnd
9188
*/
92-
public void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey, boolean finishOnEnd) {
93-
executeAfterAuthentication(connectionMode, username, sshKey, false, finishOnEnd);
89+
public void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey) {
90+
executeAfterAuthentication(connectionMode, username, sshKey, false);
9491
}
9592

9693
/**
@@ -100,14 +97,8 @@ public void executeAfterAuthentication(final String connectionMode, final String
10097
* @param username the username
10198
* @param sshKey the ssh-key file
10299
* @param showError show the passphrase edit text in red
103-
* @param finishOnEnd
104100
*/
105-
private void executeAfterAuthentication(
106-
final String connectionMode,
107-
final String username,
108-
@Nullable final File sshKey,
109-
final boolean showError,
110-
final boolean finishOnEnd) {
101+
private void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey, final boolean showError) {
111102
if (connectionMode.equalsIgnoreCase("ssh-key")) {
112103
if (sshKey == null || !sshKey.exists()) {
113104
new AlertDialog.Builder(callingActivity)
@@ -170,21 +161,19 @@ public void onClick(DialogInterface dialog, int id) {
170161
public void onClick(DialogInterface dialog, int whichButton) {
171162
if (keyPair.decrypt(passphrase.getText().toString())) {
172163
// Authenticate using the ssh-key and then execute the command
173-
setAuthentication(sshKey, username, passphrase.getText().toString()).execute(finishOnEnd);
174-
callingActivity.finish();
164+
setAuthentication(sshKey, username, passphrase.getText().toString()).execute();
175165
} else {
176166
// call back the method
177-
executeAfterAuthentication(connectionMode, username, sshKey, true, finishOnEnd);
167+
executeAfterAuthentication(connectionMode, username, sshKey, true);
178168
}
179169
}
180170
}).setNegativeButton(callingActivity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
181171
public void onClick(DialogInterface dialog, int whichButton) {
182-
callingActivity.finish();
172+
// Do nothing.
183173
}
184174
}).show();
185175
} else {
186-
setAuthentication(sshKey, username, "").execute(finishOnEnd);
187-
callingActivity.finish();
176+
setAuthentication(sshKey, username, "").execute();
188177
}
189178
} catch (JSchException e) {
190179
new AlertDialog.Builder(callingActivity)
@@ -211,7 +200,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
211200
.setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
212201
public void onClick(DialogInterface dialog, int whichButton) {
213202
// authenticate using the user/pwd and then execute the command
214-
setAuthentication(username, password.getText().toString()).execute(finishOnEnd);
203+
setAuthentication(username, password.getText().toString()).execute();
215204

216205
}
217206
}).setNegativeButton(callingActivity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {

app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public PullOperation setCommand() {
3636
}
3737

3838
@Override
39-
public void execute(boolean finishOnEnd) {
39+
public void execute() {
4040
if (this.provider != null) {
4141
((PullCommand) this.command).setCredentialsProvider(this.provider);
4242
}
43-
new GitAsyncTask(callingActivity, finishOnEnd, false, this).execute(this.command);
43+
new GitAsyncTask(callingActivity, true, false, this).execute(this.command);
4444
}
4545

4646
@Override

app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public PushOperation setCommand() {
3636
}
3737

3838
@Override
39-
public void execute(boolean finishOnEnd) {
39+
public void execute() {
4040
if (this.provider != null) {
4141
((PushCommand) this.command).setCredentialsProvider(this.provider);
4242
}
43-
new GitAsyncTask(callingActivity, finishOnEnd, false, this).execute(this.command);
43+
new GitAsyncTask(callingActivity, true, false, this).execute(this.command);
4444
}
4545

4646
@Override

app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ public SyncOperation setCommands() {
4848
}
4949

5050
@Override
51-
public void execute(boolean finishOnEnd) {
51+
public void execute() {
5252
if (this.provider != null) {
5353
this.pullCommand.setCredentialsProvider(this.provider);
5454
this.pushCommand.setCredentialsProvider(this.provider);
5555
}
56-
new GitAsyncTask(callingActivity, finishOnEnd, false, this).execute(this.addCommand, this.statusCommand, this.commitCommand, this.pullCommand, this.pushCommand);
56+
new GitAsyncTask(callingActivity, true, false, this).execute(this.addCommand, this.statusCommand, this.commitCommand, this.pullCommand, this.pushCommand);
5757
}
5858

5959
@Override

app/src/main/res/layout/activity_pwdstore.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
55
tools:context=".pwdstore"
6-
android:orientation="vertical"
7-
android:id="@+id/main_activity">
6+
android:orientation="vertical">
87

98
<LinearLayout
109
android:id="@+id/main_layout"

app/src/main/res/values/strings.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,4 @@
197197
<string name="no_repo_selected2">No external repository selected</string>
198198
<string name="send_plaintext_password_to">Send password as plaintext using…</string>
199199
<string name="show_password">Show password</string>
200-
<string name="git_auto_sync_title">Auto Sync on start</string>
201-
<string name="git_auto_sync_summary">Synchronize the repository when starting the application or when resuming.</string>
202200
</resources>

0 commit comments

Comments
 (0)