summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java1
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.java54
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.java1
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java38
4 files changed, 60 insertions, 34 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
index 07ed9895..6bc24a8c 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
@@ -54,7 +54,6 @@ public class PasswordFragment extends Fragment{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
String path = getArguments().getString("Path");
settings = PreferenceManager.getDefaultSharedPreferences(getActivity());
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
index 5562f0b9..79a95c0a 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
@@ -198,7 +198,9 @@ public class PasswordStore extends AppCompatActivity {
}
private void createRepository() {
-// final String keyId = settings.getString("openpgp_key_ids", "");
+ if (!PasswordRepository.isInitialized()) {
+ PasswordRepository.initialize(this);
+ }
File localDir = PasswordRepository.getWorkTree();
@@ -251,35 +253,7 @@ public class PasswordStore extends AppCompatActivity {
}
private void checkLocalRepository() {
- File dir = null;
-
- if (settings.getBoolean("git_external", false)) {
- if (settings.getString("git_external_repo", null) != null) {
- dir = new File(settings.getString("git_external_repo", null));
- }
- } else {
- dir = new File(getFilesDir() + "/store");
- }
- // temp for debug
- if (dir == null) {
- Intent intent = new Intent(this, UserPreference.class);
- intent.putExtra("operation", "git_external");
- startActivity(intent);
- return;
- }
-
- // uninitialize the repo if the dir does not exist or is absolutely empty
- if (!dir.exists() || !dir.isDirectory() || FileUtils.listFiles(dir, null, false).isEmpty()) {
- settings.edit().putBoolean("repository_initialized", false).apply();
- }
-
- if (!PasswordRepository.getPasswords(dir).isEmpty()) {
- settings.edit().putBoolean("repository_initialized", true).apply();
- }
-
- // create the repository static variable in PasswordRepository
- PasswordRepository.getRepository(new File(dir.getAbsolutePath() + "/.git"));
-
+ PasswordRepository.initialize(this);
checkLocalRepository(PasswordRepository.getWorkTree());
}
@@ -287,7 +261,6 @@ public class PasswordStore extends AppCompatActivity {
Log.d("PASS", "Check, dir: " + localDir.getAbsolutePath());
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
-
if (settings.getBoolean("repository_initialized", false)) {
// do not push the fragment if we already have it
if (fragmentManager.findFragmentByTag("PasswordsList") == null || settings.getBoolean("repo_changed", false)) {
@@ -483,6 +456,8 @@ public class PasswordStore extends AppCompatActivity {
}
protected void initRepository(final int operation) {
+ PasswordRepository.closeRepository();
+
new AlertDialog.Builder(this)
.setTitle("Repositiory location")
.setMessage("Select where to create or clone your password repository.")
@@ -495,19 +470,32 @@ public class PasswordStore extends AppCompatActivity {
intent.putExtra("operation", "git_external");
startActivityForResult(intent, operation);
} else {
- PasswordRepository.closeRepository();
- checkLocalRepository();
+ switch (operation) {
+ case NEW_REPO_BUTTON:
+ initializeRepositoryInfo();
+ break;
+ case CLONE_REPO_BUTTON:
+ PasswordRepository.initialize(PasswordStore.this);
+
+ Intent intent = new Intent(activity, GitActivity.class);
+ intent.putExtra("Operation", GitActivity.REQUEST_CLONE);
+ startActivityForResult(intent, GitActivity.REQUEST_CLONE);
+ break;
+ }
}
}
})
.setNegativeButton("Internal", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
settings.edit().putBoolean("git_external", false).apply();
+
switch (operation) {
case NEW_REPO_BUTTON:
initializeRepositoryInfo();
break;
case CLONE_REPO_BUTTON:
+ PasswordRepository.initialize(PasswordStore.this);
+
Intent intent = new Intent(activity, GitActivity.class);
intent.putExtra("Operation", GitActivity.REQUEST_CLONE);
startActivityForResult(intent, GitActivity.REQUEST_CLONE);
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
index ff6f5048..e2b3de9a 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
@@ -104,6 +104,7 @@ public class UserPreference extends AppCompatActivity {
public void onClick(DialogInterface dialogInterface, int i) {
try {
FileUtils.cleanDirectory(PasswordRepository.getWorkTree());
+ PasswordRepository.closeRepository();
} catch (Exception e) {
//TODO Handle the diffent cases of exceptions
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java
index 245d9604..4836c41d 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java
@@ -1,7 +1,13 @@
package com.zeapo.pwdstore.utils;
+import android.app.Activity;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
import android.util.Log;
+import com.zeapo.pwdstore.UserPreference;
+
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.eclipse.jgit.api.Git;
@@ -111,6 +117,38 @@ public class PasswordRepository {
repository = null;
}
+ public static void initialize(Activity callingActivity) {
+ File dir = null;
+ SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(callingActivity.getApplicationContext());
+
+ if (settings.getBoolean("git_external", false)) {
+ if (settings.getString("git_external_repo", null) != null) {
+ dir = new File(settings.getString("git_external_repo", null));
+ }
+ } else {
+ dir = new File(callingActivity.getFilesDir() + "/store");
+ }
+ // temp for debug
+ if (dir == null) {
+ Intent intent = new Intent(callingActivity, UserPreference.class);
+ intent.putExtra("operation", "git_external");
+ callingActivity.startActivity(intent);
+ return;
+ }
+
+ // uninitialize the repo if the dir does not exist or is absolutely empty
+ if (!dir.exists() || !dir.isDirectory() || FileUtils.listFiles(dir, null, false).isEmpty()) {
+ settings.edit().putBoolean("repository_initialized", false).apply();
+ }
+
+ if (!PasswordRepository.getPasswords(dir).isEmpty()) {
+ settings.edit().putBoolean("repository_initialized", true).apply();
+ }
+
+ // create the repository static variable in PasswordRepository
+ PasswordRepository.getRepository(new File(dir.getAbsolutePath() + "/.git"));
+ }
+
public static ArrayList<File> getFilesList(){
return getFilesList(repository.getWorkTree());
}