diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2020-02-23 20:00:35 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2020-02-25 08:57:28 +0530 |
commit | 01e8e535f4617e6888598a0e8c4a9ee09fea41d2 (patch) | |
tree | d349be134ef4d6faa39d3bfab9fc5fcf5ab855a1 | |
parent | e5e2e7571fc16f18b431f8cadeb583bc5783a9f6 (diff) |
Ensure insets are dispatched to all fragments
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
-rw-r--r-- | app/src/main/java/com/wireguard/android/activity/MainActivity.java | 19 |
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 |