ui: retire EdgeToEdge
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
a906c478c9
commit
4bee579e48
@ -39,9 +39,6 @@ import com.wireguard.android.R
|
||||
import com.wireguard.android.databinding.LogViewerActivityBinding
|
||||
import com.wireguard.android.util.DownloadsFileSaver
|
||||
import com.wireguard.android.util.ErrorMessages
|
||||
import com.wireguard.android.widget.EdgeToEdge.setUpFAB
|
||||
import com.wireguard.android.widget.EdgeToEdge.setUpRoot
|
||||
import com.wireguard.android.widget.EdgeToEdge.setUpScrollingContent
|
||||
import com.wireguard.crypto.KeyPair
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -97,9 +94,6 @@ class LogViewerActivity : AppCompatActivity() {
|
||||
binding = LogViewerActivityBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
setUpFAB(binding.shareFab)
|
||||
setUpRoot(binding.root)
|
||||
setUpScrollingContent(binding.recyclerView, binding.shareFab)
|
||||
logAdapter = LogEntryAdapter()
|
||||
binding.recyclerView.apply {
|
||||
recyclerView = this
|
||||
|
@ -10,8 +10,6 @@ import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.ActionBar
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import com.wireguard.android.R
|
||||
@ -59,16 +57,6 @@ class MainActivity : BaseActivity(), FragmentManager.OnBackStackChangedListener
|
||||
isTwoPaneLayout = findViewById<View?>(R.id.master_detail_wrapper) != null
|
||||
supportFragmentManager.addOnBackStackChangedListener(this)
|
||||
onBackStackChanged()
|
||||
// Dispatch insets on back stack change
|
||||
// This is required to ensure replaced fragments are also able to consume insets
|
||||
findViewById<View>(R.id.main_activity_container).setOnApplyWindowInsetsListener { _, insets ->
|
||||
supportFragmentManager.addOnBackStackChangedListener {
|
||||
supportFragmentManager.fragments.forEach {
|
||||
ViewCompat.dispatchApplyWindowInsets(it.requireView(), WindowInsetsCompat.toWindowInsetsCompat(insets))
|
||||
}
|
||||
}
|
||||
insets
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
|
@ -17,8 +17,6 @@ import com.wireguard.android.backend.Tunnel
|
||||
import com.wireguard.android.databinding.TunnelDetailFragmentBinding
|
||||
import com.wireguard.android.databinding.TunnelDetailPeerBinding
|
||||
import com.wireguard.android.model.ObservableTunnel
|
||||
import com.wireguard.android.widget.EdgeToEdge.setUpRoot
|
||||
import com.wireguard.android.widget.EdgeToEdge.setUpScrollingContent
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Timer
|
||||
import java.util.TimerTask
|
||||
@ -55,11 +53,7 @@ class TunnelDetailFragment : BaseFragment() {
|
||||
savedInstanceState: Bundle?): View? {
|
||||
super.onCreateView(inflater, container, savedInstanceState)
|
||||
binding = TunnelDetailFragmentBinding.inflate(inflater, container, false)
|
||||
binding?.apply {
|
||||
executePendingBindings()
|
||||
setUpRoot(root as ViewGroup)
|
||||
setUpScrollingContent(root as ViewGroup, null)
|
||||
}
|
||||
binding?.executePendingBindings()
|
||||
return binding!!.root
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,6 @@ import com.wireguard.android.util.AdminKnobs
|
||||
import com.wireguard.android.util.BiometricAuthenticator
|
||||
import com.wireguard.android.util.ErrorMessages
|
||||
import com.wireguard.android.viewmodel.ConfigProxy
|
||||
import com.wireguard.android.widget.EdgeToEdge.setUpRoot
|
||||
import com.wireguard.android.widget.EdgeToEdge.setUpScrollingContent
|
||||
import com.wireguard.config.Config
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@ -77,8 +75,6 @@ class TunnelEditorFragment : BaseFragment() {
|
||||
binding = TunnelEditorFragmentBinding.inflate(inflater, container, false)
|
||||
binding?.apply {
|
||||
executePendingBindings()
|
||||
setUpRoot(root as ViewGroup)
|
||||
setUpScrollingContent(mainContainer, null)
|
||||
privateKeyTextLayout.setEndIconOnClickListener { config?.`interface`?.generateKeyPair() }
|
||||
}
|
||||
return binding?.root
|
||||
|
@ -32,9 +32,6 @@ import com.wireguard.android.databinding.TunnelListItemBinding
|
||||
import com.wireguard.android.fragment.ConfigNamingDialogFragment.Companion.newInstance
|
||||
import com.wireguard.android.model.ObservableTunnel
|
||||
import com.wireguard.android.util.ErrorMessages
|
||||
import com.wireguard.android.widget.EdgeToEdge.setUpFAB
|
||||
import com.wireguard.android.widget.EdgeToEdge.setUpRoot
|
||||
import com.wireguard.android.widget.EdgeToEdge.setUpScrollingContent
|
||||
import com.wireguard.android.widget.MultiselectableRelativeLayout
|
||||
import com.wireguard.config.Config
|
||||
import kotlinx.coroutines.Deferred
|
||||
@ -209,9 +206,6 @@ class TunnelListFragment : BaseFragment() {
|
||||
bottomSheet.show(childFragmentManager, "BOTTOM_SHEET")
|
||||
}
|
||||
executePendingBindings()
|
||||
setUpRoot(root as ViewGroup)
|
||||
setUpFAB(createFab)
|
||||
setUpScrollingContent(tunnelList, createFab)
|
||||
}
|
||||
return binding!!.root
|
||||
}
|
||||
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2020 WireGuard LLC. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package com.wireguard.android.widget
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.marginBottom
|
||||
import androidx.core.view.marginLeft
|
||||
import androidx.core.view.marginRight
|
||||
import androidx.core.view.marginTop
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.view.updatePadding
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
|
||||
/**
|
||||
* A utility for edge-to-edge display. It provides several features needed to make the app
|
||||
* displayed edge-to-edge on Android Q with gestural navigation.
|
||||
*/
|
||||
|
||||
object EdgeToEdge {
|
||||
@JvmStatic
|
||||
fun setUpRoot(root: ViewGroup) {
|
||||
root.systemUiVisibility =
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setUpScrollingContent(scrollingContent: ViewGroup, fab: FloatingActionButton?) {
|
||||
val originalPaddingLeft = scrollingContent.paddingLeft
|
||||
val originalPaddingRight = scrollingContent.paddingRight
|
||||
val originalPaddingBottom = scrollingContent.paddingBottom
|
||||
|
||||
val fabPaddingBottom = fab?.height ?: 0
|
||||
|
||||
val originalMarginTop = scrollingContent.marginTop
|
||||
|
||||
scrollingContent.setOnApplyWindowInsetsListener { _, windowInsets ->
|
||||
scrollingContent.updatePadding(
|
||||
left = originalPaddingLeft + windowInsets.systemWindowInsetLeft,
|
||||
right = originalPaddingRight + windowInsets.systemWindowInsetRight,
|
||||
bottom = originalPaddingBottom + fabPaddingBottom + windowInsets.systemWindowInsetBottom
|
||||
)
|
||||
scrollingContent.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
topMargin = originalMarginTop + windowInsets.systemWindowInsetTop
|
||||
}
|
||||
windowInsets
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setUpFAB(fab: FloatingActionButton) {
|
||||
val originalMarginLeft = fab.marginLeft
|
||||
val originalMarginRight = fab.marginRight
|
||||
val originalMarginBottom = fab.marginBottom
|
||||
fab.setOnApplyWindowInsetsListener { _, windowInsets ->
|
||||
fab.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
leftMargin = originalMarginLeft + windowInsets.systemWindowInsetLeft
|
||||
rightMargin = originalMarginRight + windowInsets.systemWindowInsetRight
|
||||
bottomMargin = originalMarginBottom + windowInsets.systemWindowInsetBottom
|
||||
}
|
||||
windowInsets
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user