CheckInCheckOutDataStore
This commit is contained in:
@@ -0,0 +1,86 @@
|
|||||||
|
package `in`.sminnovations.attendanceapp.screens.home.data
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.datastore.preferences.core.booleanPreferencesKey
|
||||||
|
import androidx.datastore.preferences.core.edit
|
||||||
|
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||||
|
import androidx.datastore.preferences.preferencesDataStore
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
private const val DATASTORE_NAME = "check_in_check_out_prefs"
|
||||||
|
private val Context.dataStore by preferencesDataStore(name = DATASTORE_NAME)
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class CheckInCheckOutDataStore @Inject constructor(@ApplicationContext context: Context) {
|
||||||
|
|
||||||
|
private val dataStore = context.dataStore
|
||||||
|
|
||||||
|
private val CHECK_IN_KEY = stringPreferencesKey("check_in_id")
|
||||||
|
private val CHECK_OUT_KEY = stringPreferencesKey("check_out_id")
|
||||||
|
private val CHECK_IN_Date = stringPreferencesKey("check_in_date_id")
|
||||||
|
private val IS_CHECK_IN = booleanPreferencesKey("is_checked_in_id")
|
||||||
|
private val IS_CHECK_OUT = booleanPreferencesKey("is_checked_in_id")
|
||||||
|
|
||||||
|
|
||||||
|
val checkInId: Flow<String> = dataStore.data.map { preferences ->
|
||||||
|
preferences[CHECK_IN_KEY] ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
val checkOutId: Flow<String> = dataStore.data.map { preferences ->
|
||||||
|
preferences[CHECK_OUT_KEY] ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
val checkInDate: Flow<String> = dataStore.data.map { preferences ->
|
||||||
|
preferences[CHECK_IN_Date] ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
val isCheckedIn : Flow<Boolean> = dataStore.data.map { preferences ->
|
||||||
|
preferences[IS_CHECK_IN] ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
val isCheckedOut : Flow<Boolean> = dataStore.data.map { preferences ->
|
||||||
|
preferences[IS_CHECK_OUT] ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun saveLoginData(checkIn: String, checkOut: String) {
|
||||||
|
dataStore.edit { preferences ->
|
||||||
|
preferences[CHECK_IN_KEY] = checkIn
|
||||||
|
preferences[CHECK_OUT_KEY] = checkOut
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun saveLoginDate(checkDate: String) {
|
||||||
|
dataStore.edit { preferences ->
|
||||||
|
preferences[CHECK_IN_Date] = checkDate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun saveIsLogIn(isCheckIn: Boolean) {
|
||||||
|
dataStore.edit { preferences ->
|
||||||
|
preferences[IS_CHECK_IN] = isCheckIn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun saveIsLogOut(isCheckOut: Boolean) {
|
||||||
|
dataStore.edit { preferences ->
|
||||||
|
preferences[IS_CHECK_OUT] = isCheckOut
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun clearLoginData() {
|
||||||
|
dataStore.edit { preferences ->
|
||||||
|
preferences.remove(CHECK_IN_Date)
|
||||||
|
preferences.remove(IS_CHECK_OUT)
|
||||||
|
preferences.remove(IS_CHECK_IN)
|
||||||
|
preferences.remove(CHECK_IN_KEY)
|
||||||
|
preferences.remove(CHECK_OUT_KEY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
package `in`.sminnovations.attendanceapp.screens.home.data
|
|
||||||
|
|
||||||
class EmployeeData
|
|
||||||
Reference in New Issue
Block a user