Skip to content

Commit

Permalink
Add bottom inset to fragments without bottom bar
Browse files Browse the repository at this point in the history
  • Loading branch information
cemrich committed Sep 8, 2024
1 parent 8c6d526 commit 3f8c48d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.fragment.app.Fragment
import de.christinecoenen.code.zapp.R
import de.christinecoenen.code.zapp.databinding.ChangelogFragmentBinding
import de.christinecoenen.code.zapp.utils.io.IoUtils.readAllText
import de.christinecoenen.code.zapp.utils.system.SystemUiHelper.applyBottomInsetAsPadding
import io.noties.markwon.Markwon
import org.koin.android.ext.android.inject

Expand All @@ -29,6 +30,8 @@ class ChangelogFragment : Fragment() {
val markdown = resources.readAllText(R.raw.changelog)
markwon.setMarkdown(binding.txtChangelog, markdown)

binding.txtChangelog.applyBottomInsetAsPadding()

return binding.root
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.fragment.app.Fragment
import de.christinecoenen.code.zapp.R
import de.christinecoenen.code.zapp.databinding.FaqFragmentBinding
import de.christinecoenen.code.zapp.utils.io.IoUtils.readAllText
import de.christinecoenen.code.zapp.utils.system.SystemUiHelper.applyBottomInsetAsPadding
import io.noties.markwon.Markwon
import org.koin.android.ext.android.inject

Expand All @@ -29,6 +30,8 @@ class FaqFragment : Fragment() {
val markdown = resources.readAllText(R.raw.faq)
markwon.setMarkdown(binding.txtFaq, markdown)

binding.txtFaq.applyBottomInsetAsPadding()

return binding.root
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import de.christinecoenen.code.zapp.repositories.MediathekRepository
import de.christinecoenen.code.zapp.utils.system.ImageHelper.loadThumbnailAsync
import de.christinecoenen.code.zapp.utils.system.IntentHelper.openUrl
import de.christinecoenen.code.zapp.utils.system.LifecycleOwnerHelper.launchOnCreated
import de.christinecoenen.code.zapp.utils.system.SystemUiHelper.applyBottomInsetAsPadding
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.catch
Expand Down Expand Up @@ -63,6 +64,8 @@ class MediathekDetailFragment : Fragment() {
loadOrPersistShowFromArguments()
}

binding.root.applyBottomInsetAsPadding()

return binding.root
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import de.christinecoenen.code.zapp.databinding.PersonalDetailsFragmentBinding
import de.christinecoenen.code.zapp.databinding.ViewNoShowsBinding
import de.christinecoenen.code.zapp.models.shows.MediathekShow
import de.christinecoenen.code.zapp.utils.system.LifecycleOwnerHelper.launchOnCreated
import de.christinecoenen.code.zapp.utils.system.SystemUiHelper.applyBottomInsetAsPadding

abstract class DetailsBaseFragment : Fragment(), MediathekShowListItemListener {

Expand Down Expand Up @@ -80,6 +81,8 @@ abstract class DetailsBaseFragment : Fragment(), MediathekShowListItemListener {
}
}

binding.root.applyBottomInsetAsPadding()

return binding.root
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
package de.christinecoenen.code.zapp.app.settings.ui

import androidx.preference.*
import android.os.Bundle
import android.view.View
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.MultiSelectListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import de.christinecoenen.code.zapp.app.settings.repository.SettingsRepository
import de.christinecoenen.code.zapp.databinding.DialogEditTextPreferenceBinding
import de.christinecoenen.code.zapp.utils.system.SystemUiHelper.applyBottomInsetAsPadding

abstract class BaseSettingsFragment : PreferenceFragmentCompat() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

listView.applyBottomInsetAsPadding()
}

/**
* Show [ListPreference] and [EditTextPreference] dialog by [MaterialAlertDialogBuilder]
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package de.christinecoenen.code.zapp.utils.system

import android.view.View
import android.view.Window
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding


object SystemUiHelper {
Expand All @@ -15,4 +19,18 @@ object SystemUiHelper {
windowInsetController.isAppearanceLightStatusBars = lightStatusBar
}

/**
* Sets the bottom padding of this view to the bottom system bar inset to avoid overlapping
* with system ui.
*/
fun View.applyBottomInsetAsPadding() {
ViewCompat.setOnApplyWindowInsetsListener(this) { v, insets ->
val systemBars = insets.getInsets(
WindowInsetsCompat.Type.systemBars() or
WindowInsetsCompat.Type.ime()
)
v.updatePadding(bottom = systemBars.bottom)
insets
}
}
}

0 comments on commit 3f8c48d

Please sign in to comment.