-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
change order of checks for adding the border color #286
base: master
Are you sure you want to change the base?
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.
Looks good.
One little bug (I think?) and a suggested refactor for readability.
if (BuildConfig.IS_TRAINING_APP) { | ||
// Add an alarming red border if using configurable (i.e. dev) | ||
// app with a medic production server. | ||
if (settings.allowsConfiguration() && appUrl != null && appUrl.contains("dev.medicmobile.org")) { |
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.
You've changed the URL from "app" to "dev" - pretty sure this should still be "app", eg:
if (settings.allowsConfiguration() && appUrl != null && appUrl.contains("dev.medicmobile.org")) { | |
if (settings.allowsConfiguration() && appUrl != null && appUrl.contains("app.medicmobile.org")) { |
// Add a noticeable border to easily identify a training app | ||
if (BuildConfig.IS_TRAINING_APP) { | ||
View webviewContainer = findViewById(R.id.lytWebView); | ||
webviewContainer.setPadding(10, 10, 10, 10); | ||
webviewContainer.setBackgroundResource(R.drawable.warning_background); | ||
webviewContainer.setBackgroundResource(R.drawable.training_background); | ||
} | ||
|
||
// Add a noticeable border to easily identify a training app | ||
if (BuildConfig.IS_TRAINING_APP) { | ||
// Add an alarming red border if using configurable (i.e. dev) | ||
// app with a medic production server. | ||
if (settings.allowsConfiguration() && appUrl != null && appUrl.contains("dev.medicmobile.org")) { | ||
View webviewContainer = findViewById(R.id.lytWebView); | ||
webviewContainer.setPadding(10, 10, 10, 10); | ||
webviewContainer.setBackgroundResource(R.drawable.training_background); | ||
webviewContainer.setBackgroundResource(R.drawable.warning_background); | ||
} |
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.
While you're working on it, let's improve the code a little too.
- There's no point setting the background resource twice, so let's use if/else.
- The production check is hard to read and should be named so a casual observer can understand what's going on. We could either pull out the production URL as a constant string and name it well, or (as in my example) pull out a method to check
isProduction
. This makes also makes it less likely for bugs like switching to "dev" to sneak through, because it'll be obvious from the method name that it's doing the wrong thing! - There's also duplicate code - we should pull out a private method to set the background.
For example...
private void setBackground(Object background) { // fix the type here...
View webviewContainer = findViewById(R.id.lytWebView);
webviewContainer.setPadding(10, 10, 10, 10);
webviewContainer.setBackgroundResource(background);
}
private boolean isProduction(String appUrl) {
return appUrl != null && appUrl.contains("app.medicmobile.org");
}
...
if (settings.allowsConfiguration() && isProduction(appUrl)) {
setBackground(R.drawable.warning_background);
} else if (BuildConfig.IS_TRAINING_APP) {
setBackground(R.drawable.training_background);
}
I haven't tested any of this so please treat it as pseudo code but to me this is much more readable and maintainable.
No description provided.