-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3465 from CruGlobal/shortcutUpdates
GT-2311 Update Shortcuts to preserve selected languages when created
- Loading branch information
Showing
9 changed files
with
524 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
ui/shortcuts/src/main/kotlin/org/cru/godtools/shortcuts/ShortcutId.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.cru.godtools.shortcuts | ||
|
||
import java.util.Locale | ||
|
||
internal sealed interface ShortcutId { | ||
val id: String | ||
|
||
companion object { | ||
const val SEPARATOR = "|" | ||
|
||
fun parseId(id: String): ShortcutId? = when (id.substringBefore(SEPARATOR)) { | ||
Tool.TYPE -> Tool.parseId(id) | ||
else -> null | ||
} | ||
} | ||
|
||
data class Tool internal constructor(val tool: String, val locales: List<Locale>) : ShortcutId { | ||
internal constructor(tool: String, vararg locales: Locale?) : this(tool, locales.filterNotNull()) | ||
|
||
override val id = (listOf(TYPE, tool) + locales.map { it.toLanguageTag() }).joinToString(SEPARATOR) | ||
|
||
val isFavoriteToolShortcut get() = locales.isEmpty() | ||
|
||
companion object { | ||
const val TYPE = "tool" | ||
|
||
fun parseId(id: String): Tool? { | ||
val components = id.split(SEPARATOR) | ||
return when { | ||
components.size < 2 -> null | ||
components[0] != TYPE -> null | ||
else -> Tool( | ||
tool = components[1], | ||
locales = components.subList(2, components.size).map { Locale.forLanguageTag(it) } | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.