mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
4664: Moved PageableMediaFragment to ViewBinding (#5090)
This commit is contained in:
parent
4c24b65d2d
commit
3fd63b009a
1 changed files with 20 additions and 3 deletions
|
|
@ -2,17 +2,24 @@ package fr.free.nrw.commons.explore.media
|
|||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.category.CategoryImagesCallback
|
||||
import fr.free.nrw.commons.databinding.FragmentSearchPaginatedBinding
|
||||
import fr.free.nrw.commons.explore.paging.BasePagingFragment
|
||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment.MediaDetailProvider
|
||||
import kotlinx.android.synthetic.main.fragment_search_paginated.*
|
||||
|
||||
|
||||
abstract class PageableMediaFragment : BasePagingFragment<Media>(), MediaDetailProvider {
|
||||
|
||||
/**
|
||||
* ViewBinding
|
||||
*/
|
||||
private var _binding: FragmentSearchPaginatedBinding? = null
|
||||
private val binding get() = _binding
|
||||
|
||||
override val pagedListAdapter by lazy {
|
||||
PagedMediaAdapter(categoryImagesCallback::onMediaClicked)
|
||||
}
|
||||
|
|
@ -32,6 +39,15 @@ abstract class PageableMediaFragment : BasePagingFragment<Media>(), MediaDetailP
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = FragmentSearchPaginatedBinding.inflate(inflater, container, false)
|
||||
return binding?.root
|
||||
}
|
||||
|
||||
private val simpleDataObserver =
|
||||
SimpleDataObserver { categoryImagesCallback.viewPagerNotifyDataSetChanged() }
|
||||
|
||||
|
|
@ -41,6 +57,7 @@ abstract class PageableMediaFragment : BasePagingFragment<Media>(), MediaDetailP
|
|||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
_binding = null
|
||||
super.onDestroyView()
|
||||
pagedListAdapter.unregisterAdapterDataObserver(simpleDataObserver)
|
||||
}
|
||||
|
|
@ -49,7 +66,7 @@ abstract class PageableMediaFragment : BasePagingFragment<Media>(), MediaDetailP
|
|||
pagedListAdapter.currentList?.get(position)?.takeIf { it.filename != null }
|
||||
.also {
|
||||
pagedListAdapter.currentList?.loadAround(position)
|
||||
paginatedSearchResultsList.scrollToPosition(position)
|
||||
binding?.paginatedSearchResultsList?.scrollToPosition(position)
|
||||
}
|
||||
|
||||
override fun getTotalMediaCount(): Int = pagedListAdapter.itemCount
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue