-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 增加 Activity 的利用 ViewModel 初始化一次的扩展功能
- Loading branch information
1 parent
83d9c8c
commit 5045450
Showing
4 changed files
with
21 additions
and
2 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
17 changes: 17 additions & 0 deletions
17
lib-ktx/src/main/java/com/xiaojinzi/support/ktx/Activities.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.xiaojinzi.support.ktx | ||
|
||
import androidx.activity.viewModels | ||
import androidx.fragment.app.FragmentActivity | ||
import androidx.lifecycle.ViewModel | ||
|
||
class InitOnceViewModel: ViewModel() { | ||
var isInit: Boolean = false | ||
} | ||
|
||
fun FragmentActivity.initOnceUseViewModel(action: () -> Unit) { | ||
val initViewModel: InitOnceViewModel by this.viewModels() | ||
if (!initViewModel.isInit) { | ||
initViewModel.isInit = true | ||
action.invoke() | ||
} | ||
} |