-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
SimpleDialog #1269
SimpleDialog #1269
Conversation
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.
Overall looks great, this is exactly the PR I was hoping for!
A few small questions more than anything else, so I'm submitting as a comment rather than requesting changes.
alertDialog.show(); | ||
} | ||
}); | ||
SimpleDialog simpleDialog = SimpleDialog.newInstance(getContext().getString(R.string.reset_app_state_result), android.R.drawable.ic_dialog_info, resultMessage, getContext().getString(R.string.ok)); |
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.
Does Collect have any line length limits? This is longer than I keep in my own projects, but if there are no style guidelines this is fine.
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.
Not yet. We were working on checkstyle but this one is still not ready.
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.
I do think this is hard to read. I would write it as
String title = SimpleDialog.newInstance(getContext().getString(R.string.reset_app_state_result);
int iconID = android.R.drawable.ic_dialog_info;
String buttonTitle = getContext().getString(R.string.ok);
SimpleDialog simpleDialog = SimpleDialog.newInstance(title, iconID, resultMessage, buttonTitle);
That more closely matches what you liked about using a Builder
, @grzesiek2010.
} | ||
}); | ||
SimpleDialog simpleDialog = SimpleDialog.newInstance(getContext().getString(R.string.reset_app_state_result), android.R.drawable.ic_dialog_info, resultMessage, getContext().getString(R.string.ok)); | ||
simpleDialog.show(((AdminPreferencesActivity) context).getSupportFragmentManager(), SimpleDialog.COLLECT_DIALOG_TAG); |
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.
Is there a reason you're using getContext()
in the previous line, but the bare context
field here? Saving references to a context
like this class does makes me nervous, as in the past I've run into problems doing so. I'd prefer relying on the getContext()
method in this line if it works.
Do you think it's safe to cast to android.support.v4.app.FragmentActivity
rather than AdminPreferencesActivity
? My intuition is to cast as high as possible in the hierarchy, but I don't have any good motivation for that. I'd be curious to hear what you think.
And what do you think of wrapping this cast in a try/catch
like Android does in their dialog docs? If this fails it can just log an error maybe, rather than throw an exception. I don't know that it'd be worth crashing the app over if the wrong Context
was used. I'm not sure about this one either, it just seems dangerous to trust a cast when contexts are involved.
.setMessage(getArguments().getString(MESSAGE)) | ||
.setPositiveButton(getArguments().getString(BUTTON_TITLE), new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialog, int id) { |
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.
Does a no-op here in the onClick
dismiss the dialog?
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.
Yes dialog is dissmised if you click on the button.
setCancelable(false); | ||
|
||
return new AlertDialog.Builder(getActivity()) | ||
.setTitle(getArguments().getString(DIALOG_TITLE)) |
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.
Is it worth doing any checks here to make sure the string isn't null, the icon IDs are >0, etc? I don't know that it should happen at all, or here or in the newInstance()
method. We just should be aware that they can return default values that might behave. Maybe we're fine with it.
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.
No if you pass a null value or 0 when it comes to icon that element is just invisible.
2209dd1
to
b065931
Compare
@srsudar I added some small changes like try/catch block https://github.com/opendatakit/collect/pull/1269/files#diff-8be972fa817297fe2db3c718c69da61bR187 to be honest - I'm not sure we need that but we can just in case. |
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.
We're really close here! I would suggest making the one style change I described inline. Then we can first merge this and then @grzesiek2010 you can follow up with a second PR to move all of the other ~14 simple dialogs over to this structure.
alertDialog.show(); | ||
} | ||
}); | ||
SimpleDialog simpleDialog = SimpleDialog.newInstance(getContext().getString(R.string.reset_app_state_result), android.R.drawable.ic_dialog_info, resultMessage, getContext().getString(R.string.ok)); |
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.
I do think this is hard to read. I would write it as
String title = SimpleDialog.newInstance(getContext().getString(R.string.reset_app_state_result);
int iconID = android.R.drawable.ic_dialog_info;
String buttonTitle = getContext().getString(R.string.ok);
SimpleDialog simpleDialog = SimpleDialog.newInstance(title, iconID, resultMessage, buttonTitle);
That more closely matches what you liked about using a Builder
, @grzesiek2010.
@lognaturel fixed. |
This looks good to me. I agree that I'm not sure if the |
I'm not sure but I believe most of dialogs are placed in activities so we don't need try/catch there in other cases we can use it just in case. |
Thanks again, @grzesiek2010, @srsudar. |
Tested with success. |
@opendatakit-bot unlabel "needs testing" |
No description provided.