From fffb18ff8ba484d71ec698ac820a743ec84b5c81 Mon Sep 17 00:00:00 2001 From: Njuguna Ndung'u Date: Tue, 14 Jun 2022 17:32:50 +0300 Subject: [PATCH 1/2] change order of checks for adding the border color --- .../webapp/mobile/EmbeddedBrowserActivity.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java b/src/main/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java index dafa0975..ea4e5046 100644 --- a/src/main/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java +++ b/src/main/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java @@ -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")) { View webviewContainer = findViewById(R.id.lytWebView); webviewContainer.setPadding(10, 10, 10, 10); - webviewContainer.setBackgroundResource(R.drawable.training_background); + webviewContainer.setBackgroundResource(R.drawable.warning_background); } container = findViewById(R.id.wbvMain); From f1f4f498ecf55f42f8862f4822ee05d4d4ffdfbb Mon Sep 17 00:00:00 2001 From: Njuguna Ndung'u Date: Thu, 16 Jun 2022 10:22:44 +0300 Subject: [PATCH 2/2] refactor how we set the background resource to improve readability --- .../webapp/mobile/EmbeddedBrowserActivity.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java b/src/main/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java index ea4e5046..8705f831 100644 --- a/src/main/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java +++ b/src/main/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java @@ -60,6 +60,16 @@ public void onReceiveValue(String result) { } }; + private void setBackground(int background) { + 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"); + } + //> ACTIVITY LIFECYCLE METHODS @SuppressLint("ClickableViewAccessibility") @@ -84,6 +94,12 @@ public void onReceiveValue(String result) { this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); + if (settings.allowsConfiguration() && isProduction(appUrl)) { + setBackground(R.drawable.warning_background); + } else if (BuildConfig.IS_TRAINING_APP) { + setBackground(R.drawable.training_background); + } + // Add a noticeable border to easily identify a training app if (BuildConfig.IS_TRAINING_APP) { View webviewContainer = findViewById(R.id.lytWebView); @@ -93,7 +109,7 @@ public void onReceiveValue(String result) { // 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")) { + 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.warning_background);