Skip to content

Some simple kotlin extension methods and tools can speed up the development of Android.

License

Notifications You must be signed in to change notification settings

snowman-team/Toolbox

Repository files navigation

Snowball Android Toolbox
Download

Some simple kotlin extension methods and tools can speed up the development of Android.

Installation

dependencies {
    // add dependency, please replace x.y.z to the latest version
    implementation "com.xueqiu.toolbox:toolbox:x.y.z"
}

Usage

GsonManager

// init gson manager
GsonManager.init(GsonOptions().setLowercaseWithUnderscores(true).setSerializeSpecialFloatingPointValues(true))

// then use it everywhere
val gson = GsonManager.getGson()

Storage(SharedPreferences)

Create a storage class which extends BaseStorage

object AppStore {

    var testData by AppStorage("test", "fake value")

    class AppStorage<T>(key: String, defValue: T) : BaseStorage<T>(key, defValue) {

        override fun getStorage(): SharedPreferences =
            AppContext.INSTANCE.getSharedPreferences("app", Context.MODE_PRIVATE)

    }

}

Then use it

// write data
AppStore.testData = "test data"
// read data
val data = AppStore.testData

RxBus

// post message
Courier.post(TestEvent(params))

// and receive message
Courier.toObservable(TestEvent::class.java)
    .observeOn(MainSchedulers.mainThread)
    .subscribe { 
        // do something
    }

Ext

Utils

About

Some simple kotlin extension methods and tools can speed up the development of Android.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published