Skip to content

Latest commit

 

History

History

androidx-kt-arch

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

ANDROIDX-KT-ARCH

Platform Platform API License

Kotlin extension to Android Architecture related libraries

Getting Started

Add the following to your build.gradle file

implementation "me.panpf:androidx-kt-arch:$lastVersion"

Please replace $lastVersion with the latest version: Download

Dependencies:

  • org.jetbrains.kotlin:kotlin-stdlib-jdk7: 1.2.71
  • com.android.support:support-fragment: 28.0.0
  • android.arch.lifecycle:viewmodel: 1.1.1
  • android.arch.lifecycle:extensions: 1.1.1

Usage Guide

ViewModelBinder

Provide ViewModel binding capabilities as follows:

class TestActivity : FragmentActivity() {

    val viewModel: TestViewModel  by bindViewModel(TestViewModel::class)
}

Use ViewModelProvider.Factory:

class TestActivity : FragmentActivity() {

    val factoryViewModel: TestFactoryViewModel  by bindViewModel(TestFactoryViewModel::class, object : ViewModelProvider.Factory {
        override fun <T : ViewModel?> create(modelClass: Class<T>): T {
            return modelClass.getConstructor(String::class.java).newInstance("testFactoryViewModel")
        }
    })
}

See the test code for more examples.

Change Log

Please view the CHANGELOG.md file

License

Copyright (C) 2018 Peng fei Pan <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.