aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Wong <wongma@protonmail.ch>2015-07-16 03:16:25 -0400
committerMatthew Wong <wongma@protonmail.ch>2015-07-16 03:16:25 -0400
commit61ae170f6cef761407216dcf545ebb80410ca023 (patch)
tree3fee90efdc0a76e6b9ae818d8ed9679ee8b6fdf0
parentd03ab8ee3c9585e862435b621edd2360232be083 (diff)
Make the generated public key viewer a dialog instead of fragment and add a "preference" that opens the dialog.
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java69
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.java22
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java4
-rw-r--r--app/src/main/res/layout/fragment_show_ssh_key.xml22
-rw-r--r--app/src/main/res/values/strings.xml5
-rw-r--r--app/src/main/res/xml/preference.xml3
6 files changed, 78 insertions, 47 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java b/app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java
index 17d952ad..dd9ef5ce 100644
--- a/app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java
+++ b/app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java
@@ -1,20 +1,25 @@
package com.zeapo.pwdstore;
-import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
import android.app.Fragment;
import android.app.ProgressDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
+import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@@ -50,14 +55,16 @@ public class SshKeyGen extends AppCompatActivity {
}
// Displays the generated public key .ssh_key.pub
- public static class ShowSshKeyFragment extends Fragment {
+ public static class ShowSshKeyFragment extends DialogFragment {
public ShowSshKeyFragment() {
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.fragment_show_ssh_key, container, false);
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ LayoutInflater inflater = getActivity().getLayoutInflater();
+ final View v = inflater.inflate(R.layout.fragment_show_ssh_key, null);
+ builder.setView(v);
TextView textView = (TextView) v.findViewById(R.id.public_key);
File file = new File(getActivity().getFilesDir() + "/.ssh_key.pub");
@@ -68,14 +75,40 @@ public class SshKeyGen extends AppCompatActivity {
e.printStackTrace();
}
- v.findViewById(R.id.ok_ssh_key).setOnClickListener(new View.OnClickListener() {
+ builder.setPositiveButton(getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override
- public void onClick(View v) {
- getActivity().finish();
+ public void onClick(DialogInterface dialog, int which) {
+ if (getActivity() instanceof SshKeyGen)
+ getActivity().finish();
}
});
- return v;
+ builder.setNegativeButton(getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+
+ }
+ });
+
+ builder.setNeutralButton(getResources().getString(R.string.ssh_keygen_copy), null);
+
+ final AlertDialog ad = builder.setTitle("Your public key").create();
+ ad.setOnShowListener(new DialogInterface.OnShowListener() {
+ @Override
+ public void onShow(DialogInterface dialog) {
+ Button b = ad.getButton(AlertDialog.BUTTON_NEUTRAL);
+ b.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ TextView textView = (TextView) getDialog().findViewById(R.id.public_key);
+ ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
+ ClipData clip = ClipData.newPlainText("public key", textView.getText().toString());
+ clipboard.setPrimaryClip(clip);
+ }
+ });
+ }
+ });
+ return ad;
}
}
@@ -145,8 +178,12 @@ public class SshKeyGen extends AppCompatActivity {
pd.dismiss();
if (e == null) {
Toast.makeText(SshKeyGen.this, "SSH-key generated", Toast.LENGTH_LONG).show();
- getFragmentManager().beginTransaction()
- .replace(android.R.id.content, new ShowSshKeyFragment()).commit();
+ DialogFragment df = new ShowSshKeyFragment();
+ df.show(getFragmentManager(), "public_key");
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putBoolean("use_generated_key", true);
+ editor.apply();
} else {
new AlertDialog.Builder(SshKeyGen.this)
.setTitle("Error while trying to generate the ssh-key")
@@ -168,14 +205,4 @@ public class SshKeyGen extends AppCompatActivity {
public void generate(View view) {
new generateTask().execute(view);
}
-
- // Invoked when 'Copy' button of ShowSshKeyFragment clicked. Copies the
- // displayed public key to the clipboard.
- public void copy (View view) {
- TextView textView = (TextView) findViewById(R.id.public_key);
- ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
- ClipData clip = ClipData.newPlainText("public key", textView.getText().toString());
- clipboard.setPrimaryClip(clip);
- }
-
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
index dc535990..8344e8b3 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
@@ -1,6 +1,7 @@
package com.zeapo.pwdstore;
import android.app.AlertDialog;
+import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -90,6 +91,16 @@ public class UserPreference extends AppCompatActivity {
}
});
+ findPreference("ssh_see_key").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ DialogFragment df = new SshKeyGen.ShowSshKeyFragment();
+ df.show(getFragmentManager(), "public_key");
+ return true;
+ }
+ });
+
+
findPreference("git_server_info").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
@@ -171,6 +182,13 @@ public class UserPreference extends AppCompatActivity {
findPreference("pref_select_external").setOnPreferenceChangeListener(resetRepo);
findPreference("git_external").setOnPreferenceChangeListener(resetRepo);
}
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ final SharedPreferences sharedPreferences = getPreferenceManager().getSharedPreferences();
+ findPreference("ssh_see_key").setEnabled(sharedPreferences.getBoolean("use_generated_key", false));
+ }
}
@Override
@@ -256,6 +274,10 @@ public class UserPreference extends AppCompatActivity {
}
copySshKey(data.getData());
Toast.makeText(this, this.getResources().getString(R.string.ssh_key_success_dialog_title), Toast.LENGTH_LONG).show();
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putBoolean("use_generated_key", false);
+ editor.apply();
setResult(RESULT_OK);
finish();
} catch (IOException e) {
diff --git a/app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java b/app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java
index 0e2b96ef..5dae4d23 100644
--- a/app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java
@@ -58,8 +58,8 @@ public class pwgenDialogFragment extends DialogFragment {
builder.setPositiveButton(getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- TextView edit = (TextView) pwgenDialogFragment.this.getActivity().findViewById(R.id.crypto_password_edit);
- TextView generate = (TextView) pwgenDialogFragment.this.getDialog().findViewById(R.id.passwordText);
+ TextView edit = (TextView) getActivity().findViewById(R.id.crypto_password_edit);
+ TextView generate = (TextView) getDialog().findViewById(R.id.passwordText);
edit.append(generate.getText());
}
});
diff --git a/app/src/main/res/layout/fragment_show_ssh_key.xml b/app/src/main/res/layout/fragment_show_ssh_key.xml
index 6590a98f..e81ae8c4 100644
--- a/app/src/main/res/layout/fragment_show_ssh_key.xml
+++ b/app/src/main/res/layout/fragment_show_ssh_key.xml
@@ -24,27 +24,5 @@
android:text="@string/ssh_keygen_tip"
android:textAppearance="?android:attr/textAppearanceMedium"/>
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="right"
- android:layout_marginRight="16dp"
- android:layout_marginTop="8dp"
- android:orientation="horizontal">
-
- <Button
- android:id="@+id/copy_public_key"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/ssh_keygen_copy"
- android:onClick="copy" />
-
- <Button
- android:id="@+id/ok_ssh_key"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/dialog_ok"/>
- </LinearLayout>
-
</LinearLayout>
</ScrollView> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e746419d..5f97cf51 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -96,8 +96,9 @@
<string name="pref_git_username_title">Username</string>
<string name="pref_git_username_hint">username</string>
<string name="pref_edit_server_info">Edit git server settings</string>
- <string name="pref_ssh_title">Import ssh-key</string>
- <string name="pref_ssh_keygen_title">Generate ssh-key</string>
+ <string name="pref_ssh_title">Import SSH key</string>
+ <string name="pref_ssh_keygen_title">Generate SSH key pair</string>
+ <string name="pref_ssh_see_key_title">View generated public SSH key</string>
<string name="pref_git_delete_repo">Delete repository</string>
<string name="pref_dialog_delete_title">Clear repository</string>
<string name="pref_dialog_delete_msg">Do you want to delete the current password store directory? This will not clear your configuration.</string>
diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml
index e8772616..67217c9d 100644
--- a/app/src/main/res/xml/preference.xml
+++ b/app/src/main/res/xml/preference.xml
@@ -11,6 +11,9 @@
android:key="ssh_keygen"
android:title="@string/pref_ssh_keygen_title" />
<Preference
+ android:key="ssh_see_key"
+ android:title="@string/pref_ssh_see_key_title" />
+ <Preference
android:key="git_delete_repo"
android:summary="Deletes local repository"
android:title="@string/pref_git_delete_repo" />