mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 12:41:50 +01:00
more insets work
This commit is contained in:
parent
b9e3e3de55
commit
3930345cbd
@ -22,6 +22,7 @@ import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog
|
||||
import eu.kanade.tachiyomi.ui.library.HeightTopWindowInsetsListener
|
||||
import eu.kanade.tachiyomi.ui.main.doOnApplyWindowInsets
|
||||
import eu.kanade.tachiyomi.ui.main.updatePaddingRelative
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
@ -154,9 +155,10 @@ open class BrowseCatalogueController(bundle: Bundle) :
|
||||
presenter.sourceFilters = newFilters
|
||||
navView.setFilters(presenter.filterItems)
|
||||
}
|
||||
|
||||
val statusScrim = navView.findViewById(R.id.status_bar_scrim) as View
|
||||
statusScrim.setOnApplyWindowInsetsListener(HeightTopWindowInsetsListener)
|
||||
navView.doOnApplyWindowInsets { v, insets, padding ->
|
||||
v.updatePaddingRelative(
|
||||
navView.recycler.updatePaddingRelative(
|
||||
bottom = padding.bottom + insets.systemWindowInsetBottom,
|
||||
top = padding.top + insets.systemWindowInsetTop
|
||||
)
|
||||
|
@ -191,10 +191,16 @@ class LibraryController(
|
||||
is LibraryNavigationView.BadgeGroup -> onDownloadBadgeChanged()
|
||||
}
|
||||
}
|
||||
|
||||
drawer.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
val statusScrim = view.findViewById(R.id.status_bar_scrim) as View
|
||||
statusScrim.setOnApplyWindowInsetsListener(HeightTopWindowInsetsListener)
|
||||
view.doOnApplyWindowInsets { v, insets, padding ->
|
||||
v.updatePaddingRelative(
|
||||
bottom = padding.bottom + insets.systemWindowInsetBottom,
|
||||
top = padding.top + insets.systemWindowInsetTop
|
||||
view.recycler.updatePaddingRelative(
|
||||
bottom = view.recycler.bottom + insets.systemWindowInsetBottom,
|
||||
top = view.recycler.top + insets.systemWindowInsetTop
|
||||
)
|
||||
}
|
||||
return view
|
||||
@ -530,3 +536,15 @@ class LibraryController(
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object HeightTopWindowInsetsListener : View.OnApplyWindowInsetsListener {
|
||||
override fun onApplyWindowInsets(v: View, insets: WindowInsets): WindowInsets {
|
||||
val topInset = insets.systemWindowInsetTop
|
||||
v.setPadding(0,topInset,0,0)
|
||||
if (v.layoutParams.height != topInset) {
|
||||
v.layoutParams.height = topInset
|
||||
v.requestLayout()
|
||||
}
|
||||
return insets
|
||||
}
|
||||
}
|
@ -5,7 +5,9 @@ import android.app.SearchManager
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.support.annotation.NonNull
|
||||
import android.support.annotation.Px
|
||||
import android.support.annotation.RequiresApi
|
||||
import android.support.v4.view.GravityCompat
|
||||
@ -120,6 +122,12 @@ class MainActivity : BaseActivity() {
|
||||
true
|
||||
}
|
||||
|
||||
nav_view.doOnApplyWindowInsets { v, insets, padding ->
|
||||
v.updatePaddingRelative(
|
||||
start = padding.left + insets.systemWindowInsetLeft
|
||||
)
|
||||
}
|
||||
|
||||
val container: ViewGroup = findViewById(R.id.controller_container)
|
||||
|
||||
val content: LinearLayout = findViewById(R.id.main_content)
|
||||
@ -130,6 +138,10 @@ class MainActivity : BaseActivity() {
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
content.setOnApplyWindowInsetsListener(NoopWindowInsetsListener)
|
||||
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||
if (Build.VERSION.SDK_INT >= 26 && currentNightMode == Configuration.UI_MODE_NIGHT_NO) {
|
||||
content.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
}
|
||||
|
||||
router = Conductor.attachRouter(this, container, savedInstanceState)
|
||||
if (!router.hasRootController()) {
|
||||
@ -319,16 +331,17 @@ object NoopWindowInsetsListener : View.OnApplyWindowInsetsListener {
|
||||
|
||||
object NoopWindowInsetsListener2 : View.OnApplyWindowInsetsListener {
|
||||
override fun onApplyWindowInsets(v: View, insets: WindowInsets): WindowInsets {
|
||||
v.setPadding(0,0,0,insets.systemWindowInsetBottom)
|
||||
v.setPadding(0,0,0,insets
|
||||
.systemWindowInsetBottom)
|
||||
insets.consumeSystemWindowInsets()
|
||||
return insets
|
||||
}
|
||||
}
|
||||
|
||||
fun View.doOnApplyWindowInsets(f: (View, WindowInsetsCompat, ViewPaddingState) -> Unit) {
|
||||
fun View.doOnApplyWindowInsets(f: (View, WindowInsets, ViewPaddingState) -> Unit) {
|
||||
// Create a snapshot of the view's padding state
|
||||
val paddingState = createStateForView(this)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this) { v, insets ->
|
||||
setOnApplyWindowInsetsListener { v, insets ->
|
||||
f(v, insets, paddingState)
|
||||
insets
|
||||
}
|
||||
|
@ -98,7 +98,6 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
||||
bottomMargin = insets.systemWindowInsetBottom
|
||||
}
|
||||
}
|
||||
//fast_scroller.setOnApplyWindowInsetsListener(NoopWindowInsetsListener2)
|
||||
swipe_refresh.refreshes().subscribeUntilDestroy { fetchChaptersFromSource() }
|
||||
|
||||
fab.clicks().subscribeUntilDestroy {
|
||||
|
@ -21,6 +21,9 @@ import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
|
||||
import eu.kanade.tachiyomi.ui.main.doOnApplyWindowInsets
|
||||
import eu.kanade.tachiyomi.ui.main.updateLayoutParams
|
||||
import eu.kanade.tachiyomi.ui.main.updatePaddingRelative
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.AddToLibraryFirst
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Error
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success
|
||||
@ -136,6 +139,16 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
|
||||
config = ReaderConfig()
|
||||
initializeMenu()
|
||||
val container: ViewGroup = findViewById(R.id.reader_container)
|
||||
val readerBHeight = reader_menu_bottom.layoutParams.height
|
||||
container.doOnApplyWindowInsets { _, insets, padding ->
|
||||
val bottomInset = insets.mandatorySystemGestureInsets.bottom - insets
|
||||
.systemWindowInsetBottom
|
||||
reader_menu_bottom.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
height = readerBHeight + bottomInset
|
||||
}
|
||||
reader_menu_bottom.updatePaddingRelative(bottom = padding.bottom + bottomInset)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,14 +2,26 @@
|
||||
|
||||
package eu.kanade.tachiyomi.util
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.Point
|
||||
import android.graphics.Typeface
|
||||
import android.os.Build
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v4.view.ViewCompat
|
||||
import android.support.v4.view.WindowInsetsCompat
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.view.WindowInsets
|
||||
import android.widget.TextView
|
||||
import com.amulyakhare.textdrawable.TextDrawable
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.main.doOnApplyWindowInsets
|
||||
import eu.kanade.tachiyomi.ui.main.marginBottom
|
||||
import eu.kanade.tachiyomi.ui.main.updateLayoutParams
|
||||
import eu.kanade.tachiyomi.ui.main.updatePaddingRelative
|
||||
|
||||
/**
|
||||
* Returns coordinates of view.
|
||||
@ -30,11 +42,25 @@ inline fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Sn
|
||||
val snack = Snackbar.make(this, message, length)
|
||||
val textView: TextView = snack.view.findViewById(android.support.design.R.id.snackbar_text)
|
||||
textView.setTextColor(Color.WHITE)
|
||||
when {
|
||||
Build.VERSION.SDK_INT >= 23 -> snack.config(context, rootWindowInsets.systemWindowInsetBottom)
|
||||
else -> snack.config(context)
|
||||
}
|
||||
snack.f()
|
||||
snack.show()
|
||||
return snack
|
||||
}
|
||||
|
||||
fun Snackbar.config(context: Context, bottomMargin: Int = 0) {
|
||||
val params = this.view.layoutParams as ViewGroup.MarginLayoutParams
|
||||
params.setMargins(12, 12, 12, 12 + bottomMargin)
|
||||
this.view.layoutParams = params
|
||||
|
||||
this.view.background = context.getDrawable(R.drawable.bg_snackbar)
|
||||
|
||||
ViewCompat.setElevation(this.view, 6f)
|
||||
}
|
||||
|
||||
inline fun View.visible() {
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ open class SimpleNavigationView @JvmOverloads constructor(
|
||||
/**
|
||||
* Recycler view containing all the items.
|
||||
*/
|
||||
protected val recycler = RecyclerView(context)
|
||||
val recycler = RecyclerView(context)
|
||||
|
||||
init {
|
||||
// Custom attributes
|
||||
@ -57,6 +57,7 @@ open class SimpleNavigationView @JvmOverloads constructor(
|
||||
a.recycle()
|
||||
|
||||
recycler.layoutManager = LinearLayoutManager(context)
|
||||
recycler.clipToPadding = false
|
||||
}
|
||||
|
||||
/**
|
||||
|
6
app/src/main/res/drawable/bg_snackbar.xml
Normal file
6
app/src/main/res/drawable/bg_snackbar.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="#323232" />
|
||||
<corners android:radius="4dp" />
|
||||
</shape>
|
@ -5,5 +5,10 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="end"
|
||||
android:fitsSystemWindows="true"/>
|
||||
|
||||
android:fitsSystemWindows="true">
|
||||
<View
|
||||
android:id="@+id/status_bar_scrim"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:background="?attr/colorPrimary" />
|
||||
</eu.kanade.tachiyomi.ui.catalogue.browse.CatalogueNavigationView>
|
||||
|
@ -5,4 +5,11 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="end"
|
||||
android:fitsSystemWindows="true" />
|
||||
android:fitsSystemWindows="true"
|
||||
android:clipToPadding="true">
|
||||
<View
|
||||
android:id="@+id/status_bar_scrim"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:background="?attr/colorPrimary" />
|
||||
</eu.kanade.tachiyomi.ui.library.LibraryNavigationView>
|
2
app/src/main/res/values-notnight-v29/themes.xml
Normal file
2
app/src/main/res/values-notnight-v29/themes.xml
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources></resources>
|
Loading…
Reference in New Issue
Block a user