-
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
b1urrrr
committed
Aug 15, 2024
1 parent
6ac47a7
commit 2dd57c7
Showing
5 changed files
with
106 additions
and
77 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
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/el/yello/presentation/splash/SplashViewModel.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,13 +1,44 @@ | ||
package com.el.yello.presentation.splash | ||
|
||
import androidx.lifecycle.ViewModel | ||
import com.el.yello.BuildConfig.VERSION_NAME | ||
import com.example.domain.repository.AuthRepository | ||
import com.example.ui.state.UiState | ||
import com.google.firebase.database.DatabaseReference | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SplashViewModel @Inject constructor( | ||
private val authRepository: AuthRepository, | ||
private val firebaseDatabase: DatabaseReference, | ||
) : ViewModel() { | ||
private val _isLatestVersion = MutableStateFlow<UiState<Boolean>>(UiState.Empty) | ||
val isLatestVersion get() = _isLatestVersion.asStateFlow() | ||
|
||
init { | ||
checkLatestUpdate() | ||
} | ||
|
||
fun getIsAutoLogin(): Boolean = authRepository.getAutoLogin() | ||
|
||
fun checkLatestUpdate() { | ||
firebaseDatabase.child(PATH_REALTIME_VERSION).get() | ||
.addOnSuccessListener { snapshot -> | ||
val updateVersion = snapshot.value.toString().toFloat() | ||
val currentVersion = VERSION_NAME.toFloat() | ||
|
||
val isLatestVersion = currentVersion < updateVersion | ||
_isLatestVersion.value = UiState.Success(isLatestVersion) | ||
} | ||
.addOnFailureListener { e -> | ||
_isLatestVersion.value = UiState.Failure(e.toString()) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val PATH_REALTIME_VERSION = "version" | ||
} | ||
} |
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