Git Product home page Git Product logo

modernandroidpreferences's Introduction

ModernAndroidPreferences

GitHub release Maven Central Build status Lint status License

Android preferences in Kotlin DSL, displayed in a RecyclerView.

No XML, no troubles with PreferenceManager, Fragments, or styling, no more ListView. 🎉

Code example

// Setup a preference screen
val screen = screen(context) {
    pref("first") {
        title = "A preference"
        summary = "Click me to do stuff"
        click {
            doStuff()
        }
    }
    pref("second") {
        title = "Another one"
        iconRes = R.drawable.preference_icon_24dp
    }
    categoryHeader("more") {
        titleRes = R.string.category_more
    }
    switch("toggle_feature") {
        title = "Also supports switches"
    }
    // and many other preference widgets!
}

// Wrap the created screen in a preference adapter…
val preferencesAdapter = PreferencesAdapter(screen)

// …that can be attached to a RecyclerView
recyclerView.adapter = preferencesAdapter

Example app

Example Activities (with and without using ViewModel) show advanced info like back handling, saving/restoring scroll position, and using the OnScreenChangeListener.

Screenshots

Click to show

Include to project

ModernAndroidPreferences is on Maven Central, so you can get it like any other dependency:

dependencies {
    implementation 'de.maxr1998:modernandroidpreferences:2.3.2'
}

NOTE: This library has previously been available as de.Maxr1998.android:modernpreferences on Bintray JCenter, but was migrated to Sonatype Maven Central in light of the impending JCenter sunsetting.
To get in line with Maven naming standards, it was renamed to de.maxr1998:modernandroidpreferences.

License

Copyright © 2018-2021 Max Rumpf alias Maxr1998

This library is released under the Apache License version 2.0. If you use this library (or code from it) in your projects, crediting me is appreciated.

The example application however is licensed under the GNU General Public version 3, or any later version.

modernandroidpreferences's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar kdrag0n avatar maxr1998 avatar maxr1998-bot avatar rosenpin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

modernandroidpreferences's Issues

Add option to show multiline preference titles

Right now, preference titles can get cut off pretty quickly if the user set their display or font size to 'large', especially switch preference titles (see screenshot below). Note: Preferences are padded with (2x) 8dp horizontal padding.
image

How to specify a summary that contains the current value of the preference

Hi, great library!
I am trying to specify a summary for preferences that always have the current value of the preference formatted by a custom formatter. My usecase for this is a preference that opens a dialog window with a NumberPicker. I want to be nice and show the currently set value. For consistency, I would also like to do that for everything else too, like for seekbars which would mean hiding the built-in value display.
Is it possible somehow?
Thanks!

Support arbitrary storage providers

I've made a fork here https://github.com/MFlisar/ModernAndroidPreferences and implemented an arbitrary storage layer here

What I did:

  • created an interface Storage
  • created a default storage implementation SharedPreferencesStorage which works just as your current solution
  • replaced the SharedPreferences inside your library with the Storage instance (builder, dsl, ...)

Why?

In my case I need multi process support and therefore I have written a room based preference library and I want to plug in this library into yours. Additionally, preferences are not the most modern solution for preferences, datastore is the new way - with my solution you can easily provide a storage implementation that uses the DataStore instead of the SharedPreferences in the future and still let your users choose. And of course, any user can replace the storage implementation with their own

Question

