Skip to content

Commit

Permalink
viewBinding refactorings & use delegates;
Browse files Browse the repository at this point in the history
LBaseQuickAdapter
  • Loading branch information
ultraxz committed Jul 15, 2023
1 parent cb22439 commit 38fe6cc
Show file tree
Hide file tree
Showing 51 changed files with 965 additions and 1,132 deletions.
13 changes: 10 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ dependencies {
//implementation("io.github.cymchad:BaseRecyclerViewAdapterHelper:4.0.0-beta14")
implementation("io.github.cymchad:BaseRecyclerViewAdapterHelper:3.0.14")

//val ViewBindingKTXVersion = "2.1.0"
//implementation("com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-ktx:$ViewBindingKTXVersion")
//implementation("com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-nonreflection-ktx:$ViewBindingKTXVersion")
//implementation("com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-base:$ViewBindingKTXVersion")
//implementation("com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-brvah:$ViewBindingKTXVersion")


//implementation("androidx.annotation:annotation:1.5.0")
//implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.20")

Expand Down Expand Up @@ -313,9 +320,9 @@ dependencies {
//"buglyImplementation"("com.tencent.bugly:crashreport_upgrade:1.6.1")
//"buglyImplementation"("com.github.supersu-man:apkupdater-library:v2.0.0")

//debugImplementation("io.github.knight-zxw:blockcanary:0.0.4")
//debugImplementation("io.github.knight-zxw:blockcanary-ui:0.0.4")
//debugImplementation("com.squareup.leakcanary:leakcanary-android:2.9.1")
debugImplementation("io.github.knight-zxw:blockcanary:0.0.5")
debugImplementation("io.github.knight-zxw:blockcanary-ui:0.0.5")
debugImplementation("com.squareup.leakcanary:leakcanary-android:2.12")

//debugImplementation("com.bytedance.tools.codelocator:codelocator-core:2.0.0")
//debugImplementation("com.bytedance.tools.codelocator:codelocator-lancet-all:2.0.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class PixivsionActivity : RinkActivity() {
viewmodel.nextPixivisonUrl.observe(this) {
if (::pixiVisionAdapter.isInitialized) {
if (it == null) {
pixiVisionAdapter.loadMoreModule.loadMoreEnd()
pixiVisionAdapter.loadMoreEnd()
}
else {
pixiVisionAdapter.loadMoreModule.loadMoreComplete()
pixiVisionAdapter.loadMoreComplete()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule

import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.perol.asdpl.pixivez.R
import com.perol.asdpl.pixivez.objects.EmojiUtil
Expand All @@ -40,7 +39,7 @@ import com.perol.asdpl.pixivez.responses.IllustCommentsResponse.CommentsBean
class CommentAdapter(
layoutResId: Int,
data: MutableList<CommentsBean>?
) : BaseQuickAdapter<CommentsBean, BaseViewHolder>(layoutResId, data), LoadMoreModule {
) : LBaseQuickAdapter<CommentsBean, BaseViewHolder>(layoutResId, data) {
override fun convert(holder: BaseViewHolder, item: CommentsBean) {
holder.setText(R.id.commentdate, item.date)
if (item.parent_comment.user != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.perol.asdpl.pixivez.adapters

import androidx.annotation.LayoutRes
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnLoadMoreListener
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder

abstract class LBaseQuickAdapter<T, VH : BaseViewHolder>(@LayoutRes private val layoutResId: Int,
data: MutableList<T>?=null)
:BaseQuickAdapter<T,VH>(layoutResId, data), LoadMoreModule {
fun loadMoreEnd() {
this.loadMoreModule.loadMoreEnd()
}

fun loadMoreComplete() {
this.loadMoreModule.loadMoreComplete()
}

fun loadMoreFail() {
this.loadMoreModule.loadMoreFail()
}

fun setOnLoadMoreListener(onLoadMoreListener: OnLoadMoreListener) {
this.loadMoreModule.setOnLoadMoreListener(onLoadMoreListener)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade
import com.bumptech.glide.request.target.ImageViewTarget
import com.bumptech.glide.request.transition.Transition
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnLoadMoreListener
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.perol.asdpl.pixivez.R
Expand All @@ -47,7 +44,7 @@ abstract class PicListAdapter(
data: List<Illust>?,
val illustFilter: IllustFilter
) :
BaseQuickAdapter<Illust, BaseViewHolder>(layoutResId, data?.toMutableList()), LoadMoreModule {
LBaseQuickAdapter<Illust, BaseViewHolder>(layoutResId, data?.toMutableList()) {

var colorPrimary: Int = R.color.colorPrimary
var colorPrimaryDark: Int = R.color.colorPrimaryDark
Expand All @@ -65,22 +62,6 @@ abstract class PicListAdapter(
}
}

fun loadMoreEnd() {
this.loadMoreModule.loadMoreEnd()
}

fun loadMoreComplete() {
this.loadMoreModule.loadMoreComplete()
}

fun loadMoreFail() {
this.loadMoreModule.loadMoreFail()
}

fun setOnLoadMoreListener(onLoadMoreListener: OnLoadMoreListener) {
this.loadMoreModule.setOnLoadMoreListener(onLoadMoreListener)
}

private fun setAction(CollectMode: Int) {
if (CollectMode == 2) {
setOnItemClickListener { adapter, view, position ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package com.perol.asdpl.pixivez.adapters

import android.os.Bundle
import android.view.View
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.perol.asdpl.pixivez.R
import com.perol.asdpl.pixivez.objects.IllustFilter
Expand All @@ -42,7 +41,7 @@ class PicListBtnUserAdapter(
data: List<Illust>?,
filter: IllustFilter
) :
PicListBtnAdapter(layoutResId, data, filter), LoadMoreModule {
PicListBtnAdapter(layoutResId, data, filter) {

override fun viewPicsOptions(view: View, illust: Illust): Bundle {
return PicListXUserAdapter.viewOptions(this, view, illust)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.target.ImageViewTarget
import com.bumptech.glide.request.transition.Transition
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.perol.asdpl.pixivez.R
import com.perol.asdpl.pixivez.activity.UserMActivity
Expand All @@ -50,7 +49,7 @@ import com.perol.asdpl.pixivez.ui.NiceImageView
*/
class PicListXUserAdapter(
layoutResId: Int, data: List<Illust>?, filter: IllustFilter
) : PicListXAdapter(layoutResId, data, filter), LoadMoreModule {
) : PicListXAdapter(layoutResId, data, filter) {

override fun viewPicsOptions(view: View, illust: Illust): Bundle {
return viewOptions(this, view, illust)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ import com.perol.asdpl.pixivez.viewmodel.ProgressInfo
import com.waynejo.androidndkgif.GifEncoder
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter
import com.zhy.view.flowlayout.TagFlowLayout
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
Expand Down Expand Up @@ -200,16 +199,6 @@ class PictureXAdapter(
var binding: ViewPicturexDetailBinding
) :
RecyclerView.ViewHolder(binding.root) {
private val tagFlowLayout = itemView.findViewById<TagFlowLayout>(R.id.tagflowlayout)
private val captionTextView = itemView.findViewById<TextView>(R.id.textview_caption)
private val btnTranslate = itemView.findViewById<TextView>(R.id.btn_translate)
private val viewCommentTextView = itemView.findViewById<TextView>(R.id.textview_viewcomment)
private val imageViewUser = itemView.findViewById<NiceImageView>(R.id.imageViewUser_picX)
private val imageButtonDownload =
itemView.findViewById<ImageButton>(R.id.imagebutton_download)
private val bookmarkedUserNum =
itemView.findViewById<TextView>(R.id.bookmarked_user_num)

fun updateWithPage(
mContext: Context,
illust: Illust,
Expand All @@ -219,7 +208,7 @@ class PictureXAdapter(
) {
//binding.illust = illust
binding.apply {
loadUserImage(imageViewUserPicX, illust.user.profile_image_urls.medium)
loadUserImage(binding.imageviewUserPicX, illust.user.profile_image_urls.medium)

textViewTitle.text = illust.title
textViewUserName.text = illust.user.name
Expand All @@ -235,33 +224,34 @@ class PictureXAdapter(
val colorPrimaryDark = ThemeUtil.getColorPrimaryDark(mContext)
val badgeTextColor = ThemeUtil.getColorHighlight(mContext)
if (illust.user.is_followed) {
imageViewUser.setBorderColor(badgeTextColor)
binding.imageviewUserPicX.setBorderColor(badgeTextColor)
}
else {
imageViewUser.setBorderColor(colorPrimary)
binding.imageviewUserPicX.setBorderColor(colorPrimary)
}
imageViewUser.setOnLongClickListener {
binding.imageviewUserPicX.setOnLongClickListener {
mUserPicLongClick.invoke()
true
}
imageViewUser.setOnClickListener {
binding.imageviewUserPicX.setOnClickListener {
val options = if (PxEZApp.animationEnable) {
ActivityOptions.makeSceneTransitionAnimation(
mContext as Activity,
Pair(imageViewUser, "userimage")
Pair(binding.imageviewUserPicX, "userimage")
).toBundle()
} else null
UserMActivity.start(mContext, illust.user, options)
}
binding.textviewCaption.text = Html.fromHtml(illust.caption.ifBlank { "~" })
Linkify.addLinks(captionTextView, Linkify.WEB_URLS)
Log.d("url", captionTextView.urls.toString())
captionTextView.movementMethod = LinkMovementMethod.getInstance()
viewCommentTextView.text = "${viewCommentTextView.text}(${illust.total_comments})"
viewCommentTextView.setOnClickListener {
Linkify.addLinks(binding.textviewCaption, Linkify.WEB_URLS)
Log.d("url", binding.textviewCaption.urls.toString())
binding.textviewCaption.movementMethod = LinkMovementMethod.getInstance()
//TODO: get real comment count
// binding.textviewViewComment.text = "${binding.textviewViewComment.text}(${illust.total_comments})"
binding.textviewViewComment.setOnClickListener {
mViewCommentListen.invoke()
}
bookmarkedUserNum.setOnClickListener {
binding.bookmarkedUserNum.setOnClickListener {
mBookmarkedUserListen.invoke()
}
// google translate app btn click listener
Expand All @@ -287,17 +277,17 @@ class PictureXAdapter(
}
}
if (!isGoogleTranslateEnabled) {
btnTranslate.visibility = View.GONE
binding.btnTranslate.visibility = View.GONE
}
else {
btnTranslate.setOnClickListener {
binding.btnTranslate.setOnClickListener {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
intent.action = Intent.ACTION_PROCESS_TEXT
intent.putExtra(Intent.EXTRA_PROCESS_TEXT, captionTextView.text.toString())
intent.putExtra(Intent.EXTRA_PROCESS_TEXT, binding.textviewCaption.text.toString())
}
else {
intent.action = Intent.ACTION_SEND
intent.putExtra(Intent.EXTRA_TEXT, captionTextView.text.toString())
intent.putExtra(Intent.EXTRA_TEXT, binding.textviewCaption.text.toString())
}
intent.component = ComponentName(
componentPackageName,
Expand All @@ -307,7 +297,7 @@ class PictureXAdapter(
}
}

tagFlowLayout.apply {
binding.tagFlowlayout.apply {
adapter = object : TagAdapter<Tag>(illust.tags) {
@SuppressLint("SetTextI18n")
override fun getView(parent: FlowLayout, position: Int, t: Tag): View {
Expand Down Expand Up @@ -359,11 +349,11 @@ class PictureXAdapter(
mContext.startActivity(Intent.createChooser(textIntent, mContext.getString(R.string.share)))
}
if (FileUtil.isDownloaded(illust)) {
imageButtonDownload.drawable.setTint(badgeTextColor)
binding.imagebuttonDownload.drawable.setTint(badgeTextColor)
}
if (illust.type == "ugoira") {
// gif
imageButtonDownload.setOnClickListener {
binding.imagebuttonDownload.setOnClickListener {
MaterialAlertDialogBuilder(mContext as Activity)
.setTitle(R.string.download)
.setPositiveButton(R.string.savefirst) { _, _ ->
Expand All @@ -372,12 +362,12 @@ class PictureXAdapter(
}
}
else {
imageButtonDownload.setOnClickListener {
imageButtonDownload.drawable.setTint(colorPrimaryDark)
binding.imagebuttonDownload.setOnClickListener {
binding.imagebuttonDownload.drawable.setTint(colorPrimaryDark)
Works.imageDownloadAll(illust)
}
}
imageButtonDownload.setOnLongClickListener {
binding.imagebuttonDownload.setOnLongClickListener {
// show detail of illust
val detailstring = InteractionUtil.toDetailString(illust, false)
MaterialAlertDialogBuilder(mContext as Activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule

import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.perol.asdpl.pixivez.R
import com.perol.asdpl.pixivez.objects.ThemeUtil
Expand All @@ -40,7 +39,7 @@ import com.perol.asdpl.pixivez.responses.SpotlightArticlesBean
class PixiVisionAdapter(
layoutResId: Int,
data: MutableList<SpotlightArticlesBean>?
) : BaseQuickAdapter<SpotlightArticlesBean, BaseViewHolder>(layoutResId, data), LoadMoreModule {
) : LBaseQuickAdapter<SpotlightArticlesBean, BaseViewHolder>(layoutResId, data) {
override fun convert(
holder: BaseViewHolder,
item: SpotlightArticlesBean
Expand All @@ -58,8 +57,4 @@ class PixiVisionAdapter(
animationEnable = true
setAnimationWithDefault(AnimationType.ScaleIn)
}

fun loadMoreFail() {
this.loadMoreModule.loadMoreFail()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@

package com.perol.asdpl.pixivez.adapters

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule

import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.perol.asdpl.pixivez.R
import com.perol.asdpl.pixivez.responses.BookMarkTagsResponse.BookmarkTagsBean

class TagsShowAdapter(layoutResId: Int, data: List<BookmarkTagsBean>) :
BaseQuickAdapter<BookmarkTagsBean, BaseViewHolder>(layoutResId, data.toMutableList()), LoadMoreModule {

LBaseQuickAdapter<BookmarkTagsBean, BaseViewHolder>(layoutResId, data.toMutableList()) {
override fun convert(holder: BaseViewHolder, item: BookmarkTagsBean) {
holder.setText(R.id.textview_tagname, item.name)
.setText(R.id.textView_tagnum, item.count.toString())
holder.setText(R.id.textview_tag_name, item.name)
.setText(R.id.textview_tag_num, item.count.toString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnLoadMoreListener
import com.chad.library.adapter.base.module.LoadMoreModule

import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.perol.asdpl.pixivez.R
import com.perol.asdpl.pixivez.activity.UserMActivity
import com.perol.asdpl.pixivez.responses.User
import com.perol.asdpl.pixivez.services.PxEZApp

class UserListAdapter(layoutResId: Int) :
BaseQuickAdapter<User, BaseViewHolder>(layoutResId), LoadMoreModule {
LBaseQuickAdapter<User, BaseViewHolder>(layoutResId) {

init {
setOnItemClickListener { adapter, view, position ->
Expand All @@ -68,21 +66,4 @@ class UserListAdapter(layoutResId: Int) :
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC).transition(withCrossFade())
.into(userImage)
}


fun loadMoreEnd() {
this.loadMoreModule.loadMoreEnd()
}

fun loadMoreComplete() {
this.loadMoreModule.loadMoreComplete()
}

fun loadMoreFail() {
this.loadMoreModule.loadMoreFail()
}

fun setOnLoadMoreListener(onLoadMoreListener: OnLoadMoreListener) {
this.loadMoreModule.setOnLoadMoreListener(onLoadMoreListener)
}
}
Loading

0 comments on commit 38fe6cc

Please sign in to comment.