mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-10 11:57:47 +01:00
Create extension function for applying system insets
This commit is contained in:
parent
38bc8ec6b4
commit
1d7c692e89
4 changed files with 14 additions and 17 deletions
|
@ -9,8 +9,6 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.marginBottom
|
||||
import androidx.core.view.updateLayoutParams
|
||||
|
@ -49,6 +47,7 @@ import eu.kanade.tachiyomi.ui.recent.history.HistoryController
|
|||
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.view.applyInsets
|
||||
import kotlinx.android.synthetic.main.main_activity.appbar
|
||||
import kotlinx.android.synthetic.main.main_activity.tabs
|
||||
import kotlinx.coroutines.delay
|
||||
|
@ -92,19 +91,15 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
|
|||
|
||||
// Inset paddings when drawing edge-to-edge in Android 9+
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
ViewCompat.setOnApplyWindowInsetsListener(binding.bottomNav) { view, insets ->
|
||||
val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
binding.bottomNav.applyInsets { view, systemInsets ->
|
||||
view.updatePadding(bottom = systemInsets.bottom)
|
||||
insets
|
||||
}
|
||||
|
||||
val initialFabBottomMargin = binding.rootFab.marginBottom
|
||||
ViewCompat.setOnApplyWindowInsetsListener(binding.rootFab) { view, insets ->
|
||||
val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
binding.rootFab.applyInsets { view, systemInsets ->
|
||||
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = initialFabBottomMargin + systemInsets.bottom
|
||||
}
|
||||
insets
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,11 +71,6 @@ class HistoryController :
|
|||
return binding.root
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when view is created
|
||||
*
|
||||
* @param view created view
|
||||
*/
|
||||
override fun onViewCreated(view: View) {
|
||||
super.onViewCreated(view)
|
||||
|
||||
|
|
|
@ -77,10 +77,6 @@ class UpdatesController :
|
|||
return binding.root
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when view is created
|
||||
* @param view created view
|
||||
*/
|
||||
override fun onViewCreated(view: View) {
|
||||
super.onViewCreated(view)
|
||||
view.context.notificationManager.cancel(Notifications.ID_NEW_CHAPTERS)
|
||||
|
|
|
@ -11,6 +11,9 @@ import androidx.annotation.MenuRes
|
|||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.appcompat.widget.TooltipCompat
|
||||
import androidx.core.graphics.Insets
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.chip.ChipGroup
|
||||
|
@ -117,3 +120,11 @@ inline fun ChipGroup.setChips(
|
|||
addView(chip)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun View.applyInsets(noinline block: (view: View, systemInsets: Insets) -> Unit) {
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
|
||||
val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
block(view, systemInsets)
|
||||
insets
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue