/kapt_viewmodel

use kapt to automatic generate ViewModel class to enhance develop more efficient

Primary LanguageKotlin

kapt_viewmodel

use kapt to automatic generate ViewModel class to enhance develop more efficient

we can add Method or Class Annotation on Retrofit Service Interface to automatic generate your ViewModelClass whitch contains LiveData Property And getXXXApi or PostXXXApi method, the demo library support three types annotation to support different request code types

the generated code is like(you can modify to generate code according to your bussiness logic):


package com.xxx.xxx.architecture.xxx

import android.app.Application
import android.arch.lifecycle.MediatorLiveData
import com.baseproject.architecture.BaseViewModel
import com.xxx.xxx.appbase.BaseAppLiveDataObserver

/**
 * This file is generated by kapt, please do not edit this file */
open class BaseAnchorServiceViewModel(application: Application) : BaseViewModel<AnchorService>(application) {
    val getHotAnchorListLiveData: MediatorLiveData<kotlin.collections.List<SearchHotAnchorModel>> by lazy { MediatorLiveData<kotlin.collections.List<SearchHotAnchorModel>>() }

    fun getHotAnchorList() {
        mService.getHotAnchorList().subscribe(BaseAppLiveDataObserver(getHotAnchorListLiveData))
    }
}


    val getUserAssetsLiveData: MediatorLiveData<UserAssetsModel> by lazy { MediatorLiveData<UserAssetsModel>() }

    fun getUserAssets() {
        object : BaseAppNetworkBoundResource<UserAssetsModel>(getUserAssetsLiveData) {
        override fun doApiCall(): Observable<UserAssetsModel> {
        return mService.getUserAssets()}}
    }
    
    val postRewardReceiveLiveData: MediatorLiveData<PostRewardReceiveModel> by lazy { MediatorLiveData<PostRewardReceiveModel>() }

    fun postRewardReceive(reward_ids: List<Int>, anchor_id: String) {
        val params = BaseJSONObject().put("reward_ids",reward_ids).put("anchor_id",anchor_id)
        mService.postRewardReceive(RequestBody.create(MediaType.parse("application/json"), params.toString())).subscribe(BaseAppLiveDataObserver(postRewardReceiveLiveData))
    }
    
    ```