From a9cfa5cad2293033be0c15ac6c6b4a2d05bacf62 Mon Sep 17 00:00:00 2001 From: 985892345 Date: Sun, 28 Aug 2022 18:37:41 +0800 Subject: [PATCH 1/3] =?UTF-8?q?:bug:=20=E4=BF=AE=E6=8A=A4=20IntentHelper.k?= =?UTF-8?q?t=20=E6=B3=9B=E5=9E=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mredrock/cyxbs/lib/base/ui/BaseActivity.kt | 2 +- .../cyxbs/lib/base/utils/IntentHelper.kt | 17 ++++++++--------- .../cyxbs/lib/utils/utils/GenericityUtils.kt | 3 +-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib_base/src/main/java/com/mredrock/cyxbs/lib/base/ui/BaseActivity.kt b/lib_base/src/main/java/com/mredrock/cyxbs/lib/base/ui/BaseActivity.kt index 885221c64..f5a6d3b87 100644 --- a/lib_base/src/main/java/com/mredrock/cyxbs/lib/base/ui/BaseActivity.kt +++ b/lib_base/src/main/java/com/mredrock/cyxbs/lib/base/ui/BaseActivity.kt @@ -126,5 +126,5 @@ abstract class BaseActivity : OperationActivity() { * 这样写会在 intent 中寻找名字叫 key 的参数 * ``` */ - fun Intent.helper() = IntentHelper { intent } + inline fun Intent?.helper() = IntentHelper(T::class.java) { intent } } diff --git a/lib_base/src/main/java/com/mredrock/cyxbs/lib/base/utils/IntentHelper.kt b/lib_base/src/main/java/com/mredrock/cyxbs/lib/base/utils/IntentHelper.kt index ec9d1162e..b179ac3bf 100644 --- a/lib_base/src/main/java/com/mredrock/cyxbs/lib/base/utils/IntentHelper.kt +++ b/lib_base/src/main/java/com/mredrock/cyxbs/lib/base/utils/IntentHelper.kt @@ -4,7 +4,6 @@ import android.content.Intent import android.os.Bundle import android.os.Parcelable import androidx.core.os.bundleOf -import com.mredrock.cyxbs.lib.utils.utils.GenericityUtils import java.io.Serializable import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty @@ -13,11 +12,11 @@ import kotlin.reflect.KProperty * 这里面所有的类型参考了官方的设计:[bundleOf] */ class IntentHelper( - val intent: () -> Intent + private val clazz: Class, + private val intent: () -> Intent ) : ReadWriteProperty { private var mValue: T? = null - private val mType = GenericityUtils.getGenericClassFromSuperClass(javaClass) @Suppress("UNCHECKED_CAST") override fun getValue(thisRef: Any, property: KProperty<*>): T { @@ -25,7 +24,7 @@ class IntentHelper( val name = property.name mValue = intent.invoke().run { // 因为 intent 的 getExtra() 方法被废弃,所以只能一个一个判断 - when (mType) { + when (clazz) { String::class -> getStringExtra(name) Int::class -> getIntExtra(name, Int.MIN_VALUE) @@ -48,7 +47,7 @@ class IntentHelper( ShortArray::class -> getShortArrayExtra(name) Array::class -> { - val componentType = mType::class.java.componentType!! + val componentType = clazz.componentType!! when { Parcelable::class.java.isAssignableFrom(componentType) -> { getParcelableArrayExtra(name) @@ -73,10 +72,10 @@ class IntentHelper( else -> { when { - CharSequence::class.java.isAssignableFrom(mType) -> getCharExtra(name, ' ') - Parcelable::class.java.isAssignableFrom(mType) -> getParcelableExtra(name) - Serializable::class.java.isAssignableFrom(mType) -> getSerializableExtra(name) - else -> error("未实现该类型 ${mType::class.java.name} for key \"$name\"") + CharSequence::class.java.isAssignableFrom(clazz) -> getCharExtra(name, ' ') + Parcelable::class.java.isAssignableFrom(clazz) -> getParcelableExtra(name) + Serializable::class.java.isAssignableFrom(clazz) -> getSerializableExtra(name) + else -> error("未实现该类型 ${clazz.name} for key \"$name\"") } } } diff --git a/lib_utils/src/main/java/com/mredrock/cyxbs/lib/utils/utils/GenericityUtils.kt b/lib_utils/src/main/java/com/mredrock/cyxbs/lib/utils/utils/GenericityUtils.kt index 9f5362160..152358bd4 100644 --- a/lib_utils/src/main/java/com/mredrock/cyxbs/lib/utils/utils/GenericityUtils.kt +++ b/lib_utils/src/main/java/com/mredrock/cyxbs/lib/utils/utils/GenericityUtils.kt @@ -1,6 +1,5 @@ package com.mredrock.cyxbs.lib.utils.utils -import java.lang.RuntimeException import java.lang.reflect.ParameterizedType /** @@ -49,6 +48,6 @@ object GenericityUtils { } } } - throw RuntimeException("你父类的泛型为: $genericSuperclass, 其中不存在 ${E::class.java.simpleName}") + throw IllegalStateException("你父类的泛型为: $genericSuperclass, 其中不存在 ${E::class.java.simpleName}") } } \ No newline at end of file From 18491562b1265127aa1aa100979a068d41bc5b59 Mon Sep 17 00:00:00 2001 From: 985892345 Date: Sun, 28 Aug 2022 20:58:36 +0800 Subject: [PATCH 2/3] =?UTF-8?q?:bug:=20=E4=BF=AE=E6=8A=A4=E5=9C=B0?= =?UTF-8?q?=E5=9B=BE=E7=9A=84=20tags=20=E6=98=BE=E7=A4=BA=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../map/ui/adapter/DetailTagRvAdapter.kt | 33 ++++++++++--------- .../inner/PlaceDetailBottomSheetFragment.kt | 13 +++++--- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/module_map/src/main/java/com/mredrock/cyxbs/discover/map/ui/adapter/DetailTagRvAdapter.kt b/module_map/src/main/java/com/mredrock/cyxbs/discover/map/ui/adapter/DetailTagRvAdapter.kt index 15e2d3b00..f1ff001cb 100644 --- a/module_map/src/main/java/com/mredrock/cyxbs/discover/map/ui/adapter/DetailTagRvAdapter.kt +++ b/module_map/src/main/java/com/mredrock/cyxbs/discover/map/ui/adapter/DetailTagRvAdapter.kt @@ -1,16 +1,30 @@ package com.mredrock.cyxbs.discover.map.ui.adapter -import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.mredrock.cyxbs.common.utils.extensions.pressToZoomOut import com.mredrock.cyxbs.discover.map.R -class DetailTagRvAdapter(val context: Context, private val mList: MutableList) : RecyclerView.Adapter() { - +class DetailTagRvAdapter : ListAdapter( + object : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: String, newItem: String): Boolean { + return oldItem == newItem + } + + override fun areContentsTheSame(oldItem: String, newItem: String): Boolean { + return true + } + + override fun getChangePayload(oldItem: String, newItem: String): Any { + return "" // 不返回 null 可以避免 ViewHolder 互换,减少性能消耗 + } + } +) { inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { val tag: TextView = view.findViewById(R.id.map_tv_recycle_item_detail_tag).apply { pressToZoomOut() } @@ -22,18 +36,7 @@ class DetailTagRvAdapter(val context: Context, private val mList: MutableList) { - mList.clear() - mList.addAll(list) - } - } \ No newline at end of file diff --git a/module_map/src/main/java/com/mredrock/cyxbs/discover/map/ui/fragment/inner/PlaceDetailBottomSheetFragment.kt b/module_map/src/main/java/com/mredrock/cyxbs/discover/map/ui/fragment/inner/PlaceDetailBottomSheetFragment.kt index a902b6b60..0373052c7 100644 --- a/module_map/src/main/java/com/mredrock/cyxbs/discover/map/ui/fragment/inner/PlaceDetailBottomSheetFragment.kt +++ b/module_map/src/main/java/com/mredrock/cyxbs/discover/map/ui/fragment/inner/PlaceDetailBottomSheetFragment.kt @@ -72,7 +72,7 @@ class PlaceDetailBottomSheetFragment : BaseFragment() { val flexBoxManager = FlexboxLayoutManager(context) flexBoxManager.flexWrap = FlexWrap.WRAP mRvDetailAboutList.layoutManager = flexBoxManager - val tagAdapter = context?.let { DetailTagRvAdapter(it, mutableListOf()) } + val tagAdapter = DetailTagRvAdapter() mRvDetailAboutList.adapter = tagAdapter val linearLayoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) @@ -103,10 +103,15 @@ class PlaceDetailBottomSheetFragment : BaseFragment() { mIndicatorDetail.setupWithViewPager(mBannerDetailImage) } } - if (tagAdapter != null && t.tags != null) { - tagAdapter.setList(t.tags!!) - tagAdapter.notifyDataSetChanged() + if (t.tags != null) { + mBinding.mapTvDetailAboutText.visible() + mBinding.mapRvDetailAboutList.visible() + tagAdapter.submitList(t.tags ?: emptyList()) + } else { + mBinding.mapTvDetailAboutText.gone() + mBinding.mapRvDetailAboutList.gone() } + if (attributeAdapter != null) { if (t.placeAttribute != null) { attributeAdapter.setList(t.placeAttribute!!) From bd5e1a33318c45ba4b6f1312511abe944ae436f3 Mon Sep 17 00:00:00 2001 From: 985892345 Date: Tue, 30 Aug 2022 02:11:27 +0800 Subject: [PATCH 3/3] =?UTF-8?q?:bug:=20=E4=BD=93=E8=82=B2=E6=89=93?= =?UTF-8?q?=E5=8D=A1=E8=AF=B7=E6=B1=82=E5=BF=98=E8=AE=B0=E5=88=87=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mredrock/cyxbs/sport/model/SportRepository.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/module_sport/src/main/java/com/mredrock/cyxbs/sport/model/SportRepository.kt b/module_sport/src/main/java/com/mredrock/cyxbs/sport/model/SportRepository.kt index c6286916c..15c9f615f 100644 --- a/module_sport/src/main/java/com/mredrock/cyxbs/sport/model/SportRepository.kt +++ b/module_sport/src/main/java/com/mredrock/cyxbs/sport/model/SportRepository.kt @@ -10,6 +10,8 @@ import com.mredrock.cyxbs.lib.utils.extensions.* import com.mredrock.cyxbs.lib.utils.network.mapOrThrowApiException import com.mredrock.cyxbs.lib.utils.service.impl import com.mredrock.cyxbs.sport.model.network.SportDetailApiService +import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers +import io.reactivex.rxjava3.schedulers.Schedulers import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch @@ -85,6 +87,8 @@ class SportRepository : InitialService { if (stuNum != null && sSportData == null) { SportDetailApiService.INSTANCE .getSportDetailData() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) .mapOrThrowApiException() .interceptExceptionByResult { emitter.onSuccess(Result.failure(throwable))