Port manage/settings flows to Compose and wire settings persistence.
Add contract-driven state/action/event view models for manage and settings, migrate settings UI toward legacy preference rows (with anonymous stub behavior), and back SettingsServiceImpl with SharedPreferences for real toggle/city storage. Made-with: Cursor
This commit is contained in:
@@ -1,25 +1,55 @@
|
||||
package org.db3.airmq.sdk.settings
|
||||
|
||||
import android.content.Context
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
|
||||
class SettingsServiceImpl @Inject constructor() : SettingsService {
|
||||
override suspend fun getCity(): String? = throw NotImplementedError("getCity is not implemented yet")
|
||||
class SettingsServiceImpl @Inject constructor(
|
||||
@ApplicationContext context: Context
|
||||
) : SettingsService {
|
||||
private val sharedPreferences =
|
||||
context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE)
|
||||
|
||||
override suspend fun setCity(city: String?): Result<Unit> = throw NotImplementedError("setCity is not implemented yet")
|
||||
override suspend fun getCity(): String? = sharedPreferences.getString(KEY_CITY, DEFAULT_CITY)
|
||||
|
||||
override suspend fun getOfflineDevicesVisible(): Boolean = false
|
||||
override suspend fun setCity(city: String?): Result<Unit> = runCatching {
|
||||
sharedPreferences.edit().putString(KEY_CITY, city ?: DEFAULT_CITY).apply()
|
||||
}
|
||||
|
||||
override suspend fun getOfflineDevicesVisible(): Boolean =
|
||||
sharedPreferences.getBoolean(KEY_OFFLINE_DEVICES, DEFAULT_OFFLINE_DEVICES)
|
||||
|
||||
override suspend fun setOfflineDevicesVisible(visible: Boolean): Result<Unit> =
|
||||
throw NotImplementedError("setOfflineDevicesVisible is not implemented yet")
|
||||
runCatching {
|
||||
sharedPreferences.edit().putBoolean(KEY_OFFLINE_DEVICES, visible).apply()
|
||||
}
|
||||
|
||||
override suspend fun getAdvancedEnabled(): Boolean = throw NotImplementedError("getAdvancedEnabled is not implemented yet")
|
||||
override suspend fun getAdvancedEnabled(): Boolean =
|
||||
sharedPreferences.getBoolean(KEY_SHOW_ADVANCED, DEFAULT_SHOW_ADVANCED)
|
||||
|
||||
override suspend fun setAdvancedEnabled(enabled: Boolean): Result<Unit> =
|
||||
throw NotImplementedError("setAdvancedEnabled is not implemented yet")
|
||||
runCatching {
|
||||
sharedPreferences.edit().putBoolean(KEY_SHOW_ADVANCED, enabled).apply()
|
||||
}
|
||||
|
||||
override suspend fun getDeviceStatusNotificationsEnabled(): Boolean =
|
||||
throw NotImplementedError("getDeviceStatusNotificationsEnabled is not implemented yet")
|
||||
sharedPreferences.getBoolean(KEY_DEVICE_STATUS_NOTIFICATIONS, DEFAULT_DEVICE_STATUS_NOTIFICATIONS)
|
||||
|
||||
override suspend fun setDeviceStatusNotificationsEnabled(enabled: Boolean): Result<Unit> =
|
||||
throw NotImplementedError("setDeviceStatusNotificationsEnabled is not implemented yet")
|
||||
runCatching {
|
||||
sharedPreferences.edit().putBoolean(KEY_DEVICE_STATUS_NOTIFICATIONS, enabled).apply()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private const val PREFERENCES_NAME = "airmq_settings"
|
||||
private const val KEY_CITY = "dashboard_city"
|
||||
private const val KEY_OFFLINE_DEVICES = "offline_devices"
|
||||
private const val KEY_SHOW_ADVANCED = "show_advanced"
|
||||
private const val KEY_DEVICE_STATUS_NOTIFICATIONS = "device_status"
|
||||
|
||||
private const val DEFAULT_CITY = "Minsk"
|
||||
private const val DEFAULT_OFFLINE_DEVICES = false
|
||||
private const val DEFAULT_SHOW_ADVANCED = false
|
||||
private const val DEFAULT_DEVICE_STATUS_NOTIFICATIONS = true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user