summaryrefslogtreecommitdiffhomepage
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/com/wireguard/android/activity/MainActivity.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/activity/MainActivity.java b/app/src/main/java/com/wireguard/android/activity/MainActivity.java
index e70af6f1..5bc563e6 100644
--- a/app/src/main/java/com/wireguard/android/activity/MainActivity.java
+++ b/app/src/main/java/com/wireguard/android/activity/MainActivity.java
@@ -9,11 +9,17 @@ import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentManager.OnBackStackChangedListener;
import androidx.fragment.app.FragmentTransaction;
import androidx.appcompat.app.ActionBar;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnApplyWindowInsetsListener;
+import android.view.ViewGroup;
+import android.view.WindowInsets;
import android.widget.LinearLayout;
import com.wireguard.android.R;
@@ -21,6 +27,9 @@ import com.wireguard.android.fragment.TunnelDetailFragment;
import com.wireguard.android.fragment.TunnelEditorFragment;
import com.wireguard.android.model.Tunnel;
+import java.util.List;
+import java.util.Objects;
+
/**
* CRUD interface for WireGuard tunnels. This activity serves as the main entry point to the
* WireGuard application, and contains several fragments for listing, viewing details of, and
@@ -68,6 +77,16 @@ public class MainActivity extends BaseActivity
isTwoPaneLayout = findViewById(R.id.master_detail_wrapper) instanceof LinearLayout;
getSupportFragmentManager().addOnBackStackChangedListener(this);
onBackStackChanged();
+ // Dispatch insets on back stack change
+ // This is required to ensure replaced fragments are also able to consume insets
+ ((ViewGroup) findViewById(android.R.id.content)).setOnApplyWindowInsetsListener((OnApplyWindowInsetsListener) (v, insets) -> {
+ final FragmentManager fragmentManager = getSupportFragmentManager();
+ fragmentManager.addOnBackStackChangedListener(() -> {
+ final List<Fragment> fragments = fragmentManager.getFragments();
+ Objects.requireNonNull(fragments.get(fragments.size() - 1).getView()).dispatchApplyWindowInsets(insets);
+ });
+ return insets;
+ });
}
@Override