summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorzeapo <mohamed@zenadi.com>2014-12-06 01:19:56 +0100
committerzeapo <mohamed@zenadi.com>2014-12-06 01:19:56 +0100
commit112d71588c929509c8cb683548ee538466b99f9a (patch)
treebe2b241e6fcb625220720be9057c8800947a2b43 /app/src/main/java
parent1b520cff549db8bac3f2904e45dfb2f4961994ae (diff)
enable the users to delete the repositoryv1.2.0.8
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.java28
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.java32
2 files changed, 51 insertions, 9 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
index e932584f..860fc63f 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
@@ -267,19 +267,19 @@ public class PasswordStore extends ActionBarActivity {
}
private void checkLocalRepository(File localDir) {
- Log.d("PASS", localDir.getAbsolutePath());
+ Log.d("PASS", "Check, dir: " + localDir.getAbsolutePath());
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
- // if we are coming back from gpg do not anything
- if (this.leftActivity) {
- this.leftActivity = false;
- return;
- }
-
int status = 0;
if (localDir.exists()) {
+ // if we are coming back from gpg do not anything
+ if (this.leftActivity) {
+ this.leftActivity = false;
+ return;
+ }
+
File[] folders = localDir.listFiles();
status = folders.length;
@@ -291,10 +291,15 @@ public class PasswordStore extends ActionBarActivity {
// either the repo is empty or it was not correctly cloned
switch (status) {
case 0:
- if(!localDir.equals(PasswordRepository.getWorkTree()))
+ if(!localDir.equals(PasswordRepository.getWorkTree()) && localDir.exists())
break;
PasswordRepository.setInitialized(false);
+ // if we still have the pass list (after deleting for instance) remove it
+ if (fragmentManager.findFragmentByTag("PasswordsList") != null) {
+ fragmentManager.popBackStack();
+ }
+
ToCloneOrNot cloneFrag = new ToCloneOrNot();
fragmentTransaction.replace(R.id.main_layout, cloneFrag, "ToCloneOrNot");
fragmentTransaction.commit();
@@ -302,6 +307,12 @@ public class PasswordStore extends ActionBarActivity {
default:
if (fragmentManager.findFragmentByTag("PasswordsList") == null) {
+
+ // clean things up
+ if (fragmentManager.findFragmentByTag("ToCloneOrNot") != null) {
+ fragmentManager.popBackStack();
+ }
+
PasswordRepository.setInitialized(true);
plist = new PasswordFragment();
Bundle args = new Bundle();
@@ -315,7 +326,6 @@ public class PasswordStore extends ActionBarActivity {
fragmentTransaction.commit();
}
}
-
this.leftActivity = false;
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
index efd2f6a7..ff81632c 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
@@ -22,6 +22,7 @@ import com.zeapo.pwdstore.utils.PasswordRepository;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.eclipse.jgit.api.CloneCommand;
+import org.eclipse.jgit.lib.Repository;
import java.io.File;
import java.io.FileNotFoundException;
@@ -44,6 +45,7 @@ public class UserPreference extends ActionBarActivity implements Preference.OnPr
findPreference("openpgp_key_id").setOnPreferenceClickListener((UserPreference) getActivity());
findPreference("ssh_key").setOnPreferenceClickListener((UserPreference) getActivity());
findPreference("git_server_info").setOnPreferenceClickListener((UserPreference) getActivity());
+ findPreference("git_delete_repo").setOnPreferenceClickListener((UserPreference) getActivity());
}
}
@@ -117,6 +119,36 @@ public class UserPreference extends ActionBarActivity implements Preference.OnPr
startActivityForResult(intent, EDIT_GIT_INFO);
}
break;
+ case "git_delete_repo":
+ {
+ new AlertDialog.Builder(this).
+ setTitle(R.string.pref_dialog_delete_title).
+ setMessage(R.string.pref_dialog_delete_msg).
+ setCancelable(false).
+ setPositiveButton(R.string.dialog_delete,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ try {
+ FileUtils.deleteDirectory(PasswordRepository.getWorkTree());
+ } catch (Exception e) {
+ //This is what happens when jgit fails :(
+ //TODO Handle the diffent cases of exceptions
+ }
+
+ dialog.cancel();
+ finish();
+ }
+ }
+ ).
+ setNegativeButton(R.string.dialog_do_not_delete,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ }
+ ).
+ show();
+ }
}
return true;
}