-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ViewModel into presenter to reduce method count a litte bit. ;)
- Loading branch information
Showing
11 changed files
with
84 additions
and
33 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/github/iamwee/kotlinmvpstructure/base/BaseViewModel.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.github.iamwee.kotlinmvpstructure.base | ||
|
||
/** | ||
* Created by zeon on 9/11/2017 AD. | ||
*/ | ||
open class BaseViewModel { | ||
} |
13 changes: 12 additions & 1 deletion
13
app/src/main/java/com/github/iamwee/kotlinmvpstructure/base/presenter/BasePresenter.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
package com.github.iamwee.kotlinmvpstructure.base.presenter | ||
|
||
|
||
import kotlin.properties.Delegates | ||
|
||
/** | ||
* Created by zeon on 8/24/2017 AD. | ||
*/ | ||
|
||
open class BasePresenter<out REPOSITORY : MvpRepository, out VIEW : IBaseView>(val repository: REPOSITORY, val view: VIEW) | ||
@Suppress("LeakingThis") | ||
abstract class BasePresenter<out View : IBaseView<ViewModel>, ViewModel : Any>(val view: View) { | ||
|
||
var viewModel by Delegates.observable(onCreateViewModel(), { _, _, newViewModel -> | ||
view.onViewModelChanged(newViewModel) | ||
}) | ||
|
||
abstract fun onCreateViewModel(): ViewModel | ||
} |
6 changes: 5 additions & 1 deletion
6
app/src/main/java/com/github/iamwee/kotlinmvpstructure/base/presenter/IBaseView.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package com.github.iamwee.kotlinmvpstructure.base.presenter | ||
|
||
|
||
/** | ||
* Created by zeon on 8/24/2017 AD. | ||
*/ | ||
|
||
interface IBaseView | ||
interface IBaseView<in ViewModel: Any> { | ||
|
||
fun onViewModelChanged(viewModel: ViewModel) | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
7 changes: 1 addition & 6 deletions
7
app/src/main/java/com/github/iamwee/kotlinmvpstructure/view/main/presenter/IMainView.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
package com.github.iamwee.kotlinmvpstructure.view.main.presenter | ||
|
||
import com.github.iamwee.kotlinmvpstructure.base.presenter.IBaseView | ||
import com.github.iamwee.kotlinmvpstructure.http.entity.RepositoryEntity | ||
|
||
/** | ||
* Created by zeon on 8/24/2017 AD. | ||
*/ | ||
|
||
interface IMainView : IBaseView { | ||
|
||
fun onRepoSuccess(entities: List<RepositoryEntity>) | ||
|
||
} | ||
interface IMainView<in ViewModel: Any> : IBaseView<ViewModel> |
This file contains 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
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/github/iamwee/kotlinmvpstructure/view/main/presenter/MainViewModel.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.iamwee.kotlinmvpstructure.view.main.presenter | ||
|
||
|
||
import com.github.iamwee.kotlinmvpstructure.http.entity.RepositoryEntity | ||
|
||
/** | ||
* Created by zeon on 9/11/2017 AD. | ||
*/ | ||
|
||
data class MainViewModel(var loading: Boolean = false, | ||
var repositoryEntities: List<RepositoryEntity> = listOf(), | ||
var error: String? = null | ||
) |
This file contains 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