Skip to content

Commit

Permalink
refactor: adjust third party library summary display
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Mar 25, 2023
1 parent 9ea36ab commit 16128ff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
35 changes: 7 additions & 28 deletions app/src/main/java/com/osfans/trime/ui/fragments/AboutFragment.kt
Expand Up @@ -16,6 +16,8 @@ import com.osfans.trime.data.opencc.OpenCCDictManager
import com.osfans.trime.ui.components.PaddingPreferenceFragment
import com.osfans.trime.ui.main.MainViewModel
import com.osfans.trime.util.Const
import com.osfans.trime.util.optionalPreference
import com.osfans.trime.util.thirdPartySummary
import splitties.systemservices.clipboardManager

class AboutFragment : PaddingPreferenceFragment() {
Expand All @@ -41,28 +43,11 @@ class AboutFragment : PaddingPreferenceFragment() {
true
}
}
get<Preference>("about__librime_version")?.apply {
val version = Rime.getLibrimeVersion()
summary = version
intent = intent?.let {
Intent(
Intent.ACTION_VIEW,
Uri.withAppendedPath(it.data, "commits/$version"),
)
}
}
get<Preference>("about__opencc_version").apply {
val version = OpenCCDictManager.getOpenCCVersion()
summary = version
intent = intent?.let {
Intent(
Intent.ACTION_VIEW,
Uri.withAppendedPath(it.data, "commits/$version"),
)
}
}
get<Preference>("pref_trime_custom_qq")
?.hidden()
get<Preference>("about__librime_version")
?.thirdPartySummary(Rime.getLibrimeVersion())
get<Preference>("about__opencc_version")
?.thirdPartySummary(OpenCCDictManager.getOpenCCVersion())
get<Preference>("pref_trime_custom_qq")?.optionalPreference()
get<Preference>("about__open_source_licenses")?.apply {
setOnPreferenceClickListener {
findNavController().navigate(R.id.action_aboutFragment_to_licenseFragment)
Expand All @@ -76,10 +61,4 @@ class AboutFragment : PaddingPreferenceFragment() {
super.onResume()
viewModel.setToolbarTitle(getString(R.string.pref_about))
}

private fun Preference.hidden() {
if (this.summary?.isBlank() == true || this.intent?.data == null) {
this.isVisible = false
}
}
}
18 changes: 18 additions & 0 deletions app/src/main/java/com/osfans/trime/util/Utils.kt
Expand Up @@ -3,11 +3,13 @@ package com.osfans.trime.util
import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.net.Uri
import android.os.Build
import android.os.Bundle
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.preference.Preference
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.ToastUtils
import com.osfans.trime.R
Expand Down Expand Up @@ -94,3 +96,19 @@ inline fun <reified T : Serializable> Bundle.serializable(key: String): T? {
getSerializable(key) as? T
}
}

fun Preference.thirdPartySummary(versionCode: String) {
summary = versionCode
intent?.let {
val commitHash = if (versionCode.contains("-g")) {
versionCode.replace("^(.*-g)([0-9a-f]+)(.*)$".toRegex(), "$2")
} else {
versionCode.replace("^([^-]*)(-.*)$".toRegex(), "$1")
}
it.data = Uri.withAppendedPath(it.data, "commits/$commitHash")
}
}

fun Preference.optionalPreference() {
isVisible = summary.isNullOrBlank() || intent?.data == null
}

0 comments on commit 16128ff

Please sign in to comment.