ktlint: Newline expected before expression body

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2023-12-05 16:26:33 +01:00
parent 627e9d5c20
commit 88970c59a5
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
7 changed files with 236 additions and 201 deletions

View File

@ -95,10 +95,11 @@ data class MessageResultItem constructor(
const val VIEW_TYPE = FlexibleItemViewType.MESSAGE_RESULT_ITEM const val VIEW_TYPE = FlexibleItemViewType.MESSAGE_RESULT_ITEM
} }
override fun getHeader(): GenericTextHeaderItem = MessagesTextHeaderItem(context, viewThemeUtils) override fun getHeader(): GenericTextHeaderItem =
.apply { MessagesTextHeaderItem(context, viewThemeUtils)
isHidden = showHeader // FlexibleAdapter needs this hack for some reason .apply {
} isHidden = showHeader // FlexibleAdapter needs this hack for some reason
}
override fun setHeader(header: GenericTextHeaderItem?) { override fun setHeader(header: GenericTextHeaderItem?) {
// nothing, header is always the same // nothing, header is always the same

View File

@ -1714,14 +1714,17 @@ class ChatActivity :
} }
} }
fun isOneToOneConversation() = currentConversation != null && currentConversation?.type != null && fun isOneToOneConversation() =
currentConversation?.type == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL currentConversation != null && currentConversation?.type != null &&
currentConversation?.type == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL
private fun isGroupConversation() = currentConversation != null && currentConversation?.type != null && private fun isGroupConversation() =
currentConversation?.type == ConversationType.ROOM_GROUP_CALL currentConversation != null && currentConversation?.type != null &&
currentConversation?.type == ConversationType.ROOM_GROUP_CALL
private fun isPublicConversation() = currentConversation != null && currentConversation?.type != null && private fun isPublicConversation() =
currentConversation?.type == ConversationType.ROOM_PUBLIC_CALL currentConversation != null && currentConversation?.type != null &&
currentConversation?.type == ConversationType.ROOM_PUBLIC_CALL
private fun switchToRoom(token: String, startCallAfterRoomSwitch: Boolean, isVoiceOnlyCall: Boolean) { private fun switchToRoom(token: String, startCallAfterRoomSwitch: Boolean, isVoiceOnlyCall: Boolean) {
if (conversationUser != null) { if (conversationUser != null) {

View File

@ -335,41 +335,42 @@ class LocationPickerActivity :
) )
} }
private fun delayedMapListener() = DelayedMapListener( private fun delayedMapListener() =
object : MapListener { DelayedMapListener(
@Suppress("Detekt.TooGenericExceptionCaught") object : MapListener {
override fun onScroll(paramScrollEvent: ScrollEvent): Boolean { @Suppress("Detekt.TooGenericExceptionCaught")
try { override fun onScroll(paramScrollEvent: ScrollEvent): Boolean {
when { try {
moveToCurrentLocation -> { when {
setLocationDescription(isGpsLocation = true, isGeocodedResult = false) moveToCurrentLocation -> {
moveToCurrentLocation = false setLocationDescription(isGpsLocation = true, isGeocodedResult = false)
} moveToCurrentLocation = false
}
geocodingResult != null -> { geocodingResult != null -> {
binding.shareLocation.isClickable = true binding.shareLocation.isClickable = true
setLocationDescription(isGpsLocation = false, isGeocodedResult = true) setLocationDescription(isGpsLocation = false, isGeocodedResult = true)
geocodingResult = null geocodingResult = null
} }
else -> { else -> {
binding.shareLocation.isClickable = true binding.shareLocation.isClickable = true
setLocationDescription(isGpsLocation = false, isGeocodedResult = false) setLocationDescription(isGpsLocation = false, isGeocodedResult = false)
}
} }
} catch (e: NullPointerException) {
Log.d(TAG, "UI already closed")
} }
} catch (e: NullPointerException) {
Log.d(TAG, "UI already closed") readyToShareLocation = true
return true
} }
readyToShareLocation = true override fun onZoom(event: ZoomEvent): Boolean {
return true return false
}
} }
)
override fun onZoom(event: ZoomEvent): Boolean {
return false
}
}
)
@Suppress("Detekt.TooGenericExceptionCaught") @Suppress("Detekt.TooGenericExceptionCaught")
private fun requestLocationUpdates() { private fun requestLocationUpdates() {

View File

@ -374,11 +374,12 @@ data class ChatMessage(
return "" return ""
} }
private fun getNullsafeActorDisplayName() = if (!TextUtils.isEmpty(actorDisplayName)) { private fun getNullsafeActorDisplayName() =
actorDisplayName if (!TextUtils.isEmpty(actorDisplayName)) {
} else { actorDisplayName
sharedApplication!!.getString(R.string.nc_guest) } else {
} sharedApplication!!.getString(R.string.nc_guest)
}
override fun getUser(): IUser { override fun getUser(): IUser {
return object : IUser { return object : IUser {

View File

@ -98,10 +98,11 @@ class SharedItemsViewModel @Inject constructor(
}) })
} }
private fun chooseInitialType(newTypes: Set<SharedItemType>): SharedItemType = when { private fun chooseInitialType(newTypes: Set<SharedItemType>): SharedItemType =
newTypes.contains(SharedItemType.MEDIA) -> SharedItemType.MEDIA when {
else -> newTypes.toList().first() newTypes.contains(SharedItemType.MEDIA) -> SharedItemType.MEDIA
} else -> newTypes.toList().first()
}
fun initialLoadItems(type: SharedItemType) { fun initialLoadItems(type: SharedItemType) {
val state = _viewState.value val state = _viewState.value

View File

@ -46,13 +46,14 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
}.getCompleted() }.getCompleted()
} }
override fun setProxyType(proxyType: String?) = runBlocking<Unit> { override fun setProxyType(proxyType: String?) =
async { runBlocking<Unit> {
if (proxyType != null) { async {
writeString(PROXY_TYPE, proxyType) if (proxyType != null) {
writeString(PROXY_TYPE, proxyType)
}
} }
} }
}
override fun removeProxyType() { override fun removeProxyType() {
proxyType = "" proxyType = ""
@ -62,13 +63,14 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readString(PROXY_HOST).first() } }.getCompleted() return runBlocking { async { readString(PROXY_HOST).first() } }.getCompleted()
} }
override fun setProxyHost(proxyHost: String?) = runBlocking<Unit> { override fun setProxyHost(proxyHost: String?) =
async { runBlocking<Unit> {
if (proxyHost != null) { async {
writeString(PROXY_HOST, proxyHost) if (proxyHost != null) {
writeString(PROXY_HOST, proxyHost)
}
} }
} }
}
override fun removeProxyHost() { override fun removeProxyHost() {
proxyHost = "" proxyHost = ""
@ -78,13 +80,14 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readString(PROXY_PORT).first() } }.getCompleted() return runBlocking { async { readString(PROXY_PORT).first() } }.getCompleted()
} }
override fun setProxyPort(proxyPort: String?) = runBlocking<Unit> { override fun setProxyPort(proxyPort: String?) =
async { runBlocking<Unit> {
if (proxyPort != null) { async {
writeString(PROXY_PORT, proxyPort) if (proxyPort != null) {
writeString(PROXY_PORT, proxyPort)
}
} }
} }
}
override fun removeProxyPort() { override fun removeProxyPort() {
proxyPort = "" proxyPort = ""
@ -94,11 +97,12 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readBoolean(PROXY_CRED).first() } }.getCompleted() return runBlocking { async { readBoolean(PROXY_CRED).first() } }.getCompleted()
} }
override fun setProxyNeedsCredentials(proxyNeedsCredentials: Boolean) = runBlocking<Unit> { override fun setProxyNeedsCredentials(proxyNeedsCredentials: Boolean) =
async { runBlocking<Unit> {
writeBoolean(PROXY_CRED, proxyNeedsCredentials) async {
writeBoolean(PROXY_CRED, proxyNeedsCredentials)
}
} }
}
override fun removeProxyCredentials() { override fun removeProxyCredentials() {
setProxyNeedsCredentials(false) setProxyNeedsCredentials(false)
@ -108,13 +112,14 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readString(PROXY_USERNAME).first() } }.getCompleted() return runBlocking { async { readString(PROXY_USERNAME).first() } }.getCompleted()
} }
override fun setProxyUsername(proxyUsername: String?) = runBlocking<Unit> { override fun setProxyUsername(proxyUsername: String?) =
async { runBlocking<Unit> {
if (proxyUsername != null) { async {
writeString(PROXY_USERNAME, proxyUsername) if (proxyUsername != null) {
writeString(PROXY_USERNAME, proxyUsername)
}
} }
} }
}
override fun removeProxyUsername() { override fun removeProxyUsername() {
proxyUsername = "" proxyUsername = ""
@ -124,13 +129,14 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readString(PROXY_PASSWORD).first() } }.getCompleted() return runBlocking { async { readString(PROXY_PASSWORD).first() } }.getCompleted()
} }
override fun setProxyPassword(proxyPassword: String?) = runBlocking<Unit> { override fun setProxyPassword(proxyPassword: String?) =
async { runBlocking<Unit> {
if (proxyPassword != null) { async {
writeString(PROXY_PASSWORD, proxyPassword) if (proxyPassword != null) {
writeString(PROXY_PASSWORD, proxyPassword)
}
} }
} }
}
override fun removeProxyPassword() { override fun removeProxyPassword() {
proxyPassword = "" proxyPassword = ""
@ -140,13 +146,14 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readString(PUSH_TOKEN).first() } }.getCompleted() return runBlocking { async { readString(PUSH_TOKEN).first() } }.getCompleted()
} }
override fun setPushToken(pushToken: String?) = runBlocking<Unit> { override fun setPushToken(pushToken: String?) =
async { runBlocking<Unit> {
if (pushToken != null) { async {
writeString(PUSH_TOKEN, pushToken) if (pushToken != null) {
writeString(PUSH_TOKEN, pushToken)
}
} }
} }
}
override fun removePushToken() { override fun removePushToken() {
pushToken = "" pushToken = ""
@ -156,13 +163,14 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readString(TEMP_CLIENT_CERT_ALIAS).first() } }.getCompleted() return runBlocking { async { readString(TEMP_CLIENT_CERT_ALIAS).first() } }.getCompleted()
} }
override fun setTemporaryClientCertAlias(alias: String?) = runBlocking<Unit> { override fun setTemporaryClientCertAlias(alias: String?) =
async { runBlocking<Unit> {
if (alias != null) { async {
writeString(TEMP_CLIENT_CERT_ALIAS, alias) if (alias != null) {
writeString(TEMP_CLIENT_CERT_ALIAS, alias)
}
} }
} }
}
override fun removeTemporaryClientCertAlias() { override fun removeTemporaryClientCertAlias() {
temporaryClientCertAlias = "" temporaryClientCertAlias = ""
@ -172,11 +180,12 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readBoolean(PUSH_TO_TALK_INTRO_SHOWN).first() } }.getCompleted() return runBlocking { async { readBoolean(PUSH_TO_TALK_INTRO_SHOWN).first() } }.getCompleted()
} }
override fun setPushToTalkIntroShown(shown: Boolean) = runBlocking<Unit> { override fun setPushToTalkIntroShown(shown: Boolean) =
async { runBlocking<Unit> {
writeBoolean(PUSH_TO_TALK_INTRO_SHOWN, shown) async {
writeBoolean(PUSH_TO_TALK_INTRO_SHOWN, shown)
}
} }
}
override fun removePushToTalkIntroShown() { override fun removePushToTalkIntroShown() {
pushToTalkIntroShown = false pushToTalkIntroShown = false
@ -186,13 +195,14 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readString(CALL_RINGTONE).first() } }.getCompleted() return runBlocking { async { readString(CALL_RINGTONE).first() } }.getCompleted()
} }
override fun setCallRingtoneUri(value: String?) = runBlocking<Unit> { override fun setCallRingtoneUri(value: String?) =
async { runBlocking<Unit> {
if (value != null) { async {
writeString(CALL_RINGTONE, value) if (value != null) {
writeString(CALL_RINGTONE, value)
}
} }
} }
}
override fun removeCallRingtoneUri() { override fun removeCallRingtoneUri() {
callRingtoneUri = "" callRingtoneUri = ""
@ -202,13 +212,14 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readString(MESSAGE_RINGTONE).first() } }.getCompleted() return runBlocking { async { readString(MESSAGE_RINGTONE).first() } }.getCompleted()
} }
override fun setMessageRingtoneUri(value: String?) = runBlocking<Unit> { override fun setMessageRingtoneUri(value: String?) =
async { runBlocking<Unit> {
if (value != null) { async {
writeString(MESSAGE_RINGTONE, value) if (value != null) {
writeString(MESSAGE_RINGTONE, value)
}
} }
} }
}
override fun removeMessageRingtoneUri() { override fun removeMessageRingtoneUri() {
messageRingtoneUri = "" messageRingtoneUri = ""
@ -218,11 +229,12 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readBoolean(NOTIFY_UPGRADE_V2).first() } }.getCompleted() return runBlocking { async { readBoolean(NOTIFY_UPGRADE_V2).first() } }.getCompleted()
} }
override fun setNotificationChannelIsUpgradedToV2(value: Boolean) = runBlocking<Unit> { override fun setNotificationChannelIsUpgradedToV2(value: Boolean) =
async { runBlocking<Unit> {
writeBoolean(NOTIFY_UPGRADE_V2, value) async {
writeBoolean(NOTIFY_UPGRADE_V2, value)
}
} }
}
override fun removeNotificationChannelUpgradeToV2() { override fun removeNotificationChannelUpgradeToV2() {
setNotificationChannelIsUpgradedToV2(false) setNotificationChannelIsUpgradedToV2(false)
@ -232,11 +244,12 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readBoolean(NOTIFY_UPGRADE_V3).first() } }.getCompleted() return runBlocking { async { readBoolean(NOTIFY_UPGRADE_V3).first() } }.getCompleted()
} }
override fun setNotificationChannelIsUpgradedToV3(value: Boolean) = runBlocking<Unit> { override fun setNotificationChannelIsUpgradedToV3(value: Boolean) =
async { runBlocking<Unit> {
writeBoolean(NOTIFY_UPGRADE_V3, value) async {
writeBoolean(NOTIFY_UPGRADE_V3, value)
}
} }
}
override fun removeNotificationChannelUpgradeToV3() { override fun removeNotificationChannelUpgradeToV3() {
setNotificationChannelIsUpgradedToV3(false) setNotificationChannelIsUpgradedToV3(false)
@ -246,11 +259,12 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readBoolean(SCREEN_SECURITY).first() } }.getCompleted() return runBlocking { async { readBoolean(SCREEN_SECURITY).first() } }.getCompleted()
} }
override fun setScreenSecurity(value: Boolean) = runBlocking<Unit> { override fun setScreenSecurity(value: Boolean) =
async { runBlocking<Unit> {
writeBoolean(SCREEN_SECURITY, value) async {
writeBoolean(SCREEN_SECURITY, value)
}
} }
}
override fun removeScreenSecurity() { override fun removeScreenSecurity() {
setScreenSecurity(false) setScreenSecurity(false)
@ -260,11 +274,12 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readBoolean(SCREEN_LOCK).first() } }.getCompleted() return runBlocking { async { readBoolean(SCREEN_LOCK).first() } }.getCompleted()
} }
override fun setScreenLock(value: Boolean) = runBlocking<Unit> { override fun setScreenLock(value: Boolean) =
async { runBlocking<Unit> {
writeBoolean(SCREEN_LOCK, value) async {
writeBoolean(SCREEN_LOCK, value)
}
} }
}
override fun removeScreenLock() { override fun removeScreenLock() {
setScreenLock(false) setScreenLock(false)
@ -275,11 +290,12 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return read return read
} }
override fun setIncognitoKeyboard(value: Boolean) = runBlocking<Unit> { override fun setIncognitoKeyboard(value: Boolean) =
async { runBlocking<Unit> {
writeBoolean(INCOGNITO_KEYBOARD, value) async {
writeBoolean(INCOGNITO_KEYBOARD, value)
}
} }
}
override fun removeIncognitoKeyboard() { override fun removeIncognitoKeyboard() {
setIncognitoKeyboard(false) setIncognitoKeyboard(false)
@ -289,17 +305,19 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return runBlocking { async { readBoolean(PHONE_BOOK_INTEGRATION).first() } }.getCompleted() return runBlocking { async { readBoolean(PHONE_BOOK_INTEGRATION).first() } }.getCompleted()
} }
override fun setPhoneBookIntegration(value: Boolean) = runBlocking<Unit> { override fun setPhoneBookIntegration(value: Boolean) =
async { runBlocking<Unit> {
writeBoolean(PHONE_BOOK_INTEGRATION, value) async {
writeBoolean(PHONE_BOOK_INTEGRATION, value)
}
} }
}
override fun removeLinkPreviews() = runBlocking<Unit> { override fun removeLinkPreviews() =
async { runBlocking<Unit> {
writeBoolean(LINK_PREVIEWS, false) async {
writeBoolean(LINK_PREVIEWS, false)
}
} }
}
override fun getScreenLockTimeout(): String { override fun getScreenLockTimeout(): String {
val default = context.resources.getString(R.string.nc_screen_lock_timeout_sixty) val default = context.resources.getString(R.string.nc_screen_lock_timeout_sixty)
@ -307,13 +325,14 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return read.ifEmpty { default } return read.ifEmpty { default }
} }
override fun setScreenLockTimeout(value: String?) = runBlocking<Unit> { override fun setScreenLockTimeout(value: String?) =
async { runBlocking<Unit> {
if (value != null) { async {
writeString(SCREEN_LOCK_TIMEOUT, value) if (value != null) {
writeString(SCREEN_LOCK_TIMEOUT, value)
}
} }
} }
}
override fun removeScreenLockTimeout() { override fun removeScreenLockTimeout() {
screenLockTimeout = "" screenLockTimeout = ""
@ -326,14 +345,15 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return read.ifEmpty { default } return read.ifEmpty { default }
} }
override fun setTheme(value: String?) = runBlocking<Unit> { override fun setTheme(value: String?) =
async { runBlocking<Unit> {
if (value != null) { async {
val key = context.resources.getString(R.string.nc_settings_theme_key) if (value != null) {
writeString(key, value) val key = context.resources.getString(R.string.nc_settings_theme_key)
writeString(key, value)
}
} }
} }
}
override fun removeTheme() { override fun removeTheme() {
theme = "" theme = ""
@ -344,27 +364,30 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return read return read
} }
override fun setDbCypherToUpgrade(value: Boolean) = runBlocking<Unit> { override fun setDbCypherToUpgrade(value: Boolean) =
async { runBlocking<Unit> {
writeBoolean(DB_CYPHER_V4_UPGRADE, value) async {
writeBoolean(DB_CYPHER_V4_UPGRADE, value)
}
} }
}
override fun getIsDbRoomMigrated(): Boolean { override fun getIsDbRoomMigrated(): Boolean {
return runBlocking { async { readBoolean(DB_ROOM_MIGRATED).first() } }.getCompleted() return runBlocking { async { readBoolean(DB_ROOM_MIGRATED).first() } }.getCompleted()
} }
override fun setIsDbRoomMigrated(value: Boolean) = runBlocking<Unit> { override fun setIsDbRoomMigrated(value: Boolean) =
async { runBlocking<Unit> {
writeBoolean(DB_ROOM_MIGRATED, value) async {
writeBoolean(DB_ROOM_MIGRATED, value)
}
} }
}
override fun setPhoneBookIntegrationLastRun(currentTimeMillis: Long) = runBlocking<Unit> { override fun setPhoneBookIntegrationLastRun(currentTimeMillis: Long) =
async { runBlocking<Unit> {
writeLong(PHONE_BOOK_INTEGRATION_LAST_RUN, currentTimeMillis) async {
writeLong(PHONE_BOOK_INTEGRATION_LAST_RUN, currentTimeMillis)
}
} }
}
override fun getPhoneBookIntegrationLastRun(defaultValue: Long?): Long { override fun getPhoneBookIntegrationLastRun(defaultValue: Long?): Long {
val result = if (defaultValue != null) { val result = if (defaultValue != null) {
@ -376,36 +399,39 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return result return result
} }
override fun setReadPrivacy(value: Boolean) = runBlocking<Unit> { override fun setReadPrivacy(value: Boolean) =
val key = context.resources.getString(R.string.nc_settings_read_privacy_key) runBlocking<Unit> {
async { val key = context.resources.getString(R.string.nc_settings_read_privacy_key)
writeBoolean(key, value) async {
writeBoolean(key, value)
}
} }
}
override fun getReadPrivacy(): Boolean { override fun getReadPrivacy(): Boolean {
val key = context.resources.getString(R.string.nc_settings_read_privacy_key) val key = context.resources.getString(R.string.nc_settings_read_privacy_key)
return runBlocking { async { readBoolean(key).first() } }.getCompleted() return runBlocking { async { readBoolean(key).first() } }.getCompleted()
} }
override fun setTypingStatus(value: Boolean) = runBlocking<Unit> { override fun setTypingStatus(value: Boolean) =
async { runBlocking<Unit> {
writeBoolean(TYPING_STATUS, value) async {
writeBoolean(TYPING_STATUS, value)
}
} }
}
override fun getTypingStatus(): Boolean { override fun getTypingStatus(): Boolean {
return runBlocking { async { readBoolean(TYPING_STATUS).first() } }.getCompleted() return runBlocking { async { readBoolean(TYPING_STATUS).first() } }.getCompleted()
} }
override fun setSorting(value: String?) = runBlocking<Unit> { override fun setSorting(value: String?) =
val key = context.resources.getString(R.string.nc_file_browser_sort_by_key) runBlocking<Unit> {
async { val key = context.resources.getString(R.string.nc_file_browser_sort_by_key)
if (value != null) { async {
writeString(key, value) if (value != null) {
writeString(key, value)
}
} }
} }
}
override fun getSorting(): String { override fun getSorting(): String {
val key = context.resources.getString(R.string.nc_file_browser_sort_by_key) val key = context.resources.getString(R.string.nc_file_browser_sort_by_key)
@ -414,11 +440,12 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
return read.ifEmpty { default } return read.ifEmpty { default }
} }
override fun saveWaveFormForFile(filename: String, array: Array<Float>) = runBlocking<Unit> { override fun saveWaveFormForFile(filename: String, array: Array<Float>) =
async { runBlocking<Unit> {
writeString(filename, array.contentToString()) async {
writeString(filename, array.contentToString())
}
} }
}
override fun getWaveFormFromFile(filename: String): Array<Float> { override fun getWaveFormFromFile(filename: String): Array<Float> {
val string = runBlocking { async { readString(filename).first() } }.getCompleted() val string = runBlocking { async { readString(filename).first() } }.getCompleted()
@ -427,29 +454,32 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
override fun clear() {} override fun clear() {}
private suspend fun writeString(key: String, value: String) = context.dataStore.edit { settings -> private suspend fun writeString(key: String, value: String) =
settings[ context.dataStore.edit { settings ->
stringPreferencesKey( settings[
key stringPreferencesKey(
) key
] = value )
} ] = value
}
/** /**
* Returns a Flow of type String * Returns a Flow of type String
* @param key the key of the persisted data to be observed * @param key the key of the persisted data to be observed
*/ */
fun readString(key: String, defaultValue: String = ""): Flow<String> = context.dataStore.data.map { preferences -> fun readString(key: String, defaultValue: String = ""): Flow<String> =
preferences[stringPreferencesKey(key)] ?: defaultValue context.dataStore.data.map { preferences ->
} preferences[stringPreferencesKey(key)] ?: defaultValue
}
private suspend fun writeBoolean(key: String, value: Boolean) = context.dataStore.edit { settings -> private suspend fun writeBoolean(key: String, value: Boolean) =
settings[ context.dataStore.edit { settings ->
booleanPreferencesKey( settings[
key booleanPreferencesKey(
) key
] = value )
} ] = value
}
/** /**
* Returns a Flow of type Boolean * Returns a Flow of type Boolean
@ -460,17 +490,15 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
preferences[booleanPreferencesKey(key)] ?: defaultValue preferences[booleanPreferencesKey(key)] ?: defaultValue
} }
private suspend fun writeLong(key: String, value: Long) = context.dataStore.edit { settings -> private suspend fun writeLong(key: String, value: Long) =
settings[ context.dataStore.edit { settings ->
longPreferencesKey( settings[longPreferencesKey(key)] = value
key }
)
] = value
}
private fun readLong(key: String, defaultValue: Long = 0): Flow<Long> = context.dataStore.data.map { preferences -> private fun readLong(key: String, defaultValue: Long = 0): Flow<Long> =
preferences[longPreferencesKey(key)] ?: defaultValue context.dataStore.data.map { preferences ->
} preferences[longPreferencesKey(key)] ?: defaultValue
}
companion object { companion object {
@Suppress("UnusedPrivateProperty") @Suppress("UnusedPrivateProperty")

View File

@ -55,11 +55,11 @@ class SSLSocketFactoryCompat(
} }
} }
override fun getDefaultCipherSuites(): Array<String>? = cipherSuites override fun getDefaultCipherSuites(): Array<String>? =
?: delegate.defaultCipherSuites cipherSuites ?: delegate.defaultCipherSuites
override fun getSupportedCipherSuites(): Array<String>? = cipherSuites override fun getSupportedCipherSuites(): Array<String>? =
?: delegate.supportedCipherSuites cipherSuites ?: delegate.supportedCipherSuites
override fun createSocket(s: Socket, host: String, port: Int, autoClose: Boolean): Socket { override fun createSocket(s: Socket, host: String, port: Int, autoClose: Boolean): Socket {
val ssl = delegate.createSocket(s, host, port, autoClose) val ssl = delegate.createSocket(s, host, port, autoClose)