change order of checks for adding the border color#286
Open
Conversation
garethbowen
suggested changes
Jun 14, 2022
Contributor
garethbowen
left a comment
There was a problem hiding this comment.
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")) { |
Contributor
There was a problem hiding this comment.
You've changed the URL from "app" to "dev" - pretty sure this should still be "app", eg:
Suggested change
| if (settings.allowsConfiguration() && appUrl != null && appUrl.contains("dev.medicmobile.org")) { | |
| if (settings.allowsConfiguration() && appUrl != null && appUrl.contains("app.medicmobile.org")) { |
Comment on lines
87
to
100
| // 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); | ||
| } |
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.