compose: details: Specify key for hiltViewModel
This ensures that hilt doesn't reuses ViewModel for another app with another one. Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -95,7 +95,7 @@ fun AppDetailsScreen(
|
|||||||
packageName: String,
|
packageName: String,
|
||||||
onNavigateUp: () -> Unit,
|
onNavigateUp: () -> Unit,
|
||||||
onNavigateToAppDetails: (packageName: String) -> Unit,
|
onNavigateToAppDetails: (packageName: String) -> Unit,
|
||||||
viewModel: AppDetailsViewModel = hiltViewModel()
|
viewModel: AppDetailsViewModel = hiltViewModel(key = packageName)
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
|||||||
@@ -146,10 +146,6 @@ class AppDetailsViewModel @Inject constructor(
|
|||||||
fun fetchAppDetails(packageName: String) {
|
fun fetchAppDetails(packageName: String) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
// Reset current details to show latest ones
|
|
||||||
_app.value = App("")
|
|
||||||
_suggestions.value = emptyList()
|
|
||||||
|
|
||||||
_app.value = appDetailsHelper.getAppByPackageName(packageName).copy(
|
_app.value = appDetailsHelper.getAppByPackageName(packageName).copy(
|
||||||
isInstalled = PackageUtil.isInstalled(context, packageName)
|
isInstalled = PackageUtil.isInstalled(context, packageName)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user