add links to discussin sections to load dialogs for laoyuts and colors

and gather links in a single place
This commit is contained in:
Helium314 2025-02-25 20:24:24 +01:00
parent 6212f44283
commit 3c9d1c8795
8 changed files with 58 additions and 25 deletions

View file

@ -0,0 +1,13 @@
package helium314.keyboard.latin.common
object Links {
const val DICTIONARY_URL = "https://codeberg.org/Helium314/aosp-dictionaries"
const val DICTIONARY_DOWNLOAD_SUFFIX = "/src/branch/main/"
const val DICTIONARY_NORMAL_SUFFIX = "dictionaries/"
const val DICTIONARY_EXPERIMENTAL_SUFFIX = "dictionaries_experimental/"
const val GITHUB = "https://github.com/Helium314/HeliBoard"
const val LICENSE = "$GITHUB/blob/main/LICENSE-GPL-3"
const val LAYOUT_FORMAT_URL = "$GITHUB/blob/main/layouts.md"
const val CUSTOM_LAYOUTS = "$GITHUB/discussions/categories/custom-layout"
const val CUSTOM_COLORS = "$GITHUB/discussions/categories/custom-colors"
}

View file

@ -22,6 +22,8 @@ import helium314.keyboard.dictionarypack.DictionaryPackConstants
import helium314.keyboard.keyboard.KeyboardLayoutSet
import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.Links.DICTIONARY_URL
import helium314.keyboard.latin.common.Links.LAYOUT_FORMAT_URL
import helium314.keyboard.latin.common.LocaleUtils
import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.databinding.LanguageListItemBinding
@ -425,4 +427,3 @@ private fun getAvailableSecondaryLocales(context: Context, mainLocale: Locale, a
return locales
}
private const val LAYOUT_FORMAT_URL = "https://github.com/Helium314/HeliBoard/blob/main/layouts.md"

View file

