diff options
Diffstat (limited to 'app/src')
5 files changed, 115 insertions, 78 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java index 7d54edf2..fed557fa 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 57386c00..aff71d74 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 6c945598..c94f08a6 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java @@ -123,6 +123,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/crypto/PgpHandler.java b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java index 2d007618..ca5ab33d 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java @@ -213,59 +213,66 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne public class DelayShow extends AsyncTask<Void, Integer, Boolean> { ProgressBar pb; + int current, SHOW_TIME; + boolean showPassword; @Override protected void onPreExecute() { - LinearLayout container = (LinearLayout) findViewById(R.id.crypto_container); - container.setVisibility(View.VISIBLE); - - TextView extraText = (TextView) findViewById(R.id.crypto_extra_show); - - if (extraText.getText().length() != 0) - ((LinearLayout) findViewById(R.id.crypto_extra_show_layout)).setVisibility(View.VISIBLE); - - this.pb = (ProgressBar) findViewById(R.id.pbLoading); - - // Make Show Time a user preference - // kLeZ: Changed to match the default for pass - SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(container.getContext()); - int SHOW_TIME; try { SHOW_TIME = Integer.parseInt(settings.getString("general_show_time", "45")); } catch (NumberFormatException e) { SHOW_TIME = 45; } - this.pb.setMax(SHOW_TIME); + current = 0; + + showPassword = settings.getBoolean("show_password", true); + if (showPassword) { + LinearLayout container = (LinearLayout) findViewById(R.id.crypto_container); + container.setVisibility(View.VISIBLE); + + TextView extraText = (TextView) findViewById(R.id.crypto_extra_show); + + if (extraText.getText().length() != 0) + ((LinearLayout) findViewById(R.id.crypto_extra_show_layout)).setVisibility(View.VISIBLE); + + this.pb = (ProgressBar) findViewById(R.id.pbLoading); + this.pb.setMax(SHOW_TIME); + } } @Override protected Boolean doInBackground(Void... params) { - while (this.pb.getProgress() < this.pb.getMax()) { + while (current < SHOW_TIME) { SystemClock.sleep(1000); - publishProgress(this.pb.getProgress() + 1); + current++; + if (showPassword) { + publishProgress(current); + } } return true; } @Override protected void onPostExecute(Boolean b) { - ClipData clip = ClipData.newPlainText("pgp_handler_result_pm", "MyPasswordIsDaBest!"); clipboard.setPrimaryClip(clip); - - //clear password - ((TextView) findViewById(R.id.crypto_password_show)).setText(""); - ((TextView) findViewById(R.id.crypto_extra_show)).setText(""); - findViewById(R.id.crypto_extra_show_layout).setVisibility(View.INVISIBLE); - findViewById(R.id.crypto_container).setVisibility(View.INVISIBLE); - activity.setResult(RESULT_CANCELED); - activity.finish(); + if (showPassword) { + //clear password + ((TextView) findViewById(R.id.crypto_password_show)).setText(""); + ((TextView) findViewById(R.id.crypto_extra_show)).setText(""); + findViewById(R.id.crypto_extra_show_layout).setVisibility(View.INVISIBLE); + findViewById(R.id.crypto_container).setVisibility(View.INVISIBLE); + activity.setResult(RESULT_CANCELED); + activity.finish(); + } } @Override protected void onProgressUpdate(Integer... values) { - this.pb.setProgress(values[0]); + if (showPassword) { + this.pb.setProgress(values[0]); + } } } @@ -327,28 +334,32 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne if (showPassword) { findViewById(R.id.crypto_container).setVisibility(View.VISIBLE); - Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf"); - String[] passContent = os.toString("UTF-8").split("\n"); - ((TextView) findViewById(R.id.crypto_password_show)) + } + + Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf"); + String[] passContent = os.toString("UTF-8").split("\n"); + ((TextView) findViewById(R.id.crypto_password_show)) + .setTypeface(monoTypeface); + ((TextView) findViewById(R.id.crypto_password_show)) + .setText(passContent[0]); + + String extraContent = os.toString("UTF-8").replaceFirst(".*\n", ""); + if (extraContent.length() != 0) { + ((TextView) findViewById(R.id.crypto_extra_show)) .setTypeface(monoTypeface); - ((TextView) findViewById(R.id.crypto_password_show)) - .setText(passContent[0]); - - String extraContent = os.toString("UTF-8").replaceFirst(".*\n", ""); - if (extraContent.length() != 0) { - ((TextView) findViewById(R.id.crypto_extra_show)) - .setTypeface(monoTypeface); - ((TextView) findViewById(R.id.crypto_extra_show)) - .setText(extraContent); - } - new DelayShow().execute(); - } else { - activity.setResult(RESULT_CANCELED); - activity.finish(); + ((TextView) findViewById(R.id.crypto_extra_show)) + .setText(extraContent); } + if (settings.getBoolean("copy_on_decrypt", true)) { copyToClipBoard(); } + + new DelayShow().execute(); + if (!showPassword) { + activity.setResult(RESULT_CANCELED); + activity.finish(); + } } else { Log.d("PGPHANDLER", "Error message after decrypt : " + os.toString()); } 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()); } |