diff options
author | zeapo <mohamed@zenadi.com> | 2014-12-06 01:19:56 +0100 |
---|---|---|
committer | zeapo <mohamed@zenadi.com> | 2014-12-06 01:19:56 +0100 |
commit | 112d71588c929509c8cb683548ee538466b99f9a (patch) | |
tree | be2b241e6fcb625220720be9057c8800947a2b43 | |
parent | 1b520cff549db8bac3f2904e45dfb2f4961994ae (diff) |
enable the users to delete the repositoryv1.2.0.8
-rw-r--r-- | app/app-release.apk | bin | 2031434 -> 2032354 bytes | |||
-rw-r--r-- | app/build.gradle | 4 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/PasswordStore.java | 28 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/UserPreference.java | 32 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 3 | ||||
-rw-r--r-- | 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 Binary files differindex 40102dda..9f624ea4 100644 --- a/app/app-release.apk +++ b/app/app-release.apk 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 @@ <string name="pref_git_username_hint">username</string> <string name="pref_edit_server_info">Edit git server settings</string> <string name="pref_ssh_title">Import ssh-key</string> + <string name="pref_git_delete_repo">Delete repository</string> + <string name="pref_dialog_delete_title">Clear repository</string> + <string name="pref_dialog_delete_msg">Do you want to delete the current password store directory? This will not clear your configuration.</string> <string name="pref_crypto_title">Crypto</string> <string name="pref_provider_title">Select OpenPGP Provider!</string> <string name="pref_provider_account_title">Set your OpenPGP account</string> 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 @@ <PreferenceCategory android:title="@string/pref_git_title"> <Preference android:title="@string/pref_edit_server_info" android:key="git_server_info"/> <Preference android:title="@string/pref_ssh_title" android:key="ssh_key" /> + <Preference android:title="@string/pref_git_delete_repo" android:key="git_delete_repo"/> </PreferenceCategory> <PreferenceCategory android:title="@string/pref_crypto_title"> |