Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
m5r committed Jun 11, 2024
1 parent 20b4b64 commit faa1f1c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,40 +88,28 @@ public void onReceiveValue(String result) {

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
View webviewContainer = findViewById(R.id.lytWebView);
// TODO: replace `UPSIDE_DOWN_CAKE` with `VANILLA_ICE_CREAM` when SDK 35 comes out of preview
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ViewCompat.requestApplyInsets(webviewContainer.getRootView());
// ((View) webviewContainer.getParent()).requestApplyInsets();
}

// 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")) {
View webviewContainer = findViewById(R.id.lytWebView);
webviewContainer.setPadding(10, 10, 10, 10);
webviewContainer.setBackgroundResource(R.drawable.warning_background);
}

// 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.training_background);
}

container = findViewById(R.id.wbvMain);

// TODO: replace `UPSIDE_DOWN_CAKE` with `VANILLA_ICE_CREAM` when SDK 35 comes out of preview
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
// https://developer.android.com/about/versions/15/behavior-changes-15#window-insets
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.lytWebView), (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
mlp.topMargin = insets.top;
mlp.rightMargin = insets.right;
mlp.bottomMargin = insets.bottom;
mlp.leftMargin = insets.left;
v.setLayoutParams(mlp);

return WindowInsetsCompat.CONSUMED;
});
}

getFragmentManager()
.beginTransaction()
.add(new OpenSettingsDialogFragment(), OpenSettingsDialogFragment.class.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ private void displayCustomServerForm() {
state = STATE_FORM;

setContentView(R.layout.custom_server_form);

// TODO: replace `UPSIDE_DOWN_CAKE` with `VANILLA_ICE_CREAM` when SDK 35 comes out of preview
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
View view = findViewById(R.id.customServerFormLayout);
ViewCompat.requestApplyInsets(view.getRootView());
// ((View) view.getParent()).requestApplyInsets();
}

if(!this.settings.hasWebappSettings()) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lytWebView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_height="fill_parent"
android:fitsSystemWindows="true">
<WebView android:id="@+id/wbvMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Expand Down

0 comments on commit faa1f1c

Please sign in to comment.