Skip to content

Commit

Permalink
[fix]: insets for settings in landscape, also liftOnScroll for AppBar
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Oct 2, 2023
1 parent 25ad9f7 commit a8aab1b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.f0x1d.logfox.ui.fragment.settings

import android.os.Bundle
import androidx.preference.PreferenceFragmentCompat
import com.f0x1d.logfox.R
import com.f0x1d.logfox.ui.fragment.settings.base.BasePreferenceFragment
import com.f0x1d.logfox.ui.fragment.settings.base.BaseSettingsWrapperFragment
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -14,7 +14,7 @@ class SettingsCrashesFragment: BaseSettingsWrapperFragment() {
override val showBackArrow = true

@AndroidEntryPoint
class SettingsCrashesWrappedFragment: PreferenceFragmentCompat() {
class SettingsCrashesWrappedFragment: BasePreferenceFragment() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.settings_crashes)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.f0x1d.logfox.ui.fragment.settings
import android.os.Bundle
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.f0x1d.logfox.BuildConfig
import com.f0x1d.logfox.R
import com.f0x1d.logfox.ui.fragment.settings.base.BasePreferenceFragment
import com.f0x1d.logfox.ui.fragment.settings.base.BaseSettingsWrapperFragment
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -15,7 +15,7 @@ class SettingsMenuFragment: BaseSettingsWrapperFragment() {
override val wrappedFragment get() = SettingsMenuWrappedFragment()

@AndroidEntryPoint
class SettingsMenuWrappedFragment: PreferenceFragmentCompat() {
class SettingsMenuWrappedFragment: BasePreferenceFragment() {

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.settings_menu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import android.os.Build
import android.os.Bundle
import android.provider.Settings
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.f0x1d.logfox.BuildConfig
import com.f0x1d.logfox.LogFoxApp
import com.f0x1d.logfox.R
import com.f0x1d.logfox.extensions.hasNotificationsPermission
import com.f0x1d.logfox.ui.fragment.settings.base.BasePreferenceFragment
import com.f0x1d.logfox.ui.fragment.settings.base.BaseSettingsWrapperFragment
import com.f0x1d.logfox.utils.preferences.AppPreferences
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -24,7 +24,7 @@ class SettingsNotificationsFragment: BaseSettingsWrapperFragment() {
override val showBackArrow = true

@AndroidEntryPoint
class SettingsNotificationWrappedFragment: PreferenceFragmentCompat() {
class SettingsNotificationWrappedFragment: BasePreferenceFragment() {

@Inject
lateinit var appPreferences: AppPreferences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import android.os.Build
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import com.f0x1d.logfox.R
import com.f0x1d.logfox.extensions.observeAndUpdateSummaryForList
import com.f0x1d.logfox.extensions.setupAsListPreference
import com.f0x1d.logfox.extensions.toast
import com.f0x1d.logfox.repository.logging.LoggingRepository
import com.f0x1d.logfox.ui.fragment.settings.base.BasePreferenceFragment
import com.f0x1d.logfox.ui.fragment.settings.base.BaseSettingsWrapperFragment
import com.f0x1d.logfox.utils.fillWithStrings
import com.f0x1d.logfox.utils.preferences.AppPreferences
Expand All @@ -29,7 +29,7 @@ class SettingsServiceFragment: BaseSettingsWrapperFragment() {
override val showBackArrow = true

@AndroidEntryPoint
class SettingsServiceWrappedFragment: PreferenceFragmentCompat() {
class SettingsServiceWrappedFragment: BasePreferenceFragment() {

@Inject
lateinit var loggingRepository: LoggingRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.f0x1d.logfox.ui.fragment.settings
import android.os.Bundle
import android.text.InputType
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.f0x1d.logfox.R
import com.f0x1d.logfox.extensions.applyTheme
import com.f0x1d.logfox.extensions.catchingNotNumber
import com.f0x1d.logfox.extensions.observeAndUpdateSummary
import com.f0x1d.logfox.extensions.observeAndUpdateSummaryForList
import com.f0x1d.logfox.extensions.setupAsEditTextPreference
import com.f0x1d.logfox.extensions.setupAsListPreference
import com.f0x1d.logfox.ui.fragment.settings.base.BasePreferenceFragment
import com.f0x1d.logfox.ui.fragment.settings.base.BaseSettingsWrapperFragment
import com.f0x1d.logfox.utils.fillWithStrings
import com.f0x1d.logfox.utils.preferences.AppPreferences
Expand All @@ -26,7 +26,7 @@ class SettingsUIFragment: BaseSettingsWrapperFragment() {
override val showBackArrow = true

@AndroidEntryPoint
class SettingsUIWrappedFragment: PreferenceFragmentCompat() {
class SettingsUIWrappedFragment: BasePreferenceFragment() {

@Inject
lateinit var appPreferences: AppPreferences
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.f0x1d.logfox.ui.fragment.settings.base

import android.os.Bundle
import android.view.View
import androidx.preference.PreferenceFragmentCompat
import com.f0x1d.logfox.extensions.isHorizontalOrientation
import dev.chrisbanes.insetter.applyInsetter

abstract class BasePreferenceFragment: PreferenceFragmentCompat() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

listView.apply {
clipToPadding = false

applyInsetter {
type(navigationBars = true) {
padding(vertical = requireContext().isHorizontalOrientation)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.f0x1d.logfox.R
import com.f0x1d.logfox.databinding.FragmentSettingsBinding
import com.f0x1d.logfox.extensions.isHorizontalOrientation
import com.f0x1d.logfox.ui.fragment.base.BaseFragment
import dev.chrisbanes.insetter.applyInsetter

abstract class BaseSettingsWrapperFragment: BaseFragment<FragmentSettingsBinding>() {

Expand All @@ -23,12 +21,6 @@ abstract class BaseSettingsWrapperFragment: BaseFragment<FragmentSettingsBinding
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.container.applyInsetter {
type(navigationBars = true) {
padding(vertical = requireContext().isHorizontalOrientation)
}
}

binding.toolbar.setTitle(title)
if (showBackArrow) {
binding.toolbar.setNavigationIcon(R.drawable.ic_arrow_back)
Expand Down
18 changes: 6 additions & 12 deletions app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
Expand All @@ -9,10 +9,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:liftOnScroll="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
app:liftOnScroll="true">

<com.f0x1d.logfox.ui.view.OpenSansToolbar
android:id="@+id/toolbar"
Expand All @@ -25,11 +22,8 @@

<androidx.fragment.app.FragmentContainerView
android:id="@+id/container"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/app_bar_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

0 comments on commit a8aab1b

Please sign in to comment.