Skip to content

Commit

Permalink
Added Some data classes
Browse files Browse the repository at this point in the history
  • Loading branch information
revanthkumarJ committed Jan 11, 2025
1 parent af009a1 commit e837a6f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import com.russhwolf.settings.set
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import org.mifos.mobile.core.datastore.model.AppSettings
import org.mifos.mobile.core.datastore.model.AppTheme
import org.mifos.mobile.core.datastore.model.MifosAppLanguage
import org.mifos.mobile.core.datastore.model.User
import org.mifos.mobile.core.datastore.model.UserData

class PreferencesHelper(private val settings: Settings) {

Expand Down Expand Up @@ -96,7 +99,7 @@ class PreferencesHelper(private val settings: Settings) {
private val token: String?
get() = getString(TOKEN, "")

val isAuthenticated: Boolean
var isAuthenticated: Boolean = false
get() = !token.isNullOrEmpty()

var userId: Long?
Expand All @@ -105,7 +108,7 @@ class PreferencesHelper(private val settings: Settings) {
putLong(USER_ID, value)
}

var username: String?
var userName: String?
get() = getString(USER_NAME, "")
set(value) {
putString(USER_NAME, value)
Expand All @@ -129,12 +132,6 @@ class PreferencesHelper(private val settings: Settings) {
putLong(CLIENT_ID, value)
}

var userName: String?
get() = getString(USER_NAME, "")
set(value) {
putString(USER_NAME, value)
}

var clientName: String?
get() = getString(CLIENT_NAME, "")
set(value) {
Expand Down Expand Up @@ -201,6 +198,53 @@ class PreferencesHelper(private val settings: Settings) {
putBoolean(DEFAULT_SYSTEM_LANGUAGE, value)
}

fun getUserData(): UserData {
return UserData(
clientId = clientId,
userName = userName,
isAuthenticated = isAuthenticated

)
}

fun saveUserData(userData: UserData) {
clientId = userData.clientId
userName = userData.userName
isAuthenticated=userData.isAuthenticated
}

fun getUser(): User {
return User(
userId = userId,
userName = userName,
)
}

fun saveUser(user: User) {
userId = user.userId
userName = user.userName

}

fun getAppSettings(): AppSettings {
return AppSettings(
tenant = tenant,
baseUrl = baseUrl,
passcode = passcode,
appTheme = appTheme,
language = language
)
}

fun saveAppSettings(appSettings: AppSettings) {
putString(TENANT, appSettings.tenant)
putString(BASE_URL, appSettings.baseUrl)
putString(PASSCODE, appSettings.passcode)
putInt(APPLICATION_THEME, appSettings.appTheme)
putString(LANGUAGE_TYPE, appSettings.language)
}


companion object {
private const val USER_ID = "preferences_user_id"
private const val TOKEN = "preferences_token"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.mifos.mobile.core.datastore.model

data class AppSettings(
val tenant: String?,
val baseUrl: String?,
val passcode: String?,
val appTheme: Int?,
val language: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.mifos.mobile.core.datastore.model

data class User(
val userName: String?,
val userId: Long?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.mifos.mobile.core.datastore.model

data class UserData(
val isAuthenticated: Boolean,
val userName: String?,
val clientId: Long?,
)

0 comments on commit e837a6f

Please sign in to comment.