[Android] 2.0.1 - Refactoring & Minor Optimizations
This commit is contained in:
@@ -40,7 +40,6 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
|
|
||||||
val isEnabled: Flow<Boolean> = _isEnabled.asStateFlow()
|
val isEnabled: Flow<Boolean> = _isEnabled.asStateFlow()
|
||||||
val hasPermissions: Flow<Boolean> = _hasPermissions.asStateFlow()
|
val hasPermissions: Flow<Boolean> = _hasPermissions.asStateFlow()
|
||||||
val autoSyncEnabled: Flow<Boolean> = _autoSync.asStateFlow()
|
|
||||||
val isCompatible: Flow<Boolean> = _isCompatible.asStateFlow()
|
val isCompatible: Flow<Boolean> = _isCompatible.asStateFlow()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -112,12 +111,6 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
_hasPermissions.value = granted
|
_hasPermissions.value = granted
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Enable or disable auto-sync */
|
|
||||||
fun setAutoSyncEnabled(enabled: Boolean) {
|
|
||||||
preferences.edit().putBoolean("auto_sync", enabled).apply()
|
|
||||||
_autoSync.value = enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Check if all required permissions are granted */
|
/** Check if all required permissions are granted */
|
||||||
suspend fun hasAllPermissions(): Boolean {
|
suspend fun hasAllPermissions(): Boolean {
|
||||||
return try {
|
return try {
|
||||||
@@ -163,7 +156,7 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
/** Get required permissions as strings */
|
/** Get required permissions as strings */
|
||||||
fun getRequiredPermissions(): Set<String> {
|
fun getRequiredPermissions(): Set<String> {
|
||||||
return try {
|
return try {
|
||||||
REQUIRED_PERMISSIONS.map { it.toString() }.toSet()
|
REQUIRED_PERMISSIONS.map { it }.toSet()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Error getting required permissions", e)
|
Log.e(TAG, "Error getting required permissions", e)
|
||||||
emptySet()
|
emptySet()
|
||||||
@@ -359,8 +352,4 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
return _isEnabled.value && _hasPermissions.value
|
return _isEnabled.value && _hasPermissions.value
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get last successful sync timestamp */
|
|
||||||
fun getLastSyncSuccess(): String? {
|
|
||||||
return preferences.getString("last_sync_success", null)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.serialization.encodeToString
|
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ fun AddEditGymScreen(gymId: String?, viewModel: ClimbViewModel, onNavigateBack:
|
|||||||
notes = notes
|
notes = notes
|
||||||
)
|
)
|
||||||
|
|
||||||
if (isEditing && gymId != null) {
|
if (isEditing) {
|
||||||
viewModel.updateGym(gym.copy(id = gymId))
|
viewModel.updateGym(gym.copy(id = gymId))
|
||||||
} else {
|
} else {
|
||||||
viewModel.addGym(gym)
|
viewModel.addGym(gym)
|
||||||
@@ -386,7 +386,7 @@ fun AddEditProblemScreen(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
problemId?.let { id ->
|
problemId.let { id ->
|
||||||
viewModel.updateProblem(problem.copy(id = id))
|
viewModel.updateProblem(problem.copy(id = id))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -762,7 +762,7 @@ fun AddEditSessionScreen(
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
sessionId?.let { id ->
|
sessionId.let { id ->
|
||||||
viewModel.updateSession(session.copy(id = id))
|
viewModel.updateSession(session.copy(id = id))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class ClimbViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun renameTemporaryImages(problem: Problem): Problem {
|
private fun renameTemporaryImages(problem: Problem): Problem {
|
||||||
if (problem.imagePaths.isEmpty()) {
|
if (problem.imagePaths.isEmpty()) {
|
||||||
return problem
|
return problem
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user