fix #100 where passwords were not copied if we didn't show them

This commit is contained in:
Mohamed Zenadi 2015-07-19 00:53:07 +02:00
parent 608f61b605
commit eb65c2283f

View File

@ -213,9 +213,20 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
public class DelayShow extends AsyncTask<Void, Integer, Boolean> { public class DelayShow extends AsyncTask<Void, Integer, Boolean> {
ProgressBar pb; ProgressBar pb;
int current, SHOW_TIME;
boolean showPassword;
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
try {
SHOW_TIME = Integer.parseInt(settings.getString("general_show_time", "45"));
} catch (NumberFormatException e) {
SHOW_TIME = 45;
}
current = 0;
showPassword = settings.getBoolean("show_password", true);
if (showPassword) {
LinearLayout container = (LinearLayout) findViewById(R.id.crypto_container); LinearLayout container = (LinearLayout) findViewById(R.id.crypto_container);
container.setVisibility(View.VISIBLE); container.setVisibility(View.VISIBLE);
@ -225,34 +236,27 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
((LinearLayout) findViewById(R.id.crypto_extra_show_layout)).setVisibility(View.VISIBLE); ((LinearLayout) findViewById(R.id.crypto_extra_show_layout)).setVisibility(View.VISIBLE);
this.pb = (ProgressBar) findViewById(R.id.pbLoading); 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); this.pb.setMax(SHOW_TIME);
} }
}
@Override @Override
protected Boolean doInBackground(Void... params) { protected Boolean doInBackground(Void... params) {
while (this.pb.getProgress() < this.pb.getMax()) { while (current < SHOW_TIME) {
SystemClock.sleep(1000); SystemClock.sleep(1000);
publishProgress(this.pb.getProgress() + 1); current++;
if (showPassword) {
publishProgress(current);
}
} }
return true; return true;
} }
@Override @Override
protected void onPostExecute(Boolean b) { protected void onPostExecute(Boolean b) {
ClipData clip = ClipData.newPlainText("pgp_handler_result_pm", "MyPasswordIsDaBest!"); ClipData clip = ClipData.newPlainText("pgp_handler_result_pm", "MyPasswordIsDaBest!");
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
if (showPassword) {
//clear password //clear password
((TextView) findViewById(R.id.crypto_password_show)).setText(""); ((TextView) findViewById(R.id.crypto_password_show)).setText("");
((TextView) findViewById(R.id.crypto_extra_show)).setText(""); ((TextView) findViewById(R.id.crypto_extra_show)).setText("");
@ -261,12 +265,15 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
activity.setResult(RESULT_CANCELED); activity.setResult(RESULT_CANCELED);
activity.finish(); activity.finish();
} }
}
@Override @Override
protected void onProgressUpdate(Integer... values) { protected void onProgressUpdate(Integer... values) {
if (showPassword) {
this.pb.setProgress(values[0]); this.pb.setProgress(values[0]);
} }
}
} }
@ -327,6 +334,8 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
if (showPassword) { if (showPassword) {
findViewById(R.id.crypto_container).setVisibility(View.VISIBLE); findViewById(R.id.crypto_container).setVisibility(View.VISIBLE);
}
Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf"); Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf");
String[] passContent = os.toString("UTF-8").split("\n"); String[] passContent = os.toString("UTF-8").split("\n");
((TextView) findViewById(R.id.crypto_password_show)) ((TextView) findViewById(R.id.crypto_password_show))
@ -341,14 +350,16 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
((TextView) findViewById(R.id.crypto_extra_show)) ((TextView) findViewById(R.id.crypto_extra_show))
.setText(extraContent); .setText(extraContent);
} }
new DelayShow().execute();
} else {
activity.setResult(RESULT_CANCELED);
activity.finish();
}
if (settings.getBoolean("copy_on_decrypt", true)) { if (settings.getBoolean("copy_on_decrypt", true)) {
copyToClipBoard(); copyToClipBoard();
} }
new DelayShow().execute();
if (!showPassword) {
activity.setResult(RESULT_CANCELED);
activity.finish();
}
} else { } else {
Log.d("PGPHANDLER", "Error message after decrypt : " + os.toString()); Log.d("PGPHANDLER", "Error message after decrypt : " + os.toString());
} }