Do you think such a change (it's small and does not add any complexity to your library) does make sense and should be merged into your library? I did not adjust any tests yet but if you like the idea, I'll make those adjustments and create a pull request.

multiChoice preference doesn't show summary

Hi Max what's up?
Long time

This library is pretty awesome, it looks fantastic and this is the least painful way I encountered to handle preferences in Android

I messed around a bit with it in a new app I'm working on and it seems like when providing summary to the multiChoice preference it isn't shown anywhere, not where the normal summaries are and not in the dialog

Code:

 multiChoice("special_buttons", specialButtons) {
            title = "Special buttons"
            summary = "WIP: Choose what the special button to show"
        }

Thanks!

Implement an `EditTextPreference` counterpart

androidx.preference provides EditTextPreference as a way to accept arbitrary text input from users, which has no parallel in ModernAndroidPreference as of now.

It'd also be great to be able to have an optional validator method that would be called when the user attempts to save the value, and possibly a way to provide inputType flags for the underlying EditText so we can enforce things like numeric input without needing the validator or inconveniencing the user.

Create custom preferences

In PreferencesAdapter#onCreateViewHolder() only few types of layouts can be used. How can I create a custom preferences with custom layout?

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>Maxr1998-bot/.github//renovate-presets/default). Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Option to set default option in SingleChoice preference

There should be a way to set a default value for the SingleChoice preference, example could be

val styleOption = listOf(
            SelectionItem(
                Prefs.Keys.ListStyles.COMPACT,
                "compact",
                ...
            ),
            SelectionItem(
                Prefs.Keys.ListStyles.STANDARD,
                "standard",
                ...
            ),
        )
        singleChoice(..., styleOption) {
            title = ...
            summary = ...
            icon = ...
            default = Prefs.Keys.ListStyles.STANDARD
        }

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • ⬆️ Update CI dependencies (actions/checkout, github/codeql-action, gradle/actions, gradle/wrapper-validation-action)
  • ⬆️ Update Kotlin to v1.9.24 (org.jetbrains.kotlin.plugin.parcelize, org.jetbrains.kotlin.android)
  • ⬆️ Update android.plugin to v8.5.0 (com.android.application, com.android.library)
  • ⬆️ Update dependency androidx.appcompat:appcompat to v1.7.0
  • ⬆️ Update dependency gradle to v8.8
  • ⬆️ Update Kotlin to v2 (major) (org.jetbrains.kotlin.plugin.parcelize, org.jetbrains.kotlin.android)
  • ⬆️ Update gradle/wrapper-validation-action action to v3
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/gradlew-validate.yaml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • gradle/wrapper-validation-action v2.1.2@b231772637bb498f11fdbc86052b6e8a8dc9fc92
  • ubuntu 22.04
.github/workflows/library-lint.yaml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/setup-java v4.2.1@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9
  • gradle/actions v3.2.0@e24011a3b5db78bd5ab798036042d9312002f252
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/setup-java v4.2.1@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9
  • gradle/actions v3.2.0@e24011a3b5db78bd5ab798036042d9312002f252
  • github/codeql-action v3.24.10@4355270be187e1b672a7a1c7c7bae5afdc1ab94a
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/setup-java v4.2.1@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9
  • gradle/actions v3.2.0@e24011a3b5db78bd5ab798036042d9312002f252
  • github/codeql-action v3.24.10@4355270be187e1b672a7a1c7c7bae5afdc1ab94a
  • ubuntu 22.04
  • ubuntu 22.04
  • ubuntu 22.04
.github/workflows/library-test.yaml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/setup-java v4.2.1@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9
  • gradle/actions v3.2.0@e24011a3b5db78bd5ab798036042d9312002f252
  • ubuntu 22.04
gradle
gradle.properties
settings.gradle.kts
build.gradle.kts
gradle/libs.versions.toml
  • androidx.core:core-ktx 1.10.1
  • androidx.appcompat:appcompat 1.6.1
  • androidx.activity:activity-ktx 1.7.2
  • androidx.constraintlayout:constraintlayout 2.1.4
  • androidx.recyclerview:recyclerview 1.3.1
  • com.google.android.material:material 1.9.0
  • androidx.lifecycle:lifecycle-viewmodel-ktx 2.6.2
  • androidx.lifecycle:lifecycle-runtime-ktx 2.6.2
  • androidx.lifecycle:lifecycle-common-java8 2.6.2
  • org.junit.jupiter:junit-jupiter-api 5.10.0
  • org.junit.jupiter:junit-jupiter-engine 5.10.0
  • io.kotest:kotest-runner-junit5-jvm 5.7.2
  • io.kotest:kotest-assertions-core-jvm 5.7.2
  • io.kotest:kotest-property-jvm 5.7.2
  • io.mockk:mockk-android 1.13.7
  • com.squareup.leakcanary:leakcanary-android 2.12
  • io.gitlab.arturbosch.detekt:detekt-formatting 1.21.0
  • com.android.library 8.3.1
  • com.android.application 8.3.1
  • org.jetbrains.kotlin.android 1.9.23
  • org.jetbrains.kotlin.plugin.parcelize 1.9.23
  • org.jetbrains.kotlinx.binary-compatibility-validator 0.14.0
  • de.mannodermaus.android-junit5 1.9.3.0
  • com.adarshr.test-logger 3.2.0
  • io.gitlab.arturbosch.detekt 1.21.0
library/build.gradle.kts
testapp/build.gradle.kts
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.