enable the users to delete the repository

This commit is contained in:
zeapo 2014-12-06 01:19:56 +01:00
parent 1b520cff54
commit 112d71588c
6 changed files with 57 additions and 11 deletions

Binary file not shown.

View file

@ -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 {

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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>

View file

@ -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">