-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c051300
commit 7e208ff
Showing
5 changed files
with
155 additions
and
155 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
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
42 changes: 21 additions & 21 deletions
42
app/src/main/java/com/geekymusketeers/uncrack/viewModel/ViewModelFactory.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,21 +1,21 @@ | ||
package com.geekymusketeers.uncrack.viewModel | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.lifecycle.viewmodel.CreationExtras | ||
|
||
|
||
class ViewModelFactory : ViewModelProvider.Factory { | ||
@Suppress("UNCHECKED_CAST") | ||
override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T = | ||
with(modelClass) { | ||
// Get the Application object from extras | ||
val application = checkNotNull(extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY]) | ||
when { | ||
isAssignableFrom(KeyViewModel::class.java) -> { | ||
KeyViewModel(application) | ||
} | ||
else -> throw IllegalArgumentException("Unknown ViewModel class") | ||
} | ||
} as T | ||
} | ||
//package com.geekymusketeers.uncrack.viewModel | ||
// | ||
//import androidx.lifecycle.ViewModel | ||
//import androidx.lifecycle.ViewModelProvider | ||
//import androidx.lifecycle.viewmodel.CreationExtras | ||
// | ||
// | ||
//class ViewModelFactory : ViewModelProvider.Factory { | ||
// @Suppress("UNCHECKED_CAST") | ||
// override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T = | ||
// with(modelClass) { | ||
// // Get the Application object from extras | ||
// val application = checkNotNull(extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY]) | ||
// when { | ||
// isAssignableFrom(KeyViewModel::class.java) -> { | ||
// KeyViewModel(application) | ||
// } | ||
// else -> throw IllegalArgumentException("Unknown ViewModel class") | ||
// } | ||
// } as T | ||
//} |