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
| @AndroidEntryPoint | |
| class MessageActivity : AppCompatActivity() { | |
| @Inject | |
| lateinit var mInjectedFragment: MessageFragment | |
| } |
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
| @HiltAndroidApp | |
| class MessageApplication : Application() { } |
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
| apply plugin: 'kotlin-kapt' | |
| apply plugin: 'dagger.hilt.android.plugin' | |
| ... | |
| dependencies { | |
| ... | |
| implementation "com.google.dagger:hilt-android:2.28-alpha" | |
| implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha02' | |
| kapt "com.google.dagger:hilt-android-compiler:2.28-alpha" |
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 WeatherListFragment: Fragment() { | |
| fun onCreate() { | |
| val vm = DataViewModel(DependencyInjector.injectedRepository) | |
| } | |
| } | |
| class WeatherItemDetailsFragment: Fragment() { | |
| fun onCreate() { | |
| val vm = DataViewModel(DependencyInjector.injectedRepository) | |
| } |
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 WeatherListFragment: Fragment() { | |
| fun onCreate() { | |
| val vm = DataViewModel(DependencyInjector.injectedRepoistory) | |
| } | |
| } | |
| class WeatherItemDetailsFragment: Fragment() { | |
| fun onCreate() { | |
| val vm = DataViewModel(DependencyInjector.injectedRepoistory) | |
| } |
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 DataViewModel(val repository: WeatherRepository) | |
| class WeatherRepository(val localClient: LocalDataClient, | |
| val inMemoryClient: InMemoryDataClient, | |
| val remoteClient: RemoteDataClient) | |
| class LocalDataClient(val localDatabase: LocalDatabase) | |
| class InMemoryDataClient(val memoryCache: MemoryCache) | |
| class RemoteDataClient(val retrofit: RetrofitClient) |
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 WeatherListFragment: Fragment() { | |
| fun onCreate() { | |
| val repo = WeatherRepository(LocalDataClient(LocalDataBase()), | |
| InMemoryDataClient(MemoryCache()), | |
| RemoteDataClient(RetrofitCLient())) | |
| val vm = DataViewModel(repo) | |
| } | |
| } | |
| class WeatherItemDetailsFragment: Fragment() { |
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 DataViewModelTest { | |
| @Mock | |
| lateinit var mockedDataSource: DataSource // Our mocked dependency | |
| lateinit var dataViewModel: DataViewModel | |
| @Before | |
| fun setup() { | |
| dataViewModel = DataViewModel(mockedDataSource) // This will now work! |
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 DataViewModelTest { | |
| lateinit var dataViewModel: DataViewModel | |
| @Mock | |
| lateinit var dataManager: DataSource | |
| @Before | |
| fun setup() { | |
| MockitoAnnotations.initMocks(this) | |
| loyaltyClient = LoyaltyClient(userLoyaltyRestClient, userSessionManager) |
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 DataSource { | |
| fun getCachedData(): String | |
| } | |
| class LocalDataClient: DataSource { | |
| private val jsonFile = resources.getFile(JSON_FILE_TAG) | |
| override fun getCachedData() = jsonFile.toString() | |
| } |