-
-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Features for disappearing prompt and MasterPassword Lock Editing Conn… #480
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
import android.content.ContextWrapper; | ||
import android.content.DialogInterface; | ||
import android.content.DialogInterface.OnClickListener; | ||
import android.content.DialogInterface.OnShowListener; | ||
import android.widget.Button; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.content.SharedPreferences.Editor; | ||
|
@@ -39,6 +41,7 @@ | |
import android.graphics.Bitmap; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.os.CountDownTimer; | ||
import android.os.Message; | ||
import android.text.ClipboardManager; | ||
import android.text.Html; | ||
|
@@ -58,6 +61,7 @@ | |
import com.google.android.play.core.review.ReviewManager; | ||
import com.google.android.play.core.review.ReviewManagerFactory; | ||
import com.undatech.opaque.ConnectionSetupActivity; | ||
import com.undatech.opaque.RemoteClientLibConstants; | ||
import com.undatech.remoteClientUi.R; | ||
|
||
import net.sqlcipher.database.SQLiteDatabase; | ||
|
@@ -79,6 +83,8 @@ | |
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.UUID; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.Locale; | ||
|
||
public class Utils { | ||
private final static String TAG = "Utils"; | ||
|
@@ -137,7 +143,7 @@ public static void showErrorMessage(Context _context, String message) { | |
public void onClick(DialogInterface dialog, int which) { | ||
dialog.dismiss(); | ||
} | ||
}); | ||
}, null); | ||
} | ||
|
||
public static void showFatalErrorMessage(final Context _context, String message) { | ||
|
@@ -150,10 +156,50 @@ public void onClick(DialogInterface dialog, int which) { | |
Utils.justFinish(activity); | ||
} | ||
} | ||
}, null); | ||
} | ||
|
||
public static void showFatalErrorMessageTimer(final Context _context, String message) { | ||
showMessage(_context, _context.getString(R.string.error) + "!", message, android.R.drawable.ic_dialog_alert, new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
dialog.dismiss(); | ||
Activity activity = Utils.getActivity(_context); | ||
if (activity != null) { | ||
Utils.justFinish(activity); | ||
} | ||
} | ||
}, new DialogInterface.OnShowListener() { | ||
private static final int AUTO_DISMISS_MILLIS = RemoteClientLibConstants.ON_SHOW_LISTENER_TIMER; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just import ON_SHOW_LISTENER_TIMER from RemoteClientLibConstants? |
||
@Override | ||
public void onShow(final DialogInterface dialog) { | ||
final Button defaultButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); | ||
final CharSequence negativeButtonText = defaultButton.getText(); | ||
new CountDownTimer(AUTO_DISMISS_MILLIS, RemoteClientLibConstants.ON_SHOW_LISTENER_CHECK_INTERVAL) { | ||
@Override | ||
public void onTick(long millisUntilFinished) { | ||
defaultButton.setText(String.format( | ||
Locale.getDefault(), "%s (%d)", | ||
negativeButtonText, | ||
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) + 1 //add one so it never displays zero | ||
)); | ||
} | ||
@Override | ||
public void onFinish() { | ||
if (((AlertDialog) dialog).isShowing()) { | ||
dialog.dismiss(); | ||
Activity activity = Utils.getActivity(_context); | ||
if (activity != null) { | ||
Utils.justFinish(activity); | ||
} | ||
} | ||
} | ||
}.start(); | ||
} | ||
}); | ||
} | ||
|
||
public static void showMessage(Context _context, String title, String message, int icon, DialogInterface.OnClickListener ackHandler) { | ||
public static void showMessage(Context _context, String title, String message, int icon, DialogInterface.OnClickListener ackHandler, DialogInterface.OnShowListener showHandler) { | ||
try { | ||
if (alertDialog != null && alertDialog.isShowing() && !isContextActivityThatIsFinishing(_context)) { | ||
alertDialog.dismiss(); | ||
|
@@ -166,6 +212,9 @@ public static void showMessage(Context _context, String title, String message, i | |
builder.setIcon(icon); | ||
if (!(alertDialog != null && alertDialog.isShowing()) && !isContextActivityThatIsFinishing(_context)) { | ||
alertDialog = builder.create(); | ||
if ( showHandler != null ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove spacing around parentheses. |
||
alertDialog.setOnShowListener(showHandler); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setOnShowListener shows its parameter is nullable, so maybe you can just pass showHandler even if it's null? |
||
} | ||
alertDialog.show(); | ||
} | ||
} catch (IllegalArgumentException e) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
import android.widget.Button; | ||
import android.widget.CheckBox; | ||
import android.widget.EditText; | ||
import android.widget.Switch; | ||
import android.widget.TextView; | ||
|
||
import androidx.fragment.app.DialogFragment; | ||
|
@@ -68,7 +69,7 @@ public class GetTextFragment extends DialogFragment { | |
public static final String DIALOG_ID_GET_OPAQUE_OTP_CODE = "DIALOG_ID_GET_OPAQUE_OTP_CODE"; | ||
|
||
public interface OnFragmentDismissedListener { | ||
void onTextObtained(String dialogId, String[] obtainedStrings, boolean dialogCancelled, boolean save); | ||
void onTextObtained(String dialogId, String[] obtainedStrings, boolean dialogCancelled, boolean save, boolean[] obtainedBools); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please name obtainedBools vs obtainedBooleans consistently. |
||
} | ||
|
||
private class TextMatcher implements TextWatcher { | ||
|
@@ -90,6 +91,7 @@ public void afterTextChanged(Editable arg0) {} | |
private EditText textBox; | ||
private EditText textBox2; | ||
private EditText textBox3; | ||
private Switch switch1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this switch numbered? Is there a specific function that it fulfills or is its function generic? If there is a specific function, let's please name it more specifically! |
||
private Button buttonConfirm; | ||
private Button buttonCancel; | ||
private CheckBox checkboxKeepPassword; | ||
|
@@ -100,7 +102,7 @@ public void afterTextChanged(Editable arg0) {} | |
private String t2; | ||
private String t3; | ||
private boolean keepPassword; | ||
|
||
private boolean sw1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are keeping the switch name, let's make this variable named with a full word. |
||
private int dialogType = 0; | ||
private int messageNum = 0; | ||
private int errorNum = 0; | ||
|
@@ -111,7 +113,8 @@ public GetTextFragment () { | |
public static GetTextFragment newInstance(String dialogId, String title, | ||
OnFragmentDismissedListener dismissalListener, | ||
int dialogType, int messageNum, int errorNum, | ||
String t1, String t2, String t3, boolean keepPassword) { | ||
String t1, String t2, String t3, boolean keepPassword, | ||
boolean sw1) { | ||
android.util.Log.i(TAG, "newInstance called"); | ||
GetTextFragment f = new GetTextFragment(); | ||
f.setDismissalListener(dismissalListener); | ||
|
@@ -126,6 +129,7 @@ public static GetTextFragment newInstance(String dialogId, String title, | |
args.putString("t2", t2); | ||
args.putString("t3", t3); | ||
args.putBoolean("keepPassword", keepPassword); | ||
args.putBoolean("sw1", sw1); | ||
f.setArguments(args); | ||
f.setRetainInstance(false); | ||
|
||
|
@@ -145,6 +149,7 @@ public void onCreate(Bundle savedInstanceState) { | |
t2 = getArguments().getString("t2"); | ||
t3 = getArguments().getString("t3"); | ||
keepPassword = getArguments().getBoolean("keepPassword"); | ||
sw1 = getArguments().getBoolean("sw1"); | ||
} | ||
|
||
@Override | ||
|
@@ -192,12 +197,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa | |
error = (TextView) v.findViewById(R.id.error); | ||
textBox = (EditText) v.findViewById(R.id.textBox); | ||
textBox2 = (EditText) v.findViewById(R.id.textBox2); | ||
switch1 = (Switch) v.findViewById(R.id.switch1); | ||
switch1.setVisibility(View.VISIBLE); | ||
switch1.setText(R.string.master_password_only_lock_connection_editing); | ||
hideText(textBox); | ||
hideText(textBox2); | ||
buttonConfirm = (Button) v.findViewById(R.id.buttonConfirm); | ||
buttonCancel = (Button) v.findViewById(R.id.buttonCancel); | ||
dismissOnCancel(buttonCancel); | ||
ensureMatchingDismissOnConfirm (buttonConfirm, textBox, textBox2, error); | ||
ensureMatchingDismissOnConfirm (buttonConfirm, textBox, textBox2, switch1, error); | ||
break; | ||
case CredentialsWithDomain: | ||
v = inflater.inflate(R.layout.get_credentials_with_domain, container, false); | ||
|
@@ -252,10 +260,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa | |
textBox2.setText(t2); | ||
if (textBox3 != null && t3 != null) | ||
textBox3.setText(t3); | ||
|
||
if (checkboxKeepPassword != null) { | ||
if (checkboxKeepPassword != null) | ||
checkboxKeepPassword.setChecked(keepPassword); | ||
} | ||
if (switch1 != null) | ||
switch1.setChecked(sw1); | ||
|
||
message = (TextView) v.findViewById(R.id.message); | ||
message.setText(messageNum); | ||
|
@@ -293,7 +301,7 @@ public void onClick(View v) { | |
}); | ||
} | ||
|
||
private void ensureMatchingDismissOnConfirm (Button buttonConfirm, final EditText textBox1, final EditText textBox2, final TextView error) { | ||
private void ensureMatchingDismissOnConfirm (Button buttonConfirm, final EditText textBox1, final EditText textBox2, final Switch switch1, final TextView error) { | ||
buttonConfirm.setOnClickListener(new OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
|
@@ -316,6 +324,7 @@ public void onClick(View v) { | |
public void onDismiss (DialogInterface dialog) { | ||
android.util.Log.i(TAG, "onDismiss called: Sending data back to Activity"); | ||
String[] results = new String[3]; | ||
boolean[] b_results = new boolean[3]; | ||
if (textViewBox != null) { | ||
results[0] = textViewBox.getText().toString(); | ||
textViewBox.setText(""); | ||
|
@@ -335,11 +344,15 @@ public void onDismiss (DialogInterface dialog) { | |
if (checkboxKeepPassword != null) { | ||
keepPassword = checkboxKeepPassword.isChecked(); | ||
} | ||
if (switch1 != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not quite certain why you have decided to make this an array of booleans and not opted out for a more specific naming convention that does not require for us to unpack booleans from an array by index. |
||
b_results[0] = switch1.isChecked(); | ||
switch1.setChecked(false); | ||
} | ||
if (dismissalListener != null && (wasConfirmed||wasCancelled)) { | ||
boolean cancelled = wasCancelled; | ||
wasCancelled = false; | ||
wasConfirmed = false; | ||
dismissalListener.onTextObtained(dialogId, results, cancelled, keepPassword); | ||
dismissalListener.onTextObtained(dialogId, results, cancelled, keepPassword, b_results); | ||
} | ||
super.onDismiss(dialog); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,7 @@ private void showGetTextFragment(String tag, String dialogId, String title, | |
c.pd.dismiss(); | ||
} | ||
GetTextFragment frag = GetTextFragment.newInstance(dialogId, title, dismissalListener, | ||
dialogType, messageNum, errorNum, t1, t2, t3, keep); | ||
dialogType, messageNum, errorNum, t1, t2, t3, keep, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is always false, why is it a constructor parameter and not a constant? |
||
frag.setCancelable(false); | ||
frag.show(fm, tag); | ||
} | ||
|
@@ -124,7 +124,7 @@ private void showGetTextFragmentRemoteCanvas(String tag, String dialogId, String | |
c.pd.dismiss(); | ||
} | ||
GetTextFragment frag = GetTextFragment.newInstance(dialogId, title, dismissalListener, | ||
dialogType, messageNum, errorNum, t1, t2, t3, keep); | ||
dialogType, messageNum, errorNum, t1, t2, t3, keep, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is always false, why is it a constructor parameter and not a constant? |
||
frag.setCancelable(false); | ||
frag.show(fm, tag); | ||
} | ||
|
@@ -452,7 +452,7 @@ public void handleMessage(final Message msg) { | |
break; | ||
case RemoteClientLibConstants.RDP_CONNECT_FAILURE: | ||
if (c.maintainConnection) { | ||
c.showFatalMessageAndQuit(context.getString(R.string.error_rdp_connection_failed)); | ||
c.showFatalMessageAndQuitTimer(context.getString(R.string.error_rdp_connection_failed)); | ||
} | ||
break; | ||
case RemoteClientLibConstants.RDP_UNABLE_TO_CONNECT: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these square brackets in the right place?