mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
homeparentitemadapterpreview -> viewbinding
This commit is contained in:
parent
4d6e64adb6
commit
f30506a394
3 changed files with 358 additions and 413 deletions
|
@ -918,7 +918,6 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
showApply = false,
|
||||
{}) {
|
||||
viewModel.updateWatchStatus(WatchType.values()[it])
|
||||
bookmarksUpdatedEvent(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import androidx.viewbinding.ViewBinding
|
|||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.chip.ChipDrawable
|
||||
import com.google.android.material.navigationrail.NavigationRailView
|
||||
import com.lagradost.cloudstream3.APIHolder.getId
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity
|
||||
import com.lagradost.cloudstream3.HomePageList
|
||||
|
@ -39,35 +40,6 @@ import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showOptionSelectSt
|
|||
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarView
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
||||
import kotlinx.android.synthetic.main.activity_main.view.nav_rail_view
|
||||
import kotlinx.android.synthetic.main.fragment_home_head.view.home_bookmark_parent_item_title
|
||||
import kotlinx.android.synthetic.main.fragment_home_head.view.home_bookmarked_child_recyclerview
|
||||
import kotlinx.android.synthetic.main.fragment_home_head.view.home_preview_bookmark
|
||||
import kotlinx.android.synthetic.main.fragment_home_head.view.home_preview_image
|
||||
import kotlinx.android.synthetic.main.fragment_home_head.view.home_preview_info
|
||||
import kotlinx.android.synthetic.main.fragment_home_head.view.home_preview_play
|
||||
import kotlinx.android.synthetic.main.fragment_home_head.view.home_search
|
||||
import kotlinx.android.synthetic.main.fragment_home_head.view.home_watch_parent_item_title
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_bookmarked_holder
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_none_padding
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_plan_to_watch_btt
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview_change_api
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview_change_api2
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview_description
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview_hidden_next_focus
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview_hidden_prev_focus
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview_info_btt
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview_play_btt
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview_tags
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview_text
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview_viewpager
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_type_completed_btt
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_type_dropped_btt
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_type_on_hold_btt
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_type_watching_btt
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_watch_child_recyclerview
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_watch_holder
|
||||
|
||||
class HomeParentItemAdapterPreview(
|
||||
items: MutableList<HomeViewModel.ExpandableHomepageList>,
|
||||
|
@ -147,250 +119,13 @@ class HomeParentItemAdapterPreview(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
class HeaderViewHolder
|
||||
constructor(
|
||||
val binding: ViewBinding,
|
||||
val viewModel: HomeViewModel,
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
private var previewAdapter: HomeScrollAdapter? = null
|
||||
private val previewViewpager: ViewPager2? = itemView.home_preview_viewpager
|
||||
private val previewHeader: FrameLayout? = itemView.home_preview
|
||||
private val previewCallback: ViewPager2.OnPageChangeCallback =
|
||||
object : ViewPager2.OnPageChangeCallback() {
|
||||
override fun onPageSelected(position: Int) {
|
||||
// home_search?.isIconified = true
|
||||
//home_search?.isVisible = true
|
||||
//home_search?.clearFocus()
|
||||
|
||||
previewAdapter?.apply {
|
||||
if (position >= itemCount - 1 && hasMoreItems) {
|
||||
hasMoreItems = false // don't make two requests
|
||||
viewModel.loadMoreHomeScrollResponses()
|
||||
//homeViewModel.loadMoreHomeScrollResponses()
|
||||
}
|
||||
}
|
||||
previewAdapter?.getItem(position)
|
||||
?.apply {
|
||||
//itemView.home_preview_title_holder?.let { parent ->
|
||||
// TransitionManager.beginDelayedTransition(
|
||||
// parent,
|
||||
// ChangeBounds()
|
||||
// )
|
||||
//}
|
||||
itemView.home_preview_description?.isGone =
|
||||
this.plot.isNullOrBlank()
|
||||
itemView.home_preview_description?.text =
|
||||
this.plot ?: ""
|
||||
itemView.home_preview_text?.text = this.name
|
||||
itemView.home_preview_tags?.apply {
|
||||
removeAllViews()
|
||||
tags?.forEach { tag ->
|
||||
val chip = Chip(context)
|
||||
val chipDrawable =
|
||||
ChipDrawable.createFromAttributes(
|
||||
context,
|
||||
null,
|
||||
0,
|
||||
R.style.ChipFilledSemiTransparent
|
||||
)
|
||||
chip.setChipDrawable(chipDrawable)
|
||||
chip.text = tag
|
||||
chip.isChecked = false
|
||||
chip.isCheckable = false
|
||||
chip.isFocusable = false
|
||||
chip.isClickable = false
|
||||
addView(chip)
|
||||
}
|
||||
}
|
||||
itemView.home_preview_tags?.isGone =
|
||||
tags.isNullOrEmpty()
|
||||
itemView.home_preview_image?.setImage(
|
||||
posterUrl,
|
||||
posterHeaders
|
||||
)
|
||||
// itemView.home_preview_title?.text = name
|
||||
|
||||
itemView.home_preview_play?.setOnClickListener { view ->
|
||||
viewModel.click(
|
||||
LoadClickCallback(
|
||||
START_ACTION_RESUME_LATEST,
|
||||
view,
|
||||
position,
|
||||
this
|
||||
)
|
||||
)
|
||||
}
|
||||
itemView.home_preview_info?.setOnClickListener { view ->
|
||||
viewModel.click(
|
||||
LoadClickCallback(0, view, position, this)
|
||||
)
|
||||
}
|
||||
|
||||
itemView.home_preview_play_btt?.setOnClickListener { view ->
|
||||
viewModel.click(
|
||||
LoadClickCallback(
|
||||
START_ACTION_RESUME_LATEST,
|
||||
view,
|
||||
position,
|
||||
this
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// This makes the hidden next buttons only available when on the info button
|
||||
// Otherwise you might be able to go to the next item without being at the info button
|
||||
itemView.home_preview_info_btt?.setOnFocusChangeListener { _, hasFocus ->
|
||||
itemView.home_preview_hidden_next_focus?.isFocusable = hasFocus
|
||||
}
|
||||
itemView.home_preview_play_btt?.setOnFocusChangeListener { _, hasFocus ->
|
||||
itemView.home_preview_hidden_prev_focus?.isFocusable = hasFocus
|
||||
}
|
||||
|
||||
|
||||
itemView.home_preview_info_btt?.setOnClickListener { view ->
|
||||
viewModel.click(
|
||||
LoadClickCallback(0, view, position, this)
|
||||
)
|
||||
}
|
||||
|
||||
itemView.home_preview_hidden_next_focus?.setOnFocusChangeListener { _, hasFocus ->
|
||||
if (hasFocus) {
|
||||
previewViewpager?.apply {
|
||||
setCurrentItem(currentItem + 1, true)
|
||||
}
|
||||
itemView.home_preview_info_btt?.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
itemView.home_preview_hidden_prev_focus?.setOnFocusChangeListener { _, hasFocus ->
|
||||
if (hasFocus) {
|
||||
previewViewpager?.apply {
|
||||
if (currentItem <= 0) {
|
||||
nav_rail_view?.menu?.getItem(0)?.actionView?.requestFocus()
|
||||
} else {
|
||||
setCurrentItem(currentItem - 1, true)
|
||||
itemView.home_preview_play_btt?.requestFocus()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// very ugly code, but I dont care
|
||||
val watchType =
|
||||
DataStoreHelper.getResultWatchState(this.getId())
|
||||
itemView.home_preview_bookmark?.setText(watchType.stringRes)
|
||||
itemView.home_preview_bookmark?.setCompoundDrawablesWithIntrinsicBounds(
|
||||
null,
|
||||
ContextCompat.getDrawable(
|
||||
itemView.home_preview_bookmark.context,
|
||||
watchType.iconRes
|
||||
),
|
||||
null,
|
||||
null
|
||||
)
|
||||
itemView.home_preview_bookmark?.setOnClickListener { fab ->
|
||||
fab.context.getActivity()?.showBottomDialog(
|
||||
WatchType.values()
|
||||
.map { fab.context.getString(it.stringRes) }
|
||||
.toList(),
|
||||
DataStoreHelper.getResultWatchState(this.getId()).ordinal,
|
||||
fab.context.getString(R.string.action_add_to_bookmarks),
|
||||
showApply = false,
|
||||
{}) {
|
||||
val newValue = WatchType.values()[it]
|
||||
itemView.home_preview_bookmark?.setCompoundDrawablesWithIntrinsicBounds(
|
||||
null,
|
||||
ContextCompat.getDrawable(
|
||||
itemView.home_preview_bookmark.context,
|
||||
newValue.iconRes
|
||||
),
|
||||
null,
|
||||
null
|
||||
)
|
||||
itemView.home_preview_bookmark?.setText(newValue.stringRes)
|
||||
|
||||
ResultViewModel2.updateWatchStatus(
|
||||
this,
|
||||
newValue
|
||||
)
|
||||
viewModel.reloadStored()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var resumeAdapter: HomeChildItemAdapter? = null
|
||||
private var resumeHolder: View? = itemView.home_watch_holder
|
||||
private var resumeRecyclerView: RecyclerView? = itemView.home_watch_child_recyclerview
|
||||
|
||||
private var bookmarkHolder: View? = itemView.home_bookmarked_holder
|
||||
private var bookmarkAdapter: HomeChildItemAdapter? = null
|
||||
private var bookmarkRecyclerView: RecyclerView? =
|
||||
itemView.home_bookmarked_child_recyclerview
|
||||
|
||||
fun onViewDetachedFromWindow() {
|
||||
previewViewpager?.unregisterOnPageChangeCallback(previewCallback)
|
||||
}
|
||||
|
||||
fun onViewAttachedToWindow() {
|
||||
previewViewpager?.registerOnPageChangeCallback(previewCallback)
|
||||
|
||||
binding.root.findViewTreeLifecycleOwner()?.apply {
|
||||
observe(viewModel.preview) {
|
||||
updatePreview(it)
|
||||
}
|
||||
observe(viewModel.apiName) {
|
||||
updateApiName(it)
|
||||
}
|
||||
observe(viewModel.resumeWatching) {
|
||||
updateResume(it)
|
||||
}
|
||||
observe(viewModel.bookmarks) {
|
||||
updateBookmarks(it)
|
||||
}
|
||||
observe(viewModel.availableWatchStatusTypes) {
|
||||
setAvailableWatchStatusTypes(it)
|
||||
}
|
||||
} ?: debugException { "Expected findViewTreeLifecycleOwner" }
|
||||
}
|
||||
|
||||
private val toggleList = listOf(
|
||||
Pair(itemView.home_type_watching_btt, WatchType.WATCHING),
|
||||
Pair(itemView.home_type_completed_btt, WatchType.COMPLETED),
|
||||
Pair(itemView.home_type_dropped_btt, WatchType.DROPPED),
|
||||
Pair(itemView.home_type_on_hold_btt, WatchType.ONHOLD),
|
||||
Pair(itemView.home_plan_to_watch_btt, WatchType.PLANTOWATCH),
|
||||
)
|
||||
|
||||
init {
|
||||
if (binding is FragmentHomeHeadTvBinding) {
|
||||
binding.homePreviewChangeApi.setOnClickListener { view ->
|
||||
view.context.selectHomepage(viewModel.repo?.name) { api ->
|
||||
viewModel.loadAndCancel(api)
|
||||
}
|
||||
}
|
||||
binding.homePreviewChangeApi2.setOnClickListener { view ->
|
||||
view.context.selectHomepage(viewModel.repo?.name) { api ->
|
||||
viewModel.loadAndCancel(api)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
previewViewpager?.apply {
|
||||
//if (!isTvSettings())
|
||||
setPageTransformer(HomeScrollTransformer())
|
||||
//else
|
||||
// setPageTransformer(null)
|
||||
|
||||
if (adapter == null)
|
||||
adapter = HomeScrollAdapter()
|
||||
}
|
||||
previewAdapter = previewViewpager?.adapter as? HomeScrollAdapter?
|
||||
// previewViewpager?.registerOnPageChangeCallback(previewCallback)
|
||||
|
||||
if (resumeAdapter == null) {
|
||||
resumeRecyclerView?.adapter = HomeChildItemAdapter(
|
||||
private var previewAdapter: HomeScrollAdapter = HomeScrollAdapter()
|
||||
private var resumeAdapter: HomeChildItemAdapter = HomeChildItemAdapter(
|
||||
ArrayList(),
|
||||
nextFocusUp = itemView.nextFocusUpId,
|
||||
nextFocusDown = itemView.nextFocusDownId
|
||||
|
@ -423,7 +158,6 @@ class HomeParentItemAdapterPreview(
|
|||
callback.card
|
||||
)
|
||||
)
|
||||
viewModel.reloadStored()
|
||||
}
|
||||
//info
|
||||
1 -> {
|
||||
|
@ -435,8 +169,6 @@ class HomeParentItemAdapterPreview(
|
|||
callback.card
|
||||
)
|
||||
)
|
||||
|
||||
viewModel.reloadStored()
|
||||
}
|
||||
// remove
|
||||
2 -> {
|
||||
|
@ -449,10 +181,7 @@ class HomeParentItemAdapterPreview(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
resumeAdapter = resumeRecyclerView?.adapter as? HomeChildItemAdapter
|
||||
if (bookmarkAdapter == null) {
|
||||
bookmarkRecyclerView?.adapter = HomeChildItemAdapter(
|
||||
private var bookmarkAdapter: HomeChildItemAdapter = HomeChildItemAdapter(
|
||||
ArrayList(),
|
||||
nextFocusUp = itemView.nextFocusUpId,
|
||||
nextFocusDown = itemView.nextFocusDownId
|
||||
|
@ -484,7 +213,6 @@ class HomeParentItemAdapterPreview(
|
|||
callback.card
|
||||
)
|
||||
)
|
||||
viewModel.reloadStored()
|
||||
}
|
||||
|
||||
1 -> { // info
|
||||
|
@ -496,8 +224,6 @@ class HomeParentItemAdapterPreview(
|
|||
callback.card
|
||||
)
|
||||
)
|
||||
|
||||
viewModel.reloadStored()
|
||||
}
|
||||
|
||||
2 -> { // remove
|
||||
|
@ -510,99 +236,323 @@ class HomeParentItemAdapterPreview(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bookmarkAdapter = bookmarkRecyclerView?.adapter as? HomeChildItemAdapter
|
||||
|
||||
for ((chip, watch) in toggleList) {
|
||||
chip?.isChecked = false
|
||||
chip?.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
viewModel.loadStoredData(
|
||||
setOf(watch)
|
||||
// If we filter all buttons then two can be checked at the same time
|
||||
// Revert this if you want to go back to multi selection
|
||||
// toggleList.filter { it.first?.isChecked == true }.map { it.second }.toSet()
|
||||
|
||||
private val previewViewpager: ViewPager2 =
|
||||
itemView.findViewById(R.id.home_preview_viewpager)
|
||||
private val previewHeader: FrameLayout = itemView.findViewById(R.id.home_preview)
|
||||
private var resumeHolder: View = itemView.findViewById(R.id.home_watch_holder)
|
||||
private var resumeRecyclerView: RecyclerView =
|
||||
itemView.findViewById(R.id.home_watch_child_recyclerview)
|
||||
private var bookmarkHolder: View = itemView.findViewById(R.id.home_bookmarked_holder)
|
||||
private var bookmarkRecyclerView: RecyclerView =
|
||||
itemView.findViewById(R.id.home_bookmarked_child_recyclerview)
|
||||
|
||||
private val homeNonePadding: View = itemView.findViewById(R.id.home_none_padding)
|
||||
|
||||
private val previewCallback: ViewPager2.OnPageChangeCallback =
|
||||
object : ViewPager2.OnPageChangeCallback() {
|
||||
override fun onPageSelected(position: Int) {
|
||||
previewAdapter.apply {
|
||||
if (position >= itemCount - 1 && hasMoreItems) {
|
||||
hasMoreItems = false // don't make two requests
|
||||
viewModel.loadMoreHomeScrollResponses()
|
||||
}
|
||||
}
|
||||
val item = previewAdapter.getItem(position) ?: return
|
||||
onSelect(item, position)
|
||||
}
|
||||
}
|
||||
|
||||
fun onSelect(item: LoadResponse, position: Int) {
|
||||
(binding as? FragmentHomeHeadTvBinding)?.apply {
|
||||
homePreviewDescription.isGone =
|
||||
item.plot.isNullOrBlank()
|
||||
homePreviewDescription.text =
|
||||
item.plot ?: ""
|
||||
|
||||
homePreviewText.text = item.name
|
||||
homePreviewTags.apply {
|
||||
removeAllViews()
|
||||
item.tags?.forEach { tag ->
|
||||
val chip = Chip(context)
|
||||
val chipDrawable =
|
||||
ChipDrawable.createFromAttributes(
|
||||
context,
|
||||
null,
|
||||
0,
|
||||
R.style.ChipFilledSemiTransparent
|
||||
)
|
||||
chip.setChipDrawable(chipDrawable)
|
||||
chip.text = tag
|
||||
chip.isChecked = false
|
||||
chip.isCheckable = false
|
||||
chip.isFocusable = false
|
||||
chip.isClickable = false
|
||||
addView(chip)
|
||||
}
|
||||
}
|
||||
homePreviewTags.isGone =
|
||||
item.tags.isNullOrEmpty()
|
||||
|
||||
homePreviewPlayBtt.setOnClickListener { view ->
|
||||
viewModel.click(
|
||||
LoadClickCallback(
|
||||
START_ACTION_RESUME_LATEST,
|
||||
view,
|
||||
position,
|
||||
item
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
homePreviewInfoBtt.setOnClickListener { view ->
|
||||
viewModel.click(
|
||||
LoadClickCallback(0, view, position, item)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
(binding as? FragmentHomeHeadBinding)?.apply {
|
||||
homePreviewImage.setImage(item.posterUrl, item.posterHeaders)
|
||||
|
||||
homePreviewPlay.setOnClickListener { view ->
|
||||
viewModel.click(
|
||||
LoadClickCallback(
|
||||
START_ACTION_RESUME_LATEST,
|
||||
view,
|
||||
position,
|
||||
item
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
homePreviewInfo.setOnClickListener { view ->
|
||||
viewModel.click(
|
||||
LoadClickCallback(0, view, position, item)
|
||||
)
|
||||
}
|
||||
|
||||
// very ugly code, but I don't care
|
||||
val id = item.getId()
|
||||
val watchType =
|
||||
DataStoreHelper.getResultWatchState(id)
|
||||
homePreviewBookmark.setText(watchType.stringRes)
|
||||
homePreviewBookmark.setCompoundDrawablesWithIntrinsicBounds(
|
||||
null,
|
||||
ContextCompat.getDrawable(
|
||||
homePreviewBookmark.context,
|
||||
watchType.iconRes
|
||||
),
|
||||
null,
|
||||
null
|
||||
)
|
||||
|
||||
homePreviewBookmark.setOnClickListener { fab ->
|
||||
fab.context.getActivity()?.showBottomDialog(
|
||||
WatchType.values()
|
||||
.map { fab.context.getString(it.stringRes) }
|
||||
.toList(),
|
||||
DataStoreHelper.getResultWatchState(id).ordinal,
|
||||
fab.context.getString(R.string.action_add_to_bookmarks),
|
||||
showApply = false,
|
||||
{}) {
|
||||
val newValue = WatchType.values()[it]
|
||||
homePreviewBookmark.setCompoundDrawablesWithIntrinsicBounds(
|
||||
null,
|
||||
ContextCompat.getDrawable(
|
||||
homePreviewBookmark.context,
|
||||
newValue.iconRes
|
||||
),
|
||||
null,
|
||||
null
|
||||
)
|
||||
homePreviewBookmark.setText(newValue.stringRes)
|
||||
|
||||
ResultViewModel2.updateWatchStatus(
|
||||
item,
|
||||
newValue
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onViewDetachedFromWindow() {
|
||||
previewViewpager.unregisterOnPageChangeCallback(previewCallback)
|
||||
}
|
||||
|
||||
fun onViewAttachedToWindow() {
|
||||
previewViewpager.registerOnPageChangeCallback(previewCallback)
|
||||
|
||||
binding.root.findViewTreeLifecycleOwner()?.apply {
|
||||
observe(viewModel.preview) {
|
||||
updatePreview(it)
|
||||
}
|
||||
if (binding is FragmentHomeHeadTvBinding) {
|
||||
observe(viewModel.apiName) { name ->
|
||||
binding.homePreviewChangeApi.text = name
|
||||
binding.homePreviewChangeApi2.text = name
|
||||
}
|
||||
}
|
||||
observe(viewModel.resumeWatching) {
|
||||
updateResume(it)
|
||||
}
|
||||
observe(viewModel.bookmarks) {
|
||||
updateBookmarks(it)
|
||||
}
|
||||
observe(viewModel.availableWatchStatusTypes) { (visible, checked) ->
|
||||
for ((chip, watch) in toggleList) {
|
||||
chip.apply {
|
||||
isVisible = visible.contains(watch)
|
||||
isChecked = checked.contains(watch)
|
||||
}
|
||||
}
|
||||
}
|
||||
} ?: debugException { "Expected findViewTreeLifecycleOwner" }
|
||||
}
|
||||
|
||||
private val toggleList = listOf<Pair<Chip, WatchType>>(
|
||||
Pair(itemView.findViewById(R.id.home_type_watching_btt), WatchType.WATCHING),
|
||||
Pair(itemView.findViewById(R.id.home_type_completed_btt), WatchType.COMPLETED),
|
||||
Pair(itemView.findViewById(R.id.home_type_dropped_btt), WatchType.DROPPED),
|
||||
Pair(itemView.findViewById(R.id.home_type_on_hold_btt), WatchType.ONHOLD),
|
||||
Pair(itemView.findViewById(R.id.home_plan_to_watch_btt), WatchType.PLANTOWATCH),
|
||||
)
|
||||
|
||||
init {
|
||||
previewViewpager.setPageTransformer(HomeScrollTransformer())
|
||||
|
||||
previewViewpager.adapter = previewAdapter
|
||||
resumeRecyclerView.adapter = resumeAdapter
|
||||
bookmarkRecyclerView.adapter = bookmarkAdapter
|
||||
|
||||
for ((chip, watch) in toggleList) {
|
||||
chip.isChecked = false
|
||||
chip.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
viewModel.loadStoredData(setOf(watch))
|
||||
}
|
||||
// Else if all are unchecked -> Do not load data
|
||||
else if (toggleList.all { it.first?.isChecked != true }) {
|
||||
else if (toggleList.all { !it.first.isChecked }) {
|
||||
viewModel.loadStoredData(emptySet())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fixPaddingStatusbar(itemView.home_search)
|
||||
(binding as? FragmentHomeHeadTvBinding)?.apply {
|
||||
homePreviewChangeApi.setOnClickListener { view ->
|
||||
view.context.selectHomepage(viewModel.repo?.name) { api ->
|
||||
viewModel.loadAndCancel(api)
|
||||
}
|
||||
}
|
||||
homePreviewChangeApi2.setOnClickListener { view ->
|
||||
view.context.selectHomepage(viewModel.repo?.name) { api ->
|
||||
viewModel.loadAndCancel(api)
|
||||
}
|
||||
}
|
||||
|
||||
itemView.home_search?.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
// This makes the hidden next buttons only available when on the info button
|
||||
// Otherwise you might be able to go to the next item without being at the info button
|
||||
homePreviewInfoBtt.setOnFocusChangeListener { _, hasFocus ->
|
||||
homePreviewHiddenNextFocus.isFocusable = hasFocus
|
||||
}
|
||||
|
||||
homePreviewPlayBtt.setOnFocusChangeListener { _, hasFocus ->
|
||||
homePreviewHiddenPrevFocus.isFocusable = hasFocus
|
||||
}
|
||||
|
||||
homePreviewHiddenNextFocus.setOnFocusChangeListener { _, hasFocus ->
|
||||
if (hasFocus) {
|
||||
previewViewpager.setCurrentItem(previewViewpager.currentItem + 1, true)
|
||||
homePreviewInfoBtt.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
homePreviewHiddenPrevFocus.setOnFocusChangeListener { _, hasFocus ->
|
||||
if (hasFocus) {
|
||||
previewViewpager.apply {
|
||||
if (currentItem <= 0) {
|
||||
findViewById<NavigationRailView?>(R.id.nav_rail_view)?.menu?.getItem(
|
||||
0
|
||||
)?.actionView?.requestFocus()
|
||||
} else {
|
||||
setCurrentItem(currentItem - 1, true)
|
||||
binding.homePreviewPlayBtt.requestFocus()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(binding as? FragmentHomeHeadBinding)?.apply {
|
||||
fixPaddingStatusbar(binding.homeSearch)
|
||||
|
||||
homeSearch.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String): Boolean {
|
||||
viewModel.queryTextSubmit(query)
|
||||
|
||||
//QuickSearchFragment.pushSearch(activity, query, currentApiName?.let { arrayOf(it) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String): Boolean {
|
||||
viewModel.queryTextChange(newText)
|
||||
//searchViewModel.quickSearch(newText)
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun updateApiName(name: String) {
|
||||
itemView.home_preview_change_api2?.text = name
|
||||
itemView.home_preview_change_api?.text = name
|
||||
}
|
||||
|
||||
private fun updatePreview(preview: Resource<Pair<Boolean, List<LoadResponse>>>) {
|
||||
itemView.home_preview_change_api2?.isGone = preview is Resource.Success
|
||||
if (binding is FragmentHomeHeadTvBinding) {
|
||||
binding.homePreviewChangeApi2.isGone = preview is Resource.Success
|
||||
}
|
||||
|
||||
if (preview is Resource.Success) {
|
||||
itemView.home_none_padding?.apply {
|
||||
homeNonePadding.apply {
|
||||
val params = layoutParams
|
||||
params.height = 0
|
||||
layoutParams = params
|
||||
}
|
||||
} else {
|
||||
fixPaddingStatusbarView(itemView.home_none_padding)
|
||||
fixPaddingStatusbarView(homeNonePadding)
|
||||
}
|
||||
|
||||
when (preview) {
|
||||
is Resource.Success -> {
|
||||
if (true != previewAdapter?.setItems(
|
||||
if (!previewAdapter.setItems(
|
||||
preview.value.second,
|
||||
preview.value.first
|
||||
)
|
||||
) {
|
||||
// this might seam weird and useless, however this prevents a very weird andrid bug were the viewpager is not rendered properly
|
||||
// I have no idea why that happens, but this is my ducktape solution
|
||||
previewViewpager?.setCurrentItem(0, false)
|
||||
previewViewpager?.beginFakeDrag()
|
||||
previewViewpager?.fakeDragBy(1f)
|
||||
previewViewpager?.endFakeDrag()
|
||||
previewViewpager.setCurrentItem(0, false)
|
||||
previewViewpager.beginFakeDrag()
|
||||
previewViewpager.fakeDragBy(1f)
|
||||
previewViewpager.endFakeDrag()
|
||||
previewCallback.onPageSelected(0)
|
||||
previewHeader?.isVisible = true
|
||||
previewHeader.isVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
previewAdapter?.setItems(listOf(), false)
|
||||
previewViewpager?.setCurrentItem(0, false)
|
||||
previewHeader?.isVisible = false
|
||||
previewAdapter.setItems(listOf(), false)
|
||||
previewViewpager.setCurrentItem(0, false)
|
||||
previewHeader.isVisible = false
|
||||
}
|
||||
}
|
||||
// previewViewpager?.postDelayed({ previewViewpager?.scr(100, 0) }, 1000)
|
||||
//previewViewpager?.postInvalidate()
|
||||
}
|
||||
|
||||
private fun updateResume(resumeWatching: List<SearchResponse>) {
|
||||
resumeHolder?.isVisible = resumeWatching.isNotEmpty()
|
||||
resumeAdapter?.updateList(resumeWatching)
|
||||
resumeHolder.isVisible = resumeWatching.isNotEmpty()
|
||||
resumeAdapter.updateList(resumeWatching)
|
||||
|
||||
if (!isTvSettings()) {
|
||||
itemView.home_watch_parent_item_title?.setOnClickListener {
|
||||
if (binding is FragmentHomeHeadBinding) {
|
||||
binding.homeBookmarkParentItemTitle.setOnClickListener {
|
||||
viewModel.popup(
|
||||
HomeViewModel.ExpandableHomepageList(
|
||||
HomePageList(
|
||||
itemView.home_watch_parent_item_title?.text.toString(),
|
||||
binding.homeWatchParentItemTitle.text.toString(),
|
||||
resumeWatching,
|
||||
false
|
||||
), 1, false
|
||||
|
@ -614,11 +564,12 @@ class HomeParentItemAdapterPreview(
|
|||
|
||||
private fun updateBookmarks(data: Pair<Boolean, List<SearchResponse>>) {
|
||||
val (visible, list) = data
|
||||
bookmarkHolder?.isVisible = visible
|
||||
bookmarkAdapter?.updateList(list)
|
||||
if (!isTvSettings()) {
|
||||
itemView.home_bookmark_parent_item_title?.setOnClickListener {
|
||||
val items = toggleList.mapNotNull { it.first }.filter { it.isChecked }
|
||||
bookmarkHolder.isVisible = visible
|
||||
bookmarkAdapter.updateList(list)
|
||||
|
||||
if (binding is FragmentHomeHeadBinding) {
|
||||
binding.homeBookmarkParentItemTitle.setOnClickListener {
|
||||
val items = toggleList.map { it.first }.filter { it.isChecked }
|
||||
if (items.isEmpty()) return@setOnClickListener // we don't want to show an empty dialog
|
||||
val textSum = items
|
||||
.mapNotNull { it.text }.joinToString()
|
||||
|
@ -635,15 +586,5 @@ class HomeParentItemAdapterPreview(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setAvailableWatchStatusTypes(availableWatchStatusTypes: Pair<Set<WatchType>, Set<WatchType>>) {
|
||||
val (visible, checked) = availableWatchStatusTypes
|
||||
for ((chip, watch) in toggleList) {
|
||||
chip?.apply {
|
||||
isVisible = visible.contains(watch)
|
||||
isChecked = checked.contains(watch)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -436,6 +436,8 @@ class ResultViewModel2 : ViewModel() {
|
|||
fun updateWatchStatus(currentResponse: LoadResponse, status: WatchType) {
|
||||
val currentId = currentResponse.getId()
|
||||
|
||||
val currentWatchType = getResultWatchState(currentId)
|
||||
|
||||
DataStoreHelper.setResultWatchState(currentId, status.internalId)
|
||||
val current = DataStoreHelper.getBookmarkedData(currentId)
|
||||
val currentTime = System.currentTimeMillis()
|
||||
|
@ -453,6 +455,9 @@ class ResultViewModel2 : ViewModel() {
|
|||
currentResponse.year
|
||||
)
|
||||
)
|
||||
if(currentWatchType != status) {
|
||||
MainActivity.bookmarksUpdatedEvent(true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun filterName(name: String?): String? {
|
||||
|
|
Loading…
Reference in a new issue