From 68366b3d09bfa3cb486cf22644e755c83a62395b Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 19:27:00 +0100 Subject: [PATCH 01/12] convert rxjava to coroutine - favourite conversation Signed-off-by: sowjanyakch --- .../com/nextcloud/talk/api/NcApiCoroutines.kt | 6 ++ .../dialog/ConversationsListBottomDialog.kt | 55 ++++++++----------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index f47978d99a..d5eb41f601 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -119,6 +119,12 @@ interface NcApiCoroutines { @DELETE suspend fun unarchiveConversation(@Header("Authorization") authorization: String, @Url url: String): GenericOverall + @POST + suspend fun addConversationToFavorites( + @Header("Authorization") authorization: String, + @Url url: String + ): GenericOverall + @POST suspend fun setReadStatusPrivacy( @Header("Authorization") authorization: String, diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt index 9dbd718413..232d5bf4a0 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt @@ -11,6 +11,7 @@ import android.os.Bundle import android.text.TextUtils import android.view.View import android.view.ViewGroup +import androidx.lifecycle.lifecycleScope import androidx.work.Data import androidx.work.OneTimeWorkRequest import androidx.work.WorkInfo @@ -21,6 +22,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog import com.nextcloud.talk.R import com.nextcloud.talk.activities.MainActivity import com.nextcloud.talk.api.NcApi +import com.nextcloud.talk.api.NcApiCoroutines import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.conversation.RenameConversationDialogFragment import com.nextcloud.talk.conversationlist.ConversationsListActivity @@ -42,6 +44,9 @@ import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) @@ -56,6 +61,9 @@ class ConversationsListBottomDialog( @Inject lateinit var ncApi: NcApi + @Inject + lateinit var ncApiCoroutines: NcApiCoroutines + @Inject lateinit var viewThemeUtils: ViewThemeUtils @@ -195,42 +203,27 @@ class ConversationsListBottomDialog( private fun addConversationToFavorites() { val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) - ncApi.addConversationToFavorites( - credentials, - ApiUtils.getUrlForRoomFavorite( - apiVersion, - currentUser.baseUrl!!, - conversation.token - ) - ) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .retry(1) - .subscribe(object : Observer { - override fun onSubscribe(d: Disposable) { - // unused atm + val url = ApiUtils.getUrlForRoomFavorite(apiVersion, currentUser.baseUrl!!, conversation.token) + lifecycleScope.launch { + try { + withContext(Dispatchers.IO) { + ncApiCoroutines.addConversationToFavorites(credentials, url) } - - override fun onNext(genericOverall: GenericOverall) { - activity.fetchRooms() - activity.showSnackbar( - String.format( - context.resources.getString(R.string.added_to_favorites), - conversation.displayName - ) + activity.fetchRooms() + activity.showSnackbar( + String.format( + context.resources.getString(R.string.added_to_favorites), + conversation.displayName ) - dismiss() - } - - override fun onError(e: Throwable) { + ) + dismiss() + } catch (e: Exception) { + withContext(Dispatchers.Main) { activity.showSnackbar(context.resources.getString(R.string.nc_common_error_sorry)) dismiss() } - - override fun onComplete() { - // unused atm - } - }) + } + } } private fun removeConversationFromFavorites() { From e9d2a866a72284ecd565eedda9735c656bea544d Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 19:29:09 +0100 Subject: [PATCH 02/12] remove unused endpoint Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index b0f5199fb0..5faa996de8 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -373,10 +373,6 @@ Observable getMentionAutocompleteSuggestions(@Header("Authorizat @Nullable @Query("limit") Integer limit, @QueryMap Map fields); - // Url is: /api/{apiVersion}/room/{token}/pin - @POST - Observable addConversationToFavorites(@Header("Authorization") String authorization, - @Url String url); // Url is: /api/{apiVersion}/room/{token}/favorites @DELETE From 9ba07f575fed1919c4d8861a39195360780ee56b Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 19:45:19 +0100 Subject: [PATCH 03/12] convert rxjava to coroutine - unfavourite conversation Signed-off-by: sowjanyakch --- .../com/nextcloud/talk/api/NcApiCoroutines.kt | 6 +++ .../dialog/ConversationsListBottomDialog.kt | 53 ++++++++----------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index d5eb41f601..ff464b48f8 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -125,6 +125,12 @@ interface NcApiCoroutines { @Url url: String ): GenericOverall + @DELETE + suspend fun removeConversationFromFavorites( + @Header("Authorization") authorization: String, + @Url url: String + ): GenericOverall + @POST suspend fun setReadStatusPrivacy( @Header("Authorization") authorization: String, diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt index 232d5bf4a0..9b4f009ee1 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt @@ -6,6 +6,7 @@ */ package com.nextcloud.talk.ui.dialog +import android.annotation.SuppressLint import android.content.Intent import android.os.Bundle import android.text.TextUtils @@ -201,6 +202,7 @@ class ConversationsListBottomDialog( } } + @SuppressLint("StringFormatInvalid") private fun addConversationToFavorites() { val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) val url = ApiUtils.getUrlForRoomFavorite(apiVersion, currentUser.baseUrl!!, conversation.token) @@ -226,44 +228,30 @@ class ConversationsListBottomDialog( } } + @SuppressLint("StringFormatInvalid") private fun removeConversationFromFavorites() { val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) - ncApi.removeConversationFromFavorites( - credentials, - ApiUtils.getUrlForRoomFavorite( - apiVersion, - currentUser.baseUrl!!, - conversation.token - ) - ) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .retry(1) - .subscribe(object : Observer { - override fun onSubscribe(d: Disposable) { - // unused atm + val url = ApiUtils.getUrlForRoomFavorite(apiVersion, currentUser.baseUrl!!, conversation.token) + lifecycleScope.launch { + try { + withContext(Dispatchers.IO) { + ncApiCoroutines.removeConversationFromFavorites(credentials, url) } - - override fun onNext(genericOverall: GenericOverall) { - activity.fetchRooms() - activity.showSnackbar( - String.format( - context.resources.getString(R.string.removed_from_favorites), - conversation.displayName - ) + activity.fetchRooms() + activity.showSnackbar( + String.format( + context.resources.getString(R.string.removed_from_favorites), + conversation.displayName ) - dismiss() - } - - override fun onError(e: Throwable) { + ) + dismiss() + } catch (e: Exception) { + withContext(Dispatchers.Main) { activity.showSnackbar(context.resources.getString(R.string.nc_common_error_sorry)) dismiss() } - - override fun onComplete() { - // unused atm - } - }) + } + } } private fun markConversationAsUnread() { @@ -283,6 +271,7 @@ class ConversationsListBottomDialog( // unused atm } + @SuppressLint("StringFormatInvalid") override fun onNext(genericOverall: GenericOverall) { activity.fetchRooms() activity.showSnackbar( @@ -329,6 +318,7 @@ class ConversationsListBottomDialog( // unused atm } + @SuppressLint("StringFormatInvalid") override fun onNext(genericOverall: GenericOverall) { activity.fetchRooms() activity.showSnackbar( @@ -365,6 +355,7 @@ class ConversationsListBottomDialog( } } + @SuppressLint("StringFormatInvalid") private fun leaveConversation() { val dataBuilder = Data.Builder() dataBuilder.putString(KEY_ROOM_TOKEN, conversation.token) From 75d1c548ab41921ecee3a696aa3a10c20f988a6b Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 19:47:31 +0100 Subject: [PATCH 04/12] remove unused endpoints Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 5faa996de8..2307ce7019 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -309,6 +309,12 @@ Observable registerDeviceForNotificationsWithPushProxy(@Url String url, Observable unregisterDeviceForNotificationsWithProxy(@Url String url, @QueryMap Map fields); + @FormUrlEncoded + @PUT + Observable> setPassword2(@Header("Authorization") String authorization, + @Url String url, + @Field("password") String password); + @GET Observable getCapabilities(@Header("Authorization") String authorization, @Url String url); @@ -373,12 +379,6 @@ Observable getMentionAutocompleteSuggestions(@Header("Authorizat @Nullable @Query("limit") Integer limit, @QueryMap Map fields); - - // Url is: /api/{apiVersion}/room/{token}/favorites - @DELETE - Observable removeConversationFromFavorites(@Header("Authorization") String authorization, - @Url String url); - @GET Observable getNcNotification(@Header("Authorization") String authorization, @Url String url); From 9e8a5476f97e5691e14647da69b047bee745f4a4 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 20:06:25 +0100 Subject: [PATCH 05/12] Rename .java to .kt Signed-off-by: sowjanyakch --- .../{DatabaseStorageModule.java => DatabaseStorageModule.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/{DatabaseStorageModule.java => DatabaseStorageModule.kt} (100%) diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt similarity index 100% rename from app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java rename to app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt From 77b55dcd9bcd0e5c4c35cb236dbf3212612c8a85 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Fri, 15 Nov 2024 20:06:25 +0100 Subject: [PATCH 06/12] convert java code to kotlin - DatabaseStorageModule Signed-off-by: sowjanyakch --- .../DatabaseStorageModule.kt | 348 +++++++++--------- 1 file changed, 175 insertions(+), 173 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt index 77f8079817..76efd36cb4 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt @@ -6,237 +6,239 @@ * SPDX-FileCopyrightText: 2017-2018 Mario Danic * SPDX-License-Identifier: GPL-3.0-or-later */ -package com.nextcloud.talk.utils.preferences.preferencestorage; - -import android.text.TextUtils; -import android.util.Log; - -import com.nextcloud.talk.api.NcApi; -import com.nextcloud.talk.application.NextcloudTalkApplication; -import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager; -import com.nextcloud.talk.data.storage.model.ArbitraryStorage; -import com.nextcloud.talk.data.user.model.User; -import com.nextcloud.talk.models.json.generic.GenericOverall; -import com.nextcloud.talk.utils.ApiUtils; -import com.nextcloud.talk.utils.SpreedFeatures; -import com.nextcloud.talk.utils.UserIdUtils; -import com.nextcloud.talk.utils.CapabilitiesUtil; - -import javax.inject.Inject; - -import autodagger.AutoInjector; -import io.reactivex.Observer; -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.annotations.NonNull; -import io.reactivex.disposables.Disposable; -import io.reactivex.schedulers.Schedulers; - -@AutoInjector(NextcloudTalkApplication.class) -public class DatabaseStorageModule { - private static final String TAG = "DatabaseStorageModule"; +package com.nextcloud.talk.utils.preferences.preferencestorage + +import android.text.TextUtils +import android.util.Log +import autodagger.AutoInjector +import com.nextcloud.talk.api.NcApi +import com.nextcloud.talk.application.NextcloudTalkApplication +import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication +import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager +import com.nextcloud.talk.data.storage.model.ArbitraryStorage +import com.nextcloud.talk.data.user.model.User +import com.nextcloud.talk.models.json.generic.GenericOverall +import com.nextcloud.talk.utils.ApiUtils +import com.nextcloud.talk.utils.ApiUtils.getConversationApiVersion +import com.nextcloud.talk.utils.ApiUtils.getCredentials +import com.nextcloud.talk.utils.ApiUtils.getUrlForMessageExpiration +import com.nextcloud.talk.utils.ApiUtils.getUrlForRoomNotificationCalls +import com.nextcloud.talk.utils.ApiUtils.getUrlForRoomNotificationLevel +import com.nextcloud.talk.utils.CapabilitiesUtil.hasSpreedFeatureCapability +import com.nextcloud.talk.utils.SpreedFeatures +import com.nextcloud.talk.utils.UserIdUtils.getIdForUser +import io.reactivex.Observer +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.disposables.Disposable +import io.reactivex.schedulers.Schedulers +import javax.inject.Inject + +@AutoInjector(NextcloudTalkApplication::class) +class DatabaseStorageModule(conversationUser: User, conversationToken: String) { + @JvmField @Inject - ArbitraryStorageManager arbitraryStorageManager; + var arbitraryStorageManager: ArbitraryStorageManager? = null + @JvmField @Inject - NcApi ncApi; + var ncApi: NcApi? = null - private int messageExpiration; - private final User conversationUser; - private final String conversationToken; - private final long accountIdentifier; + private var messageExpiration = 0 + private val conversationUser: User + private val conversationToken: String + private val accountIdentifier: Long - private boolean lobbyValue; + private var lobbyValue = false - private String messageNotificationLevel; + private var messageNotificationLevel: String? = null - public DatabaseStorageModule(User conversationUser, String conversationToken) { - NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); + init { + sharedApplication!!.componentApplication.inject(this) - this.conversationUser = conversationUser; - this.accountIdentifier = UserIdUtils.INSTANCE.getIdForUser(conversationUser); - this.conversationToken = conversationToken; + this.conversationUser = conversationUser + this.accountIdentifier = getIdForUser(conversationUser) + this.conversationToken = conversationToken } - public void saveBoolean(String key, boolean value) { - if ("call_notifications_switch".equals(key)) { - int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[]{4}); - ncApi.notificationCalls(ApiUtils.getCredentials(conversationUser.getUsername(), - conversationUser.getToken()), - ApiUtils.getUrlForRoomNotificationCalls(apiVersion, - conversationUser.getBaseUrl(), - conversationToken), - value ? 1 : 0) + fun saveBoolean(key: String, value: Boolean) { + if ("call_notifications_switch" == key) { + val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4)) + ncApi!!.notificationCalls( + getCredentials( + conversationUser.username, + conversationUser.token + ), + getUrlForRoomNotificationCalls( + apiVersion, + conversationUser.baseUrl, + conversationToken + ), + if (value) 1 else 0 + ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(@NonNull Disposable d) { - // unused atm - } - - @Override - public void onNext(@NonNull GenericOverall genericOverall) { - Log.d(TAG, "Toggled notification calls"); - } - - @Override - public void onError(@NonNull Throwable e) { - Log.e(TAG, "Error when trying to toggle notification calls", e); - } - - @Override - public void onComplete() { - // unused atm - } - } - ); + .subscribe( + object : Observer { + override fun onSubscribe(d: Disposable) { + // unused atm + } + + override fun onNext(genericOverall: GenericOverall) { + Log.d(TAG, "Toggled notification calls") + } + + override fun onError(e: Throwable) { + Log.e(TAG, "Error when trying to toggle notification calls", e) + } + + override fun onComplete() { + // unused atm + } + } + ) } - if (!"lobby_switch".equals(key)) { - arbitraryStorageManager.storeStorageSetting(accountIdentifier, - key, - Boolean.toString(value), - conversationToken); + if ("lobby_switch" != key) { + arbitraryStorageManager!!.storeStorageSetting( + accountIdentifier, + key, + value.toString(), + conversationToken + ) } else { - lobbyValue = value; + lobbyValue = value } } - public void saveString(String key, String value) { - if ("conversation_settings_dropdown".equals(key)) { - int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[]{4}); - - String trimmedValue = value.replace("expire_", ""); - int valueInt = Integer.parseInt(trimmedValue); - - ncApi.setMessageExpiration( - ApiUtils.getCredentials( - conversationUser.getUsername(), - conversationUser.getToken()), - ApiUtils.getUrlForMessageExpiration( - apiVersion, - conversationUser.getBaseUrl(), - conversationToken), - valueInt) + fun saveString(key: String, value: String) { + if ("conversation_settings_dropdown" == key) { + val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4)) + + val trimmedValue = value.replace("expire_", "") + val valueInt = trimmedValue.toInt() + + ncApi!!.setMessageExpiration( + getCredentials( + conversationUser.username, + conversationUser.token + ), + getUrlForMessageExpiration( + apiVersion, + conversationUser.baseUrl, + conversationToken + ), + valueInt + ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Observer() { - @Override - public void onSubscribe(@NonNull Disposable d) { + .subscribe(object : Observer { + override fun onSubscribe(d: Disposable) { // unused atm } - @Override - public void onNext(@NonNull GenericOverall genericOverall) { - messageExpiration = valueInt; + override fun onNext(genericOverall: GenericOverall) { + messageExpiration = valueInt } - @Override - public void onError(@NonNull Throwable e) { - Log.e(TAG, "Error when trying to set message expiration", e); + override fun onError(e: Throwable) { + Log.e(TAG, "Error when trying to set message expiration", e) } - @Override - public void onComplete() { + override fun onComplete() { // unused atm } - }); - - } else if ("conversation_info_message_notifications_dropdown".equals(key)) { - if (CapabilitiesUtil.hasSpreedFeatureCapability( - conversationUser.getCapabilities().getSpreedCapability(), - SpreedFeatures.NOTIFICATION_LEVELS) + }) + } else if ("conversation_info_message_notifications_dropdown" == key) { + if (hasSpreedFeatureCapability( + conversationUser.capabilities!!.spreedCapability!!, + SpreedFeatures.NOTIFICATION_LEVELS + ) ) { - if (TextUtils.isEmpty(messageNotificationLevel) || !messageNotificationLevel.equals(value)) { - int intValue; - switch (value) { - case "never": - intValue = 3; - break; - case "mention": - intValue = 2; - break; - case "always": - intValue = 1; - break; - default: - intValue = 0; + if (TextUtils.isEmpty(messageNotificationLevel) || messageNotificationLevel != value) { + val intValue = when (value) { + "never" -> 3 + "mention" -> 2 + "always" -> 1 + else -> 0 } - int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[]{ApiUtils.API_V4, 1}); - - ncApi.setNotificationLevel(ApiUtils.getCredentials(conversationUser.getUsername(), - conversationUser.getToken()), - ApiUtils.getUrlForRoomNotificationLevel(apiVersion, - conversationUser.getBaseUrl(), - conversationToken), - intValue) + val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.API_V4, 1)) + + ncApi!!.setNotificationLevel( + getCredentials( + conversationUser.username, + conversationUser.token + ), + getUrlForRoomNotificationLevel( + apiVersion, + conversationUser.baseUrl, + conversationToken + ), + intValue + ) .subscribeOn(Schedulers.io()) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { + .subscribe(object : Observer { + override fun onSubscribe(d: Disposable) { // unused atm } - @Override - public void onNext(GenericOverall genericOverall) {messageNotificationLevel = value;} + override fun onNext(p0: GenericOverall) { + messageNotificationLevel = value + } - @Override - public void onError(Throwable e) { + override fun onError(e: Throwable) { // unused atm } - @Override - public void onComplete() { + override fun onComplete() { // unused atm } - }); + }) } else { - messageNotificationLevel = value; + messageNotificationLevel = value } } } else { - arbitraryStorageManager.storeStorageSetting(accountIdentifier, key, value, conversationToken); + arbitraryStorageManager!!.storeStorageSetting(accountIdentifier, key, value, conversationToken) } } - public boolean getBoolean(String key, boolean defaultVal) { - if ("lobby_switch".equals(key)) { - return lobbyValue; + + fun getBoolean(key: String, defaultVal: Boolean): Boolean { + return if ("lobby_switch" == key) { + lobbyValue } else { - return arbitraryStorageManager + arbitraryStorageManager!! .getStorageSetting(accountIdentifier, key, conversationToken) - .map(arbitraryStorage -> Boolean.parseBoolean(arbitraryStorage.getValue())) - .blockingGet(defaultVal); + .map { arbitraryStorage: ArbitraryStorage -> arbitraryStorage.value.toBoolean() } + .blockingGet(defaultVal) } } - public String getString(String key, String defaultVal) { - if ("conversation_settings_dropdown".equals(key)) { - switch (messageExpiration) { - case 2419200: - return "expire_2419200"; - case 604800: - return "expire_604800"; - case 86400: - return "expire_86400"; - case 28800: - return "expire_28800"; - case 3600: - return "expire_3600"; - default: - return "expire_0"; + fun getString(key: String, defaultVal: String): String? { + return if ("conversation_settings_dropdown" == key) { + when (messageExpiration) { + 2419200 -> "expire_2419200" + 604800 -> "expire_604800" + 86400 -> "expire_86400" + 28800 -> "expire_28800" + 3600 -> "expire_3600" + else -> "expire_0" } - } else if ("conversation_info_message_notifications_dropdown".equals(key)) { - return messageNotificationLevel; + } else if ("conversation_info_message_notifications_dropdown" == key) { + messageNotificationLevel } else { - return arbitraryStorageManager + arbitraryStorageManager!! .getStorageSetting(accountIdentifier, key, conversationToken) - .map(ArbitraryStorage::getValue) - .blockingGet(defaultVal); + .map(ArbitraryStorage::value) + .blockingGet(defaultVal) } } - public void setMessageExpiration(int messageExpiration) { - this.messageExpiration = messageExpiration; + fun setMessageExpiration(messageExpiration: Int) { + this.messageExpiration = messageExpiration + } + + companion object { + private const val TAG = "DatabaseStorageModule" } } From f4f943ff5a72a753c32d13157472d0cabd271e18 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Sun, 17 Nov 2024 20:32:55 +0100 Subject: [PATCH 07/12] convert rxjava to coroutines - notification calls Signed-off-by: sowjanyakch --- .../com/nextcloud/talk/api/NcApiCoroutines.kt | 8 +++ .../ConversationInfoActivity.kt | 13 +++-- .../DatabaseStorageModule.kt | 54 +++++++------------ 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index ff464b48f8..ba0bc911f2 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -131,6 +131,14 @@ interface NcApiCoroutines { @Url url: String ): GenericOverall + @FormUrlEncoded + @POST + suspend fun notificationCalls( + @Header("Authorization") authorization: String, + @Url url: String, + @Field("level") level: Int + ): GenericOverall + @POST suspend fun setReadStatusPrivacy( @Header("Authorization") authorization: String, diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt index da36a2d09c..eeb8a5ae04 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -835,7 +835,9 @@ class ConversationInfoActivity : binding.lockConversation.setOnClickListener { val isLocked = binding.lockConversationSwitch.isChecked binding.lockConversationSwitch.isChecked = !isLocked - databaseStorageModule!!.saveBoolean("lock_switch", !isLocked) + lifecycleScope.launch{ + databaseStorageModule!!.saveBoolean("lock_switch", !isLocked) + } val state = if (isLocked) 0 else 1 makeConversationReadOnly(conversationToken, state) } @@ -1516,12 +1518,17 @@ class ConversationInfoActivity : binding.notificationSettingsView.notificationSettingsImportantConversation.setOnClickListener { val isChecked = binding.notificationSettingsView.importantConversationSwitch.isChecked binding.notificationSettingsView.importantConversationSwitch.isChecked = !isChecked - module.saveBoolean("important_conversation_switch", !isChecked) + lifecycleScope.launch{ + module.saveBoolean("important_conversation_switch", !isChecked) + } + } binding.notificationSettingsView.notificationSettingsCallNotifications.setOnClickListener { val isChecked = binding.notificationSettingsView.callNotificationsSwitch.isChecked binding.notificationSettingsView.callNotificationsSwitch.isChecked = !isChecked - module.saveBoolean("call_notifications_switch", !isChecked) + lifecycleScope.launch{ + module.saveBoolean("call_notifications_switch", !isChecked) + } } binding.notificationSettingsView.conversationInfoMessageNotificationsDropdown .setOnItemClickListener { _, _, position, _ -> diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt index 76efd36cb4..69d9f05626 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt @@ -12,6 +12,7 @@ import android.text.TextUtils import android.util.Log import autodagger.AutoInjector import com.nextcloud.talk.api.NcApi +import com.nextcloud.talk.api.NcApiCoroutines import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager @@ -31,10 +32,13 @@ import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) class DatabaseStorageModule(conversationUser: User, conversationToken: String) { + @JvmField @Inject var arbitraryStorageManager: ArbitraryStorageManager? = null @@ -43,6 +47,10 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { @Inject var ncApi: NcApi? = null + @JvmField + @Inject + var ncApiCoroutines: NcApiCoroutines?= null + private var messageExpiration = 0 private val conversationUser: User private val conversationToken: String @@ -60,42 +68,20 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { this.conversationToken = conversationToken } - fun saveBoolean(key: String, value: Boolean) { + suspend fun saveBoolean(key: String, value: Boolean) { if ("call_notifications_switch" == key) { val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4)) - ncApi!!.notificationCalls( - getCredentials( - conversationUser.username, - conversationUser.token - ), - getUrlForRoomNotificationCalls( - apiVersion, - conversationUser.baseUrl, - conversationToken - ), - if (value) 1 else 0 - ) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe( - object : Observer { - override fun onSubscribe(d: Disposable) { - // unused atm - } - - override fun onNext(genericOverall: GenericOverall) { - Log.d(TAG, "Toggled notification calls") - } - - override fun onError(e: Throwable) { - Log.e(TAG, "Error when trying to toggle notification calls", e) - } - - override fun onComplete() { - // unused atm - } - } - ) + val url = getUrlForRoomNotificationCalls(apiVersion, conversationUser.baseUrl,conversationToken) + val credentials = getCredentials(conversationUser.username,conversationUser.token) + val notificationLevel = if(value) 1 else 0 + withContext(Dispatchers.IO) { + try { + ncApiCoroutines!!.notificationCalls(credentials!!, url, notificationLevel) + Log.d(TAG, "Toggled notification calls") + } catch (e: Throwable) { + Log.e(TAG, "Error when trying to toggle notification calls", e) + } + } } if ("lobby_switch" != key) { From 1d9f475768a5d5a968dd1ca39379d56dfdea65c7 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Sun, 17 Nov 2024 20:41:32 +0100 Subject: [PATCH 08/12] remove unused endpoints Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 2307ce7019..5b454f5f3d 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -468,6 +468,9 @@ Observable notificationCalls(@Header("Authorization") String aut @Url String url, @Field("level") Integer level); + @DELETE + Observable clearChatHistory(@Header("Authorization") String authorization, @Url String url); + @GET Observable hoverCard(@Header("Authorization") String authorization, @Url String url); From 5094cf5719351dc695be0944cbccdbf97389c272 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Sun, 17 Nov 2024 21:45:36 +0100 Subject: [PATCH 09/12] convert rxjava to coroutines - set expiration and set notification levels for messages Signed-off-by: sowjanyakch --- .../com/nextcloud/talk/api/NcApiCoroutines.kt | 16 ++ .../ConversationInfoActivity.kt | 15 +- .../DatabaseStorageModule.kt | 154 +++++++----------- 3 files changed, 86 insertions(+), 99 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index ba0bc911f2..1970d2eeda 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -163,4 +163,20 @@ interface NcApiCoroutines { @Url url: String, @Field("state") state: Int ): GenericOverall + + @FormUrlEncoded + @POST + suspend fun setNotificationLevel( + @Header("Authorization") authorization: String, + @Url url: String, + @Field("level") level: Int + ): GenericOverall + + @FormUrlEncoded + @POST + suspend fun setMessageExpiration( + @Header("Authorization") authorization: String, + @Url url: String, + @Field("seconds") seconds: Int + ): GenericOverall } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt index eeb8a5ae04..b491094ab4 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -835,7 +835,7 @@ class ConversationInfoActivity : binding.lockConversation.setOnClickListener { val isLocked = binding.lockConversationSwitch.isChecked binding.lockConversationSwitch.isChecked = !isLocked - lifecycleScope.launch{ + lifecycleScope.launch { databaseStorageModule!!.saveBoolean("lock_switch", !isLocked) } val state = if (isLocked) 0 else 1 @@ -1016,7 +1016,9 @@ class ConversationInfoActivity : .setSimpleItems(resources.getStringArray(R.array.message_expiring_descriptions)) binding.conversationSettingsDropdown.setOnItemClickListener { _, _, position, _ -> val v: String = resources.getStringArray(R.array.message_expiring_values)[position] - databaseStorageModule!!.saveString("conversation_settings_dropdown", v) + lifecycleScope.launch { + databaseStorageModule!!.saveString("conversation_settings_dropdown", v) + } } binding.messageExpirationSettings.visibility = VISIBLE } else { @@ -1518,15 +1520,14 @@ class ConversationInfoActivity : binding.notificationSettingsView.notificationSettingsImportantConversation.setOnClickListener { val isChecked = binding.notificationSettingsView.importantConversationSwitch.isChecked binding.notificationSettingsView.importantConversationSwitch.isChecked = !isChecked - lifecycleScope.launch{ + lifecycleScope.launch { module.saveBoolean("important_conversation_switch", !isChecked) } - } binding.notificationSettingsView.notificationSettingsCallNotifications.setOnClickListener { val isChecked = binding.notificationSettingsView.callNotificationsSwitch.isChecked binding.notificationSettingsView.callNotificationsSwitch.isChecked = !isChecked - lifecycleScope.launch{ + lifecycleScope.launch { module.saveBoolean("call_notifications_switch", !isChecked) } } @@ -1534,7 +1535,9 @@ class ConversationInfoActivity : .setOnItemClickListener { _, _, position, _ -> val value = resources.getStringArray(R.array.message_notification_levels_entry_values)[position] Log.i(TAG, "saved $value to module from $position") - module.saveString("conversation_info_message_notifications_dropdown", value) + lifecycleScope.launch { + module.saveString("conversation_info_message_notifications_dropdown", value) + } } binding.notificationSettingsView.importantConversationSwitch.isChecked = module diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt index 69d9f05626..5128d8958b 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt @@ -18,7 +18,6 @@ import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedA import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager import com.nextcloud.talk.data.storage.model.ArbitraryStorage import com.nextcloud.talk.data.user.model.User -import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.ApiUtils.getConversationApiVersion import com.nextcloud.talk.utils.ApiUtils.getCredentials @@ -28,10 +27,6 @@ import com.nextcloud.talk.utils.ApiUtils.getUrlForRoomNotificationLevel import com.nextcloud.talk.utils.CapabilitiesUtil.hasSpreedFeatureCapability import com.nextcloud.talk.utils.SpreedFeatures import com.nextcloud.talk.utils.UserIdUtils.getIdForUser -import io.reactivex.Observer -import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.disposables.Disposable -import io.reactivex.schedulers.Schedulers import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import javax.inject.Inject @@ -49,7 +44,7 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { @JvmField @Inject - var ncApiCoroutines: NcApiCoroutines?= null + var ncApiCoroutines: NcApiCoroutines? = null private var messageExpiration = 0 private val conversationUser: User @@ -71,9 +66,9 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { suspend fun saveBoolean(key: String, value: Boolean) { if ("call_notifications_switch" == key) { val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4)) - val url = getUrlForRoomNotificationCalls(apiVersion, conversationUser.baseUrl,conversationToken) - val credentials = getCredentials(conversationUser.username,conversationUser.token) - val notificationLevel = if(value) 1 else 0 + val url = getUrlForRoomNotificationCalls(apiVersion, conversationUser.baseUrl, conversationToken) + val credentials = getCredentials(conversationUser.username, conversationUser.token) + val notificationLevel = if (value) 1 else 0 withContext(Dispatchers.IO) { try { ncApiCoroutines!!.notificationCalls(credentials!!, url, notificationLevel) @@ -83,7 +78,6 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { } } } - if ("lobby_switch" != key) { arbitraryStorageManager!!.storeStorageSetting( accountIdentifier, @@ -96,96 +90,70 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { } } - fun saveString(key: String, value: String) { - if ("conversation_settings_dropdown" == key) { - val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4)) - - val trimmedValue = value.replace("expire_", "") - val valueInt = trimmedValue.toInt() - - ncApi!!.setMessageExpiration( - getCredentials( - conversationUser.username, - conversationUser.token - ), - getUrlForMessageExpiration( - apiVersion, - conversationUser.baseUrl, - conversationToken - ), - valueInt - ) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(object : Observer { - override fun onSubscribe(d: Disposable) { - // unused atm - } - - override fun onNext(genericOverall: GenericOverall) { + suspend fun saveString(key: String, value: String) { + when (key) { + "conversation_settings_dropdown" -> { + try { + val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4)) + val trimmedValue = value.replace("expire_", "") + val valueInt = trimmedValue.toInt() + withContext(Dispatchers.IO) { + ncApiCoroutines!!.setMessageExpiration( + getCredentials(conversationUser.username, conversationUser.token)!!, + getUrlForMessageExpiration( + apiVersion, + conversationUser.baseUrl, + conversationToken + ), + valueInt + ) messageExpiration = valueInt } - - override fun onError(e: Throwable) { - Log.e(TAG, "Error when trying to set message expiration", e) - } - - override fun onComplete() { - // unused atm - } - }) - } else if ("conversation_info_message_notifications_dropdown" == key) { - if (hasSpreedFeatureCapability( - conversationUser.capabilities!!.spreedCapability!!, - SpreedFeatures.NOTIFICATION_LEVELS - ) - ) { - if (TextUtils.isEmpty(messageNotificationLevel) || messageNotificationLevel != value) { - val intValue = when (value) { - "never" -> 3 - "mention" -> 2 - "always" -> 1 - else -> 0 - } - - val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.API_V4, 1)) - - ncApi!!.setNotificationLevel( - getCredentials( - conversationUser.username, - conversationUser.token - ), - getUrlForRoomNotificationLevel( - apiVersion, - conversationUser.baseUrl, - conversationToken - ), - intValue - ) - .subscribeOn(Schedulers.io()) - .subscribe(object : Observer { - override fun onSubscribe(d: Disposable) { - // unused atm + } catch (exception: Exception) { + Log.e(TAG, "Error when trying to set message expiration", exception) + } + } + "conversation_info_message_notifications_dropdown" -> { + try { + if (hasSpreedFeatureCapability( + conversationUser.capabilities!!.spreedCapability!!, + SpreedFeatures.NOTIFICATION_LEVELS + ) + ) { + if (TextUtils.isEmpty(messageNotificationLevel) || messageNotificationLevel != value) { + val intValue = when (value) { + "never" -> 3 + "mention" -> 2 + "always" -> 1 + else -> 0 } - - override fun onNext(p0: GenericOverall) { + val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.API_V4, 1)) + withContext(Dispatchers.IO) { + ncApiCoroutines!!.setNotificationLevel( + getCredentials( + conversationUser.username, + conversationUser.token + )!!, + getUrlForRoomNotificationLevel( + apiVersion, + conversationUser.baseUrl, + conversationToken + ), + intValue + ) messageNotificationLevel = value } - - override fun onError(e: Throwable) { - // unused atm - } - - override fun onComplete() { - // unused atm - } - }) - } else { - messageNotificationLevel = value + } else { + messageNotificationLevel = value + } + } + } catch (exception: Exception) { + Log.e(TAG, "Error trying to set notification level", exception) } } - } else { - arbitraryStorageManager!!.storeStorageSetting(accountIdentifier, key, value, conversationToken) + else -> { + arbitraryStorageManager!!.storeStorageSetting(accountIdentifier, key, value, conversationToken) + } } } From af7a395508b8405da81eb98831dbd073ac631fbc Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Sun, 17 Nov 2024 21:47:16 +0100 Subject: [PATCH 10/12] remove unused endpoints Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 5b454f5f3d..38476a29a3 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -389,6 +389,12 @@ Observable setNotificationLevel(@Header("Authorization") String @Url String url, @Field("level") int level); + @FormUrlEncoded + @PUT + Observable setConversationReadOnly(@Header("Authorization") String authorization, + @Url String url, + @Field("state") int state); + @FormUrlEncoded @POST Observable createRemoteShare(@Nullable @Header("Authorization") String authorization, @@ -572,12 +578,6 @@ Observable votePoll(@Header("Authorization") String authorization, Observable closePoll(@Header("Authorization") String authorization, @Url String url); - @FormUrlEncoded - @POST - Observable setMessageExpiration(@Header("Authorization") String authorization, - @Url String url, - @Field("seconds") Integer seconds); - @GET Observable getOpenGraph(@Header("Authorization") String authorization, @Url String url, From 33314cf0ca7f7334babcc662767acdc051c129b7 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Mon, 18 Nov 2024 16:23:55 +0100 Subject: [PATCH 11/12] use constants Signed-off-by: sowjanyakch --- .../DatabaseStorageModule.kt | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt index 5128d8958b..2a239e869c 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt @@ -122,9 +122,9 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { ) { if (TextUtils.isEmpty(messageNotificationLevel) || messageNotificationLevel != value) { val intValue = when (value) { - "never" -> 3 - "mention" -> 2 - "always" -> 1 + "never" -> NOTIFICATION_NEVER + "mention" -> NOTIFICATION_MENTION + "always" -> NOTIFICATION_ALWAYS else -> 0 } val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.API_V4, 1)) @@ -171,11 +171,11 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { fun getString(key: String, defaultVal: String): String? { return if ("conversation_settings_dropdown" == key) { when (messageExpiration) { - 2419200 -> "expire_2419200" - 604800 -> "expire_604800" - 86400 -> "expire_86400" - 28800 -> "expire_28800" - 3600 -> "expire_3600" + EXPIRE_4_WEEKS -> "expire_2419200" + EXPIRE_7_DAYS -> "expire_604800" + EXPIRE_1_DAY -> "expire_86400" + EXPIRE_8_HOURS -> "expire_28800" + EXPIRE_1_HOUR -> "expire_3600" else -> "expire_0" } } else if ("conversation_info_message_notifications_dropdown" == key) { @@ -194,5 +194,13 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { companion object { private const val TAG = "DatabaseStorageModule" + private const val EXPIRE_1_HOUR = 3600 + private const val EXPIRE_8_HOURS = 28800 + private const val EXPIRE_1_DAY = 86400 + private const val EXPIRE_7_DAYS = 604800 + private const val EXPIRE_4_WEEKS = 2419200 + private const val NOTIFICATION_NEVER = 3 + private const val NOTIFICATION_MENTION = 2 + private const val NOTIFICATION_ALWAYS = 1 } } From 626994e68caf7b83487d51b1e7332e70fff1aa6e Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Mon, 18 Nov 2024 18:20:58 +0100 Subject: [PATCH 12/12] lint warnings Signed-off-by: sowjanyakch --- .../talk/ui/dialog/ConversationsListBottomDialog.kt | 4 ++-- .../preferencestorage/DatabaseStorageModule.kt | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt index 9b4f009ee1..6a33abb7fa 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt @@ -202,7 +202,7 @@ class ConversationsListBottomDialog( } } - @SuppressLint("StringFormatInvalid") + @SuppressLint("StringFormatInvalid", "TooGenericExceptionCaught") private fun addConversationToFavorites() { val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) val url = ApiUtils.getUrlForRoomFavorite(apiVersion, currentUser.baseUrl!!, conversation.token) @@ -228,7 +228,7 @@ class ConversationsListBottomDialog( } } - @SuppressLint("StringFormatInvalid") + @SuppressLint("StringFormatInvalid", "TooGenericExceptionCaught") private fun removeConversationFromFavorites() { val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) val url = ApiUtils.getUrlForRoomFavorite(apiVersion, currentUser.baseUrl!!, conversation.token) diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt index 2a239e869c..e6b376f87a 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt @@ -8,6 +8,7 @@ */ package com.nextcloud.talk.utils.preferences.preferencestorage +import android.annotation.SuppressLint import android.text.TextUtils import android.util.Log import autodagger.AutoInjector @@ -63,6 +64,7 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { this.conversationToken = conversationToken } + @SuppressLint("TooGenericExceptionCaught") suspend fun saveBoolean(key: String, value: Boolean) { if ("call_notifications_switch" == key) { val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4)) @@ -73,7 +75,7 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { try { ncApiCoroutines!!.notificationCalls(credentials!!, url, notificationLevel) Log.d(TAG, "Toggled notification calls") - } catch (e: Throwable) { + } catch (e: Exception) { Log.e(TAG, "Error when trying to toggle notification calls", e) } } @@ -90,11 +92,12 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { } } + @SuppressLint("TooGenericExceptionCaught") suspend fun saveString(key: String, value: String) { when (key) { "conversation_settings_dropdown" -> { try { - val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4)) + val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(API_VERSION_4)) val trimmedValue = value.replace("expire_", "") val valueInt = trimmedValue.toInt() withContext(Dispatchers.IO) { @@ -202,5 +205,6 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { private const val NOTIFICATION_NEVER = 3 private const val NOTIFICATION_MENTION = 2 private const val NOTIFICATION_ALWAYS = 1 + private const val API_VERSION_4 = 4 } }