@ -16,6 +16,7 @@ import androidx.compose.ui.text.buildAnnotatedString
import androidx.core.content.edit
import helium314.keyboard.compat.locale
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.Links
import helium314.keyboard.latin.common.LocaleUtils
import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.settings.Defaults
@ -50,8 +51,8 @@ fun showMissingDictionaryDialog(context: Context, locale: Locale) {
if (prefs.getBoolean(Settings.PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG, Defaults.PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG)
|| locale.toString() == SubtypeLocaleUtils.NO_LANGUAGE)
return
val repositoryLink = "<a href='$DICTIONARY_URL'>" + context.getString(R.string.dictionary_link_text) + "</a>"
val dictionaryLink = "<a href='$DICTIONARY_URL/src/branch/main/dictionaries/main_$locale.dict'>" + context.getString(
val repositoryLink = "<a href='${Links.DICTIONARY_URL}'>" + context.getString(R.string.dictionary_link_text) + "</a>"
val dictionaryLink = "<a href='${Links.DICTIONARY_URL}/src/branch/main/dictionaries/main_$locale.dict'>" + context.getString(
R.string.dictionary_link_text) + "</a>"
val startMessage = context.getString( // todo: now with the available dicts csv, is the full text still necessary?
R.string.no_dictionary_message,
@ -88,8 +89,8 @@ fun createDictionaryTextHtml(message: String, locale: Locale, context: Context):
val rawDictString = "$type: ${dictLocale.getDisplayName(context.resources.configuration.locale())}"
val dictString = if (experimental.isEmpty()) rawDictString
else context.getString(R.string.available_dictionary_experimental, rawDictString)
val dictBaseUrl = DICTIONARY_URL + DICTIONARY_DOWNLOAD_SUFFIX +
if (experimental.isEmpty()) DICTIONARY_NORMAL_SUFFIX else DICTIONARY_EXPERIMENTAL_SUFFIX
val dictBaseUrl = Links.DICTIONARY_URL + Links.DICTIONARY_DOWNLOAD_SUFFIX +
if (experimental.isEmpty()) Links.DICTIONARY_NORMAL_SUFFIX else Links.DICTIONARY_EXPERIMENTAL_SUFFIX
val dictLink = dictBaseUrl + type + "_" + localeString.lowercase() + ".dict"
val fullText = "<li><a href='$dictLink'>$dictString</a></li>"
knownDicts.add(fullText)
@ -109,7 +110,7 @@ fun createDictionaryTextHtml(message: String, locale: Locale, context: Context):
fun MissingDictionaryDialog(onDismissRequest: () -> Unit, locale: Locale) {
val prefs = LocalContext.current.prefs()
val availableDicts = createDictionaryTextAnnotated(locale)
val dictLink = "$DICTIONARY_URL/src/branch/main/dictionaries/main_$locale.dict"
val dictLink = "${Links.DICTIONARY_URL}/src/branch/main/dictionaries/main_$locale.dict"
val message = stringResource(R.string.no_dictionary_message, "§repl1§", locale.toString(), "§repl2§")
.replace("<br>", "\n") // compose doesn't understand html... // todo: modify the string?
@ -120,7 +121,7 @@ fun MissingDictionaryDialog(onDismissRequest: () -> Unit, locale: Locale) {
val annotatedString = buildAnnotatedString {
append(part1)
appendLink(stringResource(R.string.dictionary_link_text), DICTIONARY_URL)
appendLink(stringResource(R.string.dictionary_link_text), Links.DICTIONARY_URL)
append(part2)
appendLink(stringResource(R.string.dictionary_link_text), dictLink)
append(part3)
@ -158,8 +159,8 @@ fun createDictionaryTextAnnotated(locale: Locale): AnnotatedString {
val rawDictString = "$type: ${dictLocale.getDisplayName(context.resources.configuration.locale())}"
val dictString = if (experimental.isEmpty()) rawDictString
else context.getString(R.string.available_dictionary_experimental, rawDictString)
val dictBaseUrl = DICTIONARY_URL + DICTIONARY_DOWNLOAD_SUFFIX +
if (experimental.isEmpty()) DICTIONARY_NORMAL_SUFFIX else DICTIONARY_EXPERIMENTAL_SUFFIX
val dictBaseUrl = Links.DICTIONARY_URL + Links.DICTIONARY_DOWNLOAD_SUFFIX +
if (experimental.isEmpty()) Links.DICTIONARY_NORMAL_SUFFIX else Links.DICTIONARY_EXPERIMENTAL_SUFFIX
val dictLink = dictBaseUrl + type + "_" + localeString.lowercase() + ".dict"
knownDicts.add(dictString to dictLink)
}
@ -195,8 +196,3 @@ fun cleanUnusedMainDicts(context: Context) {
private fun hasAnythingOtherThanExtractedMainDictionary(dir: File) =
dir.listFiles()?.any { it.name != DictionaryInfoUtils.getExtractedMainDictFilename() } != false
const val DICTIONARY_URL = "https://codeberg.org/Helium314/aosp-dictionaries"
const val DICTIONARY_DOWNLOAD_SUFFIX = "/src/branch/main/"
const val DICTIONARY_NORMAL_SUFFIX = "dictionaries/"
const val DICTIONARY_EXPERIMENTAL_SUFFIX = "dictionaries_experimental/"

View file

@ -33,6 +33,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
@ -40,9 +41,11 @@ import helium314.keyboard.keyboard.ColorSetting
import helium314.keyboard.keyboard.KeyboardTheme
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.ColorType
import helium314.keyboard.latin.common.Links
import helium314.keyboard.latin.common.decodeBase36
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.appendLink
import helium314.keyboard.latin.utils.getActivity
import helium314.keyboard.latin.utils.getStringResourceOrName
import helium314.keyboard.latin.utils.prefs
@ -132,6 +135,15 @@ fun ColorThemePickerDialog(
ConfirmationDialog(
onDismissRequest = { showLoadDialog = false },
title = { Text(stringResource(R.string.load)) },
content = {
val text = stringResource(R.string.get_colors_message)
val annotated = buildAnnotatedString {
append(text.substringBefore("%s"))
appendLink(stringResource(R.string.discussion_section_link), Links.CUSTOM_COLORS)
append(text.substringAfter("%s"))
}
Text(annotated)
},
onConfirmed = {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
.addCategory(Intent.CATEGORY_OPENABLE)

View file

@ -45,6 +45,7 @@ import helium314.keyboard.keyboard.internal.keyboard_parser.morePopupKeysResId
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.Constants.Separators
import helium314.keyboard.latin.common.Constants.Subtype.ExtraValue
import helium314.keyboard.latin.common.Links
import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.common.LocaleUtils.localizedDisplayName
import helium314.keyboard.latin.settings.Defaults
@ -380,10 +381,15 @@ private fun MainLayoutRow(
// layoutString contains "%s" since we didn't supply a formatArg
val layoutString = stringResource(R.string.message_add_custom_layout)
val linkText = stringResource(R.string.dictionary_link_text)
val discussionSectionText = stringResource(R.string.get_layouts_message)
val annotated = buildAnnotatedString {
append(layoutString.substringBefore("%s"))
appendLink(linkText, LAYOUT_FORMAT_URL)
appendLink(linkText, Links.LAYOUT_FORMAT_URL)
append(layoutString.substringAfter("%s"))
appendLine()
append(discussionSectionText.substringBefore("%s"))
appendLink(stringResource(R.string.discussion_section_link), Links.CUSTOM_LAYOUTS)
append(discussionSectionText.substringAfter("%s"))
}
ConfirmationDialog(
@ -460,5 +466,3 @@ fun <T>DropDownField(
private fun getAvailableSecondaryLocales(context: Context, mainLocale: Locale): List<Locale> =
getDictionaryLocales(context).filter { it != mainLocale && it.script() == mainLocale.script() }
private const val LAYOUT_FORMAT_URL = "https://github.com/Helium314/HeliBoard/blob/main/layouts.md"

View file

@ -24,6 +24,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.core.net.toUri
import helium314.keyboard.latin.BuildConfig
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.Links
import helium314.keyboard.latin.settings.DebugSettings
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.utils.Log
@ -93,7 +94,7 @@ fun createAboutSettings(context: Context) = listOf(
description = it.description,
onClick = {
val intent = Intent()
intent.data = "https://github.com/Helium314/HeliBoard/blob/main/LICENSE-GPL-3".toUri()
intent.data = Links.LICENSE.toUri()
intent.action = Intent.ACTION_VIEW
ctx.startActivity(intent)
},
@ -131,7 +132,7 @@ fun createAboutSettings(context: Context) = listOf(
description = it.description,
onClick = {
val intent = Intent()
intent.data = "https://github.com/Helium314/HeliBoard".toUri()
intent.data = Links.GITHUB.toUri()
intent.action = Intent.ACTION_VIEW
ctx.startActivity(intent)
},

View file

@ -20,12 +20,12 @@ import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.unit.dp
import helium314.keyboard.latin.Dictionary
import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.Links
import helium314.keyboard.latin.common.LocaleUtils
import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.common.LocaleUtils.localizedDisplayName
import helium314.keyboard.latin.common.splitOnWhitespace
import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX
import helium314.keyboard.latin.utils.DICTIONARY_URL
import helium314.keyboard.latin.utils.DictionaryInfoUtils
import helium314.keyboard.latin.utils.SubtypeLocaleUtils
import helium314.keyboard.latin.utils.SubtypeSettings
@ -102,7 +102,7 @@ fun DictionaryScreen(
val addDictString = stringResource(R.string.add_dictionary)
val annotated = buildAnnotatedString {
append(addDictString.substringBefore("%s"))
appendLink(stringResource(R.string.dictionary_link_text), DICTIONARY_URL)
appendLink(stringResource(R.string.dictionary_link_text), Links.DICTIONARY_URL)
append(addDictString.substringAfter("%s"))
}
Text(annotated)