Fixes to swiping chapters

Fixes also to the bottom sheets
This commit is contained in:
Jay 2020-03-24 00:05:04 -04:00
parent 776c85a954
commit fde6506842
17 changed files with 76 additions and 114 deletions

View File

@ -20,7 +20,7 @@ import kotlinx.android.synthetic.main.catalogue_drawer_content.*
import uy.kohesive.injekt.injectLazy
class CatalogueSearchSheet(activity: Activity) :
BottomSheetDialog(activity, R.style.BottomSheetDialogThemeCovered) {
BottomSheetDialog(activity, R.style.BottomSheetDialogTheme) {
/**
* Preferences helper.
@ -61,11 +61,8 @@ class CatalogueSearchSheet(activity: Activity) :
sheetBehavior.skipCollapsed = true
sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
setEdgeToEdge(
activity, recycler, view, 50.dpToPx
activity, view, 50.dpToPx
)
// window?.findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows =
// false
window?.navigationBarColor = activity.window.navigationBarColor
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && preferences.readerTheme()
.getOrDefault() == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0
) window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR

View File

@ -20,7 +20,7 @@ import kotlinx.android.synthetic.main.display_bottom_sheet.*
import uy.kohesive.injekt.injectLazy
class DisplayBottomSheet(private val controller: LibraryController) : BottomSheetDialog
(controller.activity!!, R.style.BottomSheetDialogThemeCovered) {
(controller.activity!!, R.style.BottomSheetDialogTheme) {
val activity = controller.activity!!
@ -37,10 +37,9 @@ class DisplayBottomSheet(private val controller: LibraryController) : BottomShee
setContentView(view)
sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup)
setEdgeToEdge(activity, bottom_sheet, view)
setEdgeToEdge(activity, view)
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
sheetBehavior.peekHeight = 220.dpToPx + height
window?.navigationBarColor = activity.window.navigationBarColor
sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onSlide(bottomSheet: View, progress: Float) { }

View File

@ -5,7 +5,6 @@ import android.animation.AnimatorSet
import android.animation.ValueAnimator
import android.app.SearchManager
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.Rect
import android.graphics.drawable.Drawable
@ -17,6 +16,7 @@ import android.view.MenuItem
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
import android.view.WindowManager
import android.webkit.WebView
import androidx.appcompat.content.res.AppCompatResources
@ -59,6 +59,7 @@ import eu.kanade.tachiyomi.ui.setting.SettingsController
import eu.kanade.tachiyomi.ui.setting.SettingsMainController
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets
import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.util.view.updatePadding
import java.util.Date
@ -196,29 +197,9 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
supportActionBar?.setDisplayShowCustomEnabled(true)
content.setOnApplyWindowInsetsListener { v, insets ->
window.navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1) {
// basically if in landscape on a phone
// For lollipop, draw opaque nav bar
if (v.rootWindowInsets.systemWindowInsetLeft > 0 || v.rootWindowInsets.systemWindowInsetRight > 0)
Color.BLACK
else Color.argb(179, 0, 0, 0)
}
// if the android q+ device has gesture nav, transparent nav bar
// this is here in case some crazy with a notch uses landscape
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && (v.rootWindowInsets.systemWindowInsetBottom != v.rootWindowInsets.tappableElementInsets.bottom)) {
getColor(android.R.color.transparent)
}
// if in landscape with 2/3 button mode, fully opaque nav bar
else if (v.rootWindowInsets.systemWindowInsetLeft > 0 || v.rootWindowInsets.systemWindowInsetRight > 0) {
getResourceColor(R.attr.colorPrimaryVariant)
}
// if in portrait with 2/3 button mode, translucent nav bar
else {
ColorUtils.setAlphaComponent(
getResourceColor(R.attr.colorPrimaryVariant), 179
)
}
setNavBarColor(content.rootWindowInsets)
content.doOnApplyWindowInsets { v, insets, _ ->
setNavBarColor(insets)
val contextView = window?.decorView?.findViewById<View>(R.id.action_mode_bar)
contextView?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = insets.systemWindowInsetLeft
@ -234,13 +215,10 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
)
bottom_nav.updatePadding(bottom = insets.systemWindowInsetBottom)
insets.replaceSystemWindowInsets(
/*insets.replaceSystemWindowInsets(
0, insets.systemWindowInsetTop, 0, insets.systemWindowInsetBottom
)
insets
)*/
}
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
router = Conductor.attachRouter(this, container, savedInstanceState)
if (!router.hasRootController()) {
@ -305,6 +283,33 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
setExtensionsBadge()
}
private fun setNavBarColor(insets: WindowInsets?) {
if (insets == null) return
window.navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1) {
// basically if in landscape on a phone
// For lollipop, draw opaque nav bar
if (insets.systemWindowInsetLeft > 0 || insets.systemWindowInsetRight > 0)
Color.BLACK
else Color.argb(179, 0, 0, 0)
}
// if the android q+ device has gesture nav, transparent nav bar
// this is here in case some crazy with a notch uses landscape
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && (insets
.systemWindowInsetBottom != insets.tappableElementInsets.bottom)) {
getColor(android.R.color.transparent)
}
// if in landscape with 2/3 button mode, fully opaque nav bar
else if (insets.systemWindowInsetLeft > 0 || insets.systemWindowInsetRight > 0) {
getResourceColor(R.attr.colorPrimaryVariant)
}
// if in portrait with 2/3 button mode, translucent nav bar
else {
ColorUtils.setAlphaComponent(
getResourceColor(R.attr.colorPrimaryVariant), 179
)
}
}
fun updateRecentsIcon() {
bottom_nav.menu.findItem(R.id.nav_recents).icon = AppCompatResources.getDrawable(
this,

View File

@ -52,7 +52,7 @@ class MangaDetailsAdapter(
fun performFilter() {
val s = getFilter(String::class.java)
if (s.isNullOrBlank()) {
updateDataSet(items)
updateDataSet(items, true)
} else {
updateDataSet(items.filter { it.name.contains(s, true) ||
it.scanlator?.contains(s, true) == true })

View File

@ -526,14 +526,11 @@ class MangaDetailsController : BaseController,
}
private fun markAsRead(chapters: List<ChapterItem>) {
presenter.markChaptersRead(chapters, read = true)
if (presenter.preferences.removeAfterMarkedAsRead()) {
presenter.deleteChapters(chapters)
}
presenter.markChaptersRead(chapters, true)
}
private fun markAsUnread(chapters: List<ChapterItem>) {
presenter.markChaptersRead(chapters, read = false)
presenter.markChaptersRead(chapters, false)
}
private fun openChapter(chapter: Chapter) {

View File

@ -292,14 +292,15 @@ class MangaDetailsPresenter(
* Deletes the given list of chapter.
* @param chapters the list of chapters to delete.
*/
fun deleteChapters(chapters: List<ChapterItem>) {
fun deleteChapters(chapters: List<ChapterItem>, update: Boolean = true) {
deleteChaptersInternal(chapters)
chapters.forEach { chapter ->
this.chapters.find { it.id == chapter.id }?.download?.status = Download.NOT_DOWNLOADED
}
controller.updateChapters(this.chapters)
if (update)
controller.updateChapters(this.chapters)
}
/**
@ -404,6 +405,7 @@ class MangaDetailsPresenter(
it.bookmark = bookmarked
}
db.updateChaptersProgress(selectedChapters).executeAsBlocking()
getChapters()
withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
}
}
@ -423,6 +425,10 @@ class MangaDetailsPresenter(
}
}
db.updateChaptersProgress(selectedChapters).executeAsBlocking()
if (read && preferences.removeAfterMarkedAsRead()) {
deleteChapters(selectedChapters, false)
}
getChapters()
withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
}
}

View File

@ -169,7 +169,7 @@ class MangaHeaderHolder(
)
}
} else {
text = resources.getString(R.string.start_reading)
text = resources.getString(R.string.all_chapters_read)
}
}

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.ui.manga.chapter
import android.animation.Animator
import android.text.format.DateUtils
import android.view.View
import androidx.appcompat.widget.PopupMenu
@ -147,23 +146,7 @@ class ChapterHolder(
private fun resetFrontView() {
if (front_view.translationX == 0f) return
itemView.post {
adapter.recyclerView.itemAnimator?.changeDuration = 0
val anim = front_view.animate().translationX(0f).setDuration(250)
anim.setListener(object : Animator.AnimatorListener {
override fun onAnimationEnd(animation: Animator?) {
adapter.itemTouchHelper.startSwipe(this@ChapterHolder)
adapter.notifyItemChanged(adapterPosition)
}
override fun onAnimationCancel(animation: Animator?) {}
override fun onAnimationRepeat(animation: Animator?) {}
override fun onAnimationStart(animation: Animator?) {}
})
anim.start()
}
itemView.post { adapter.notifyItemChanged(adapterPosition) }
}
fun notifyStatus(status: Int, locked: Boolean, progress: Int) = with(download_button) {

View File

@ -16,7 +16,7 @@ import eu.kanade.tachiyomi.util.view.visibleIf
import kotlinx.android.synthetic.main.chapter_sort_bottom_sheet.*
class ChaptersSortBottomSheet(controller: MangaDetailsController) : BottomSheetDialog
(controller.activity!!, R.style.BottomSheetDialogThemeCovered) {
(controller.activity!!, R.style.BottomSheetDialogTheme) {
val activity = controller.activity!!
@ -30,10 +30,9 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : BottomSheetD
setContentView(view)
sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup)
setEdgeToEdge(activity, bottom_sheet, view)
setEdgeToEdge(activity, view)
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
sheetBehavior.peekHeight = 380.dpToPx + height
window?.navigationBarColor = activity.window.navigationBarColor
sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onSlide(bottomSheet: View, progress: Float) { }

View File

@ -40,7 +40,7 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) : Bott
setContentView(view)
sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup)
setEdgeToEdge(activity, display_bottom_sheet, view)
setEdgeToEdge(activity, view)
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
sheetBehavior.peekHeight = 380.dpToPx + height

View File

@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.migration.manga.design
import android.app.Activity
import android.content.res.Configuration
import android.os.Bundle
import android.view.WindowManager
import android.widget.CompoundButton
import android.widget.LinearLayout
import android.widget.RadioButton
@ -62,7 +61,7 @@ class MigrationBottomSheetDialog(
params3.endToEnd = -1
extra_search_param.layoutParams = params3
}
setEdgeToEdge(activity, constraint_layout, view)
setEdgeToEdge(activity, view)
setBottomEdge(
if (activity.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) extra_search_param_text
else skip_step, activity
@ -77,7 +76,7 @@ class MigrationBottomSheetDialog(
initPreferences()
window?.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
// window?.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
fab.setOnClickListener {
preferences.skipPreMigration().set(skip_step.isChecked)

View File

@ -54,7 +54,7 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog
val view = activity.layoutInflater.inflate(R.layout.reader_color_filter_sheet, null)
setContentView(view)
setEdgeToEdge(activity, constraint_layout, view, 0)
setEdgeToEdge(activity, view, 0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
preferences.readerTheme().getOrDefault() == 0 &&
activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 &&

View File

@ -32,7 +32,7 @@ class ReaderPageSheet(
init {
setContentView(view)
setEdgeToEdge(activity, view, view)
setEdgeToEdge(activity, view)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
Injekt.get<PreferencesHelper>().readerTheme().getOrDefault() == 0 &&
activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 &&

View File

@ -49,10 +49,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) :
sheetBehavior = BottomSheetBehavior.from(scroll.parent as ViewGroup)
setEdgeToEdge(
activity,
constraint_layout,
scroll,
if (context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE)
activity, scroll, if (context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE)
0 else -1
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && preferences.readerTheme()

View File

@ -8,7 +8,6 @@ import android.content.res.Configuration
import android.graphics.Color
import android.graphics.Point
import android.graphics.Typeface
import android.graphics.drawable.GradientDrawable
import android.os.Build
import android.view.View
import android.view.ViewGroup
@ -21,8 +20,6 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.Px
import androidx.appcompat.widget.SearchView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.graphics.ColorUtils
import androidx.core.math.MathUtils.clamp
import androidx.core.view.ViewCompat
import androidx.recyclerview.widget.LinearLayoutManager
@ -37,11 +34,11 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor
import kotlin.math.abs
import kotlin.math.min
import kotlinx.android.synthetic.main.main_activity.*
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import kotlin.math.abs
import kotlin.math.min
/**
* Returns coordinates of view.
@ -396,42 +393,31 @@ inline fun View.updatePaddingRelative(
fun BottomSheetDialog.setEdgeToEdge(
activity: Activity,
layout: View,
contentView: View,
setTopMargin: Int = -1
) {
window?.setBackgroundDrawable(null)
val currentNightMode =
activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0) window?.decorView?.systemUiVisibility =
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
} else if (layout is ConstraintLayout) {
val nView = View(context)
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
val params = ConstraintLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, height
)
params.bottomToBottom = layout.id
params.startToStart = layout.id
params.endToEnd = layout.id
nView.layoutParams = params
nView.background = GradientDrawable(
GradientDrawable.Orientation.BOTTOM_TOP, intArrayOf(
ColorUtils.setAlphaComponent(Color.BLACK, 179), Color.TRANSPARENT
)
)
layout.addView(nView)
}
window?.navigationBarColor = activity.window.navigationBarColor
val isLight = (activity.window?.decorView?.systemUiVisibility ?: 0) and View
.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR == View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isLight)
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
window?.findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows =
false
contentView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
/*contentView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
if (setTopMargin > -1) topMargin =
activity.window.decorView.rootWindowInsets.systemWindowInsetTop + setTopMargin
}*/
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN //
// or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
if (activity.window.decorView.rootWindowInsets.systemWindowInsetLeft +
activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0)
contentView.systemUiVisibility = contentView.systemUiVisibility
.or(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
/*contentView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetLeft
rightMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetRight
}*/
if (setTopMargin > 0) (contentView.parent as View).updateLayoutParams<ViewGroup.MarginLayoutParams> {
height =
activity.window.decorView.height - activity.window.decorView.rootWindowInsets.systemWindowInsetTop - setTopMargin

View File

@ -8,7 +8,6 @@
style="@style/Theme.MaterialComponents.BottomSheetDialog"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:fitsSystemWindows="true"
android:orientation="vertical">

View File

@ -210,11 +210,6 @@
</style>
<style name="BottomSheetDialogTheme" parent="@style/Theme.MaterialComponents.BottomSheetDialog">
<item name="android:colorBackground">@android:color/transparent</item>
</style>
<style name="BottomSheetDialogThemeCovered"
parent="@style/Theme.MaterialComponents.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:colorBackground">@android:color/transparent</item>
<item name="android:statusBarColor">@android:color/transparent</item>