Skip to content

Commit

Permalink
refactor(app): 重构关于页面文本生成逻辑
Browse files Browse the repository at this point in the history
- 将关于页面的文本生成逻辑移至 InfoUtil 类中
- 新增 qverbowAboutText 扩展函数,用于生成关于页面的 SpannableString
- 优化了文本中 URL 的处理方式,使用列表存储链接和对应文本
- 简化了 MainActivity 中的代码,提高了可读性和可维护性
  • Loading branch information
ArcticFoxPro committed Nov 14, 2024
1 parent 3b558fe commit a2c3e92
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 95 deletions.
96 changes: 2 additions & 94 deletions app/src/main/java/com/xiaoniu/qqversionlist/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.text.Editable
import android.text.SpannableString
import android.text.TextWatcher
import android.text.style.URLSpan
import android.util.Base64
import android.view.MenuItem
import android.view.View
Expand Down Expand Up @@ -104,6 +102,7 @@ import com.xiaoniu.qqversionlist.util.DataStoreUtil
import com.xiaoniu.qqversionlist.util.Extensions.downloadFile
import com.xiaoniu.qqversionlist.util.Extensions.dp
import com.xiaoniu.qqversionlist.util.InfoUtil.dialogError
import com.xiaoniu.qqversionlist.util.InfoUtil.qverbowAboutText
import com.xiaoniu.qqversionlist.util.InfoUtil.showToast
import com.xiaoniu.qqversionlist.util.ShiplyUtil
import com.xiaoniu.qqversionlist.util.StringUtil.getAllAPKUrl
Expand Down Expand Up @@ -296,97 +295,7 @@ class MainActivity : AppCompatActivity() {
aboutText.movementMethod =
LinkMovementMethodCompat.getInstance()

// 九七通知中心因为内容安全原因去掉了 GitHub Releases 更新订阅
aboutText.text = SpannableString(
"${getString(R.string.aboutAppName)}\n\n" +
"${getString(R.string.version)}${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})\n" +
"${getString(R.string.aboutAuthor)}快乐小牛、有鲫雪狐\n" +
"${getString(R.string.aboutContributor)}Col_or、bggRGjQaUbCoE、Minarx、zwJimRaynor\n" +
"${getString(R.string.aboutSpecialThanksTo)}owo233、钟路帆\n" +
"${getString(R.string.aboutOpenSourceRepo)}GitHub\n" +
"${getString(R.string.aboutGetUpdate)}GitHub Releases、Obtainium\n" +
"${getString(R.string.facilitateI18n)}Crowdin\n\n" +
"Since 2023.8.9"
).apply {
setSpan(
URLSpan("https://github.com/klxiaoniu"),
indexOf("快乐小牛"),
indexOf("快乐小牛") + "快乐小牛".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
setSpan(
URLSpan("https://github.com/ArcticFoxPro"),
indexOf("有鲫雪狐"),
indexOf("有鲫雪狐") + "有鲫雪狐".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
setSpan(
URLSpan("https://github.com/color597"),
indexOf("Col_or"),
indexOf("Col_or") + "Col_or".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
setSpan(
URLSpan("https://github.com/bggRGjQaUbCoE"),
indexOf("bggRGjQaUbCoE"),
indexOf("bggRGjQaUbCoE") + "bggRGjQaUbCoE".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
setSpan(
URLSpan("https://github.com/eminarx"),
indexOf("Minarx"),
indexOf("Minarx") + "Minarx".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
setSpan(
URLSpan("https://github.com/zwJimRaynor"),
indexOf("zwJimRaynor"),
indexOf("zwJimRaynor") + "zwJimRaynor".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
setSpan(
URLSpan("https://github.com/callng"),
indexOf("owo233"),
indexOf("owo233") + "owo233".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
setSpan(
URLSpan("https://github.com/Hill-98"),
indexOf("钟路帆"),
indexOf("钟路帆") + "钟路帆".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
setSpan(
URLSpan("https://github.com/klxiaoniu/QQVersionList"),
indexOf("GitHub"),
indexOf("GitHub") + "GitHub".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
setSpan(
URLSpan("https://github.com/klxiaoniu/QQVersionList/releases"),
indexOf("GitHub Releases"),
indexOf("GitHub Releases") + "GitHub Releases".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
setSpan(
URLSpan("https://github.com/klxiaoniu/QQVersionList/blob/master/ReadmeAssets/Get-it-on-Obtainium.md"),
indexOf("Obtainium"),
indexOf("Obtainium") + "Obtainium".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
/*setSpan(
URLSpan("https://github.com/klxiaoniu/QQVersionList/blob/master/ReadmeAssets/Get-it-on-JiuQi-NotifCenter-WeChatMiniProgram.md"),
indexOf("九七通知中心"),
indexOf("九七通知中心") + "九七通知中心".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)*/
setSpan(
URLSpan("https://crowdin.com/project/qqversionstool"),
indexOf("Crowdin"),
indexOf("Crowdin") + "Crowdin".length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
aboutText.text = this@MainActivity.qverbowAboutText()
}

btnAboutWithdrawConsentUA.setOnClickListener {
Expand Down Expand Up @@ -2629,4 +2538,3 @@ class MainActivity : AppCompatActivity() {
val MODE_TIM: String by lazy { context.getString(R.string.timVersion) }
}
}

37 changes: 36 additions & 1 deletion app/src/main/java/com/xiaoniu/qqversionlist/util/InfoUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ package com.xiaoniu.qqversionlist.util
import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.os.Build
import android.provider.Settings
import android.text.SpannableString
import android.text.style.URLSpan
import android.widget.Toast
import androidx.annotation.StringRes
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.xiaoniu.qqversionlist.BuildConfig
import com.xiaoniu.qqversionlist.QVTApplication
import com.xiaoniu.qqversionlist.R
import com.xiaoniu.qqversionlist.util.ClipboardUtil.copyText
Expand Down Expand Up @@ -104,4 +106,37 @@ object InfoUtil {
}
}
}

fun Context.qverbowAboutText(): SpannableString {
return SpannableString(
"${getString(R.string.aboutAppName)}\n\n" +
"${getString(R.string.version)}${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})\n" +
"${getString(R.string.aboutAuthor)}快乐小牛、有鲫雪狐\n" +
"${getString(R.string.aboutContributor)}Col_or、bggRGjQaUbCoE、MinaFluo、zwJimRaynor\n" +
"${getString(R.string.aboutSpecialThanksTo)}owo233、钟路帆\n" +
"${getString(R.string.aboutOpenSourceRepo)}GitHub\n" +
"${getString(R.string.aboutGetUpdate)}GitHub Releases、Obtainium\n" +
"${getString(R.string.facilitateI18n)}Crowdin\n\n" +
"Since 2023.8.9"
).apply {
listOf(
"https://github.com/klxiaoniu" to "快乐小牛",
"https://github.com/ArcticFoxPro" to "有鲫雪狐",
"https://github.com/color597" to "Col_or",
"https://github.com/bggRGjQaUbCoE" to "bggRGjQaUbCoE",
"https://github.com/MinaFluo" to "MinaFluo",
"https://github.com/zwJimRaynor" to "zwJimRaynor",
"https://github.com/callng" to "owo233",
"https://github.com/Hill-98" to "钟路帆",
"https://github.com/klxiaoniu/QQVersionList" to "GitHub",
"https://github.com/klxiaoniu/QQVersionList/releases" to "GitHub Releases",
"https://github.com/klxiaoniu/QQVersionList/blob/master/ReadmeAssets/Get-it-on-Obtainium.md" to "Obtainium",
"https://crowdin.com/project/qqversionstool" to "Crowdin"
).forEach { (url, text) ->
val start = indexOf(text)
val end = start + text.length
setSpan(URLSpan(url), start, end, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE)
}
}
}
}

0 comments on commit a2c3e92

Please sign in to comment.