Skip to content

Commit

Permalink
Make in app links localizable
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Jul 16, 2024
1 parent 31c6817 commit f69a1b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
17 changes: 13 additions & 4 deletions app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ class MainActivity : AppCompatActivity(R.layout.activity_main),
builder.setTitle(R.string.privacy_policy_alert_title)
builder.setMessage(R.string.privacy_policy_alert_detail)
builder.setNeutralButton(R.string.privacy_policy_alert_show_policy_button_title) { _, _ ->
openURL("https://celestia.mobi/privacy")
val baseURL = "https://celestia.mobi/privacy"
val uri = Uri.parse(baseURL).buildUpon().appendQueryParameter("lang", "zh_CN").build()
openURI(uri)
finishAndRemoveTask()
exitProcess(0)
}
Expand Down Expand Up @@ -1331,8 +1333,11 @@ class MainActivity : AppCompatActivity(R.layout.activity_main),
(supportFragmentManager.findFragmentById(R.id.celestia_fragment_container) as? CelestiaFragment)?.updateFrameRateOption(frameRateOption)
}

override fun onAboutURLSelected(url: String) {
openURL(url)
override fun onAboutURLSelected(url: String, localizable: Boolean) {
var uri = Uri.parse(url)
if (localizable)
uri = uri.buildUpon().appendQueryParameter("lang", AppCore.getLanguage()).build()
openURI(uri)
}

override fun onSearchForEvent(objectName: String, startDate: Date, endDate: Date) {
Expand Down Expand Up @@ -1416,7 +1421,11 @@ class MainActivity : AppCompatActivity(R.layout.activity_main),
}

private fun openURL(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
openURI(Uri.parse(url))
}

private fun openURI(uri: Uri) {
val intent = Intent(Intent.ACTION_VIEW, uri)
val ai = intent.resolveActivityInfo(packageManager, PackageManager.MATCH_DEFAULT_ONLY)
if (ai != null && ai.exported)
startActivity(intent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class AboutFragment : NavigationFragment.SubFragment() {
when (item) {
is ActionItem -> {
TextRow(primaryText = item.title, primaryTextColor = MaterialTheme.colorScheme.primary, modifier = Modifier.clickable {
listener?.onAboutURLSelected(item.url)
listener?.onAboutURLSelected(item.url, localizable = item.localizable)
})
}
is VersionItem -> {
Expand Down Expand Up @@ -134,7 +134,7 @@ class AboutFragment : NavigationFragment.SubFragment() {
vertical = dimensionResource(id = R.dimen.list_item_medium_margin_vertical)
)) {
Text(text = "苏ICP备2023039249号-4A", color = colorResource(id = com.google.android.material.R.color.material_on_background_emphasis_medium), style = MaterialTheme.typography.bodySmall, modifier = Modifier.clickable {
listener?.onAboutURLSelected("https://beian.miit.gov.cn")
listener?.onAboutURLSelected("https://beian.miit.gov.cn", localizable = false)
})
}
}
Expand Down Expand Up @@ -165,16 +165,16 @@ class AboutFragment : NavigationFragment.SubFragment() {
// Links
array.add(
listOf(
ActionItem(CelestiaString("Development", "URL for Development wiki"),"https://celestia.mobi/help/development"),
ActionItem(CelestiaString("Third Party Dependencies", "URL for Third Party Dependencies wiki"), "https://celestia.mobi/help/dependencies"),
ActionItem(CelestiaString("Privacy Policy and Service Agreement", "Privacy Policy and Service Agreement"), "https://celestia.mobi/privacy")
ActionItem(CelestiaString("Development", "URL for Development wiki"),"https://celestia.mobi/help/development", localizable = false),
ActionItem(CelestiaString("Third Party Dependencies", "URL for Third Party Dependencies wiki"), "https://celestia.mobi/help/dependencies", localizable = true),
ActionItem(CelestiaString("Privacy Policy and Service Agreement", "Privacy Policy and Service Agreement"), "https://celestia.mobi/privacy", localizable = true)
)
)

array.add(
listOf(
ActionItem(CelestiaString("Official Website", ""), "https://celestia.mobi"),
ActionItem(CelestiaString("About Celestia", "System menu item"), "https://celestia.mobi/about")
ActionItem(CelestiaString("Official Website", ""), "https://celestia.mobi", localizable = true),
ActionItem(CelestiaString("About Celestia", "System menu item"), "https://celestia.mobi/about", localizable = true)
)
)

Expand Down Expand Up @@ -208,7 +208,7 @@ class AboutFragment : NavigationFragment.SubFragment() {
}

interface Listener {
fun onAboutURLSelected(url: String)
fun onAboutURLSelected(url: String, localizable: Boolean)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ package space.celestia.mobilecelestia.settings

sealed class AboutItem
class VersionItem(val versionName: String) : AboutItem()
class ActionItem(val title: String, val url: String) : AboutItem()
class ActionItem(val title: String, val url: String, val localizable: Boolean) : AboutItem()
class TitleItem(val title: String) : AboutItem()
class DetailItem(val detail: String) : AboutItem()

0 comments on commit f69a1b9

Please sign in to comment.