Skip to content
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

Merged
merged 2 commits into from
Jul 25, 2017
Merged

SimpleDialog #1269

merged 2 commits into from
Jul 25, 2017

Conversation

grzesiek2010
Copy link
Member

No description provided.

Copy link
Contributor

@srsudar srsudar left a 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));
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member

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);
Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Member Author

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))
Copy link
Contributor

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.

Copy link
Member Author

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.

@grzesiek2010
Copy link
Member Author

@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.

Copy link
Member

@lognaturel lognaturel left a 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));
Copy link
Member

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.

@grzesiek2010
Copy link
Member Author

@lognaturel fixed.

@srsudar
Copy link
Contributor

srsudar commented Jul 25, 2017

This looks good to me. I agree that I'm not sure if the try/catch around the cast is necessary. I don't know that it will hurt, though, aside from adding a bit of complexity. If people are happy with it I'd vote to keep it.

@grzesiek2010
Copy link
Member Author

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.

@lognaturel
Copy link
Member

Thanks again, @grzesiek2010, @srsudar.

@lognaturel lognaturel merged commit 318b887 into getodk:master Jul 25, 2017
@mmarciniak90
Copy link
Contributor

mmarciniak90 commented Jul 27, 2017

Tested with success.
Tested on Android 4.1, 4.2, 4.4, 5.1, 6.0
'Reset results' dialog does not disappear if device orientation is changed.
User is able to scroll on the dialog.
Locking the screen does not affect the dialog.
Dialog does not disappear even if 'Don't keep activities' option is turned on.

screenshot_20170727-114251

@mmarciniak90
Copy link
Contributor

@opendatakit-bot unlabel "needs testing"

snavarreteimmap pushed a commit to snavarreteimmap/collect that referenced this pull request Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants