{"id":21595145,"url":"https://github.com/kazakago/preferhythm","last_synced_at":"2025-04-10T23:51:45.118Z","repository":{"id":103797500,"uuid":"84318062","full_name":"kazakago/Preferhythm","owner":"kazakago","description":"Generate Android's SharedPreferences related boilerplate code.","archived":false,"fork":false,"pushed_at":"2020-04-12T09:32:25.000Z","size":247,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T23:51:42.800Z","etag":null,"topics":["android","sharedpreferences"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kazakago.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2017-03-08T12:30:59.000Z","updated_at":"2023-06-10T06:09:12.000Z","dependencies_parsed_at":"2023-03-27T22:06:27.243Z","dependency_job_id":null,"html_url":"https://github.com/kazakago/Preferhythm","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazakago%2FPreferhythm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazakago%2FPreferhythm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazakago%2FPreferhythm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazakago%2FPreferhythm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kazakago","download_url":"https://codeload.github.com/kazakago/Preferhythm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317706,"owners_count":21083528,"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","sharedpreferences"],"created_at":"2024-11-24T17:27:37.100Z","updated_at":"2025-04-10T23:51:45.111Z","avatar_url":"https://github.com/kazakago.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"![./artwork/logo.png](./artwork/logo.png)\n\nPreferhythm\n====\n\n[![Download](https://api.bintray.com/packages/kazakago/maven/preferhythm/images/download.svg)](https://bintray.com/kazakago/maven/preferhythm/_latestVersion)\n[![Build Status](https://app.bitrise.io/app/ae4ee3f69a27ccc5/status.svg?token=OUnnoRKMjEkYyhc-CXyPQQ\u0026branch=master)](https://app.bitrise.io/app/ae4ee3f69a27ccc5)\n[![license](https://img.shields.io/github/license/kazakago/preferhythm.svg)](LICENSE.md)\n\nAutomatically generate classes to use Android's SharedPreferences easily and safely.\n\n## Requirement\n\n- Android 4.0.3 (API 15) or later\n\n## Install\n\nAdd the following gradle dependency exchanging x.x.x for the latest release.\n\n### Java\n\n```groovy\ndependencies {\n    implementation 'com.kazakago.preferhythm:preferhythm:x.x.x'\n    annotationProcessor 'com.kazakago.preferhythm:preferhythm-processor:x.x.x'\n}\n```\n\n### Kotlin\n\n```groovy\napply plugin: 'kotlin-kapt'\n\ndependencies {\n    implementation 'com.kazakago.preferhythm:preferhythm:x.x.x'\n    kapt 'com.kazakago.preferhythm:preferhythm-processor:x.x.x'\n}\n```\n\n## Supported Type\n\n- Primitive Type\n  - int\n  - long\n  - float\n  - boolean\n- Object Type\n  - Integer \n  - Long\n  - Float\n  - Boolean\n  - String\n  - Set\\\u003cString\\\u003e\n\nThis is the same as Android's SharedPreferences specification. [More details](https://developer.android.com/training/basics/data-storage/shared-preferences.html).\n\n\n## Usage\n\nCreate a preference model class and add `@PrefClass` annotation.  \nNext, define field variable and add `@PrefField` annotation.\n\n```java\n@PrefClass // `@PrefClass` is nessesary for your preferences model class.\nclass MyPreferences {\n\n    @PrefField // `@PrefField` is nessesary for your preference value.\n    int intValue = 3; // default value is `3`.\n\n    @PrefField\n    boolean booleanValue; // default value is `false`. (primitive default value)\n\n    @PrefField\n    String stringValue; // default value is `null`.\n\n    @NonNull\n    @PrefField\n    String nonNullStringValue = \"foo\"; // NonNull annotation with default value.\n\n}\n```\n\nWhen building, `[PREFERENCES_MODEL_NAME] + Manager` class is auto generated based on the class with `@PrefClass` annotation.  \nAlso, Put and get methods are auto created based on the original field name with `@PrefField` annotation.  \n\n```java\npublic class MainActivity extends Activity {\n\n    // `MyPreferencesManager` class is auto generated.\n    private MyPreferencesManager myPreferencesManager = new MyPreferencesManager(this);\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n        \n        System.out.print(myPreferencesManager.getIntValue()); // 3 (default value)\n\n        myPreferencesManager.setIntValue(100); // set 100\n        myPreferencesManager.commit(); // commit change.\n\n        System.out.print(myPreferencesManager.getIntValue()); // 100\n        \n        myPreferencesManager.clear(); // clear value.\n        myPreferencesManager.commit(); // commit change.\n\n        System.out.print(myPreferencesManager.getIntValue()); // 3 (default value)\n    }\n\n}\n```\n\nRefer to the sample module ([Java](https://github.com/KazaKago/Preferhythm/tree/master/samplejava) \u0026 [Kotlin](https://github.com/KazaKago/Preferhythm/tree/master/samplekotlin)) for details.\n\n## Important\n\n### Preferences Name\n\nBy default, the SharedPreferences name is **Class Name**.  \nTherefore, if you change the class name, the saved value can not be retrieved.  \n\nIf you want to set the SharedPreferences name to an arbitrary value, please add parameters to `@PrefField`.  \n\n```java\n@PrefClass(\"YOUR_ORIGINAL_PREFERENCES_NAME\")\nclass YourPreferencesClass {\n\n...\n\n}\n\n```\n\n### Key Name\n\nBy default, the key name when saving to SharedPreferences is **Field Name**.  \nTherefore, if you change the field name, the saved value can not be retrieved.  \n\nIf you want to set the key name to an arbitrary value, please add parameters to `@PrefField`.  \n\n```java\n@PrefClass\nclass YourPreferencesClass {\n\n    @PrefField(\"YOUR_ORIGINAL_KEY_NAME\")\n    int yourSaveValue;\n\n}\n\n```\n\n## Advanced\n\n### Override Put and Get Method.\n\nyou can override put and get method in `[PREFERENCES_MODEL_NAME] + Manager` class.\n\n```java\npublic class CustomMyPreferencesManager extends MyPreferencesManager {\n\n    public CustomMyPreferencesManager(@NonNull Context context) {\n        super(context);\n    }\n    \n    @Nullable\n    @Override\n    public String getStringValue() {\n        // ### Your custom step. (if needed) ###\n        // ex) decryption code.\n        // ###\n        return super.getStringValue();\n    }\n\n    @NonNull\n    @Override\n    public MyPreferencesManager putStringValue(@Nullable String value) {\n        // ### Your custom step. (if needed) ###\n        // ex) encryption code.\n        // ###\n        return super.putStringValue(value);\n    }\n\n}\n```\n\n## Kotlin Support\n\nThis library supports Kotlin's Nullable.\n\n```kotlin\n@PrefClass\nclass MyPreferences {\n\n    @PrefField\n    val intValue: Int = 3 // NonNull \u0026 default value is `3`.\n\n    @PrefField\n    val booleanValue: Boolean = false // NonNull \u0026 default value is `false`\n\n    @PrefField\n    val stringValue: String = \"foo\" // NonNull \u0026 default value is `foo`\n\n    @PrefField\n    val nullableStringValue: String? = null // Nullable \u0026 default value is `null`\n\n    @PrefField\n    val nullableStringWithInitValue: String? = \"bar\" // Nullable \u0026 default value is `bar`\n\n}\n```\n\n## License\nMIT License\n\nCopyright (c) 2017 KazaKago\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazakago%2Fpreferhythm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkazakago%2Fpreferhythm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazakago%2Fpreferhythm/lists"}