mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-23 04:31:15 +01:00
Binding for Browse Section
This commit is contained in:
parent
c92b1ce956
commit
96aa91e75d
@ -2,9 +2,9 @@ package eu.kanade.tachiyomi.ui.extension
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
@ -13,15 +13,17 @@ import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.databinding.ExtensionsBottomSheetBinding
|
||||
import eu.kanade.tachiyomi.databinding.RecyclerWithScrollerBinding
|
||||
import eu.kanade.tachiyomi.extension.model.Extension
|
||||
import eu.kanade.tachiyomi.ui.extension.details.ExtensionDetailsController
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.ui.migration.MangaAdapter
|
||||
import eu.kanade.tachiyomi.ui.migration.MangaItem
|
||||
import eu.kanade.tachiyomi.ui.migration.SourceAdapter
|
||||
import eu.kanade.tachiyomi.ui.migration.SourceItem
|
||||
import eu.kanade.tachiyomi.ui.migration.manga.design.PreMigrationController
|
||||
import eu.kanade.tachiyomi.ui.source.BrowseController
|
||||
import eu.kanade.tachiyomi.util.view.activityBinding
|
||||
import eu.kanade.tachiyomi.util.view.collapse
|
||||
import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets
|
||||
import eu.kanade.tachiyomi.util.view.expand
|
||||
@ -29,11 +31,6 @@ import eu.kanade.tachiyomi.util.view.isExpanded
|
||||
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
|
||||
import eu.kanade.tachiyomi.util.view.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.widget.ViewPagerAdapter
|
||||
import kotlinx.android.synthetic.main.extensions_bottom_sheet.view.*
|
||||
import kotlinx.android.synthetic.main.main_activity.*
|
||||
import kotlinx.android.synthetic.main.migration_controller.*
|
||||
import kotlinx.android.synthetic.main.recents_controller.*
|
||||
import kotlinx.android.synthetic.main.recycler_with_scroller.view.*
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
@ -59,13 +56,17 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||
|
||||
private var extensions: List<ExtensionItem> = emptyList()
|
||||
var canExpand = false
|
||||
private lateinit var binding: ExtensionsBottomSheetBinding
|
||||
|
||||
lateinit var controller: BrowseController
|
||||
|
||||
val extensionFrameLayout =
|
||||
inflate(context, R.layout.recycler_with_scroller, null) as FrameLayout
|
||||
val migrationFrameLayout =
|
||||
inflate(context, R.layout.recycler_with_scroller, null) as FrameLayout
|
||||
val extensionFrameLayout = RecyclerWithScrollerBinding.inflate(LayoutInflater.from(context))
|
||||
val migrationFrameLayout = RecyclerWithScrollerBinding.inflate(LayoutInflater.from(context))
|
||||
|
||||
override fun onFinishInflate() {
|
||||
super.onFinishInflate()
|
||||
binding = ExtensionsBottomSheetBinding.bind(this)
|
||||
}
|
||||
|
||||
fun onCreate(controller: BrowseController) {
|
||||
// Initialize adapter, scroll listener and recycler views
|
||||
@ -84,17 +85,16 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||
migRecyler.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(context)
|
||||
migRecyler.setHasFixedSize(true)
|
||||
|
||||
adapter?.fastScroller = extensionFrameLayout.fast_scroller
|
||||
adapter?.fastScroller = extensionFrameLayout.fastScroller
|
||||
this.controller = controller
|
||||
pager.doOnApplyWindowInsets { _, _, _ ->
|
||||
val bottomBar =
|
||||
(this@ExtensionBottomSheet.controller.activity as? MainActivity)?.bottom_nav
|
||||
binding.pager.doOnApplyWindowInsets { _, _, _ ->
|
||||
val bottomBar = controller.activityBinding?.bottomNav
|
||||
extRecyler.updatePaddingRelative(bottom = bottomBar?.height ?: 0)
|
||||
migRecyler.updatePaddingRelative(bottom = bottomBar?.height ?: 0)
|
||||
}
|
||||
pager.adapter = TabbedSheetAdapter()
|
||||
tabs.setupWithViewPager(pager)
|
||||
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
||||
binding.pager.adapter = TabbedSheetAdapter()
|
||||
binding.tabs.setupWithViewPager(binding.pager)
|
||||
binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
||||
override fun onTabSelected(tab: TabLayout.Tab?) {
|
||||
if (canExpand) {
|
||||
this@ExtensionBottomSheet.sheetBehavior?.expand()
|
||||
@ -103,34 +103,35 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||
when (tab?.position) {
|
||||
0 -> extensionFrameLayout
|
||||
else -> migrationFrameLayout
|
||||
}.recycler?.isNestedScrollingEnabled = true
|
||||
}.recycler.isNestedScrollingEnabled = true
|
||||
when (tab?.position) {
|
||||
0 -> extensionFrameLayout
|
||||
else -> migrationFrameLayout
|
||||
}.recycler?.requestLayout()
|
||||
}.recycler.requestLayout()
|
||||
}
|
||||
|
||||
override fun onTabUnselected(tab: TabLayout.Tab?) {
|
||||
when (tab?.position) {
|
||||
0 -> extensionFrameLayout
|
||||
else -> migrationFrameLayout
|
||||
}.recycler?.isNestedScrollingEnabled = false
|
||||
}.recycler.isNestedScrollingEnabled = false
|
||||
if (tab?.position == 1) {
|
||||
presenter.deselectSource()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTabReselected(tab: TabLayout.Tab?) {
|
||||
this@ExtensionBottomSheet.sheetBehavior?.expand()
|
||||
when (tab?.position) {
|
||||
0 -> extensionFrameLayout
|
||||
else -> migrationFrameLayout
|
||||
}.recycler?.isNestedScrollingEnabled = true
|
||||
}.recycler.isNestedScrollingEnabled = true
|
||||
}
|
||||
})
|
||||
presenter.onCreate()
|
||||
updateExtTitle()
|
||||
|
||||
sheet_layout.setOnClickListener {
|
||||
binding.sheetLayout.setOnClickListener {
|
||||
if (!sheetBehavior.isExpanded()) {
|
||||
sheetBehavior?.expand()
|
||||
fetchOnlineExtensionsIfNeeded()
|
||||
@ -150,8 +151,8 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||
|
||||
fun updateExtTitle() {
|
||||
val extCount = presenter.getExtensionUpdateCount()
|
||||
if (extCount > 0) tabs.getTabAt(0)?.orCreateBadge
|
||||
else tabs.getTabAt(0)?.removeBadge()
|
||||
if (extCount > 0) binding.tabs.getTabAt(0)?.orCreateBadge
|
||||
else binding.tabs.getTabAt(0)?.removeBadge()
|
||||
}
|
||||
|
||||
override fun onButtonClick(position: Int) {
|
||||
@ -174,7 +175,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||
}
|
||||
|
||||
override fun onItemClick(view: View?, position: Int): Boolean {
|
||||
when (tabs.selectedTabPosition) {
|
||||
when (binding.tabs.selectedTabPosition) {
|
||||
0 -> {
|
||||
val extension =
|
||||
(adapter?.getItem(position) as? ExtensionItem)?.extension ?: return false
|
||||
@ -202,7 +203,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||
}
|
||||
|
||||
override fun onItemLongClick(position: Int) {
|
||||
if (tabs.selectedTabPosition == 0) {
|
||||
if (binding.tabs.selectedTabPosition == 0) {
|
||||
val extension = (adapter?.getItem(position) as? ExtensionItem)?.extension ?: return
|
||||
if (extension is Extension.Installed || extension is Extension.Untrusted) {
|
||||
uninstallExtension(extension.pkgName)
|
||||
@ -246,7 +247,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||
if (migAdapter !is SourceAdapter) {
|
||||
migAdapter = SourceAdapter(this)
|
||||
migRecyler.adapter = migAdapter
|
||||
migAdapter?.fastScroller = migrationFrameLayout.fast_scroller
|
||||
migAdapter?.fastScroller = migrationFrameLayout.fastScroller
|
||||
}
|
||||
migAdapter?.updateDataSet(sources, true)
|
||||
}
|
||||
@ -256,7 +257,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||
if (migAdapter !is MangaAdapter) {
|
||||
migAdapter = MangaAdapter(this)
|
||||
migRecyler.adapter = migAdapter
|
||||
migAdapter?.fastScroller = migrationFrameLayout.fast_scroller
|
||||
migAdapter?.fastScroller = migrationFrameLayout.fastScroller
|
||||
}
|
||||
migAdapter?.updateDataSet(manga, true)
|
||||
}
|
||||
@ -275,7 +276,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||
}
|
||||
|
||||
fun canGoBack(): Boolean {
|
||||
if (tabs.selectedTabPosition == 1 && migAdapter is MangaAdapter) {
|
||||
if (binding.tabs.selectedTabPosition == 1 && migAdapter is MangaAdapter) {
|
||||
presenter.deselectSource()
|
||||
return false
|
||||
}
|
||||
@ -298,8 +299,8 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||
|
||||
override fun createView(container: ViewGroup, position: Int): View {
|
||||
return when (position) {
|
||||
0 -> extensionFrameLayout
|
||||
else -> migrationFrameLayout
|
||||
0 -> extensionFrameLayout.root
|
||||
else -> migrationFrameLayout.root
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,14 +5,16 @@ import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.databinding.ExtensionCardHeaderBinding
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import kotlinx.android.synthetic.main.extension_card_header.*
|
||||
|
||||
class ExtensionGroupHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = ExtensionCardHeaderBinding.bind(view)
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
fun bind(item: ExtensionGroupItem) {
|
||||
title.text = item.name
|
||||
binding.title.text = item.name
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,7 @@ import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.view.resetStrokeColor
|
||||
import eu.kanade.tachiyomi.data.image.coil.CoverViewTarget
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import kotlinx.android.synthetic.main.extension_card_item.*
|
||||
import kotlinx.android.synthetic.main.source_global_search_controller_card_item.*
|
||||
import eu.kanade.tachiyomi.databinding.ExtensionCardItemBinding
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.util.Locale
|
||||
@ -24,8 +23,9 @@ import java.util.Locale
|
||||
class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = ExtensionCardItemBinding.bind(view)
|
||||
init {
|
||||
ext_button.setOnClickListener {
|
||||
binding.extButton.setOnClickListener {
|
||||
adapter.buttonClickListener.onButtonClick(flexibleAdapterPosition)
|
||||
}
|
||||
}
|
||||
@ -38,10 +38,10 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
|
||||
val extension = item.extension
|
||||
|
||||
// Set source name
|
||||
ext_title.text = extension.name
|
||||
version.text = extension.versionName
|
||||
lang.text = LocaleHelper.getDisplayName(extension.lang)
|
||||
warning.text = when {
|
||||
binding.extTitle.text = extension.name
|
||||
binding.version.text = extension.versionName
|
||||
binding.lang.text = LocaleHelper.getDisplayName(extension.lang)
|
||||
binding.warning.text = when {
|
||||
extension is Extension.Untrusted -> itemView.context.getString(R.string.untrusted)
|
||||
extension is Extension.Installed && extension.isObsolete -> itemView.context.getString(R.string.obsolete)
|
||||
extension is Extension.Installed && extension.isUnofficial -> itemView.context.getString(R.string.unofficial)
|
||||
@ -49,20 +49,20 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
|
||||
else -> ""
|
||||
}.toUpperCase(Locale.ROOT)
|
||||
|
||||
edit_button.clear()
|
||||
binding.sourceImage.clear()
|
||||
|
||||
if (extension is Extension.Available) {
|
||||
edit_button.load(extension.iconUrl) {
|
||||
target(CoverViewTarget(edit_button, progress))
|
||||
binding.sourceImage.load(extension.iconUrl) {
|
||||
target(CoverViewTarget(binding.sourceImage))
|
||||
}
|
||||
} else {
|
||||
extension.getApplicationIcon(itemView.context)?.let { edit_button.setImageDrawable(it) }
|
||||
extension.getApplicationIcon(itemView.context)?.let { binding.sourceImage.setImageDrawable(it) }
|
||||
}
|
||||
bindButton(item)
|
||||
}
|
||||
|
||||
@Suppress("ResourceType")
|
||||
fun bindButton(item: ExtensionItem) = with(ext_button) {
|
||||
fun bindButton(item: ExtensionItem) = with(binding.extButton) {
|
||||
isEnabled = true
|
||||
isClickable = true
|
||||
isActivated = false
|
||||
|
@ -6,21 +6,22 @@ import coil.api.clear
|
||||
import coil.api.loadAny
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.databinding.MangaListItemBinding
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import kotlinx.android.synthetic.main.manga_list_item.*
|
||||
|
||||
class MangaHolder(
|
||||
view: View,
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
|
||||
) : BaseFlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = MangaListItemBinding.bind(view)
|
||||
fun bind(item: MangaItem) {
|
||||
// Update the title of the manga.
|
||||
title.text = item.manga.title
|
||||
subtitle.text = ""
|
||||
binding.title.text = item.manga.title
|
||||
binding.subtitle.text = ""
|
||||
|
||||
// Update the cover.
|
||||
cover_thumbnail.clear()
|
||||
cover_thumbnail.loadAny(item.manga)
|
||||
binding.coverThumbnail.clear()
|
||||
binding.coverThumbnail.loadAny(item.manga)
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
package eu.kanade.tachiyomi.ui.migration
|
||||
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.databinding.MigrationCardItemBinding
|
||||
import eu.kanade.tachiyomi.source.icon
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import kotlinx.android.synthetic.main.migration_card_item.*
|
||||
import kotlinx.android.synthetic.main.source_item.edit_button
|
||||
import kotlinx.android.synthetic.main.source_item.title
|
||||
|
||||
class SourceHolder(view: View, val adapter: SourceAdapter) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = MigrationCardItemBinding.bind(view)
|
||||
init {
|
||||
migration_all.setOnClickListener {
|
||||
adapter.allClickListener?.onAllClick(flexibleAdapterPosition)
|
||||
binding.migrationAll.setOnClickListener {
|
||||
adapter.allClickListener.onAllClick(flexibleAdapterPosition)
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,11 +19,11 @@ class SourceHolder(view: View, val adapter: SourceAdapter) :
|
||||
val source = item.source
|
||||
|
||||
// Set source name
|
||||
title.text = source.name
|
||||
binding.title.text = source.name
|
||||
|
||||
// Set circle letter image.
|
||||
itemView.post {
|
||||
edit_button?.setImageDrawable(source.icon())
|
||||
binding.sourceImage.setImageDrawable(source.icon())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,16 +3,18 @@ package eu.kanade.tachiyomi.ui.migration.manga.design
|
||||
import android.graphics.Paint.STRIKE_THRU_TEXT_FLAG
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.databinding.MigrationSourceItemBinding
|
||||
import eu.kanade.tachiyomi.source.icon
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import kotlinx.android.synthetic.main.migration_source_item.*
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
class MigrationSourceHolder(view: View, val adapter: MigrationSourceAdapter) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = MigrationSourceItemBinding.bind(view)
|
||||
init {
|
||||
setDragHandleView(reorder)
|
||||
setDragHandleView(binding.reorder)
|
||||
}
|
||||
|
||||
fun bind(source: HttpSource, sourceEnabled: Boolean) {
|
||||
@ -20,21 +22,21 @@ class MigrationSourceHolder(view: View, val adapter: MigrationSourceAdapter) :
|
||||
val isMultiLanguage = preferences.enabledLanguages().get().size > 1
|
||||
// Set capitalized title.
|
||||
val sourceName = if (isMultiLanguage) source.toString() else source.name.capitalize()
|
||||
title.text = sourceName
|
||||
binding.title.text = sourceName
|
||||
// Update circle letter image.
|
||||
itemView.post {
|
||||
val icon = source.icon()
|
||||
if (icon != null) edit_button?.setImageDrawable(icon)
|
||||
if (icon != null) binding.sourceImage.setImageDrawable(icon)
|
||||
}
|
||||
|
||||
if (sourceEnabled) {
|
||||
title.alpha = 1.0f
|
||||
edit_button.alpha = 1.0f
|
||||
title.paintFlags = title.paintFlags and STRIKE_THRU_TEXT_FLAG.inv()
|
||||
binding.title.alpha = 1.0f
|
||||
binding.sourceImage.alpha = 1.0f
|
||||
binding.title.paintFlags = binding.title.paintFlags and STRIKE_THRU_TEXT_FLAG.inv()
|
||||
} else {
|
||||
title.alpha = DISABLED_ALPHA
|
||||
edit_button.alpha = DISABLED_ALPHA
|
||||
title.paintFlags = title.paintFlags or STRIKE_THRU_TEXT_FLAG
|
||||
binding.title.alpha = DISABLED_ALPHA
|
||||
binding.sourceImage.alpha = DISABLED_ALPHA
|
||||
binding.title.paintFlags = binding.title.paintFlags or STRIKE_THRU_TEXT_FLAG
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,15 +54,6 @@ import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
||||
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
|
||||
import eu.kanade.tachiyomi.util.view.withFadeTransaction
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import kotlinx.android.synthetic.main.extensions_bottom_sheet.*
|
||||
import kotlinx.android.synthetic.main.extensions_bottom_sheet.ext_bottom_sheet
|
||||
import kotlinx.android.synthetic.main.extensions_bottom_sheet.sheet_layout
|
||||
import kotlinx.android.synthetic.main.extensions_bottom_sheet.view.*
|
||||
import kotlinx.android.synthetic.main.filter_bottom_sheet.*
|
||||
import kotlinx.android.synthetic.main.main_activity.*
|
||||
import kotlinx.android.synthetic.main.recycler_with_scroller.view.*
|
||||
import kotlinx.android.synthetic.main.rounded_category_hopper.*
|
||||
import kotlinx.android.synthetic.main.browse_controller.*
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import kotlin.math.max
|
||||
@ -110,7 +101,7 @@ class BrowseController :
|
||||
override fun getTitle(): String? {
|
||||
return if (showingExtensions) {
|
||||
view?.context?.getString(
|
||||
when (ext_bottom_sheet.tabs.selectedTabPosition) {
|
||||
when (binding.bottomSheet.tabs.selectedTabPosition) {
|
||||
0 -> R.string.extensions
|
||||
else -> R.string.source_migration
|
||||
}
|
||||
@ -130,7 +121,8 @@ class BrowseController :
|
||||
* @return inflated view.
|
||||
*/
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
return inflater.inflate(R.layout.browse_controller, container, false)
|
||||
binding = BrowseControllerBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View) {
|
||||
@ -138,42 +130,41 @@ class BrowseController :
|
||||
|
||||
adapter = SourceAdapter(this)
|
||||
|
||||
// Create recycler and set adapter.
|
||||
recycler.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(view.context)
|
||||
recycler.adapter = adapter
|
||||
// Create binding.recycler and set adapter.
|
||||
binding.recycler.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(view.context)
|
||||
binding.recycler.adapter = adapter
|
||||
adapter?.isSwipeEnabled = true
|
||||
// recycler.addItemDecoration(SourceDividerItemDecoration(view.context))
|
||||
// binding.recycler.addItemDecoration(SourceDividerItemDecoration(view.context))
|
||||
val attrsArray = intArrayOf(android.R.attr.actionBarSize)
|
||||
val array = view.context.obtainStyledAttributes(attrsArray)
|
||||
val appBarHeight = array.getDimensionPixelSize(0, 0)
|
||||
array.recycle()
|
||||
scrollViewWith(
|
||||
recycler,
|
||||
binding.recycler,
|
||||
afterInsets = {
|
||||
headerHeight = it.systemWindowInsetTop + appBarHeight
|
||||
recycler.updatePaddingRelative(bottom = activity?.bottom_nav?.height ?: 0)
|
||||
binding.recycler.updatePaddingRelative(bottom = activityBinding?.bottomNav?.height ?: 0)
|
||||
},
|
||||
onBottomNavUpdate = {
|
||||
setBottomPadding()
|
||||
}
|
||||
)
|
||||
|
||||
recycler?.post {
|
||||
setBottomSheetTabs(if (ext_bottom_sheet?.sheetBehavior.isCollapsed()) 0f else 1f)
|
||||
binding.recycler?.post {
|
||||
setBottomSheetTabs(if (binding.bottomSheet.extBottomSheet?.sheetBehavior.isCollapsed()) 0f else 1f)
|
||||
}
|
||||
|
||||
requestPermissionsSafe(arrayOf(WRITE_EXTERNAL_STORAGE), 301)
|
||||
ext_bottom_sheet.onCreate(this)
|
||||
binding.bottomSheet.extBottomSheet.onCreate(this)
|
||||
|
||||
ext_bottom_sheet.sheetBehavior?.addBottomSheetCallback(
|
||||
binding.bottomSheet.extBottomSheet.sheetBehavior?.addBottomSheetCallback(
|
||||
object : BottomSheetBehavior
|
||||
.BottomSheetCallback() {
|
||||
override fun onSlide(bottomSheet: View, progress: Float) {
|
||||
val recycler = recycler ?: return
|
||||
shadow2?.alpha = (1 - max(0f, progress)) * 0.25f
|
||||
binding.shadow2.alpha = (1 - max(0f, progress)) * 0.25f
|
||||
activityBinding?.appBar?.elevation = min(
|
||||
(1f - progress) * 15f,
|
||||
if (recycler.canScrollVertically(-1)) 15f else 0f
|
||||
if (binding.recycler.canScrollVertically(-1)) 15f else 0f
|
||||
)
|
||||
activityBinding?.appBar?.y = max(activityBinding!!.appBar.y, -headerHeight * (1 - progress))
|
||||
val oldShow = showingExtensions
|
||||
@ -186,7 +177,7 @@ class BrowseController :
|
||||
}
|
||||
|
||||
override fun onStateChanged(p0: View, state: Int) {
|
||||
val extBottomSheet = ext_bottom_sheet ?: return
|
||||
val extBottomSheet = binding.bottomSheet.extBottomSheet ?: return
|
||||
if (state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
activityBinding?.appBar?.y = 0f
|
||||
}
|
||||
@ -204,8 +195,8 @@ class BrowseController :
|
||||
retainViewMode = if (state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
RetainViewMode.RETAIN_DETACH
|
||||
} else RetainViewMode.RELEASE_DETACH
|
||||
sheet_layout.isClickable = state == BottomSheetBehavior.STATE_COLLAPSED
|
||||
sheet_layout.isFocusable = state == BottomSheetBehavior.STATE_COLLAPSED
|
||||
binding.bottomSheet.sheetLayout.isClickable = state == BottomSheetBehavior.STATE_COLLAPSED
|
||||
binding.bottomSheet.sheetLayout.isFocusable = state == BottomSheetBehavior.STATE_COLLAPSED
|
||||
if (state == BottomSheetBehavior.STATE_COLLAPSED || state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
setBottomSheetTabs(if (state == BottomSheetBehavior.STATE_COLLAPSED) 0f else 1f)
|
||||
}
|
||||
@ -214,7 +205,7 @@ class BrowseController :
|
||||
)
|
||||
|
||||
if (showingExtensions) {
|
||||
ext_bottom_sheet.sheetBehavior?.expand()
|
||||
binding.bottomSheet.extBottomSheet.sheetBehavior?.expand()
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,22 +215,22 @@ class BrowseController :
|
||||
}
|
||||
|
||||
fun setBottomSheetTabs(progress: Float) {
|
||||
val bottomSheet = ext_bottom_sheet ?: return
|
||||
ext_bottom_sheet.tabs.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
val bottomSheet = binding.bottomSheet.extBottomSheet ?: return
|
||||
binding.bottomSheet.tabs.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
topMargin = ((activityBinding?.appBar?.height?.minus(9f.dpToPx) ?: 0f) * progress).toInt()
|
||||
}
|
||||
val selectedColor = ColorUtils.setAlphaComponent(
|
||||
ContextCompat.getColor(ext_bottom_sheet.tabs.context, R.color.colorAccent),
|
||||
ContextCompat.getColor(binding.bottomSheet.tabs.context, R.color.colorAccent),
|
||||
(progress * 255).toInt()
|
||||
)
|
||||
val unselectedColor = ColorUtils.setAlphaComponent(
|
||||
bottomSheet.context.getResourceColor(R.attr.colorOnBackground),
|
||||
153
|
||||
)
|
||||
ext_bottom_sheet.sheet_layout.elevation = progress * 5
|
||||
ext_bottom_sheet.pager.alpha = progress * 10
|
||||
ext_bottom_sheet.tabs.setSelectedTabIndicatorColor(selectedColor)
|
||||
ext_bottom_sheet.tabs.setTabTextColors(
|
||||
binding.bottomSheet.sheetLayout.elevation = progress * 5
|
||||
binding.bottomSheet.pager.alpha = progress * 10
|
||||
binding.bottomSheet.tabs.setSelectedTabIndicatorColor(selectedColor)
|
||||
binding.bottomSheet.tabs.setTabTextColors(
|
||||
ColorUtils.blendARGB(
|
||||
bottomSheet.context.getResourceColor(R.attr.actionBarTintColor),
|
||||
unselectedColor,
|
||||
@ -252,7 +243,7 @@ class BrowseController :
|
||||
)
|
||||
)
|
||||
|
||||
ext_bottom_sheet.sheet_layout.backgroundTintList = ColorStateList.valueOf(
|
||||
binding.bottomSheet.sheetLayout.backgroundTintList = ColorStateList.valueOf(
|
||||
ColorUtils.blendARGB(
|
||||
bottomSheet.context.getResourceColor(R.attr.colorPrimaryVariant),
|
||||
bottomSheet.context.getResourceColor(R.attr.colorSecondary),
|
||||
@ -262,43 +253,43 @@ class BrowseController :
|
||||
}
|
||||
|
||||
private fun setBottomPadding() {
|
||||
val bottomBar = activity?.bottom_nav ?: return
|
||||
ext_bottom_sheet ?: return
|
||||
val bottomBar = activityBinding?.bottomNav ?: return
|
||||
binding.bottomSheet.extBottomSheet ?: return
|
||||
val pad = bottomBar.translationY - bottomBar.height
|
||||
val padding = max(
|
||||
(-pad).toInt(),
|
||||
if (ext_bottom_sheet.sheetBehavior.isExpanded()) 0 else {
|
||||
if (binding.bottomSheet.extBottomSheet.sheetBehavior.isExpanded()) 0 else {
|
||||
view?.rootWindowInsets?.systemWindowInsetBottom ?: 0
|
||||
}
|
||||
)
|
||||
shadow2.translationY = pad
|
||||
ext_bottom_sheet.sheetBehavior?.peekHeight = 58.spToPx + padding
|
||||
ext_bottom_sheet.extensionFrameLayout.fast_scroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
binding.shadow2.translationY = pad
|
||||
binding.bottomSheet.extBottomSheet.sheetBehavior?.peekHeight = 58.spToPx + padding
|
||||
binding.bottomSheet.extBottomSheet.extensionFrameLayout.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = -pad.toInt()
|
||||
}
|
||||
ext_bottom_sheet.migrationFrameLayout.fast_scroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
binding.bottomSheet.extBottomSheet.migrationFrameLayout.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = -pad.toInt()
|
||||
}
|
||||
}
|
||||
|
||||
override fun showSheet() {
|
||||
ext_bottom_sheet.sheetBehavior?.expand()
|
||||
binding.bottomSheet.extBottomSheet.sheetBehavior?.expand()
|
||||
}
|
||||
|
||||
override fun toggleSheet() {
|
||||
if (!ext_bottom_sheet.sheetBehavior.isCollapsed()) {
|
||||
ext_bottom_sheet.sheetBehavior?.collapse()
|
||||
if (!binding.bottomSheet.extBottomSheet.sheetBehavior.isCollapsed()) {
|
||||
binding.bottomSheet.extBottomSheet.sheetBehavior?.collapse()
|
||||
} else {
|
||||
ext_bottom_sheet.sheetBehavior?.expand()
|
||||
binding.bottomSheet.extBottomSheet.sheetBehavior?.expand()
|
||||
}
|
||||
}
|
||||
|
||||
override fun sheetIsExpanded(): Boolean = ext_bottom_sheet.sheetBehavior.isExpanded()
|
||||
override fun sheetIsExpanded(): Boolean = binding.bottomSheet.extBottomSheet.sheetBehavior.isExpanded()
|
||||
|
||||
override fun handleSheetBack(): Boolean {
|
||||
if (!ext_bottom_sheet.sheetBehavior.isCollapsed()) {
|
||||
if (ext_bottom_sheet.canGoBack()) {
|
||||
ext_bottom_sheet.sheetBehavior?.collapse()
|
||||
if (!binding.bottomSheet.extBottomSheet.sheetBehavior.isCollapsed()) {
|
||||
if (binding.bottomSheet.extBottomSheet.canGoBack()) {
|
||||
binding.bottomSheet.extBottomSheet.sheetBehavior?.collapse()
|
||||
}
|
||||
return true
|
||||
}
|
||||
@ -313,20 +304,20 @@ class BrowseController :
|
||||
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||
super.onChangeStarted(handler, type)
|
||||
if (!type.isPush) {
|
||||
ext_bottom_sheet.updateExtTitle()
|
||||
ext_bottom_sheet.presenter.refreshExtensions()
|
||||
binding.bottomSheet.extBottomSheet.updateExtTitle()
|
||||
binding.bottomSheet.extBottomSheet.presenter.refreshExtensions()
|
||||
presenter.updateSources()
|
||||
}
|
||||
if (!type.isEnter) {
|
||||
ext_bottom_sheet.canExpand = false
|
||||
binding.bottomSheet.extBottomSheet.canExpand = false
|
||||
activityBinding?.appBar?.elevation =
|
||||
when {
|
||||
ext_bottom_sheet.sheetBehavior.isExpanded() -> 0f
|
||||
recycler.canScrollVertically(-1) -> 15f
|
||||
binding.bottomSheet.extBottomSheet.sheetBehavior.isExpanded() -> 0f
|
||||
binding.recycler.canScrollVertically(-1) -> 15f
|
||||
else -> 0f
|
||||
}
|
||||
} else {
|
||||
ext_bottom_sheet.presenter.refreshMigrations()
|
||||
binding.bottomSheet.extBottomSheet.presenter.refreshMigrations()
|
||||
}
|
||||
setBottomPadding()
|
||||
}
|
||||
@ -334,15 +325,15 @@ class BrowseController :
|
||||
override fun onChangeEnded(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||
super.onChangeEnded(handler, type)
|
||||
if (type.isEnter) {
|
||||
ext_bottom_sheet.canExpand = true
|
||||
binding.bottomSheet.extBottomSheet.canExpand = true
|
||||
setBottomPadding()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResumed(activity: Activity) {
|
||||
super.onActivityResumed(activity)
|
||||
ext_bottom_sheet?.presenter?.refreshExtensions()
|
||||
ext_bottom_sheet?.presenter?.refreshMigrations()
|
||||
binding.bottomSheet.extBottomSheet?.presenter?.refreshExtensions()
|
||||
binding.bottomSheet.extBottomSheet?.presenter?.refreshMigrations()
|
||||
setBottomPadding()
|
||||
}
|
||||
|
||||
@ -362,7 +353,7 @@ class BrowseController :
|
||||
presenter.updateSources()
|
||||
|
||||
snackbar = view?.snack(R.string.source_hidden, Snackbar.LENGTH_INDEFINITE) {
|
||||
anchorView = ext_bottom_sheet
|
||||
anchorView = binding.bottomSheet.extBottomSheet
|
||||
setAction(R.string.undo) {
|
||||
val newCurrent = preferences.hiddenSources().get()
|
||||
preferences.hiddenSources().set(newCurrent - source.id.toString())
|
||||
@ -410,8 +401,8 @@ class BrowseController :
|
||||
}
|
||||
|
||||
override fun expandSearch() {
|
||||
if (showingExtensions) ext_bottom_sheet.sheetBehavior?.collapse()
|
||||
else activity?.toolbar?.menu?.findItem(R.id.action_search)?.expandActionView()
|
||||
if (showingExtensions) binding.bottomSheet.extBottomSheet.sheetBehavior?.collapse()
|
||||
else activityBinding?.toolbar?.menu?.findItem(R.id.action_search)?.expandActionView()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -423,7 +414,7 @@ class BrowseController :
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
if (onRoot) (activity as? MainActivity)?.setDismissIcon(showingExtensions)
|
||||
if (showingExtensions) {
|
||||
if (ext_bottom_sheet.tabs.selectedTabPosition == 0) {
|
||||
if (binding.bottomSheet.tabs.selectedTabPosition == 0) {
|
||||
// Inflate menu
|
||||
inflater.inflate(R.menu.extension_main, menu)
|
||||
|
||||
@ -437,7 +428,7 @@ class BrowseController :
|
||||
// Create query listener which opens the global search view.
|
||||
setOnQueryTextChangeListener(searchView) {
|
||||
extQuery = it ?: ""
|
||||
ext_bottom_sheet.drawExtensions()
|
||||
binding.bottomSheet.extBottomSheet.drawExtensions()
|
||||
true
|
||||
}
|
||||
} else {
|
||||
|
@ -3,22 +3,24 @@ package eu.kanade.tachiyomi.ui.source
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.SourceItemBinding
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
import eu.kanade.tachiyomi.source.icon
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.view.gone
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import kotlinx.android.synthetic.main.source_item.*
|
||||
|
||||
class SourceHolder(view: View, val adapter: SourceAdapter) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
|
||||
val binding = SourceItemBinding.bind(view)
|
||||
|
||||
init {
|
||||
source_pin.setOnClickListener {
|
||||
binding.sourcePin.setOnClickListener {
|
||||
adapter.sourceListener.onPinClick(flexibleAdapterPosition)
|
||||
}
|
||||
source_latest.setOnClickListener {
|
||||
binding.sourceLatest.setOnClickListener {
|
||||
adapter.sourceListener.onLatestClick(flexibleAdapterPosition)
|
||||
}
|
||||
}
|
||||
@ -28,10 +30,10 @@ class SourceHolder(view: View, val adapter: SourceAdapter) :
|
||||
// setCardEdges(item)
|
||||
|
||||
// Set source name
|
||||
title.text = source.name
|
||||
binding.title.text = source.name
|
||||
|
||||
val isPinned = item.isPinned ?: item.header?.code?.equals(SourcePresenter.PINNED_KEY) ?: false
|
||||
source_pin.apply {
|
||||
binding.sourcePin.apply {
|
||||
imageTintList = ColorStateList.valueOf(
|
||||
context.getResourceColor(
|
||||
if (isPinned) R.attr.colorAccent
|
||||
@ -48,27 +50,27 @@ class SourceHolder(view: View, val adapter: SourceAdapter) :
|
||||
itemView.post {
|
||||
val icon = source.icon()
|
||||
when {
|
||||
icon != null -> edit_button.setImageDrawable(icon)
|
||||
item.source.id == LocalSource.ID -> edit_button.setImageResource(R.mipmap.ic_local_source)
|
||||
icon != null -> binding.sourceImage.setImageDrawable(icon)
|
||||
item.source.id == LocalSource.ID -> binding.sourceImage.setImageResource(R.mipmap.ic_local_source)
|
||||
}
|
||||
}
|
||||
|
||||
if (source.supportsLatest) {
|
||||
source_latest.visible()
|
||||
binding.sourceLatest.visible()
|
||||
} else {
|
||||
source_latest.gone()
|
||||
binding.sourceLatest.gone()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFrontView(): View {
|
||||
return card
|
||||
return binding.card
|
||||
}
|
||||
|
||||
override fun getRearLeftView(): View {
|
||||
return left_view
|
||||
return binding.leftView
|
||||
}
|
||||
|
||||
override fun getRearRightView(): View {
|
||||
return right_view
|
||||
return binding.rightView
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,10 @@
|
||||
android:background="@drawable/shape_gradient_top_shadow"
|
||||
android:paddingBottom="10dp"
|
||||
app:layout_anchorGravity="top"
|
||||
app:layout_anchor="@id/ext_bottom_sheet" />
|
||||
app:layout_anchor="@id/bottom_sheet" />
|
||||
<!-- Adding bottom sheet after main content -->
|
||||
<include layout="@layout/extensions_bottom_sheet"/>
|
||||
<include layout="@layout/extensions_bottom_sheet"
|
||||
android:id="@+id/bottom_sheet"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/shadow2"
|
||||
|
@ -12,7 +12,7 @@
|
||||
android:background="@drawable/list_item_selector">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/edit_button"
|
||||
android:id="@+id/source_image"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:padding="12dp"
|
||||
@ -34,7 +34,7 @@
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintBottom_toTopOf="@id/lang"
|
||||
app:layout_constraintEnd_toStartOf="@id/ext_button"
|
||||
app:layout_constraintStart_toEndOf="@id/edit_button"
|
||||
app:layout_constraintStart_toEndOf="@id/source_image"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_chainStyle="packed"
|
||||
tools:text="Batoto" />
|
||||
@ -47,7 +47,7 @@
|
||||
android:maxLines="1"
|
||||
android:textSize="12sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/edit_button"
|
||||
app:layout_constraintStart_toEndOf="@id/source_image"
|
||||
app:layout_constraintTop_toBottomOf="@+id/ext_title"
|
||||
tools:text="English"
|
||||
tools:visibility="visible" />
|
||||
|
@ -13,7 +13,7 @@
|
||||
android:background="@drawable/list_item_selector">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/edit_button"
|
||||
android:id="@+id/source_image"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="8dp"
|
||||
@ -34,7 +34,7 @@
|
||||
android:ellipsize="end"
|
||||
android:textAppearance="@style/TextAppearance.Regular.SubHeading"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/edit_button"
|
||||
app:layout_constraintStart_toEndOf="@id/source_image"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/migration_all"
|
||||
tools:text="Source title"/>
|
||||
|
@ -8,7 +8,7 @@
|
||||
android:background="@drawable/list_item_selector">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/edit_button"
|
||||
android:id="@+id/source_image"
|
||||
android:layout_width="@dimen/material_component_lists_single_line_with_avatar_height"
|
||||
android:layout_height="@dimen/material_component_lists_single_line_with_avatar_height"
|
||||
android:paddingLeft="@dimen/material_component_lists_icon_left_padding"
|
||||
|
@ -51,7 +51,7 @@
|
||||
android:background="@drawable/list_item_selector">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/edit_button"
|
||||
android:id="@+id/source_image"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="6dp"
|
||||
@ -73,7 +73,7 @@
|
||||
android:textColor="?android:textColorPrimary"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/source_latest"
|
||||
app:layout_constraintStart_toEndOf="@+id/edit_button"
|
||||
app:layout_constraintStart_toEndOf="@+id/source_image"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Source title" />
|
||||
|
||||
@ -98,7 +98,7 @@
|
||||
android:layout_margin="10dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:src="@drawable/ic_pin_24dp"
|
||||
android:tint="?colorAccent"
|
||||
app:tint="?colorAccent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintDimensionRatio="1:1"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user