IT |
気になる、記になる… |
正式発表を前に「Samsung Galaxy Z Fold 4」がAmazonに掲載される − Sペンを収納可能な専用ケースの存在も明らかに |
https://taisy0.com/2022/08/06/159862.html
|
galaxy |
2022-08-06 00:24:34 |
IT |
ITmedia 総合記事一覧 |
[ITmedia News] AIが評価するお絵描きゲーム 判定は「アートっぽいけど、何なのか見当つかない」 高得点を狙うには? |
https://www.itmedia.co.jp/news/articles/2208/06/news010.html
|
guesstheline |
2022-08-06 09:30:00 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
AtCoder Problems | ABC261 A.Intersection |
https://qiita.com/61xxx/items/5556eae1d01dc6bb9ac0
|
yintinputltyltif |
2022-08-06 09:49:43 |
Docker |
dockerタグが付けられた新着投稿 - Qiita |
【Docker】secretsについて |
https://qiita.com/P-man_Brown/items/daa1d6d0dee7e16b2135
|
awesome |
2022-08-06 09:22:24 |
Docker |
dockerタグが付けられた新着投稿 - Qiita |
PlayFrameworkアプリをDocker化する |
https://qiita.com/kijuky/items/a54e94b293e08ff3b839
|
docker |
2022-08-06 09:13:39 |
Azure |
Azureタグが付けられた新着投稿 - Qiita |
パブリックプレビューの Azure Container Registry 「専用エージェントプールで ACR タスクを実行する」を試してみた |
https://qiita.com/mnrst/items/d58346a967fc2134261e
|
azurecontainerregistry |
2022-08-06 09:23:33 |
Git |
Gitタグが付けられた新着投稿 - Qiita |
Subversion, Git, Perforceの比較 |
https://qiita.com/taqu/items/d3befe15aac49a459624
|
perforce |
2022-08-06 09:30:41 |
海外TECH |
DEV Community |
Convert View Model to Use Hilt Dependency Injection |
https://dev.to/vtsen/convert-view-model-to-use-hilt-dependency-injection-1mb3
|
Convert View Model to Use Hilt Dependency InjectionHere are the steps I did and my key learnings to convert my Android News app to use hilt dependency injectionThis article was originally published at vtsen hashnode dev on July So I followed the steps in How to Implement Hilt in Android App article to convert the Android News app to use Hilt Dependency Injection The difference in previous article is it doesn t cover the View Model dependency injection Add Dependencies and HiltAndroidAppThe initial setup steps are exactly the same as the following Setup Hilt DependenciesAdd HiltAndroidApp in your application class Add HiltViewModel and Inject ConstructorIn order for Hilt to create MainViewModel you need to annotate the class with HiltViewModel Inject constructor is also used to tell Hilt how the dependencies can be created HiltViewModelclass MainViewModel Inject constructor private val repository ArticlesRepository ViewModel I also use Inject Constructor on the SqlArticlesRepository class SqlArticlesRepository Inject constructor private val database ArticlesDatabase private val webService WebService ArticlesRepository Add Provides and BindsTo create the dependencies we use either Provides and Binds Provides is used to create ArticlesDatabase and WebService instances Module InstallIn SingletonComponent class object DatabaseModule Provides Singleton fun provideDatabase ApplicationContext appContext Context ArticlesDatabase return Room databaseBuilder appContext ArticlesDatabase class java articles db fallbackToDestructiveMigration build Module InstallIn SingletonComponent class object WebServiceModule Provides Singleton fun provideWebService WebService return WebService Binds is used to create the implementation of ArticlesRepository interface Module InstallIn SingletonComponent class abstract class RepositoryModule Binds Singleton abstract fun bindArticlesRepository impl SqlArticlesRepository ArticlesRepository Call hiltViewModel ComposableNow it is done All manual creations below in MainActivity can be removed private val repository by lazy SqlArticlesRepository ArticlesDatabase getInstance application WebService private val homeViewModel by viewModels lt MainViewModel gt MainViewModelFactory repository The MainViewModel creation can be done by calling the hiltViewModel composable function which generates all the necessary dependencies For example replace this MainScreen composable functionMainScreen homeViewModel useSystemUIController true withMainScreen viewModel hiltViewModel useSystemUIController true The database creation below can also be removed since it has been provided by hilt Provides above companion object Volatile private lateinit var instance ArticlesDatabase fun getInstance context Context ArticlesDatabase synchronized this if instance isInitialized instance Room databaseBuilder context applicationContext ArticlesDatabase class java articles db fallbackToDestructiveMigration build return instance This MainViewModelFactory can also be removed since this has been taken care by HiltViewModel Suppress UNCHECKED CAST class MainViewModelFactory private val repository ArticlesRepository ViewModelProvider NewInstanceFactory override fun lt T ViewModel gt create modelClass Class lt T gt T if modelClass isAssignableFrom MainViewModel class java return MainViewModel repository as T throw IllegalArgumentException Unknown ViewModel class ConclusionAll my installed Hilt modules are in SingletonComponent scope If I change my installed module to another component for example ViewModelComponent or ActivityComponent it fails to compile and I don t know how to fix it I guess that is my next step to play around with this Hilt Yes I still don t like Hilt Call me grand pa I still prefer manual dependency inject like this one Recommended Ways To Create ViewModel or AndroidViewModel Source CodeGitHub Repository Android News Hilt branch Branch Diff Master vs Hilt See AlsoAndroid Development Tips and Tricks |
2022-08-06 00:24:50 |
海外ニュース |
Japan Times latest articles |
Japan to roll out COVID vaccine that targets omicron as early as October |
https://www.japantimes.co.jp/news/2022/08/06/national/japan-coronavirus-omicron-vaccine/
|
Japan to roll out COVID vaccine that targets omicron as early as OctoberThe new vaccine is under development and was found to increase neutralizing antibodies against the BA subvariant and were also effective for the BA subtype |
2022-08-06 09:31:58 |
北海道 |
北海道新聞 |
侵攻さなか、核廃絶訴え 被爆77年、広島平和式典 |
https://www.hokkaido-np.co.jp/article/714882/
|
原爆の日 |
2022-08-06 09:17:53 |
北海道 |
北海道新聞 |
中国軍、戦力向上を誇示 台湾周辺での演習3日目 |
https://www.hokkaido-np.co.jp/article/714862/
|
中国人民解放軍 |
2022-08-06 09:17:53 |
北海道 |
北海道新聞 |
コンサドーレ、韓国1部FW・金健熙を獲得 代表経験あり |
https://www.hokkaido-np.co.jp/article/714839/
|
韓国代表 |
2022-08-06 09:31:01 |
北海道 |
北海道新聞 |
幼稚園児殺傷の容疑者死亡 逃走中に事故、中国江西省 |
https://www.hokkaido-np.co.jp/article/714896/
|
逃走 |
2022-08-06 09:28:00 |
北海道 |
北海道新聞 |
ポケモンGOフェスト、札幌で開幕 国内2度目 中島公園にぎわう |
https://www.hokkaido-np.co.jp/article/714786/
|
中島公園 |
2022-08-06 09:27:14 |
北海道 |
北海道新聞 |
田中はフル出場 サッカーのドイツ2部 |
https://www.hokkaido-np.co.jp/article/714879/
|
田中碧 |
2022-08-06 09:01:00 |
ニュース |
Newsweek |
「普通の父親」になれなかった僕が、妻と娘と生きていくために受け入れた役回り |
https://www.newsweekjapan.jp/stories/culture/2022/08/post-99251.php
|
|
2022-08-06 09:30:00 |
コメント
コメントを投稿