{"id":13537222,"url":"https://github.com/softartdev/MaterialThemePrefs","last_synced_at":"2025-04-02T04:30:26.371Z","repository":{"id":57734865,"uuid":"436947042","full_name":"softartdev/MaterialThemePrefs","owner":"softartdev","description":"Kotlin Multiplatform library for easy switching dark/light Material themes on Compose","archived":false,"fork":false,"pushed_at":"2025-03-19T20:31:00.000Z","size":396,"stargazers_count":33,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-19T21:37:21.342Z","etag":null,"topics":["android","compose-multiplatform","dark-theme","desktop","jetbrains-compose","jetpack-compose","kotlin-multiplatform","library","linux","macos","material-design","preferences","windows"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softartdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-10T10:59:41.000Z","updated_at":"2025-02-26T21:12:20.000Z","dependencies_parsed_at":"2023-02-12T12:55:31.016Z","dependency_job_id":"b0f4547c-1133-4ebb-95dd-c22b732f8668","html_url":"https://github.com/softartdev/MaterialThemePrefs","commit_stats":{"total_commits":62,"total_committers":1,"mean_commits":62.0,"dds":0.0,"last_synced_commit":"9e762f8af8544084bf9a0057227bb2fb1ca3333b"},"previous_names":[],"tags_count":66,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softartdev%2FMaterialThemePrefs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softartdev%2FMaterialThemePrefs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softartdev%2FMaterialThemePrefs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softartdev%2FMaterialThemePrefs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softartdev","download_url":"https://codeload.github.com/softartdev/MaterialThemePrefs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246756750,"owners_count":20828760,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","compose-multiplatform","dark-theme","desktop","jetbrains-compose","jetpack-compose","kotlin-multiplatform","library","linux","macos","material-design","preferences","windows"],"created_at":"2024-08-01T09:00:56.467Z","updated_at":"2025-04-02T04:30:25.616Z","avatar_url":"https://github.com/softartdev.png","language":"Kotlin","funding_links":[],"categories":["Libraries"],"sub_categories":["GUI","🍎 Compose UI"],"readme":"# Material Theme Preferences\n\n![Maven Central](https://img.shields.io/maven-central/v/io.github.softartdev/theme-material)\n[![Build \u0026 Publish CI/CD](https://github.com/softartdev/MaterialThemePrefs/actions/workflows/build_publish.yml/badge.svg)](https://github.com/softartdev/MaterialThemePrefs/actions/workflows/build_publish.yml)\n\nKotlin Multiplatform library for easy switching Dark/Light Material themes on [Compose](https://github.com/JetBrains/compose-jb).\nSupported platforms:\n- Android\n- iOS\n- Desktop JVM (MacOS, Linux, Windows)\n\n![Android screenshot](screenshots/android.gif)\n![Desktop screenshot](screenshots/desktop.gif)\n\n## Usage\nCall composable functions for material theme wrap, preferences items on settings screen, showing dialog for select theme.\n```kotlin\n@Composable\nfun App() = PreferableMaterialTheme { // provides composition locals\n    SettingsScaffold { // includes TopAppBar\n        Box {\n            Column {\n                ThemePreferencesCategory() // subtitle\n                ThemePreferenceItem() // menu item\n            }\n            themePrefs.showDialogIfNeed() // shows when menu item clicked\n        }\n    }\n}\n```\nThe [NoteDelight](https://github.com/softartdev/NoteDelight/blob/master/shared-compose-ui/src/commonMain/kotlin/com/softartdev/notedelight/ui/SettingsScreen.kt#L104) app is a real example.   \n## Installation\nThe latest release is available on [Maven Central](https://repo1.maven.org/maven2/io/github/softartdev/theme-material/).\n### Gradle\n1. Add the Maven Central repository if it is not already there:\n```kotlin\nrepositories {\n    mavenCentral()\n}\n```\n2. In multiplatform projects, add a dependency to the commonMain source set dependencies\n```kotlin\ncommonMain {\n    dependencies {\n        implementation(\"io.github.softartdev:theme-material:$latestVersion\") // Material Design 2\n        implementation(\"io.github.softartdev:theme-material3:$latestVersion\") // Material Design 3\n        implementation(\"io.github.softartdev:theme-prefs:$latestVersion\") // optional, if you need only preferences\n    }\n}\n```\n## Implementation\nUsed [moko-resources](https://github.com/icerockdev/moko-resources) library for many languages (currently Russian and English are supported).\n\nPersisting preferences is implemented using [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences) on Android, and [Java Preference API](https://docs.oracle.com/javase/7/docs/api/java/util/prefs/Preferences.html) on JVM Desktop.\n```kotlin\n// common:\nexpect var themeEnum: ThemeEnum\n\n// android:\nprivate val preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)\n\nactual var themeEnum: ThemeEnum\n    get() = preferences.getInt(THEME_KEY, ThemeEnum.SystemDefault.ordinal).let(ThemeEnum.values()::get)\n    set(value) = preferences.edit().putInt(THEME_KEY, value.ordinal).apply()\n\n// desktop java:\nprivate var preferences: Preferences = Preferences.userNodeForPackage(ThemeEnum::class.java)\n\nactual var themeEnum: ThemeEnum\n    get() = preferences.getInt(THEME_KEY, ThemeEnum.SystemDefault.ordinal).let(ThemeEnum.values()::get)\n    set(value) = preferences.putInt(THEME_KEY, value.ordinal)\n```\nAlso used [composition local](https://developer.android.com/jetpack/compose/compositionlocal) for access from theme-scoped as an implicit way:\n```kotlin\nval themePrefs: ThemePrefs = LocalThemePrefs.current\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftartdev%2FMaterialThemePrefs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftartdev%2FMaterialThemePrefs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftartdev%2FMaterialThemePrefs/lists"}