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

change order of checks for adding the border color #286

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

njogz
Copy link
Contributor

@njogz njogz commented Jun 14, 2022

No description provided.

@njogz njogz requested a review from garethbowen June 14, 2022 14:36
Copy link
Member

@garethbowen garethbowen left a 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")) {
Copy link
Member

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:

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

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.

  1. There's no point setting the background resource twice, so let's use if/else.
  2. 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!
  3. 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.

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.

None yet

2 participants