{"id":33147005,"url":"https://github.com/soarcn/Favor","last_synced_at":"2025-11-16T14:01:19.464Z","repository":{"id":57718327,"uuid":"43368910","full_name":"soarcn/Favor","owner":"soarcn","description":"A easy way to use android sharepreference","archived":false,"fork":false,"pushed_at":"2017-02-05T23:58:53.000Z","size":208,"stargazers_count":461,"open_issues_count":2,"forks_count":52,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-26T01:08:05.322Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://cocosw.com/Favor/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soarcn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-29T13:25:46.000Z","updated_at":"2025-05-02T16:27:31.000Z","dependencies_parsed_at":"2022-09-14T22:42:09.668Z","dependency_job_id":null,"html_url":"https://github.com/soarcn/Favor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/soarcn/Favor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarcn%2FFavor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarcn%2FFavor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarcn%2FFavor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarcn%2FFavor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soarcn","download_url":"https://codeload.github.com/soarcn/Favor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarcn%2FFavor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284719042,"owners_count":27052182,"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","status":"online","status_checked_at":"2025-11-16T02:00:05.974Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-11-15T13:00:40.320Z","updated_at":"2025-11-16T14:01:19.459Z","avatar_url":"https://github.com/soarcn.png","language":"Java","funding_links":[],"categories":["Libs","Annotation"],"sub_categories":["\u003cA NAME=\"Code_Generation\"\u003e\u003c/A\u003eCode Generation"],"readme":"Favor\n=======\n[![Build Status](https://travis-ci.org/soarcn/Favor.svg)](https://travis-ci.org/soarcn/Favor)  [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Favor-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/2695)\n\nA easy way of using Android SharedPreferences.\n\nHow to use this library\n=======\n\n- Using Gradle\n\n```groovy\n    compile 'com.cocosw:favor:0.2.0@aar'\n```\n- Using Maven\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.cocosw\u003c/groupId\u003e\n    \u003cartifactId\u003efavor\u003c/artifactId\u003e\n    \u003cversion\u003e0.2.0\u003c/version\u003e\n    \u003ctype\u003eapklib\u003c/type\u003e\n\u003c/dependency\u003e\n```\n\nAPI\n=======\n\n1 Define a interface.\n\n```java \n@AllFavor\npublic interface Account {\n    @Default(\"No Name\")\n    String getUserName();\n    String setPassword(String password);\n}\n```\n\n2 The FavorAdapter class generates an implementation of the interface.\n\n```java \naccount = new FavorAdapter.Builder(getContext()).build().create(Account.class);\naccount.setPassword(\"Passw0rd\");\nString username = account.getUserName();\n```\n\nAPI Declaration\n======\n\n@AllFavor\n-----\n\n```java\n@AllFavor\npublic interface Account {\n    @Default(\"No Name\")\n    String getUserName();\n    String getPassword();\n}\n```\n\n@Favor\n-----\n\n```java\n    @Favor(\"city\")\n    @Default(\"Sydney\")\n    String city();\n```\n\nequals\n\n```java\n    PreferenceManager.getDefaultSharedPreferences(context).getString(\"city\",\"Sydney\");\n```\n\nAnd you can simplify it, Favor will extract the key from the method name\n\n```java\n    @Favor\n    @Default(\"Sydney\")\n    String city();\n```\n\n@Default\n------\n\n```java\n    @Default(\"18\")\n    int age();\n    \n    @Default(\"true\")\n    boolean alive();\n```\n\n@Commit\n------\n\nBy default, Favor will call editor.apply() (\u003eapi9), but you can force it to use editor.commit() by @Commit\n\n```java\n    @Favor\n    @Commit\n    void setAddress(String address);\n```\n    \nRxPreference\n------\n    \nYou are a RxJava fan, easy! (rx-preferences dependency is required)\n\n```java\n    @Favor\n    @Default(\"No Name\")\n    Preference\u003cString\u003e name();\n```    \n\nAdvanced usage\n-------\n\nFavor support put/get all primitive types, including int/long/float/String/bool, String set is also supported for API\u003e=11.\nFrom 0.2.0, Favor (Experimentally) supports Serializable object saving/loading.\n\n```java\n    public class Image implements Serializable {\n    ....\n    }\n   \n    @Favor\n    Image image();\n\n    @Favor\n    void setImage(Image image);\n```\n\nThere is one limitation that you can't set default value for Serializable preference item.\n\n\nProguard\n=======\n\n```xml\n# Favor\n-dontwarn com.cocosw.favor.** { *; }\n-keep class com.cocosw.favor.** { *; }\n```\n\nContribute\n=======\n\n- Feel free to send your pull request to me.\n\nLicense\n=======\n\n    Copyright 2011, 2015 Kai Liao\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoarcn%2FFavor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoarcn%2FFavor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoarcn%2FFavor/lists"}