Skip to content

Commit

Permalink
improve insets handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mardous committed Dec 16, 2024
1 parent 4c89ad0 commit 6e34b51
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.simplified.wsstatussaver.R
import com.simplified.wsstatussaver.WhatSaveViewModel
import com.simplified.wsstatussaver.activities.base.BaseActivity
import com.simplified.wsstatussaver.dialogs.UpdateDialog
import com.simplified.wsstatussaver.extensions.applyLandscapeInsetter
import com.simplified.wsstatussaver.extensions.currentFragment
import com.simplified.wsstatussaver.extensions.getBottomInsets
import com.simplified.wsstatussaver.extensions.getPreferredClient
Expand Down Expand Up @@ -58,6 +59,11 @@ class StatusesActivity : BaseActivity(), NavigationBarView.OnItemReselectedListe
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
contentView = findViewById(R.id.main_container)
contentView.applyLandscapeInsetter {
type(navigationBars = true, displayCutout = true) {
padding(horizontal = true)
}
}
navigationView = findViewById(R.id.navigation_view)
navigationView.setOnItemReselectedListener(this)
if (navigationView is BottomNavigationView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import android.annotation.SuppressLint
import android.view.View
import androidx.core.view.WindowInsetsCompat
import com.simplified.wsstatussaver.getApp
import dev.chrisbanes.insetter.InsetterDsl
import dev.chrisbanes.insetter.applyInsetter

@SuppressLint("DiscouragedApi", "InternalInsetResource")
Expand All @@ -31,25 +32,14 @@ fun WindowInsetsCompat?.getBottomInsets(): Int {
return bottomInsets ?: 0
}

/**
* This will draw our view above the navigation bar instead of behind it by adding margins.
*/
fun View.drawAboveSystemBars(onlyPortrait: Boolean = true) {
if (onlyPortrait && isLandscape()) return
applyInsetter {
type(navigationBars = true) {
margin()
}
fun View.applyPortraitInsetter(build: InsetterDsl.() -> Unit) {
if (!isLandscape()) {
applyInsetter(build)
}
}

/**
* This will draw our view above the navigation bar instead of behind it by adding padding.
*/
fun View.drawAboveSystemBarsWithPadding() {
applyInsetter {
type(navigationBars = true) {
padding()
}
fun View.applyLandscapeInsetter(build: InsetterDsl.() -> Unit) {
if (isLandscape()) {
applyInsetter(build)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.simplified.wsstatussaver.extensions.PREFERENCE_QUICK_DELETION
import com.simplified.wsstatussaver.extensions.PREFERENCE_STATUSES_LOCATION
import com.simplified.wsstatussaver.extensions.PREFERENCE_THEME_MODE
import com.simplified.wsstatussaver.extensions.PREFERENCE_USE_CUSTOM_FONT
import com.simplified.wsstatussaver.extensions.applyPortraitInsetter
import com.simplified.wsstatussaver.extensions.findActivityNavController
import com.simplified.wsstatussaver.extensions.getDefaultDayNightMode
import com.simplified.wsstatussaver.extensions.isNightModeEnabled
Expand All @@ -52,7 +53,6 @@ import com.simplified.wsstatussaver.preferences.SaveLocationPreferenceDialog
import com.simplified.wsstatussaver.preferences.StoragePreference
import com.simplified.wsstatussaver.preferences.StoragePreferenceDialog
import com.simplified.wsstatussaver.setAnalyticsEnabled
import dev.chrisbanes.insetter.applyInsetter

/**
* @author Christians Martínez Alvarado (mardous)
Expand Down Expand Up @@ -92,7 +92,7 @@ class SettingsFragment : BaseFragment(R.layout.fragment_settings) {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
listView.applyInsetter {
listView.applyPortraitInsetter {
type(navigationBars = true) {
padding(vertical = true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import com.simplified.wsstatussaver.adapter.MessageAdapter
import com.simplified.wsstatussaver.database.Conversation
import com.simplified.wsstatussaver.database.MessageEntity
import com.simplified.wsstatussaver.databinding.FragmentMessagesBinding
import com.simplified.wsstatussaver.extensions.drawAboveSystemBarsWithPadding
import com.simplified.wsstatussaver.extensions.applyPortraitInsetter
import com.simplified.wsstatussaver.extensions.startActivitySafe
import com.simplified.wsstatussaver.fragments.base.BaseFragment
import com.simplified.wsstatussaver.interfaces.IMessageCallback
Expand All @@ -57,7 +57,11 @@ class ConversationDetailFragment : BaseFragment(R.layout.fragment_messages), IMe
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
_binding = FragmentMessagesBinding.bind(view)
binding.recyclerView.drawAboveSystemBarsWithPadding()
binding.recyclerView.applyPortraitInsetter {
type(navigationBars = true) {
padding()
}
}

postponeEnterTransition()
view.doOnPreDraw { startPostponedEnterTransition() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import com.simplified.wsstatussaver.R
import com.simplified.wsstatussaver.WhatSaveViewModel
import com.simplified.wsstatussaver.adapter.ClientAdapter
import com.simplified.wsstatussaver.databinding.FragmentOnboardBinding
import com.simplified.wsstatussaver.extensions.drawAboveSystemBars
import com.simplified.wsstatussaver.extensions.applyPortraitInsetter
import com.simplified.wsstatussaver.extensions.formattedAsHtml
import com.simplified.wsstatussaver.extensions.getClientSAFIntent
import com.simplified.wsstatussaver.extensions.getOnBackPressedDispatcher
Expand Down Expand Up @@ -82,7 +82,11 @@ class OnboardFragment : BaseFragment(R.layout.fragment_onboard), View.OnClickLis
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
_binding = OnboardBinding(FragmentOnboardBinding.bind(view))
binding.agreementText.drawAboveSystemBars()
binding.agreementText.applyPortraitInsetter {
type(navigationBars = true) {
margin()
}
}

postponeEnterTransition()
enterTransition = MaterialFadeThrough().addTarget(view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package com.simplified.wsstatussaver.views
import android.content.Context
import android.util.AttributeSet
import androidx.constraintlayout.widget.ConstraintLayout
import dev.chrisbanes.insetter.applyInsetter
import com.simplified.wsstatussaver.extensions.applyPortraitInsetter

/**
* @author Christians M. A. (mardous)
Expand All @@ -39,7 +39,7 @@ class InsetsConstraintLayout @JvmOverloads constructor(
parent = parent.parent
}
if (!hasInsetsParent) {
applyInsetter {
applyPortraitInsetter {
type(navigationBars = true) {
padding()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package com.simplified.wsstatussaver.views
import android.content.Context
import android.util.AttributeSet
import androidx.core.widget.NestedScrollView
import dev.chrisbanes.insetter.applyInsetter
import com.simplified.wsstatussaver.extensions.applyPortraitInsetter

/**
* @author Christians M. A. (mardous)
Expand All @@ -28,7 +28,7 @@ class InsetsNestedScrollView @JvmOverloads constructor(
) : NestedScrollView(context, attrs, defStyleAttr) {

init {
applyInsetter {
applyPortraitInsetter {
type(navigationBars = true) {
padding()
}
Expand Down

0 comments on commit 6e34b51

Please sign in to comment.