From 112d71588c929509c8cb683548ee538466b99f9a Mon Sep 17 00:00:00 2001 From: zeapo Date: Sat, 6 Dec 2014 01:19:56 +0100 Subject: enable the users to delete the repository --- app/app-release.apk | Bin 2031434 -> 2032354 bytes app/build.gradle | 4 +-- .../java/com/zeapo/pwdstore/PasswordStore.java | 28 ++++++++++++------ .../java/com/zeapo/pwdstore/UserPreference.java | 32 +++++++++++++++++++++ app/src/main/res/values/strings.xml | 3 ++ app/src/main/res/xml/preference.xml | 1 + 6 files changed, 57 insertions(+), 11 deletions(-) diff --git a/app/app-release.apk b/app/app-release.apk index 40102dda..9f624ea4 100644 Binary files a/app/app-release.apk and b/app/app-release.apk differ diff --git a/app/build.gradle b/app/build.gradle index ac8e340e..539108b8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "com.zeapo.pwdstore" minSdkVersion 15 targetSdkVersion 21 - versionCode 26 - versionName "1.2.0.7" + versionCode 27 + versionName "1.2.0.8" } compileOptions { 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; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5f0db2a8..2f812e91 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -95,6 +95,9 @@ username Edit git server settings Import ssh-key + Delete repository + Clear repository + Do you want to delete the current password store directory? This will not clear your configuration. Crypto Select OpenPGP Provider! Set your OpenPGP account diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index 848a10ad..1ad898a8 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -3,6 +3,7 @@ + -- cgit v1.2.3