From 4975dfdcfaef453f564eb2dadca7580e47a3d2a6 Mon Sep 17 00:00:00 2001 From: Mohamed Zenadi Date: Sun, 3 May 2015 13:10:53 +0200 Subject: force the selection of directory until the welcome screen is implemented --- .../java/com/zeapo/pwdstore/PasswordStore.java | 13 ++++++----- .../java/com/zeapo/pwdstore/UserPreference.java | 25 ++++++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index 146b9906..a08e7d88 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -50,16 +50,19 @@ public class PasswordStore extends ActionBarActivity { File dir = null; if (settings.getBoolean("git_external", false)) { - if (settings.getString("git_external_repo", null) == null) - { - // todo: show the main screen - } else { + if (settings.getString("git_external_repo", null) != null) { dir = new File(settings.getString("git_external_repo", null)); } } else { dir = new File(getFilesDir() + "/store"); } - assert dir != null; + // 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()) { diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java index 2280019d..fbdc7d3d 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java @@ -111,11 +111,7 @@ public class UserPreference extends AppCompatActivity { }); findPreference("pref_select_external").setOnPreferenceClickListener((Preference pref) -> { - Intent intent = new Intent(callingActivity, DirectoryChooserActivity.class); - intent.putExtra(DirectoryChooserActivity.EXTRA_NEW_DIR_NAME, - "passwordstore"); - - startActivityForResult(intent, SELECT_GIT_DIRECTORY); + callingActivity.selectExternalGitRepository(); return true; }); } @@ -125,8 +121,15 @@ public class UserPreference extends AppCompatActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getIntent() != null) { - if ((getIntent().getStringExtra("operation") != null) && (getIntent().getStringExtra("operation").equals("get_ssh_key"))) { - getSshKey(); + if (getIntent().getStringExtra("operation") != null) { + switch (getIntent().getStringExtra("operation")) { + case "get_ssh_key": + getSshKey(); + break; + case "git_external": + selectExternalGitRepository(); + break; + } } } @@ -136,6 +139,14 @@ public class UserPreference extends AppCompatActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } + public void selectExternalGitRepository() { + Intent intent = new Intent(this, DirectoryChooserActivity.class); + intent.putExtra(DirectoryChooserActivity.EXTRA_NEW_DIR_NAME, + "passwordstore"); + + startActivityForResult(intent, SELECT_GIT_DIRECTORY); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will -- cgit v1.2.3