ViewBindinglize GalleryPreviewsScene
This commit is contained in:
1 parent
91013daadc
commit
1a28bbcde8
1 file changed
+16
-20
@@ -31,7 +31,6 @@ import androidx.appcompat.app.AlertDialog
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.slider.Slider
|
import com.google.android.material.slider.Slider
|
||||||
import com.hippo.app.BaseDialogBuilder
|
import com.hippo.app.BaseDialogBuilder
|
||||||
import com.hippo.easyrecyclerview.EasyRecyclerView
|
|
||||||
import com.hippo.easyrecyclerview.MarginItemDecoration
|
import com.hippo.easyrecyclerview.MarginItemDecoration
|
||||||
import com.hippo.ehviewer.R
|
import com.hippo.ehviewer.R
|
||||||
import com.hippo.ehviewer.Settings
|
import com.hippo.ehviewer.Settings
|
||||||
@@ -43,7 +42,7 @@ import com.hippo.ehviewer.client.data.GalleryInfo
|
|||||||
import com.hippo.ehviewer.client.data.GalleryPreview
|
import com.hippo.ehviewer.client.data.GalleryPreview
|
||||||
import com.hippo.ehviewer.client.data.PreviewSet
|
import com.hippo.ehviewer.client.data.PreviewSet
|
||||||
import com.hippo.ehviewer.client.exception.EhException
|
import com.hippo.ehviewer.client.exception.EhException
|
||||||
import com.hippo.widget.ContentLayout
|
import com.hippo.ehviewer.databinding.SceneGalleryPreviewsBinding
|
||||||
import com.hippo.widget.ContentLayout.ContentHelper
|
import com.hippo.widget.ContentLayout.ContentHelper
|
||||||
import com.hippo.widget.LoadImageView
|
import com.hippo.widget.LoadImageView
|
||||||
import com.hippo.widget.recyclerview.AutoGridLayoutManager
|
import com.hippo.widget.recyclerview.AutoGridLayoutManager
|
||||||
@@ -53,8 +52,10 @@ import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
|||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
class GalleryPreviewsScene : BaseToolbarScene() {
|
class GalleryPreviewsScene : BaseToolbarScene() {
|
||||||
|
private var _binding: SceneGalleryPreviewsBinding? = null
|
||||||
|
private val binding
|
||||||
|
get() = _binding!!
|
||||||
private var mGalleryInfo: GalleryInfo? = null
|
private var mGalleryInfo: GalleryInfo? = null
|
||||||
private var mRecyclerView: EasyRecyclerView? = null
|
|
||||||
private var mAdapter: GalleryPreviewAdapter? = null
|
private var mAdapter: GalleryPreviewAdapter? = null
|
||||||
private var mHelper: GalleryPreviewHelper? = null
|
private var mHelper: GalleryPreviewHelper? = null
|
||||||
private var mHasFirstRefresh = false
|
private var mHasFirstRefresh = false
|
||||||
@@ -92,32 +93,29 @@ class GalleryPreviewsScene : BaseToolbarScene() {
|
|||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?, savedInstanceState: Bundle?
|
container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
val mContentLayout = inflater.inflate(
|
_binding = SceneGalleryPreviewsBinding.inflate(inflater, container, false)
|
||||||
R.layout.scene_gallery_previews, container, false
|
binding.contentLayout.hideFastScroll()
|
||||||
) as ContentLayout
|
setLiftOnScrollTargetView(binding.contentLayout)
|
||||||
mContentLayout.hideFastScroll()
|
|
||||||
mRecyclerView = mContentLayout.recyclerView
|
|
||||||
setLiftOnScrollTargetView(mRecyclerView)
|
|
||||||
mAdapter = GalleryPreviewAdapter()
|
mAdapter = GalleryPreviewAdapter()
|
||||||
mRecyclerView!!.adapter = mAdapter
|
binding.contentLayout.recyclerView.adapter = mAdapter
|
||||||
val columnWidth = Settings.getThumbSize()
|
val columnWidth = Settings.getThumbSize()
|
||||||
val layoutManager =
|
val layoutManager =
|
||||||
AutoGridLayoutManager(context, columnWidth, LayoutUtils.dp2pix(context, 16f))
|
AutoGridLayoutManager(context, columnWidth, LayoutUtils.dp2pix(context, 16f))
|
||||||
layoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_SUITABLE_SIZE)
|
layoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_SUITABLE_SIZE)
|
||||||
mRecyclerView!!.layoutManager = layoutManager
|
binding.contentLayout.recyclerView.layoutManager = layoutManager
|
||||||
mRecyclerView!!.clipToPadding = false
|
binding.contentLayout.recyclerView.clipToPadding = false
|
||||||
val padding = LayoutUtils.dp2pix(context, 4f)
|
val padding = LayoutUtils.dp2pix(context, 4f)
|
||||||
val decoration = MarginItemDecoration(padding, padding, padding, padding, padding)
|
val decoration = MarginItemDecoration(padding, padding, padding, padding, padding)
|
||||||
mRecyclerView!!.addItemDecoration(decoration)
|
binding.contentLayout.recyclerView.addItemDecoration(decoration)
|
||||||
mHelper = GalleryPreviewHelper()
|
mHelper = GalleryPreviewHelper()
|
||||||
mContentLayout.setHelper(mHelper)
|
binding.contentLayout.setHelper(mHelper)
|
||||||
|
|
||||||
// Only refresh for the first time
|
// Only refresh for the first time
|
||||||
if (!mHasFirstRefresh) {
|
if (!mHasFirstRefresh) {
|
||||||
mHasFirstRefresh = true
|
mHasFirstRefresh = true
|
||||||
mHelper!!.firstRefresh()
|
mHelper?.firstRefresh()
|
||||||
}
|
}
|
||||||
return mContentLayout
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -127,10 +125,8 @@ class GalleryPreviewsScene : BaseToolbarScene() {
|
|||||||
mHasFirstRefresh = false
|
mHasFirstRefresh = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (null != mRecyclerView) {
|
binding.contentLayout.recyclerView.stopScroll()
|
||||||
mRecyclerView!!.stopScroll()
|
_binding = null
|
||||||
mRecyclerView = null
|
|
||||||
}
|
|
||||||
mAdapter = null
|
mAdapter = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user