From 7d4aa34d12d2764fbfdffc749d3cd8b04fe80d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E5=AD=90=E7=BB=B4?= Date: Fri, 17 May 2024 17:53:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E3=80=90=E5=85=89=E7=8E=AF=E5=8A=A9?= =?UTF-8?q?=E6=89=8B=E3=80=91=E5=B7=A5=E5=85=B7=E6=96=B0=E5=A2=9E=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E7=B1=BB=E5=9E=8B=E9=85=8D=E7=BD=AE=20https://jira.sh?= =?UTF-8?q?anqu.cc/browse/GHZSCY-4618?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gamecenter/toolbox/ToolBoxItemAdapter.kt | 30 +++++++++++-------- .../gh/gamecenter/toolbox/ToolBoxViewModel.kt | 14 ++++++--- .../gamecenter/common/entity/ToolBoxEntity.kt | 21 +++++++++++++ 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/gh/gamecenter/toolbox/ToolBoxItemAdapter.kt b/app/src/main/java/com/gh/gamecenter/toolbox/ToolBoxItemAdapter.kt index b467fcd7ca..688513a36c 100644 --- a/app/src/main/java/com/gh/gamecenter/toolbox/ToolBoxItemAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/toolbox/ToolBoxItemAdapter.kt @@ -5,6 +5,7 @@ import android.view.ViewGroup import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import com.gh.common.constant.Config +import com.gh.common.util.DirectUtils import com.gh.gamecenter.R import com.gh.gamecenter.WebActivity.Companion.getWebByCollectionTools import com.gh.gamecenter.common.base.BaseRecyclerViewHolder @@ -103,19 +104,24 @@ class ToolBoxItemAdapter( viewHolder.binding.root.setOnClickListener { mViewModel.addToHistoryList(toolBoxEntity) - val url = toolBoxEntity.url - if (url != null && url.contains(Config.URL_ARTICLE)) { - val newsId = url.substring(url.lastIndexOf("/") + 1, url.length - 5) // 5: ".html" - val intent = NewsDetailActivity.getIntentById(mContext, newsId, "工具箱列表") - mContext.startActivity(intent) - } else { - mContext.startActivity( - getWebByCollectionTools( - mContext, - toolBoxEntity, - false + val linkEntity = toolBoxEntity.toLinkEntity() + if (linkEntity.type == "web") { + val url = linkEntity.link ?: "" + if (url.isNotEmpty() && url.contains(Config.URL_ARTICLE)) { + val newsId = url.substring(url.lastIndexOf("/") + 1, url.length - 5) // 5: ".html" + val intent = NewsDetailActivity.getIntentById(mContext, newsId, "工具箱列表") + mContext.startActivity(intent) + } else { + mContext.startActivity( + getWebByCollectionTools( + mContext, + toolBoxEntity, + false + ) ) - ) + } + } else { + DirectUtils.directToLinkPage(mContext, linkEntity, "工具箱", "") } } } diff --git a/app/src/main/java/com/gh/gamecenter/toolbox/ToolBoxViewModel.kt b/app/src/main/java/com/gh/gamecenter/toolbox/ToolBoxViewModel.kt index e9d34bca16..122ca7e534 100644 --- a/app/src/main/java/com/gh/gamecenter/toolbox/ToolBoxViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/toolbox/ToolBoxViewModel.kt @@ -3,16 +3,16 @@ package com.gh.gamecenter.toolbox import android.app.Application import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.MutableLiveData -import com.gh.gamecenter.common.constant.Constants import com.gh.gamecenter.common.baselist.LoadStatus +import com.gh.gamecenter.common.constant.Constants +import com.gh.gamecenter.common.entity.ToolBoxEntity +import com.gh.gamecenter.common.retrofit.Response +import com.gh.gamecenter.common.utils.toJson import com.gh.gamecenter.core.utils.GsonUtils import com.gh.gamecenter.core.utils.SPUtils import com.gh.gamecenter.core.utils.TimeUtils -import com.gh.gamecenter.common.utils.toJson import com.gh.gamecenter.core.utils.UrlFilterUtils import com.gh.gamecenter.entity.ToolBoxBlockEntity -import com.gh.gamecenter.common.entity.ToolBoxEntity -import com.gh.gamecenter.common.retrofit.Response import com.gh.gamecenter.retrofit.RetrofitManager import com.google.gson.reflect.TypeToken import io.reactivex.android.schedulers.AndroidSchedulers @@ -77,6 +77,12 @@ class ToolBoxViewModel(application: Application) : AndroidViewModel(application) for (item in historyList) { val offsetDay = TimeUtils.getBeforeDays(item.lastOpenTime / 1000) if (offsetDay <= 30) { + if (item.url != null && (item.linkId.isEmpty() || item.linkType.isEmpty() || item.linkText.isEmpty())) { + // 给历史数据补充信息 + item.linkType = "web" + item.linkId = item.url!! + item.linkText = item.url!! + } add(item) } } diff --git a/module_common/src/main/java/com/gh/gamecenter/common/entity/ToolBoxEntity.kt b/module_common/src/main/java/com/gh/gamecenter/common/entity/ToolBoxEntity.kt index 423c7006d5..d5bcda7d69 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/entity/ToolBoxEntity.kt +++ b/module_common/src/main/java/com/gh/gamecenter/common/entity/ToolBoxEntity.kt @@ -30,6 +30,14 @@ class ToolBoxEntity : Parcelable { @SerializedName("me") var me: ToolboxMeEntity? = null + @SerializedName("link_type") + var linkType: String = "" + @SerializedName("link_id") + var linkId: String = "" + @SerializedName("link_text") + var linkText: String = "" + + fun toLinkEntity() = LinkEntity(link = linkId, type = linkType, text = linkText, linkText = linkText) override fun describeContents(): Int { return 0 @@ -43,6 +51,9 @@ class ToolBoxEntity : Parcelable { dest.writeString(this.url) dest.writeLong(this.time) dest.writeParcelable(this.me, flags) + dest.writeString(this.linkType) + dest.writeString(this.linkId) + dest.writeString(this.linkText) } override fun equals(other: Any?): Boolean { @@ -58,6 +69,9 @@ class ToolBoxEntity : Parcelable { if (url != other.url) return false if (time != other.time) return false if (me != other.me) return false + if (linkType != other.linkType) return false + if (linkId != other.linkId) return false + if (linkText != other.linkText) return false return true } @@ -70,9 +84,13 @@ class ToolBoxEntity : Parcelable { result = 31 * result + (url?.hashCode() ?: 0) result = 31 * result + time.hashCode() result = 31 * result + (me?.hashCode() ?: 0) + result = 31 * result + linkType.hashCode() + result = 31 * result + linkId.hashCode() + result = 31 * result + linkText.hashCode() return result } + constructor() protected constructor(`in`: Parcel) { @@ -83,6 +101,9 @@ class ToolBoxEntity : Parcelable { this.url = `in`.readString() this.time = `in`.readLong() this.me = `in`.readParcelable(ToolboxMeEntity::class.java.classLoader) + this.linkType = `in`.readString() ?: "" + this.linkId = `in`.readString() ?: "" + this.linkText = `in`.readString() ?: "" } @Parcelize