This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UserViewModel( | |
| private val userUseCase: ExampleUserUseCase | |
| ) : ViewModel() { | |
| private val userReceivedLiveData = MutableLiveData<Unit>() | |
| val userReceivedLiveData: LiveData<Unit> | |
| get() = userReceivedLiveData | |
| fun requestUser() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MainApplication : Application(), HasActivityInjector { | |
| @Inject | |
| lateinit var activityInjector: DispatchingAndroidInjector<Activity> | |
| override fun onCreate() { | |
| super.onCreate() | |
| DaggerApplicationComponent | |
| .builder() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UserRepository( | |
| private val userRemoteRepository: UserRemoteRepository, | |
| private val userLocalRepository: UserLocalRepository | |
| ) : UserRepository { | |
| override fun getLocalUser(): Single<User> { | |
| return userLocalRepository.getUser() | |
| } | |
| override fun getRemoteUser(): Single<User> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UserViewModel @Inject constructor( | |
| savedStateHandle: SavedStateHandle, | |
| userRepository: UserRepository | |
| ) : ViewModel() { | |
| val userId : String = savedStateHandle["uid"] ?: | |
| throw IllegalArgumentException("missing user id") | |
| val user : LiveData<User> = userRepository.getUser(userId) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface ExampleUserRepository { | |
| fun getUser( | |
| id: Int, | |
| name: String, | |
| age: Int, | |
| phone: String? = null | |
| ): Single<User> | |
| fun getUser(id: Int): Single<User> | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface Webservice { | |
| /** | |
| * @GET declares GET request | |
| * @Path("user") annotation, then userId parameter specified | |
| * Uses Retrofit library | |
| */ | |
| @GET("/users/{user}") | |
| fun getUser(@Path("user") userId: String): Single<User> | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ExampleUserUseCase(private val repository: ExampleUserRepository) { | |
| sealed class Result { | |
| object InProgess | |
| data class OnSuccess(val users: List<ExampleUser>) : Result() | |
| data class OnError(val error: Throwable) : Result() | |
| } | |
| fun execute() { | |
| repository.getExampleUserList() | |
| .map(mapper::map) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface ExampleUserRepository { | |
| fun getExampleUserList( | |
| id: Int, | |
| name: String, | |
| age: Int, | |
| phone: String? = null | |
| ): Single<List<ExampleUser>> | |
| fun getUser(id: Int): Flowable<ExampleUser> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.os.Parcelable | |
| import kotlinx.android.parcel.Parcelize | |
| @Parcelize | |
| data class ExampleUser( | |
| val id: Long, | |
| val name: String, | |
| val age: Int, | |
| val phone: String? = null | |
| ) : Parcelable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ExampleFragment : BaseFragment() { | |
| val exampleJobDao: ExampleJobDao by inject() | |
| ... | |
| } |