mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-10 06:42:05 +01:00
Minor cleanup
This commit is contained in:
@@ -35,7 +35,7 @@ interface ChapterRepository {
|
||||
|
||||
/* TODO add once ktorfit supports nullable paremters
|
||||
@FormUrlEncoded
|
||||
@PATCH("/api/v1/manga/{mangaId}/chapter/{chapterIndex}")
|
||||
@PATCH("api/v1/manga/{mangaId}/chapter/{chapterIndex}")
|
||||
fun updateChapter(
|
||||
@Path("mangaId") mangaId: Long,
|
||||
@Path("chapterIndex") chapterIndex: Int,
|
||||
|
||||
@@ -29,7 +29,9 @@ actual inline fun <reified VM : ViewModel> Screen.stateViewModel(
|
||||
val viewModelFactory = LocalViewModels.current
|
||||
val lifecycle = LocalLifecycleOwner.current as AndroidScreenLifecycleOwner
|
||||
val handle = remember {
|
||||
lifecycle.defaultViewModelCreationExtras.addScreenModelKey<VM>(this, tag).createSavedStateHandle()
|
||||
lifecycle.defaultViewModelCreationExtras
|
||||
.addScreenModelKey<VM>(this, tag)
|
||||
.createSavedStateHandle()
|
||||
}
|
||||
return rememberScreenModel(tag) { viewModelFactory.factory(handle) }
|
||||
}
|
||||
|
||||
@@ -25,11 +25,10 @@ import java.lang.reflect.Method
|
||||
|
||||
private const val SAVED_STATE_KEY = "androidx.lifecycle.internal.SavedStateHandlesProvider"
|
||||
|
||||
val SavedStateHandleSupportClass: Class<*> by lazy {
|
||||
Class.forName("androidx.lifecycle.SavedStateHandleSupport")
|
||||
}
|
||||
val getSavedStateHandlesVM: Method by lazy {
|
||||
SavedStateHandleSupportClass.methods.first { it.name == "getSavedStateHandlesVM" }
|
||||
Class.forName("androidx.lifecycle.SavedStateHandleSupport")
|
||||
.methods
|
||||
.first { it.name == "getSavedStateHandlesVM" }
|
||||
}
|
||||
|
||||
private fun createSavedStateHandle(
|
||||
@@ -43,7 +42,12 @@ private fun createSavedStateHandle(
|
||||
// for a given key stored in our ViewModel, use that. Otherwise, create
|
||||
// a new SavedStateHandle, providing it any restored state we might have saved
|
||||
val vm = getSavedStateHandlesVM.invoke(null, viewModelStoreOwner)!!
|
||||
val handles = vm::class.java.methods.first { it.name == "getHandles" }.invoke(vm) as MutableMap<String, SavedStateHandle>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val handles = vm::class.java
|
||||
.methods
|
||||
.first { it.name == "getHandles" }
|
||||
.invoke(vm) as MutableMap<String, SavedStateHandle>
|
||||
|
||||
return handles[key] ?: SavedStateHandle.createHandle(
|
||||
provider.consumeRestoredStateForKey(key),
|
||||
defaultArgs
|
||||
@@ -103,7 +107,8 @@ internal class SavedStateHandlesProvider(
|
||||
* Restore the state associated with a particular SavedStateHandle, identified by its [key]
|
||||
*/
|
||||
fun consumeRestoredStateForKey(key: String): Bundle? {
|
||||
return savedStateRegistry::class.java.methods
|
||||
return savedStateRegistry::class.java
|
||||
.methods
|
||||
.find { it.name == "consumeRestoredStateForKey" }
|
||||
?.invoke(savedStateRegistry, key) as? Bundle
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user