fix: 修复一些闪退

This commit is contained in:
HuanCheng65 2023-05-05 16:38:06 +08:00
parent 20807bb061
commit 96cb8acfef
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
5 changed files with 50 additions and 8 deletions

View File

@ -174,7 +174,7 @@ public class RecyclerFloorAdapter extends BaseSingleTypeAdapter<SubFloorListBean
}) })
.setInitMenuCallback(menu -> { .setInitMenuCallback(menu -> {
PluginManager.INSTANCE.initPluginMenu(menu, PluginManager.MENU_SUB_POST_ITEM); PluginManager.INSTANCE.initPluginMenu(menu, PluginManager.MENU_SUB_POST_ITEM);
if (TextUtils.equals(AccountUtil.getLoginInfo().getUid(), postInfo.getAuthor().getId())) { if (AccountUtil.isLoggedIn() && TextUtils.equals(AccountUtil.getLoginInfo().getUid(), postInfo.getAuthor().getId())) {
menu.findItem(R.id.menu_delete).setVisible(true); menu.findItem(R.id.menu_delete).setVisible(true);
} }
}) })

View File

@ -30,14 +30,23 @@ abstract class BaseMultiTypeDelegateAdapter<Item> @JvmOverloads constructor(
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
holder.setItemOnClickListener { holder.setItemOnClickListener {
onItemClickListener?.onClick(holder, getItem(position), position) if (position in 0 until itemCount) onItemClickListener?.onClick(
holder,
getItem(position),
position
)
} }
holder.setItemOnLongClickListener { holder.setItemOnLongClickListener {
onItemLongClickListener?.onLongClick(holder, getItem(position), position) ?: false if (position !in 0 until itemCount) false
else onItemLongClickListener?.onLongClick(holder, getItem(position), position) ?: false
} }
onItemChildClickListeners.forEach { onItemChildClickListeners.forEach {
holder.setOnClickListener(it.key) { _ -> holder.setOnClickListener(it.key) { _ ->
it.value?.onItemChildClick(holder, getItem(position), position) if (position in 0 until itemCount) it.value?.onItemChildClick(
holder,
getItem(position),
position
)
} }
} }
convert(holder, getItem(position), position, getItemViewType(position)) convert(holder, getItem(position), position, getItemViewType(position))

View File

@ -6,13 +6,44 @@ import androidx.compose.runtime.Stable
@Stable @Stable
class StableHolder<T>(val item: T) { class StableHolder<T>(val item: T) {
operator fun component1(): T = item operator fun component1(): T = item
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as StableHolder<*>
if (item != other.item) return false
return true
}
override fun hashCode(): Int {
return item?.hashCode() ?: 0
}
} }
@Immutable @Immutable
class ImmutableHolder<T>(val item: T) { class ImmutableHolder<T>(val item: T) {
operator fun component1(): T = item operator fun component1(): T = item
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ImmutableHolder<*>
if (item != other.item) return false
return true
}
override fun hashCode(): Int {
return item?.hashCode() ?: 0
}
} }
fun <T> wrapStable(item: T): StableHolder<T> = StableHolder(item) fun <T> wrapStable(item: T): StableHolder<T> = StableHolder(item)
fun <T> wrapImmutable(item: T): ImmutableHolder<T> = ImmutableHolder(item) fun <T> wrapImmutable(item: T): ImmutableHolder<T> = ImmutableHolder(item)
fun <T> List<T>.wrapImmutable(): List<ImmutableHolder<T>> = map { wrapImmutable(it) }

View File

@ -22,6 +22,7 @@ import com.huanchengfly.tieba.post.activities.ThreadActivity
import com.huanchengfly.tieba.post.adapters.RecyclerFloorAdapter import com.huanchengfly.tieba.post.adapters.RecyclerFloorAdapter
import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.TiebaApi
import com.huanchengfly.tieba.post.api.models.SubFloorListBean import com.huanchengfly.tieba.post.api.models.SubFloorListBean
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
import com.huanchengfly.tieba.post.components.MyLinearLayoutManager import com.huanchengfly.tieba.post.components.MyLinearLayoutManager
import com.huanchengfly.tieba.post.components.dividers.ThreadDivider import com.huanchengfly.tieba.post.components.dividers.ThreadDivider
import com.huanchengfly.tieba.post.components.transformations.RadiusTransformation import com.huanchengfly.tieba.post.components.transformations.RadiusTransformation
@ -184,7 +185,7 @@ class FloorFragment : BaseBottomSheetDialogFragment() {
.floor(tid, pn, pid, spid) .floor(tid, pn, pid, spid)
.enqueue(object : Callback<SubFloorListBean> { .enqueue(object : Callback<SubFloorListBean> {
override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) { override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) {
Toast.makeText(attachContext, t.message, Toast.LENGTH_SHORT).show() Toast.makeText(attachContext, t.getErrorMessage(), Toast.LENGTH_SHORT).show()
refreshLayout.finishRefresh(false) refreshLayout.finishRefresh(false)
} }

View File

@ -26,8 +26,9 @@ import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
open class AppPreferencesUtils(context: Context) { open class AppPreferencesUtils(private val context: Context) {
private val preferencesDataStore: DataStore<Preferences> = context.dataStore private val preferencesDataStore: DataStore<Preferences>
get() = context.dataStore
private val coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()) private val coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
var userLikeLastRequestUnix by DataStoreDelegates.long(defaultValue = 0L) var userLikeLastRequestUnix by DataStoreDelegates.long(defaultValue = 0L)