diff options
Diffstat (limited to 'app/src/main/java')
3 files changed, 33 insertions, 53 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index 40667564..c56df7b4 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -24,7 +24,6 @@ import com.zeapo.pwdstore.utils.PasswordItem; import com.zeapo.pwdstore.utils.PasswordRecyclerAdapter; import com.zeapo.pwdstore.utils.PasswordRepository; -import org.apache.commons.io.FileUtils; import org.eclipse.jgit.api.CommitCommand; import org.eclipse.jgit.api.Git; @@ -191,25 +190,14 @@ public class PasswordStore extends ActionBarActivity { } private void createRepository() { - final String keyId = settings.getString("openpgp_key_ids", ""); +// final String keyId = settings.getString("openpgp_key_ids", ""); File localDir = new File(getFilesDir() + "/store/"); localDir.mkdir(); try { PasswordRepository.createRepository(localDir); - // we take only the first key-id, we have to think about how to handle multiple keys, and why should we do that... - // also, for compatibility use short-version of the key-id - FileUtils.writeStringToFile(new File(localDir.getAbsolutePath() + "/.gpg-id"), - keyId.substring(keyId.length() - 8)); - - Git git = new Git(PasswordRepository.getRepository(new File(""))); - GitAsyncTask tasks = new GitAsyncTask(this, false, false, CommitCommand.class); - tasks.execute( - git.add().addFilepattern("."), - git.commit().setMessage(R.string.initialization_commit_text + keyId) - ); - settings.edit().putBoolean("repository_initialized", true).commit(); + settings.edit().putBoolean("repository_initialized", true).apply(); } catch (Exception e) { e.printStackTrace(); localDir.delete(); @@ -221,7 +209,7 @@ public class PasswordStore extends ActionBarActivity { public void initRepository(View view) { final String keyId = settings.getString("openpgp_key_ids", ""); - if (keyId.isEmpty()) + if (keyId != null && keyId.isEmpty()) new AlertDialog.Builder(this) .setMessage(this.getResources().getString(R.string.key_dialog_text)) .setPositiveButton(this.getResources().getString(R.string.dialog_positive), new DialogInterface.OnClickListener() { @@ -239,29 +227,7 @@ public class PasswordStore extends ActionBarActivity { }) .show(); - else { - new AlertDialog.Builder(this) - .setMessage(this.getResources().getString(R.string.connection_dialog_text)) - .setPositiveButton("ssh-key", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - settings.edit().putString("git_remote_auth", "ssh-key").apply(); - createRepository(); - } - }) - .setNegativeButton("username/password", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - settings.edit().putString("git_remote_auth", "username/password").apply(); - createRepository(); - } - }) - .setCancelable(false) - - - .show(); - - } + createRepository(); } private void checkLocalRepository() { diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java index becf44ea..82c278df 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java @@ -8,7 +8,7 @@ import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import android.widget.Toast; @@ -18,15 +18,17 @@ import com.zeapo.pwdstore.utils.PasswordRepository; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; +import org.openintents.openpgp.util.OpenPgpKeyPreference; import java.io.File; import java.io.IOException; import java.io.InputStream; -public class UserPreference extends ActionBarActivity implements Preference.OnPreferenceClickListener { +public class UserPreference extends AppCompatActivity implements Preference.OnPreferenceClickListener { private final static int IMPORT_SSH_KEY = 1; private final static int IMPORT_PGP_KEY = 2; private final static int EDIT_GIT_INFO = 3; + private OpenPgpKeyPreference mKey; public static class PrefsFragment extends PreferenceFragment { @Override @@ -34,12 +36,24 @@ public class UserPreference extends ActionBarActivity implements Preference.OnPr super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preference); - Preference keyPref = findPreference("openpgp_key_id"); - keyPref.setSummary(getPreferenceManager().getSharedPreferences().getString("openpgp_key_ids", "No key selected")); - keyPref.setOnPreferenceClickListener((UserPreference) getActivity()); +// Preference keyPref = findPreference("openpgp_key_id"); +// keyPref.setSummary(getPreferenceManager().getSharedPreferences().getString("openpgp_key_ids", "No key selected")); +// keyPref.setOnPreferenceClickListener((UserPreference) getActivity()); findPreference("ssh_key").setOnPreferenceClickListener((UserPreference) getActivity()); findPreference("git_server_info").setOnPreferenceClickListener((UserPreference) getActivity()); findPreference("git_delete_repo").setOnPreferenceClickListener((UserPreference) getActivity()); +// ((UserPreference) getActivity()).mKey = (OpenPgpKeyPreference) findPreference("openpgp_key"); + +// if (getPreferenceManager().getSharedPreferences().getString("openpgp_provider_list", null) != null) +// ((UserPreference) getActivity()).mKey.setOpenPgpProvider(getPreferenceManager().getSharedPreferences().getString("openpgp_provider_list", "")); + +// findPreference("openpgp_provider_list").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { +// @Override +// public boolean onPreferenceChange(Preference preference, Object o) { +// ((UserPreference) getActivity()).mKey.setOpenPgpProvider((String) o); +// return false; +// } +// }); } } @@ -181,6 +195,14 @@ public class UserPreference extends ActionBarActivity implements Preference.OnPr } break; + case OpenPgpKeyPreference.REQUEST_CODE_KEY_PREFERENCE: + { + if (mKey.handleOnActivityResult(requestCode, resultCode, data)) { + // handled by OpenPgpKeyPreference + return; + } + } + break; default: break; } 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 2f638847..2e676b46 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java @@ -14,7 +14,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.SystemClock; import android.preference.PreferenceManager; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.util.Log; import android.view.Menu; @@ -47,7 +47,7 @@ import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.ArrayList; -public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConnection.OnBound{ +public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConnection.OnBound{ private OpenPgpServiceConnection mServiceConnection; @@ -422,21 +422,13 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne public void getKeyIds(Intent data) { - accountName = settings.getString("openpgp_account_name", ""); - if (accountName.isEmpty()) - showToast(this.getResources().getString(R.string.name_settings_toast_text)); - data.setAction(OpenPgpApi.ACTION_GET_KEY_IDS); - data.putExtra(OpenPgpApi.EXTRA_USER_IDS, new String[]{accountName.isEmpty() ? "default" : accountName}); - OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService()); - api.executeApiAsync(data, null, null, new PgpCallback(false, null, PgpHandler.REQUEST_CODE_GET_KEY_IDS)); } public void decryptAndVerify(Intent data) { data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY); - data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); try { InputStream is = FileUtils.openInputStream(new File(getIntent().getExtras().getString("FILE_PATH"))); |