Skip to content

Commit

Permalink
Set the selected position of the grid to the selected asset in the sl…
Browse files Browse the repository at this point in the history
…ideshow
  • Loading branch information
giejay committed Dec 22, 2024
1 parent b8f7e3e commit 4c3919e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ abstract class GenericAssetFragment : VerticalCardGridFragment<Asset>() {
true,
toSliderItems,
loadMore
)
) { item -> manualUpdatePosition(this.assets.indexOfFirst { item.ids().contains(it.id) }) }
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import timber.log.Timber
* A fragment for rendering items in a vertical grids.
*/
open class GridFragment(val hideProgressBar: Boolean = false) : BrandedSupportFragment(), BrowseSupportFragment.MainFragmentAdapterProvider {
private var manuallySelectedPosition: Boolean = false
private var mAdapter: ArrayObjectAdapter = ArrayObjectAdapter()
private var mGridPresenter: VerticalGridPresenter? = null
private var mGridViewHolder: VerticalGridPresenter.ViewHolder? = null
Expand Down Expand Up @@ -103,9 +104,12 @@ open class GridFragment(val hideProgressBar: Boolean = false) : BrandedSupportFr
}

private fun gridOnItemSelected(position: Int) {
if (position != mSelectedPosition) {
if (!manuallySelectedPosition && position != mSelectedPosition) {
mSelectedPosition = position
showOrHideTitle()
} else {
setSelectedPosition(mSelectedPosition)
manuallySelectedPosition = false
}
}

Expand Down Expand Up @@ -190,11 +194,20 @@ open class GridFragment(val hideProgressBar: Boolean = false) : BrandedSupportFr
if (mGridViewHolder != null) {
mGridPresenter?.onBindViewHolder(mGridViewHolder!!, mAdapter)
if (mSelectedPosition != -1) {
mGridViewHolder?.gridView?.selectedPosition = mSelectedPosition
updateSelectionPosition(mSelectedPosition)
}
}
}

fun manualUpdatePosition(position: Int){
mSelectedPosition = position
manuallySelectedPosition = true
}

private fun updateSelectionPosition(selectionPosition: Int) {
mGridViewHolder?.gridView?.selectedPosition = selectionPosition
}

fun setEntranceTransitionState(afterTransition: Boolean) {
mGridPresenter?.setEntranceTransitionState(mGridViewHolder!!, afterTransition)
}
Expand Down

0 comments on commit 4c3919e

Please sign in to comment.