Skip to content

[POC] New AppConfig API for localized strings in library#583

Open
Luna712 wants to merge 5 commits into
masterfrom
patch-5
Open

[POC] New AppConfig API for localized strings in library#583
Luna712 wants to merge 5 commits into
masterfrom
patch-5

Conversation

@Luna712

@Luna712 Luna712 commented Jul 4, 2026

Copy link
Copy Markdown
Owner

This is just a PoC API I wanted some thoughts on before I fully finish the implimentation for it.

We would set like this from CommonActivity.setLocale():

AppConfig.setStrings {
    this[AppString.AppName] = context.getString(R.string.app_name)
}

or later via compose, something like this:

LaunchedEffect(locale) {
    AppConfig.setStrings {
        this[AppString.AppName] = getString(Res.string.app_name)
    }
}

Which is necessary to get some certain strings from the app to the library in order to eventually move some things like syncproviders into the library, but there also may be a way to avoid needing this altogether, so if there are other ideas I would also like to hear it, which is also why I am opening this PR as just a PoC for now.

It also reworks it to be more reusable and expandable in the future and expands isDebug to allow passing any flavors or build types to the library for future access of certain things. In particular I was thinking a different error message for the outdated app error if already on prerelease. This would be used like:

AppConfig.setBuildType(AppBuildType.fromString(BuildConfig.BUILD_TYPE))
AppConfig.setFlavor(AppFlavor.fromString(BuildConfig.FLAVOR))

Not yet added in this PoC, but the plan for icons (e.g. AniListApi.icon, currently a raw R.drawable.ic_anilist_icon) is different from strings on purpose. Icons don't change at runtime the way locale strings do, so I don't think they need to go through AppConfig as a settable/mutable registry at all. The idea is closer to:

// Somewhere in library
enum class AppIcon {
    AnilistIcon,
    MalIcon,
    // ...
}

abstract class AuthAPI {
    open val icon: AppIcon? = null
}

and then the app or later, composeApp just maps it locally with an exhaustive when, no registration step, and no runtime state:

// Probably in AppContextUtils
fun AppIcon.toDrawableRes(): Int = when (this) {
    AppIcon.AnilistIcon -> R.drawable.ic_anilist_icon
    AppIcon.MalIcon -> R.drawable.mal_logo
    // ...
}

And would allow safety also, since it's an expression-form when with no else, forgetting to map a new AppIcon entry fails at compile time instead of silently returning null at runtime, which is why I'd rather do it this way than reuse the AppConfig.setStrings-style pattern for icons too. Same idea would apply for compose later with Res.drawable/DrawableResource instead. Again, open to better ideas for this thought as well.

@Luna712 Luna712 changed the title Draft new AppConfig API Draft new AppConfig API for localized strings in library Jul 4, 2026
@Luna712 Luna712 changed the title Draft new AppConfig API for localized strings in library [POC] New AppConfig API for localized strings in library Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant