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
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ public void onReceiveValue(String result) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

// Add an alarming red border if using configurable (i.e. dev)
// app with a medic production server.
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")) {
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")) {

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.


container = findViewById(R.id.wbvMain);
Expand Down