-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create ViewModelProvider to abstract the UI from the factory impl
- Loading branch information
1 parent
fab650e
commit d2a2b73
Showing
7 changed files
with
75 additions
and
48 deletions.
There are no files selected for viewing
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
25 changes: 13 additions & 12 deletions
25
...c/androidTest/java/com/joaquimley/transporteta/ui/di/module/TestFavoriteFragmentModule.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,20 +1,21 @@ | ||
package com.joaquimley.transporteta.ui.di.module | ||
|
||
import com.joaquimley.transporteta.presentation.home.favorite.FavoritesViewModelFactory | ||
import com.joaquimley.transporteta.presentation.home.favorite.FavoritesViewModelFactoryImpl | ||
import dagger.Module | ||
import dagger.Provides | ||
import org.mockito.Mockito.mock | ||
|
||
@Module | ||
class TestFavoriteFragmentModule { | ||
|
||
companion object { | ||
@JvmStatic val favoritesViewModelsFactory = mock(FavoritesViewModelFactory::class.java) | ||
} | ||
|
||
@Provides | ||
fun provideFavoritesViewModelFactory(): FavoritesViewModelFactory { | ||
return favoritesViewModelsFactory | ||
} | ||
// companion object { | ||
// @JvmStatic val favoritesViewModelProvider = mock(FavoritesViewModelProvider::class.java) | ||
// } | ||
// | ||
// @Provides | ||
// fun provideFavoritesViewModelProvider(favoritesViewModelFactory: FavoritesViewModelFactory): FavoritesViewModelProvider { | ||
// return FavoritesViewModelProvider(favoritesViewModelFactory) | ||
// } | ||
// | ||
// @Provides | ||
// fun provideSmsController(): SmsController { | ||
// return mock(SmsController::class.java) | ||
// } | ||
} |
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
26 changes: 26 additions & 0 deletions
26
.../src/main/java/com/joaquimley/transporteta/ui/home/favorite/FavoritesViewModelProvider.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,26 @@ | ||
package com.joaquimley.transporteta.ui.home.favorite | ||
|
||
import android.arch.lifecycle.ViewModelProviders | ||
import android.support.v4.app.Fragment | ||
import android.support.v7.app.AppCompatActivity | ||
import com.joaquimley.transporteta.presentation.home.favorite.FavoritesViewModel | ||
import com.joaquimley.transporteta.presentation.home.favorite.FavoritesViewModelFactory | ||
|
||
class FavoritesViewModelProvider(private val viewModelFactory: FavoritesViewModelFactory) { | ||
|
||
operator fun invoke(fragment: Fragment): FavoritesViewModel { | ||
return provide(fragment) | ||
} | ||
|
||
operator fun invoke(activity: AppCompatActivity): FavoritesViewModel { | ||
return provide(activity) | ||
} | ||
|
||
private fun provide(fragment: Fragment): FavoritesViewModel { | ||
return ViewModelProviders.of(fragment, viewModelFactory).get(FavoritesViewModel::class.java) | ||
} | ||
|
||
private fun provide(activity: AppCompatActivity): FavoritesViewModel { | ||
return ViewModelProviders.of(activity, viewModelFactory).get(FavoritesViewModel::class.java) | ||
} | ||
} |