SimpleConfig


Source link: https://github.com/BCsl/SimpleConfig

SimpleConfig

Remove boilerplate code for using SharePreference to persist app's config data, Inspire by retrofit

???????

Gradle

compile 'github.hellocsl:simpleconfig:{
lastest-version
}
' 

Usage

Step1 Define your config interface

Config Interface? Recommended

@CONFIG(name = "Simple") public interface TestConfig {

  String TEST_KEY_INT = "HELLO_INT";

@GET(key = TEST_KEY_INT)
  int getIndex(int def);

@GET(key = TEST_KEY_INT)
  int getIndex();

@APPLY(key = TEST_KEY_INT)
  void applyIndex(int value);

 @COMMIT(key = TEST_KEY_INT)
  boolean commitIndex(int value);
  
}

Other way to define your Config Interface? (Be careful of ProGuard)

//config name will be NoAnnotationConfig public interface NoAnnotationConfig {

  //get as prefix?HelloInt will be consider as the key?default value is def?return type is int
  int getHelloInt(int def);

//get as prefix?HelloInt will be consider as the key?default value is -1?return type is int
  int getHelloInt();

//apply as prefix?HelloInt will be consider as the key
  void applyHelloInt(int value);

//commit as prefix?HelloInt will be consider as the key value?return type is boolean which indicated the new values were successfully written to persistent storage.
  boolean commitHelloInt(int value);
 
}

Since this lib use SharePreference to save [key-value] at default, so only int|Integer? long|Long? float|Float? boolean|Boolean? String? Set<String> are support to

Step2 Use SimpleConfig to parse config interface

Use SimpleConfig.Builder to build a SimpleConfig object ?and then use SimpleConfig#create method to parse Config interface and it will return a dynamic proxy object witch implements the config interface ?now you can use this to update values to config or get values from config

SimpleConfig simpleConfig = new SimpleConfig.Builder(mAppContext).build();
 TestConfig testConfig = mSimpleConfig.create(TestConfig.class);
 //... testConfig.applyIndex(111);
 int result = testConfig.getIndex(100);
 //...

Further settings

How to define your config interface

Config interface contains two type of method? Method to get value ? Method to update value

  • Method to get value

    This type of method can be annotate by @Get or with a get as prefix of the method name.At most one argument allowed by these methods, and it will consider to be the default value , SimpleConfig use the method return type as the type of the value to retrieve

  • Method to update value

    This type of method can be annotate by @APPLY or @COMMIT,with apply or commit as prefix of the method name is also support.Only one argument allowed by these methods represent a new value for the config. Both boolean and void are support as the return type?but boolean type is meaningless when defines in apply method and alway true is returned

Here Annotations can use

Annotation Target Function Note
@CONFIG Config interface Specified the name of config If not set?Interface name will be consider as name of config
@GET Method to get value Specified the key be used to retrieve value from config If not set and the method start with "get"?such as "getHelloInt" ?"HelloInt" will be consider as the key
@APPLY Method to update value Specified the key be used to modify the config?it will update config asynchronously If not set and the method start with "apply"?such as "applyHelloInt" ?"HelloInt" will be consider as the key
@COMMIT Method to update value Specified the key be used to modify the config If not set and the method start with "commit"?such as "commitHelloInt" ?"HelloInt" will be consider as the key

Implement your Config

At Default , SimpleConfig use SharePreference to persist config value, PreferenceConfig?but you can implement your persistent systems by specified your Config.Factory when build a SimpleConfig

mSimpleConfig = new SimpleConfig.Builder(mAppContext).configFactory(new Config.Factory() {

@Override

public Config newConfig(Context context, String name, int mode) {

  // return your persistent systems

 return null;

}
  
}
).build();

DEMO

Unit Test is provided. TestConfigTest & NoAnnotationConfigTest

ProGuard

Since ProGuard may confuse your Config Interface , so define your Config Interface with annotations is recommended

License

The MIT License (MIT)  Copyright 2017 BCsl  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

Resources

advanced-textview is a companion app for Advanced Android TextView talk, demonstrating:

  • Animated CompoundDrawable
  • Text shadow
  • Custom font
  • Gradient text
  • Patterned text
  • HTML.fromHtml()
  • setFontFeatureSettings()
  • Styled string
  • AlignmentSpan
  • ClickableSpan
  • Rainbow span, animated
  • Lined paper
  • Emoji

Views and Drawable for animated GIFs in Android.

Bundled GIFLib via JNI is used to render frames. This way should be more efficient than WebView or Movie classes.
Animation starts automatically and run only if View with attached GifDrawable is visible.

Gradle plugin for Android which lets you use Java generics in your XML layouts.

droidicon provides over 1600 customizable icons, 25 ready-made social badges and more! droidicon makes it super easy to add icons and badges to your app. All of the social badges are already styled.

Just add them to your app! Or you can customize the icons however you want.

Helpstack provides mobile in-app support for your app users.

With HelpStack, you can:

  • Let users report issues within your app
  • Let users attach screenshots to their support requests
  • Receive Device and App Information automatically, along with the reported issue
  • Let users view your responses to their issues
  • Provide self-support by showing FAQ articles
  • Customise your HelpStack screen to blend with your app theme
  • Integrates with Zendesk, Desk.com and HappyFox. Even works with email if you don't have a help desk account.

Android Studio / Eclipse ADT template for including icon resources from Material Design icons by Google in your project.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes