diff options
Diffstat (limited to 'app/src/main/java')
4 files changed, 86 insertions, 17 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java index 48e33892..07ed9895 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java @@ -5,7 +5,7 @@ import android.app.Fragment; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; @@ -105,7 +105,7 @@ public class PasswordFragment extends Fragment{ recyclerAdapter.clear(); recyclerAdapter.addAll(PasswordRepository.getPasswords(item.getFile())); - ((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); + ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); } else { ((PasswordStore) getActivity()).decryptPassword(item); } @@ -138,7 +138,7 @@ public class PasswordFragment extends Fragment{ recyclerAdapter.clear(); recyclerAdapter.addAll(PasswordRepository.getPasswords()); - ((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false); + ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false); } /** diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index a08e7d88..c788821f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -10,7 +10,7 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.SearchView; import android.util.Log; import android.view.Menu; @@ -29,12 +29,16 @@ import org.eclipse.jgit.api.Git; import java.io.File; -public class PasswordStore extends ActionBarActivity { +public class PasswordStore extends AppCompatActivity { private static final String TAG = "PwdStrAct"; private File currentDir; private SharedPreferences settings; private Activity activity; private PasswordFragment plist; + private AlertDialog selectDestinationDialog; + + private final static int CLONE_REPO_BUTTON = 401; + private final static int NEW_REPO_BUTTON = 402; @Override protected void onCreate(Bundle savedInstanceState) { @@ -65,7 +69,7 @@ public class PasswordStore extends ActionBarActivity { } // uninitialize the repo if the dir does not exist or is absolutely empty - if (!dir.exists() || !dir.isDirectory()) { + if (!dir.exists() || !dir.isDirectory() || FileUtils.listFiles(dir, null, false).isEmpty()) { settings.edit().putBoolean("repository_initialized", false).apply(); } @@ -208,10 +212,12 @@ public class PasswordStore extends ActionBarActivity { } } - public void getClone(View view){ - Intent intent = new Intent(this, GitActivity.class); - intent.putExtra("Operation", GitActivity.REQUEST_CLONE); - startActivityForResult(intent, GitActivity.REQUEST_CLONE); + public void cloneExistingRepository(View view) { + initRepository(CLONE_REPO_BUTTON); + } + + public void createNewRepository(View view) { + initRepository(NEW_REPO_BUTTON); } private void createRepository() { @@ -232,7 +238,7 @@ public class PasswordStore extends ActionBarActivity { checkLocalRepository(); } - public void initRepository(View view) { + public void initializeRepositoryInfo() { final String keyId = settings.getString("openpgp_key_ids", ""); if (keyId != null && keyId.isEmpty()) @@ -267,7 +273,13 @@ public class PasswordStore extends ActionBarActivity { if (settings.getBoolean("repository_initialized", false)) { // do not push the fragment if we already have it - if (fragmentManager.findFragmentByTag("PasswordsList") == null) { + if (fragmentManager.findFragmentByTag("PasswordsList") == null || settings.getBoolean("repo_changed", false)) { + settings.edit().putBoolean("repo_changed", false).apply(); + + // todo move this as it is duplicated upthere! + if (fragmentManager.findFragmentByTag("PasswordsList") != null) { + fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); + } // clean things up if (fragmentManager.findFragmentByTag("ToCloneOrNot") != null) { @@ -425,13 +437,55 @@ public class PasswordStore extends ActionBarActivity { refreshListAdapter(); break; case GitActivity.REQUEST_INIT: - initRepository(getCurrentFocus()); + initializeRepositoryInfo(); break; case GitActivity.REQUEST_PULL: updateListAdapter(); break; + case NEW_REPO_BUTTON: + initializeRepositoryInfo(); + break; + case CLONE_REPO_BUTTON: + Intent intent = new Intent(activity, GitActivity.class); + intent.putExtra("Operation", GitActivity.REQUEST_CLONE); + startActivityForResult(intent, GitActivity.REQUEST_CLONE); + break; } - } } + + protected void initRepository(final int operation) { + new AlertDialog.Builder(this) + .setTitle("Repositiory location") + .setMessage("Select where to create or clone your password repository.") + .setPositiveButton("External", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + settings.edit().putBoolean("git_external", true).apply(); + + if (settings.getString("git_external_repo", null) == null) { + Intent intent = new Intent(activity, UserPreference.class); + intent.putExtra("operation", "git_external"); + startActivityForResult(intent, operation); + } else { + checkLocalRepository(); + } + } + }) + .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: + Intent intent = new Intent(activity, GitActivity.class); + intent.putExtra("Operation", GitActivity.REQUEST_CLONE); + startActivityForResult(intent, GitActivity.REQUEST_CLONE); + break; + } + } + }) + .show(); + } } diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java index fbdc7d3d..00e71ae8 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java @@ -110,10 +110,24 @@ public class UserPreference extends AppCompatActivity { return false; }); - findPreference("pref_select_external").setOnPreferenceClickListener((Preference pref) -> { + final Preference externalRepo = findPreference("pref_select_external"); + externalRepo.setSummary(getPreferenceManager().getSharedPreferences().getString("git_external_repo", "No external repository selected")); + externalRepo.setOnPreferenceClickListener((Preference pref) -> { callingActivity.selectExternalGitRepository(); return true; }); + + Preference.OnPreferenceChangeListener resetRepo = new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object o) { + PasswordRepository.closeRepository(); + getPreferenceManager().getSharedPreferences().edit().putBoolean("repo_changed", true).apply(); + return true; + } + }; + + findPreference("pref_select_external").setOnPreferenceChangeListener(resetRepo); + findPreference("git_external").setOnPreferenceChangeListener(resetRepo); } } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java index b763a275..2d8f2e5a 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java @@ -8,7 +8,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; @@ -34,7 +34,7 @@ import java.util.regex.Pattern; // TODO move the messages to strings.xml -public class GitActivity extends ActionBarActivity { +public class GitActivity extends AppCompatActivity { private static final String TAG = "GitAct"; private Activity activity; @@ -56,6 +56,7 @@ public class GitActivity extends ActionBarActivity { public static final int REQUEST_INIT = 104; public static final int EDIT_SERVER = 105; public static final int REQUEST_SYNC = 106; + public static final int REQUEST_CREATE = 107; @Override protected void onCreate(Bundle savedInstanceState) { |