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,
|
showApply = false,
|
||||||
{}) {
|
{}) {
|
||||||
viewModel.updateWatchStatus(WatchType.values()[it])
|
viewModel.updateWatchStatus(WatchType.values()[it])
|
||||||
bookmarksUpdatedEvent(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import androidx.viewbinding.ViewBinding
|
||||||
import androidx.viewpager2.widget.ViewPager2
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import com.google.android.material.chip.ChipDrawable
|
import com.google.android.material.chip.ChipDrawable
|
||||||
|
import com.google.android.material.navigationrail.NavigationRailView
|
||||||
import com.lagradost.cloudstream3.APIHolder.getId
|
import com.lagradost.cloudstream3.APIHolder.getId
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity
|
import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity
|
||||||
import com.lagradost.cloudstream3.HomePageList
|
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.fixPaddingStatusbar
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarView
|
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarView
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
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(
|
class HomeParentItemAdapterPreview(
|
||||||
items: MutableList<HomeViewModel.ExpandableHomepageList>,
|
items: MutableList<HomeViewModel.ExpandableHomepageList>,
|
||||||
|
@ -147,201 +119,281 @@ class HomeParentItemAdapterPreview(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class HeaderViewHolder
|
class HeaderViewHolder
|
||||||
constructor(
|
constructor(
|
||||||
val binding: ViewBinding,
|
val binding: ViewBinding,
|
||||||
val viewModel: HomeViewModel,
|
val viewModel: HomeViewModel,
|
||||||
) : RecyclerView.ViewHolder(binding.root) {
|
) : RecyclerView.ViewHolder(binding.root) {
|
||||||
private var previewAdapter: HomeScrollAdapter? = null
|
private var previewAdapter: HomeScrollAdapter = HomeScrollAdapter()
|
||||||
private val previewViewpager: ViewPager2? = itemView.home_preview_viewpager
|
private var resumeAdapter: HomeChildItemAdapter = HomeChildItemAdapter(
|
||||||
private val previewHeader: FrameLayout? = itemView.home_preview
|
ArrayList(),
|
||||||
|
nextFocusUp = itemView.nextFocusUpId,
|
||||||
|
nextFocusDown = itemView.nextFocusDownId
|
||||||
|
) { callback ->
|
||||||
|
if (callback.action != SEARCH_ACTION_SHOW_METADATA) {
|
||||||
|
viewModel.click(callback)
|
||||||
|
return@HomeChildItemAdapter
|
||||||
|
}
|
||||||
|
callback.view.context?.getActivity()?.showOptionSelectStringRes(
|
||||||
|
callback.view,
|
||||||
|
callback.card.posterUrl,
|
||||||
|
listOf(
|
||||||
|
R.string.action_open_watching,
|
||||||
|
R.string.action_remove_watching
|
||||||
|
),
|
||||||
|
listOf(
|
||||||
|
R.string.action_open_play,
|
||||||
|
R.string.action_open_watching,
|
||||||
|
R.string.action_remove_watching
|
||||||
|
)
|
||||||
|
) { (isTv, actionId) ->
|
||||||
|
when (actionId + if (isTv) 0 else 1) {
|
||||||
|
// play
|
||||||
|
0 -> {
|
||||||
|
viewModel.click(
|
||||||
|
SearchClickCallback(
|
||||||
|
START_ACTION_RESUME_LATEST,
|
||||||
|
callback.view,
|
||||||
|
-1,
|
||||||
|
callback.card
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
//info
|
||||||
|
1 -> {
|
||||||
|
viewModel.click(
|
||||||
|
SearchClickCallback(
|
||||||
|
SEARCH_ACTION_LOAD,
|
||||||
|
callback.view,
|
||||||
|
-1,
|
||||||
|
callback.card
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
// remove
|
||||||
|
2 -> {
|
||||||
|
val card = callback.card
|
||||||
|
if (card is DataStoreHelper.ResumeWatchingResult) {
|
||||||
|
DataStoreHelper.removeLastWatched(card.parentId)
|
||||||
|
viewModel.reloadStored()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private var bookmarkAdapter: HomeChildItemAdapter = HomeChildItemAdapter(
|
||||||
|
ArrayList(),
|
||||||
|
nextFocusUp = itemView.nextFocusUpId,
|
||||||
|
nextFocusDown = itemView.nextFocusDownId
|
||||||
|
) { callback ->
|
||||||
|
if (callback.action != SEARCH_ACTION_SHOW_METADATA) {
|
||||||
|
viewModel.click(callback)
|
||||||
|
return@HomeChildItemAdapter
|
||||||
|
}
|
||||||
|
callback.view.context?.getActivity()?.showOptionSelectStringRes(
|
||||||
|
callback.view,
|
||||||
|
callback.card.posterUrl,
|
||||||
|
listOf(
|
||||||
|
R.string.action_open_watching,
|
||||||
|
R.string.action_remove_from_bookmarks,
|
||||||
|
),
|
||||||
|
listOf(
|
||||||
|
R.string.action_open_play,
|
||||||
|
R.string.action_open_watching,
|
||||||
|
R.string.action_remove_from_bookmarks
|
||||||
|
)
|
||||||
|
) { (isTv, actionId) ->
|
||||||
|
when (actionId + if (isTv) 0 else 1) { // play
|
||||||
|
0 -> {
|
||||||
|
viewModel.click(
|
||||||
|
SearchClickCallback(
|
||||||
|
START_ACTION_RESUME_LATEST,
|
||||||
|
callback.view,
|
||||||
|
-1,
|
||||||
|
callback.card
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
1 -> { // info
|
||||||
|
viewModel.click(
|
||||||
|
SearchClickCallback(
|
||||||
|
SEARCH_ACTION_LOAD,
|
||||||
|
callback.view,
|
||||||
|
-1,
|
||||||
|
callback.card
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
2 -> { // remove
|
||||||
|
DataStoreHelper.setResultWatchState(
|
||||||
|
callback.card.id,
|
||||||
|
WatchType.NONE.internalId
|
||||||
|
)
|
||||||
|
viewModel.reloadStored()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 =
|
private val previewCallback: ViewPager2.OnPageChangeCallback =
|
||||||
object : ViewPager2.OnPageChangeCallback() {
|
object : ViewPager2.OnPageChangeCallback() {
|
||||||
override fun onPageSelected(position: Int) {
|
override fun onPageSelected(position: Int) {
|
||||||
// home_search?.isIconified = true
|
previewAdapter.apply {
|
||||||
//home_search?.isVisible = true
|
|
||||||
//home_search?.clearFocus()
|
|
||||||
|
|
||||||
previewAdapter?.apply {
|
|
||||||
if (position >= itemCount - 1 && hasMoreItems) {
|
if (position >= itemCount - 1 && hasMoreItems) {
|
||||||
hasMoreItems = false // don't make two requests
|
hasMoreItems = false // don't make two requests
|
||||||
viewModel.loadMoreHomeScrollResponses()
|
viewModel.loadMoreHomeScrollResponses()
|
||||||
//homeViewModel.loadMoreHomeScrollResponses()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
previewAdapter?.getItem(position)
|
val item = previewAdapter.getItem(position) ?: return
|
||||||
?.apply {
|
onSelect(item, position)
|
||||||
//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
|
fun onSelect(item: LoadResponse, position: Int) {
|
||||||
private var resumeHolder: View? = itemView.home_watch_holder
|
(binding as? FragmentHomeHeadTvBinding)?.apply {
|
||||||
private var resumeRecyclerView: RecyclerView? = itemView.home_watch_child_recyclerview
|
homePreviewDescription.isGone =
|
||||||
|
item.plot.isNullOrBlank()
|
||||||
|
homePreviewDescription.text =
|
||||||
|
item.plot ?: ""
|
||||||
|
|
||||||
private var bookmarkHolder: View? = itemView.home_bookmarked_holder
|
homePreviewText.text = item.name
|
||||||
private var bookmarkAdapter: HomeChildItemAdapter? = null
|
homePreviewTags.apply {
|
||||||
private var bookmarkRecyclerView: RecyclerView? =
|
removeAllViews()
|
||||||
itemView.home_bookmarked_child_recyclerview
|
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() {
|
fun onViewDetachedFromWindow() {
|
||||||
previewViewpager?.unregisterOnPageChangeCallback(previewCallback)
|
previewViewpager.unregisterOnPageChangeCallback(previewCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onViewAttachedToWindow() {
|
fun onViewAttachedToWindow() {
|
||||||
previewViewpager?.registerOnPageChangeCallback(previewCallback)
|
previewViewpager.registerOnPageChangeCallback(previewCallback)
|
||||||
|
|
||||||
binding.root.findViewTreeLifecycleOwner()?.apply {
|
binding.root.findViewTreeLifecycleOwner()?.apply {
|
||||||
observe(viewModel.preview) {
|
observe(viewModel.preview) {
|
||||||
updatePreview(it)
|
updatePreview(it)
|
||||||
}
|
}
|
||||||
observe(viewModel.apiName) {
|
if (binding is FragmentHomeHeadTvBinding) {
|
||||||
updateApiName(it)
|
observe(viewModel.apiName) { name ->
|
||||||
|
binding.homePreviewChangeApi.text = name
|
||||||
|
binding.homePreviewChangeApi2.text = name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
observe(viewModel.resumeWatching) {
|
observe(viewModel.resumeWatching) {
|
||||||
updateResume(it)
|
updateResume(it)
|
||||||
|
@ -349,260 +401,158 @@ class HomeParentItemAdapterPreview(
|
||||||
observe(viewModel.bookmarks) {
|
observe(viewModel.bookmarks) {
|
||||||
updateBookmarks(it)
|
updateBookmarks(it)
|
||||||
}
|
}
|
||||||
observe(viewModel.availableWatchStatusTypes) {
|
observe(viewModel.availableWatchStatusTypes) { (visible, checked) ->
|
||||||
setAvailableWatchStatusTypes(it)
|
for ((chip, watch) in toggleList) {
|
||||||
|
chip.apply {
|
||||||
|
isVisible = visible.contains(watch)
|
||||||
|
isChecked = checked.contains(watch)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} ?: debugException { "Expected findViewTreeLifecycleOwner" }
|
} ?: debugException { "Expected findViewTreeLifecycleOwner" }
|
||||||
}
|
}
|
||||||
|
|
||||||
private val toggleList = listOf(
|
private val toggleList = listOf<Pair<Chip, WatchType>>(
|
||||||
Pair(itemView.home_type_watching_btt, WatchType.WATCHING),
|
Pair(itemView.findViewById(R.id.home_type_watching_btt), WatchType.WATCHING),
|
||||||
Pair(itemView.home_type_completed_btt, WatchType.COMPLETED),
|
Pair(itemView.findViewById(R.id.home_type_completed_btt), WatchType.COMPLETED),
|
||||||
Pair(itemView.home_type_dropped_btt, WatchType.DROPPED),
|
Pair(itemView.findViewById(R.id.home_type_dropped_btt), WatchType.DROPPED),
|
||||||
Pair(itemView.home_type_on_hold_btt, WatchType.ONHOLD),
|
Pair(itemView.findViewById(R.id.home_type_on_hold_btt), WatchType.ONHOLD),
|
||||||
Pair(itemView.home_plan_to_watch_btt, WatchType.PLANTOWATCH),
|
Pair(itemView.findViewById(R.id.home_plan_to_watch_btt), WatchType.PLANTOWATCH),
|
||||||
)
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (binding is FragmentHomeHeadTvBinding) {
|
previewViewpager.setPageTransformer(HomeScrollTransformer())
|
||||||
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 {
|
previewViewpager.adapter = previewAdapter
|
||||||
//if (!isTvSettings())
|
resumeRecyclerView.adapter = resumeAdapter
|
||||||
setPageTransformer(HomeScrollTransformer())
|
bookmarkRecyclerView.adapter = bookmarkAdapter
|
||||||
//else
|
|
||||||
// setPageTransformer(null)
|
|
||||||
|
|
||||||
if (adapter == null)
|
|
||||||
adapter = HomeScrollAdapter()
|
|
||||||
}
|
|
||||||
previewAdapter = previewViewpager?.adapter as? HomeScrollAdapter?
|
|
||||||
// previewViewpager?.registerOnPageChangeCallback(previewCallback)
|
|
||||||
|
|
||||||
if (resumeAdapter == null) {
|
|
||||||
resumeRecyclerView?.adapter = HomeChildItemAdapter(
|
|
||||||
ArrayList(),
|
|
||||||
nextFocusUp = itemView.nextFocusUpId,
|
|
||||||
nextFocusDown = itemView.nextFocusDownId
|
|
||||||
) { callback ->
|
|
||||||
if (callback.action != SEARCH_ACTION_SHOW_METADATA) {
|
|
||||||
viewModel.click(callback)
|
|
||||||
return@HomeChildItemAdapter
|
|
||||||
}
|
|
||||||
callback.view.context?.getActivity()?.showOptionSelectStringRes(
|
|
||||||
callback.view,
|
|
||||||
callback.card.posterUrl,
|
|
||||||
listOf(
|
|
||||||
R.string.action_open_watching,
|
|
||||||
R.string.action_remove_watching
|
|
||||||
),
|
|
||||||
listOf(
|
|
||||||
R.string.action_open_play,
|
|
||||||
R.string.action_open_watching,
|
|
||||||
R.string.action_remove_watching
|
|
||||||
)
|
|
||||||
) { (isTv, actionId) ->
|
|
||||||
when (actionId + if (isTv) 0 else 1) {
|
|
||||||
// play
|
|
||||||
0 -> {
|
|
||||||
viewModel.click(
|
|
||||||
SearchClickCallback(
|
|
||||||
START_ACTION_RESUME_LATEST,
|
|
||||||
callback.view,
|
|
||||||
-1,
|
|
||||||
callback.card
|
|
||||||
)
|
|
||||||
)
|
|
||||||
viewModel.reloadStored()
|
|
||||||
}
|
|
||||||
//info
|
|
||||||
1 -> {
|
|
||||||
viewModel.click(
|
|
||||||
SearchClickCallback(
|
|
||||||
SEARCH_ACTION_LOAD,
|
|
||||||
callback.view,
|
|
||||||
-1,
|
|
||||||
callback.card
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
viewModel.reloadStored()
|
|
||||||
}
|
|
||||||
// remove
|
|
||||||
2 -> {
|
|
||||||
val card = callback.card
|
|
||||||
if (card is DataStoreHelper.ResumeWatchingResult) {
|
|
||||||
DataStoreHelper.removeLastWatched(card.parentId)
|
|
||||||
viewModel.reloadStored()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resumeAdapter = resumeRecyclerView?.adapter as? HomeChildItemAdapter
|
|
||||||
if (bookmarkAdapter == null) {
|
|
||||||
bookmarkRecyclerView?.adapter = HomeChildItemAdapter(
|
|
||||||
ArrayList(),
|
|
||||||
nextFocusUp = itemView.nextFocusUpId,
|
|
||||||
nextFocusDown = itemView.nextFocusDownId
|
|
||||||
) { callback ->
|
|
||||||
if (callback.action != SEARCH_ACTION_SHOW_METADATA) {
|
|
||||||
viewModel.click(callback)
|
|
||||||
return@HomeChildItemAdapter
|
|
||||||
}
|
|
||||||
callback.view.context?.getActivity()?.showOptionSelectStringRes(
|
|
||||||
callback.view,
|
|
||||||
callback.card.posterUrl,
|
|
||||||
listOf(
|
|
||||||
R.string.action_open_watching,
|
|
||||||
R.string.action_remove_from_bookmarks,
|
|
||||||
),
|
|
||||||
listOf(
|
|
||||||
R.string.action_open_play,
|
|
||||||
R.string.action_open_watching,
|
|
||||||
R.string.action_remove_from_bookmarks
|
|
||||||
)
|
|
||||||
) { (isTv, actionId) ->
|
|
||||||
when (actionId + if (isTv) 0 else 1) { // play
|
|
||||||
0 -> {
|
|
||||||
viewModel.click(
|
|
||||||
SearchClickCallback(
|
|
||||||
START_ACTION_RESUME_LATEST,
|
|
||||||
callback.view,
|
|
||||||
-1,
|
|
||||||
callback.card
|
|
||||||
)
|
|
||||||
)
|
|
||||||
viewModel.reloadStored()
|
|
||||||
}
|
|
||||||
|
|
||||||
1 -> { // info
|
|
||||||
viewModel.click(
|
|
||||||
SearchClickCallback(
|
|
||||||
SEARCH_ACTION_LOAD,
|
|
||||||
callback.view,
|
|
||||||
-1,
|
|
||||||
callback.card
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
viewModel.reloadStored()
|
|
||||||
}
|
|
||||||
|
|
||||||
2 -> { // remove
|
|
||||||
DataStoreHelper.setResultWatchState(
|
|
||||||
callback.card.id,
|
|
||||||
WatchType.NONE.internalId
|
|
||||||
)
|
|
||||||
viewModel.reloadStored()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bookmarkAdapter = bookmarkRecyclerView?.adapter as? HomeChildItemAdapter
|
|
||||||
|
|
||||||
for ((chip, watch) in toggleList) {
|
for ((chip, watch) in toggleList) {
|
||||||
chip?.isChecked = false
|
chip.isChecked = false
|
||||||
chip?.setOnCheckedChangeListener { _, isChecked ->
|
chip.setOnCheckedChangeListener { _, isChecked ->
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
viewModel.loadStoredData(
|
viewModel.loadStoredData(setOf(watch))
|
||||||
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()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
// Else if all are unchecked -> Do not load data
|
// 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())
|
viewModel.loadStoredData(emptySet())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fixPaddingStatusbar(itemView.home_search)
|
(binding as? FragmentHomeHeadTvBinding)?.apply {
|
||||||
|
homePreviewChangeApi.setOnClickListener { view ->
|
||||||
itemView.home_search?.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
view.context.selectHomepage(viewModel.repo?.name) { api ->
|
||||||
override fun onQueryTextSubmit(query: String): Boolean {
|
viewModel.loadAndCancel(api)
|
||||||
viewModel.queryTextSubmit(query)
|
}
|
||||||
|
}
|
||||||
//QuickSearchFragment.pushSearch(activity, query, currentApiName?.let { arrayOf(it) }
|
homePreviewChangeApi2.setOnClickListener { view ->
|
||||||
return true
|
view.context.selectHomepage(viewModel.repo?.name) { api ->
|
||||||
|
viewModel.loadAndCancel(api)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onQueryTextChange(newText: String): Boolean {
|
// This makes the hidden next buttons only available when on the info button
|
||||||
viewModel.queryTextChange(newText)
|
// Otherwise you might be able to go to the next item without being at the info button
|
||||||
//searchViewModel.quickSearch(newText)
|
homePreviewInfoBtt.setOnFocusChangeListener { _, hasFocus ->
|
||||||
return true
|
homePreviewHiddenNextFocus.isFocusable = hasFocus
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateApiName(name: String) {
|
homePreviewPlayBtt.setOnFocusChangeListener { _, hasFocus ->
|
||||||
itemView.home_preview_change_api2?.text = name
|
homePreviewHiddenPrevFocus.isFocusable = hasFocus
|
||||||
itemView.home_preview_change_api?.text = name
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onQueryTextChange(newText: String): Boolean {
|
||||||
|
viewModel.queryTextChange(newText)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePreview(preview: Resource<Pair<Boolean, List<LoadResponse>>>) {
|
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) {
|
if (preview is Resource.Success) {
|
||||||
itemView.home_none_padding?.apply {
|
homeNonePadding.apply {
|
||||||
val params = layoutParams
|
val params = layoutParams
|
||||||
params.height = 0
|
params.height = 0
|
||||||
layoutParams = params
|
layoutParams = params
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fixPaddingStatusbarView(itemView.home_none_padding)
|
fixPaddingStatusbarView(homeNonePadding)
|
||||||
}
|
}
|
||||||
|
|
||||||
when (preview) {
|
when (preview) {
|
||||||
is Resource.Success -> {
|
is Resource.Success -> {
|
||||||
if (true != previewAdapter?.setItems(
|
if (!previewAdapter.setItems(
|
||||||
preview.value.second,
|
preview.value.second,
|
||||||
preview.value.first
|
preview.value.first
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
// this might seam weird and useless, however this prevents a very weird andrid bug were the viewpager is not rendered properly
|
// 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
|
// I have no idea why that happens, but this is my ducktape solution
|
||||||
previewViewpager?.setCurrentItem(0, false)
|
previewViewpager.setCurrentItem(0, false)
|
||||||
previewViewpager?.beginFakeDrag()
|
previewViewpager.beginFakeDrag()
|
||||||
previewViewpager?.fakeDragBy(1f)
|
previewViewpager.fakeDragBy(1f)
|
||||||
previewViewpager?.endFakeDrag()
|
previewViewpager.endFakeDrag()
|
||||||
previewCallback.onPageSelected(0)
|
previewCallback.onPageSelected(0)
|
||||||
previewHeader?.isVisible = true
|
previewHeader.isVisible = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
previewAdapter?.setItems(listOf(), false)
|
previewAdapter.setItems(listOf(), false)
|
||||||
previewViewpager?.setCurrentItem(0, false)
|
previewViewpager.setCurrentItem(0, false)
|
||||||
previewHeader?.isVisible = false
|
previewHeader.isVisible = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// previewViewpager?.postDelayed({ previewViewpager?.scr(100, 0) }, 1000)
|
|
||||||
//previewViewpager?.postInvalidate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateResume(resumeWatching: List<SearchResponse>) {
|
private fun updateResume(resumeWatching: List<SearchResponse>) {
|
||||||
resumeHolder?.isVisible = resumeWatching.isNotEmpty()
|
resumeHolder.isVisible = resumeWatching.isNotEmpty()
|
||||||
resumeAdapter?.updateList(resumeWatching)
|
resumeAdapter.updateList(resumeWatching)
|
||||||
|
|
||||||
if (!isTvSettings()) {
|
if (binding is FragmentHomeHeadBinding) {
|
||||||
itemView.home_watch_parent_item_title?.setOnClickListener {
|
binding.homeBookmarkParentItemTitle.setOnClickListener {
|
||||||
viewModel.popup(
|
viewModel.popup(
|
||||||
HomeViewModel.ExpandableHomepageList(
|
HomeViewModel.ExpandableHomepageList(
|
||||||
HomePageList(
|
HomePageList(
|
||||||
itemView.home_watch_parent_item_title?.text.toString(),
|
binding.homeWatchParentItemTitle.text.toString(),
|
||||||
resumeWatching,
|
resumeWatching,
|
||||||
false
|
false
|
||||||
), 1, false
|
), 1, false
|
||||||
|
@ -614,11 +564,12 @@ class HomeParentItemAdapterPreview(
|
||||||
|
|
||||||
private fun updateBookmarks(data: Pair<Boolean, List<SearchResponse>>) {
|
private fun updateBookmarks(data: Pair<Boolean, List<SearchResponse>>) {
|
||||||
val (visible, list) = data
|
val (visible, list) = data
|
||||||
bookmarkHolder?.isVisible = visible
|
bookmarkHolder.isVisible = visible
|
||||||
bookmarkAdapter?.updateList(list)
|
bookmarkAdapter.updateList(list)
|
||||||
if (!isTvSettings()) {
|
|
||||||
itemView.home_bookmark_parent_item_title?.setOnClickListener {
|
if (binding is FragmentHomeHeadBinding) {
|
||||||
val items = toggleList.mapNotNull { it.first }.filter { it.isChecked }
|
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
|
if (items.isEmpty()) return@setOnClickListener // we don't want to show an empty dialog
|
||||||
val textSum = items
|
val textSum = items
|
||||||
.mapNotNull { it.text }.joinToString()
|
.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) {
|
fun updateWatchStatus(currentResponse: LoadResponse, status: WatchType) {
|
||||||
val currentId = currentResponse.getId()
|
val currentId = currentResponse.getId()
|
||||||
|
|
||||||
|
val currentWatchType = getResultWatchState(currentId)
|
||||||
|
|
||||||
DataStoreHelper.setResultWatchState(currentId, status.internalId)
|
DataStoreHelper.setResultWatchState(currentId, status.internalId)
|
||||||
val current = DataStoreHelper.getBookmarkedData(currentId)
|
val current = DataStoreHelper.getBookmarkedData(currentId)
|
||||||
val currentTime = System.currentTimeMillis()
|
val currentTime = System.currentTimeMillis()
|
||||||
|
@ -453,6 +455,9 @@ class ResultViewModel2 : ViewModel() {
|
||||||
currentResponse.year
|
currentResponse.year
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
if(currentWatchType != status) {
|
||||||
|
MainActivity.bookmarksUpdatedEvent(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun filterName(name: String?): String? {
|
private fun filterName(name: String?): String? {
|
||||||
|
|
Loading…
Reference in a new issue