diff options
Diffstat (limited to 'app/src/main')
3 files changed, 20 insertions, 15 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index aff71d74..b72fa1ca 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -28,6 +28,7 @@ import com.zeapo.pwdstore.utils.PasswordRepository; import org.apache.commons.io.FileUtils; import org.eclipse.jgit.api.CommitCommand; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.lib.Repository; import java.io.File; import java.util.HashSet; @@ -43,6 +44,7 @@ public class PasswordStore extends AppCompatActivity { private final static int CLONE_REPO_BUTTON = 401; private final static int NEW_REPO_BUTTON = 402; + private final static int HOME = 403; @Override protected void onCreate(Bundle savedInstanceState) { @@ -253,15 +255,21 @@ public class PasswordStore extends AppCompatActivity { } private void checkLocalRepository() { - PasswordRepository.initialize(this); - checkLocalRepository(PasswordRepository.getWorkTree()); + Repository repo = PasswordRepository.initialize(this); + if (repo == null) { + Intent intent = new Intent(activity, UserPreference.class); + intent.putExtra("operation", "git_external"); + startActivityForResult(intent, HOME); + } else { + checkLocalRepository(PasswordRepository.getWorkTree()); + } } private void checkLocalRepository(File localDir) { - Log.d("PASS", "Check, dir: " + localDir.getAbsolutePath()); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); - if (settings.getBoolean("repository_initialized", false)) { + if (localDir != null && settings.getBoolean("repository_initialized", false)) { + Log.d("PASS", "Check, dir: " + localDir.getAbsolutePath()); // do not push the fragment if we already have it if (fragmentManager.findFragmentByTag("PasswordsList") == null || settings.getBoolean("repo_changed", false)) { settings.edit().putBoolean("repo_changed", false).apply(); @@ -432,6 +440,9 @@ public class PasswordStore extends AppCompatActivity { case GitActivity.REQUEST_PULL: updateListAdapter(); break; + case HOME: + checkLocalRepository(); + break; case NEW_REPO_BUTTON: initializeRepositoryInfo(); break; diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java index c94f08a6..285f2316 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java @@ -318,7 +318,7 @@ public class UserPreference extends AppCompatActivity { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .edit() .putString("git_external_repo", data.getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR)) - .commit(); + .apply(); } } } 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 4836c41d..aaca0cf1 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java @@ -1,13 +1,10 @@ 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; @@ -117,7 +114,7 @@ public class PasswordRepository { repository = null; } - public static void initialize(Activity callingActivity) { + public static Repository initialize(Activity callingActivity) { File dir = null; SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(callingActivity.getApplicationContext()); @@ -128,12 +125,9 @@ public class PasswordRepository { } 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; + return null; } // uninitialize the repo if the dir does not exist or is absolutely empty @@ -146,7 +140,7 @@ public class PasswordRepository { } // create the repository static variable in PasswordRepository - PasswordRepository.getRepository(new File(dir.getAbsolutePath() + "/.git")); + return PasswordRepository.getRepository(new File(dir.getAbsolutePath() + "/.git")); } public static ArrayList<File> getFilesList(){ |