Skip to content

Commit

Permalink
Improve the concept
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur3486 committed Jul 16, 2020
1 parent f6f56ff commit a081014
Show file tree
Hide file tree
Showing 33 changed files with 396 additions and 353 deletions.
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ dependencies {
implementation project(":imageloading")
implementation project(":imageloading-glide")

implementation "com.arthurivanets.mvvm:mvvm-core:1.5.0"
implementation "com.arthurivanets.mvvm:mvvm-navigation:1.5.0"
implementation "com.arthurivanets.mvvm:mvvm-navigation-dagger:1.5.0"
implementation project(":mvvm")
implementation project(":mvvm-navigation")
implementation project(":mvvm-navigation-dagger")
// implementation "com.arthurivanets.mvvm:mvvm-core:1.5.0"
// implementation "com.arthurivanets.mvvm:mvvm-navigation:1.5.0"
// implementation "com.arthurivanets.mvvm:mvvm-navigation-dagger:1.5.0"

testImplementation unitTestingDependencies
androidTestImplementation instrumentationTestingDependencies
Expand Down
Binary file removed app/release/app-release.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package com.arthurivanets.sample.ui.base

import com.arthurivanets.mvvm.events.ViewState
import com.arthurivanets.mvvm.markers.ViewState

sealed class GeneralViewStates<T>(payload : T? = null) : ViewState<T>(payload) {
sealed class GeneralViewStates<T>(val payload : T? = null) : ViewState {

class Idle<T>(payload : T? = null) : GeneralViewStates<T>(payload)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

package com.arthurivanets.sample.ui.base

import com.arthurivanets.mvvm.events.Route
import com.arthurivanets.mvvm.markers.Route
import com.arthurivanets.sample.domain.entities.Character
import com.arthurivanets.sample.domain.entities.Comics
import com.arthurivanets.sample.domain.entities.Event

sealed class MarvelRoutes<T>(payload : T? = null) : Route<T>(payload) {
sealed class MarvelRoutes : Route {

class CharacterInfoScreen(character : Character) : MarvelRoutes<Character>(character)
class CharacterInfoScreen(val character : Character) : MarvelRoutes()

class ComicsInfoScreen(comics : Comics) : MarvelRoutes<Comics>(comics)
class ComicsInfoScreen(val comics : Comics) : MarvelRoutes()

class EventInfoScreen(event : Event) : MarvelRoutes<Event>(event)
class EventInfoScreen(val event : Event) : MarvelRoutes()

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import com.arthurivanets.adapster.ktx.isEmpty
import com.arthurivanets.adapster.listeners.DatasetChangeListenerAdapter
import com.arthurivanets.commons.ktx.getColorCompat
import com.arthurivanets.commons.ktx.statusBarSize
import com.arthurivanets.mvvm.events.Route
import com.arthurivanets.mvvm.events.ViewState
import com.arthurivanets.mvvm.markers.Route
import com.arthurivanets.mvvm.markers.ViewState
import com.arthurivanets.sample.R
import com.arthurivanets.sample.adapters.comics.ComicsItem
import com.arthurivanets.sample.adapters.comics.ComicsItemResources
Expand Down Expand Up @@ -164,12 +164,12 @@ class CharacterInfoFragment : BaseMvvmFragment<FragmentCharacterInfoBinding, Cha
}


override fun onViewStateChanged(state : ViewState<*>) {
override fun onViewStateChanged(state : ViewState) {
when(state) {
is GeneralViewStates.Idle -> onIdleState()
is GeneralViewStates.Loading -> onLoadingState()
is GeneralViewStates.Success -> onSuccessState()
is GeneralViewStates.Error -> onErrorState()
is GeneralViewStates.Idle<*> -> onIdleState()
is GeneralViewStates.Loading<*> -> onLoadingState()
is GeneralViewStates.Success<*> -> onSuccessState()
is GeneralViewStates.Error<*> -> onErrorState()
}
}

Expand All @@ -194,9 +194,9 @@ class CharacterInfoFragment : BaseMvvmFragment<FragmentCharacterInfoBinding, Cha
}


override fun onRoute(route : Route<*>) {
override fun onRoute(route : Route) {
when(route) {
is MarvelRoutes.ComicsInfoScreen -> route.payload?.let(::onOpenComicsInfoScreen)
is MarvelRoutes.ComicsInfoScreen -> onOpenComicsInfoScreen(route.comics)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CharacterInfoViewModel(

isDataLoading = true

changeViewState(GeneralViewStates.Loading<Unit>())
viewState = GeneralViewStates.Loading<Unit>()

charactersRepository.getCharacterComics(
character = character,
Expand All @@ -103,7 +103,7 @@ class CharacterInfoViewModel(
private fun onComicsLoadedSuccessfully(comics : List<Comics>) {
isDataLoading = false

changeViewState(GeneralViewStates.Success<Unit>())
viewState = GeneralViewStates.Success<Unit>()

comics.forEach { comicsItems.addOrUpdate(SmallComicsItem(it)) }
}
Expand All @@ -112,7 +112,7 @@ class CharacterInfoViewModel(
private fun onComicsLoadingFailed(throwable : Throwable) {
isDataLoading = false

changeViewState(GeneralViewStates.Error<Unit>())
viewState = GeneralViewStates.Error<Unit>()

// TODO the proper error handling should be done here
throwable.printStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import androidx.core.view.isVisible
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.arthurivanets.mvvm.events.Route
import com.arthurivanets.mvvm.events.ViewState
import com.arthurivanets.mvvm.markers.Route
import com.arthurivanets.mvvm.markers.ViewState
import com.arthurivanets.sample.R
import com.arthurivanets.sample.adapters.characters.CharacterItem
import com.arthurivanets.sample.adapters.characters.CharacterItemResources
Expand Down Expand Up @@ -90,12 +90,12 @@ class CharactersFragment : BaseMvvmFragment<FragmentCharactersBinding, Character
}


override fun onViewStateChanged(state : ViewState<*>) {
override fun onViewStateChanged(state : ViewState) {
when(state) {
is GeneralViewStates.Idle -> onIdleState()
is GeneralViewStates.Loading -> onLoadingState()
is GeneralViewStates.Success -> onSuccessState()
is GeneralViewStates.Error -> onErrorState()
is GeneralViewStates.Idle<*> -> onIdleState()
is GeneralViewStates.Loading<*> -> onLoadingState()
is GeneralViewStates.Success<*> -> onSuccessState()
is GeneralViewStates.Error<*> -> onErrorState()
}
}

Expand All @@ -120,9 +120,9 @@ class CharactersFragment : BaseMvvmFragment<FragmentCharactersBinding, Character
}


override fun onRoute(route : Route<*>) {
override fun onRoute(route : Route) {
when(route) {
is MarvelRoutes.CharacterInfoScreen -> route.payload?.let(::onOpenCharacterInfoScreen)
is MarvelRoutes.CharacterInfoScreen -> onOpenCharacterInfoScreen(route.character)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CharactersViewModel(

isDataLoading = true

changeViewState(GeneralViewStates.Loading<Unit>())
viewState = GeneralViewStates.Loading<Unit>()

charactersRepository.getCharacters(0, DEFAULT_CHARACTER_LOADING_LIMIT)
.resultOrError()
Expand All @@ -78,7 +78,7 @@ class CharactersViewModel(
private fun onLoadedSuccessfully(characters : List<Character>) {
isDataLoading = false

changeViewState(GeneralViewStates.Success<Unit>())
viewState = GeneralViewStates.Success<Unit>()

characters.forEach { items.addOrUpdate(CharacterItem(it)) }
}
Expand All @@ -87,7 +87,7 @@ class CharactersViewModel(
private fun onLoadingFailed(throwable : Throwable) {
isDataLoading = false

changeViewState(GeneralViewStates.Error<Unit>())
viewState = GeneralViewStates.Error<Unit>()

// TODO the proper error handling should be done here
throwable.printStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import com.arthurivanets.adapster.ktx.isEmpty
import com.arthurivanets.adapster.listeners.DatasetChangeListenerAdapter
import com.arthurivanets.commons.ktx.getColorCompat
import com.arthurivanets.commons.ktx.statusBarSize
import com.arthurivanets.mvvm.events.Route
import com.arthurivanets.mvvm.events.ViewState
import com.arthurivanets.mvvm.markers.Route
import com.arthurivanets.mvvm.markers.ViewState
import com.arthurivanets.sample.R
import com.arthurivanets.sample.adapters.characters.CharacterItem
import com.arthurivanets.sample.adapters.characters.CharacterItemResources
Expand Down Expand Up @@ -164,12 +164,12 @@ class ComicsInfoFragment : BaseMvvmFragment<FragmentComicsInfoBinding, ComicsInf
}


override fun onViewStateChanged(state : ViewState<*>) {
override fun onViewStateChanged(state : ViewState) {
when(state) {
is GeneralViewStates.Idle -> onIdleState()
is GeneralViewStates.Loading -> onLoadingState()
is GeneralViewStates.Success -> onSuccessState()
is GeneralViewStates.Error -> onErrorState()
is GeneralViewStates.Idle<*> -> onIdleState()
is GeneralViewStates.Loading<*> -> onLoadingState()
is GeneralViewStates.Success<*> -> onSuccessState()
is GeneralViewStates.Error<*> -> onErrorState()
}
}

Expand All @@ -194,9 +194,9 @@ class ComicsInfoFragment : BaseMvvmFragment<FragmentComicsInfoBinding, ComicsInf
}


override fun onRoute(route : Route<*>) {
override fun onRoute(route : Route) {
when(route) {
is MarvelRoutes.CharacterInfoScreen -> route.payload?.let(::onOpenCharacterInfoScreen)
is MarvelRoutes.CharacterInfoScreen -> onOpenCharacterInfoScreen(route.character)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ComicsInfoViewModel(

isDataLoading = true

changeViewState(GeneralViewStates.Loading<Unit>())
viewState = GeneralViewStates.Loading<Unit>()

comicsRepository.getComicsCharacters(
comics = comics,
Expand All @@ -103,7 +103,7 @@ class ComicsInfoViewModel(
private fun onCharactersLoadedSuccessfully(characters : List<Character>) {
isDataLoading = false

changeViewState(GeneralViewStates.Success<Unit>())
viewState = GeneralViewStates.Success<Unit>()

characters.forEach { characterItems.addOrUpdate(SmallCharacterItem(it)) }
}
Expand All @@ -112,7 +112,7 @@ class ComicsInfoViewModel(
private fun onCharacterLoadingFailed(throwable : Throwable) {
isDataLoading = false

changeViewState(GeneralViewStates.Error<Unit>())
viewState = GeneralViewStates.Error<Unit>()

// TODO the proper error handling should be done here
throwable.printStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import androidx.core.view.isVisible
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.arthurivanets.mvvm.events.Route
import com.arthurivanets.mvvm.events.ViewState
import com.arthurivanets.mvvm.markers.Route
import com.arthurivanets.mvvm.markers.ViewState
import com.arthurivanets.sample.R
import com.arthurivanets.sample.adapters.comics.ComicsItem
import com.arthurivanets.sample.adapters.comics.ComicsItemResources
Expand Down Expand Up @@ -90,12 +90,12 @@ class ComicsFragment : BaseMvvmFragment<FragmentComicsBinding, ComicsViewModel>(
}


override fun onViewStateChanged(state : ViewState<*>) {
override fun onViewStateChanged(state : ViewState) {
when(state) {
is GeneralViewStates.Idle -> onIdleState()
is GeneralViewStates.Loading -> onLoadingState()
is GeneralViewStates.Success -> onSuccessState()
is GeneralViewStates.Error -> onErrorState()
is GeneralViewStates.Idle<*> -> onIdleState()
is GeneralViewStates.Loading<*> -> onLoadingState()
is GeneralViewStates.Success<*> -> onSuccessState()
is GeneralViewStates.Error<*> -> onErrorState()
}
}

Expand All @@ -120,9 +120,9 @@ class ComicsFragment : BaseMvvmFragment<FragmentComicsBinding, ComicsViewModel>(
}


override fun onRoute(route : Route<*>) {
override fun onRoute(route : Route) {
when(route) {
is MarvelRoutes.ComicsInfoScreen -> route.payload?.let(::onOpenComicsInfoScreen)
is MarvelRoutes.ComicsInfoScreen -> onOpenComicsInfoScreen(route.comics)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ComicsViewModel(

isDataLoading = true

changeViewState(GeneralViewStates.Loading<Unit>())
viewState = GeneralViewStates.Loading<Unit>()

comicsRepository.getComics(0, DEFAULT_COMICS_LOADING_LIMIT)
.resultOrError()
Expand All @@ -78,7 +78,7 @@ class ComicsViewModel(
private fun onLoadedSuccessfully(comics : List<Comics>) {
isDataLoading = false

changeViewState(GeneralViewStates.Success<Unit>())
viewState = GeneralViewStates.Success<Unit>()

comics.forEach { items.addOrUpdate(ComicsItem(it)) }
}
Expand All @@ -87,7 +87,7 @@ class ComicsViewModel(
private fun onLoadingFailed(throwable : Throwable) {
isDataLoading = false

changeViewState(GeneralViewStates.Error<Unit>())
viewState = GeneralViewStates.Error<Unit>()

// TODO the proper error handling should be done here
throwable.printStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import com.arthurivanets.adapster.listeners.DatasetChangeListenerAdapter
import com.arthurivanets.commons.ktx.getColorCompat
import com.arthurivanets.commons.ktx.statusBarSize
import com.arthurivanets.commons.ktx.updateLayoutParams
import com.arthurivanets.mvvm.events.Route
import com.arthurivanets.mvvm.events.ViewState
import com.arthurivanets.mvvm.markers.Route
import com.arthurivanets.mvvm.markers.ViewState
import com.arthurivanets.sample.R
import com.arthurivanets.sample.adapters.characters.CharacterItem
import com.arthurivanets.sample.adapters.characters.CharacterItemResources
Expand Down Expand Up @@ -210,12 +210,12 @@ class EventInfoFragment : BaseMvvmFragment<FragmentEventInfoBinding, EventInfoVi
}


override fun onViewStateChanged(state : ViewState<*>) {
override fun onViewStateChanged(state : ViewState) {
when(state) {
is GeneralViewStates.Idle -> onIdleState()
is GeneralViewStates.Loading -> onLoadingState()
is GeneralViewStates.Success -> onSuccessState()
is GeneralViewStates.Error -> onErrorState()
is GeneralViewStates.Idle<*> -> onIdleState()
is GeneralViewStates.Loading<*> -> onLoadingState()
is GeneralViewStates.Success<*> -> onSuccessState()
is GeneralViewStates.Error<*> -> onErrorState()
}
}

Expand All @@ -240,10 +240,10 @@ class EventInfoFragment : BaseMvvmFragment<FragmentEventInfoBinding, EventInfoVi
}


override fun onRoute(route : Route<*>) {
override fun onRoute(route : Route) {
when(route) {
is MarvelRoutes.ComicsInfoScreen -> route.payload?.let(::onOpenComicsInfoScreen)
is MarvelRoutes.CharacterInfoScreen -> route.payload?.let(::onOpenCharacterInfoScreen)
is MarvelRoutes.ComicsInfoScreen -> onOpenComicsInfoScreen(route.comics)
is MarvelRoutes.CharacterInfoScreen -> onOpenCharacterInfoScreen(route.character)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class EventInfoViewModel(

isDataLoading = true

changeViewState(GeneralViewStates.Loading<Unit>())
viewState = GeneralViewStates.Loading<Unit>()

Single.zip(
eventsRepository.getEventComics(
Expand All @@ -122,7 +122,7 @@ class EventInfoViewModel(
private fun onDataLoadedSuccessfully(data : Pair<List<Comics>, List<Character>>) {
isDataLoading = false

changeViewState(GeneralViewStates.Success<Unit>())
viewState = GeneralViewStates.Success<Unit>()

data.first.forEach { comicsItems.addOrUpdate(SmallComicsItem(it)) }
data.second.forEach { characterItems.addOrUpdate(SmallCharacterItem(it)) }
Expand All @@ -132,7 +132,7 @@ class EventInfoViewModel(
private fun onDataLoadingFailed(throwable : Throwable) {
isDataLoading = false

changeViewState(GeneralViewStates.Error<Unit>())
viewState = GeneralViewStates.Error<Unit>()

// TODO the proper error handling should be done here
throwable.printStackTrace()
Expand Down
Loading

0 comments on commit a081014

Please sign in to comment.