-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
3 changed files
with
45 additions
and
3 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
34 changes: 34 additions & 0 deletions
34
app/src/main/kotlin/dev/sanmer/github/artifacts/viewmodel/SettingViewModel.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,34 @@ | ||
package dev.sanmer.github.artifacts.viewmodel | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import dev.sanmer.github.artifacts.repository.DbRepository | ||
import kotlinx.coroutines.launch | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SettingViewModel @Inject constructor( | ||
private val dbRepository: DbRepository | ||
) : ViewModel() { | ||
var hasToken by mutableStateOf(false) | ||
private set | ||
|
||
init { | ||
Timber.d("SettingViewModel init") | ||
tokenObserver() | ||
} | ||
|
||
private fun tokenObserver() { | ||
viewModelScope.launch { | ||
dbRepository.tokenFlow | ||
.collect { tokens -> | ||
hasToken = tokens.isNotEmpty() | ||
} | ||
} | ||
} | ||
} |