File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed
insets-systembar/src/main/kotlin/com/xiaocydx/insets/systembar Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -278,17 +278,16 @@ internal class WindowStateHolder(savaStateHandle: SavedStateHandle) : ViewModel(
278278 }
279279
280280 fun applyState (who : String ): WindowState ? {
281- val index = backStack.indexOf(who)
282281 val state = stateStore[who]
283282 state?.isApplied = true
284- return if (isLastApply(index )) state else null
283+ return if (isLastState(who )) state else null
285284 }
286285
287286 fun applyPrevState (who : String ): WindowState ? {
288- val index = backStack.indexOf(who)
289287 var prevState: WindowState ? = null
290- if (isLastApply(index)) {
291- val prevWho = backStack.getOrNull(index - 1 )
288+ if (isLastState(who)) {
289+ val prevIndex = backStack.lastIndex - 1
290+ val prevWho = backStack.getOrNull(prevIndex)
292291 if (prevWho != null ) prevState = stateStore[prevWho]
293292 }
294293 return prevState?.takeIf { it.isApplied }
@@ -304,8 +303,8 @@ internal class WindowStateHolder(savaStateHandle: SavedStateHandle) : ViewModel(
304303 check(! isStateSaved) { " SavedStateHandle已保存,不允许再修改" }
305304 }
306305
307- private fun isLastApply ( index : Int ): Boolean {
308- return index >= 0 && index == backStack.lastIndex
306+ private fun isLastState ( who : String ): Boolean {
307+ return backStack.lastOrNull() == who
309308 }
310309
311310 private companion object {
You can’t perform that action at this time.
0 commit comments