Skip to content

Commit

Permalink
[fix]: switched to Insetter to fix insets in landscape
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Oct 2, 2023
1 parent 998a55d commit 1132d72
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 89 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ kotlin {
}

dependencies {
implementation "dev.chrisbanes.insetter:insetter:$insetter_version"

implementation "dev.rikka.shizuku:api:$shizuku_version"
implementation "dev.rikka.shizuku:provider:$shizuku_version"

Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<activity
android:name=".ui.activity.MainActivity"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.activity.viewModels
import com.f0x1d.logfox.R
import com.f0x1d.logfox.database.entity.AppCrash
import com.f0x1d.logfox.databinding.ActivityCrashDetailsBinding
import com.f0x1d.logfox.extensions.applyBottomInsets
import com.f0x1d.logfox.extensions.copyText
import com.f0x1d.logfox.extensions.crashToZip
import com.f0x1d.logfox.extensions.exportFormatted
Expand All @@ -18,6 +17,7 @@ import com.f0x1d.logfox.ui.activity.base.BaseViewModelActivity
import com.f0x1d.logfox.utils.event.Event
import com.f0x1d.logfox.viewmodel.crashes.CrashDetailsViewModel
import dagger.hilt.android.AndroidEntryPoint
import dev.chrisbanes.insetter.applyInsetter

@AndroidEntryPoint
class CrashDetailsActivity: BaseViewModelActivity<CrashDetailsViewModel, ActivityCrashDetailsBinding>() {
Expand All @@ -36,7 +36,11 @@ class CrashDetailsActivity: BaseViewModelActivity<CrashDetailsViewModel, Activit
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding.logCard.applyBottomInsets(window.decorView)
binding.logCard.applyInsetter {
type(navigationBars = true) {
margin(vertical = true)
}
}

binding.toolbar.inflateMenu(R.menu.crash_details_menu)
binding.toolbar.setNavigationOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.f0x1d.logfox.ui.activity.base

import android.content.Context
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import androidx.viewbinding.ViewBinding
import com.f0x1d.logfox.R
import com.f0x1d.logfox.extensions.snackbar
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent
import dev.chrisbanes.insetter.applyInsetter
import io.github.inflationx.viewpump.ViewPump
import io.github.inflationx.viewpump.ViewPumpContextWrapper

Expand All @@ -25,8 +24,11 @@ abstract class BaseActivity<T : ViewBinding>: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1)
window.navigationBarColor = resources.getColor(R.color.transparent_black, theme)
window.decorView.applyInsetter {
type(navigationBars = true, displayCutout = true) {
padding(horizontal = true)
}
}

super.onCreate(savedInstanceState)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import android.view.ViewGroup
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.f0x1d.logfox.databinding.FragmentExtendedCopyBinding
import com.f0x1d.logfox.extensions.applyBottomInsets
import com.f0x1d.logfox.ui.fragment.base.BaseFragment
import dev.chrisbanes.insetter.applyInsetter

class ExtendedCopyFragment: BaseFragment<FragmentExtendedCopyBinding>() {

Expand All @@ -19,7 +19,11 @@ class ExtendedCopyFragment: BaseFragment<FragmentExtendedCopyBinding>() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.logText.applyBottomInsets(view)
binding.logText.applyInsetter {
type(navigationBars = true) {
margin(vertical = true)
}
}

binding.toolbar.setNavigationOnClickListener {
findNavController().popBackStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.view.ViewGroup
import androidx.fragment.app.viewModels
import com.f0x1d.logfox.R
import com.f0x1d.logfox.databinding.FragmentSetupBinding
import com.f0x1d.logfox.extensions.applyTopInsets
import com.f0x1d.logfox.extensions.copyText
import com.f0x1d.logfox.extensions.hardRestartApp
import com.f0x1d.logfox.ui.fragment.base.BaseViewModelFragment
Expand All @@ -26,8 +25,6 @@ class SetupFragment: BaseViewModelFragment<SetupViewModel, FragmentSetupBinding>
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.toolbar.applyTopInsets(view)

binding.rootButton.setOnClickListener {
viewModel.root()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.updatePadding
import androidx.fragment.app.viewModels
import androidx.hilt.navigation.fragment.hiltNavGraphViewModels
import androidx.lifecycle.asLiveData
Expand All @@ -13,13 +12,13 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.f0x1d.logfox.R
import com.f0x1d.logfox.adapter.AppsAdapter
import com.f0x1d.logfox.databinding.FragmentChooseAppBinding
import com.f0x1d.logfox.extensions.applyInsets
import com.f0x1d.logfox.ui.fragment.base.BaseViewModelFragment
import com.f0x1d.logfox.utils.dpToPx
import com.f0x1d.logfox.viewmodel.filters.ChooseAppViewModel
import com.f0x1d.logfox.viewmodel.filters.EditFilterViewModel
import com.google.android.material.divider.MaterialDividerItemDecoration
import dagger.hilt.android.AndroidEntryPoint
import dev.chrisbanes.insetter.applyInsetter

@AndroidEntryPoint
class ChooseAppFragment: BaseViewModelFragment<ChooseAppViewModel, FragmentChooseAppBinding>() {
Expand All @@ -41,8 +40,10 @@ class ChooseAppFragment: BaseViewModelFragment<ChooseAppViewModel, FragmentChoos
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

applyInsets(view) {
binding.appsRecycler.updatePadding(bottom = it.bottom)
binding.appsRecycler.applyInsetter {
type(navigationBars = true) {
padding(vertical = true)
}
}

binding.toolbar.setNavigationOnClickListener { findNavController().popBackStack() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,21 @@ import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.core.widget.doAfterTextChanged
import androidx.hilt.navigation.fragment.hiltNavGraphViewModels
import androidx.lifecycle.asLiveData
import androidx.navigation.fragment.findNavController
import com.f0x1d.logfox.R
import com.f0x1d.logfox.databinding.FragmentEditFilterBinding
import com.f0x1d.logfox.extensions.applyInsets
import com.f0x1d.logfox.extensions.setClickListenerOn
import com.f0x1d.logfox.model.LogLevel
import com.f0x1d.logfox.ui.fragment.base.BaseViewModelFragment
import com.f0x1d.logfox.utils.dpToPx
import com.f0x1d.logfox.utils.event.Event
import com.f0x1d.logfox.viewmodel.filters.EditFilterViewModel
import com.google.android.material.color.MaterialColors
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import dev.chrisbanes.insetter.applyInsetter
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.flow.update
Expand All @@ -43,12 +40,15 @@ class EditFilterFragment: BaseViewModelFragment<EditFilterViewModel, FragmentEdi
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

applyInsets(view) { insets ->
binding.saveFab.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = 10.dpToPx.toInt() + insets.bottom
binding.saveFab.applyInsetter {
type(navigationBars = true, ime = true) {
margin(vertical = true, animated = true)
}
}
binding.scrollView.applyInsetter {
type(navigationBars = true, ime = true) {
padding(vertical = true)
}

binding.scrollView.updatePadding(bottom = 71.dpToPx.toInt() + insets.bottom)
}

binding.toolbar.setNavigationOnClickListener { findNavController().popBackStack() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.f0x1d.logfox.R
import com.f0x1d.logfox.adapter.FiltersAdapter
import com.f0x1d.logfox.databinding.FragmentFiltersBinding
import com.f0x1d.logfox.extensions.applyInsets
import com.f0x1d.logfox.extensions.setClickListenerOn
import com.f0x1d.logfox.extensions.showAreYouSureDialog
import com.f0x1d.logfox.ui.fragment.base.BaseViewModelFragment
import com.f0x1d.logfox.utils.dpToPx
import com.f0x1d.logfox.viewmodel.filters.FiltersViewModel
import dagger.hilt.android.AndroidEntryPoint
import dev.chrisbanes.insetter.applyInsetter

@AndroidEntryPoint
class FiltersFragment: BaseViewModelFragment<FiltersViewModel, FragmentFiltersBinding>() {
Expand Down Expand Up @@ -52,12 +48,15 @@ class FiltersFragment: BaseViewModelFragment<FiltersViewModel, FragmentFiltersBi
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

applyInsets(view) { insets ->
binding.addFab.updateLayoutParams<MarginLayoutParams> {
bottomMargin = 10.dpToPx.toInt() + insets.bottom
binding.addFab.applyInsetter {
type(navigationBars = true) {
margin(vertical = true)
}
}
binding.filtersRecycler.applyInsetter {
type(navigationBars = true) {
padding(vertical = true)
}

binding.filtersRecycler.updatePadding(bottom = 71.dpToPx.toInt() + insets.bottom)
}

binding.toolbar.setNavigationOnClickListener { findNavController().popBackStack() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ 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.applyTopInsets
import com.f0x1d.logfox.ui.fragment.base.BaseFragment

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

binding.toolbar.applyTopInsets(view)

binding.toolbar.setTitle(title)
if (showBackArrow) {
binding.toolbar.setNavigationIcon(R.drawable.ic_arrow_back)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_edit_filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="71dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_filters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="71dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<com.google.android.material.floatingactionbutton.FloatingActionButton
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_logs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:title="@string/app_name"
app:titleCentered="true" />
app:titleCentered="true"
app:navigationIconTint="?colorOnSurface"/>
</com.google.android.material.appbar.AppBarLayout>

<androidx.recyclerview.widget.RecyclerView
Expand Down
26 changes: 17 additions & 9 deletions app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<com.f0x1d.logfox.ui.view.OpenSansToolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/settings"
app:titleCentered="true"
app:navigationIconTint="?colorOnSurface"
app:layout_constraintEnd_toEndOf="parent"
android:fitsSystemWindows="true"
app:liftOnScroll="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintEnd_toEndOf="parent">

<com.f0x1d.logfox.ui.view.OpenSansToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:title="@string/settings"
app:titleCentered="true"
app:navigationIconTint="?colorOnSurface"/>
</com.google.android.material.appbar.AppBarLayout>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/container"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/toolbar"
app:layout_constraintTop_toBottomOf="@id/app_bar_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
Expand Down
20 changes: 14 additions & 6 deletions app/src/main/res/layout/fragment_setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<com.f0x1d.logfox.ui.view.OpenSansToolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/setup"
app:titleCentered="true"
android:fitsSystemWindows="true"
app:liftOnScroll="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
app:layout_constraintEnd_toEndOf="parent">

<com.f0x1d.logfox.ui.view.OpenSansToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:title="@string/setup"
app:titleCentered="true" />
</com.google.android.material.appbar.AppBarLayout>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/buttons_container"
Expand Down
Loading

0 comments on commit 1132d72

Please sign in to comment.