From d08167e3ddac6a75e14cf6ec8a074ec30661582b Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 20 Nov 2024 16:05:35 +0100 Subject: [PATCH] ktlintFormat Signed-off-by: sowjanyakch --- .../talk/utils/VibrationUtilsTest.kt | 16 +++---- .../talk/adapters/items/ContactItem.kt | 5 +-- .../talk/adapters/items/ConversationItem.kt | 10 ++--- .../adapters/items/MentionAutocompleteItem.kt | 20 ++++----- .../talk/extensions/ImageViewExtensions.kt | 43 ++++++++---------- .../nextcloud/talk/jobs/NotificationWorker.kt | 22 ++++----- .../talk/settings/SettingsActivity.kt | 45 +++++++++---------- .../com/nextcloud/talk/utils/FileUtils.kt | 3 +- .../nextcloud/talk/utils/NotificationUtils.kt | 45 +++++++++---------- .../nextcloud/talk/utils/VibrationUtils.kt | 1 - 10 files changed, 96 insertions(+), 114 deletions(-) diff --git a/app/src/androidTest/java/com/nextcloud/talk/utils/VibrationUtilsTest.kt b/app/src/androidTest/java/com/nextcloud/talk/utils/VibrationUtilsTest.kt index 92019e106..a0933cbcb 100644 --- a/app/src/androidTest/java/com/nextcloud/talk/utils/VibrationUtilsTest.kt +++ b/app/src/androidTest/java/com/nextcloud/talk/utils/VibrationUtilsTest.kt @@ -33,13 +33,13 @@ class VibrationUtilsTest { @Test fun testVibrateShort() { VibrationUtils.vibrateShort(mockContext) - Mockito.verify(mockVibrator) - .vibrate( - VibrationEffect - .createOneShot( - VibrationUtils.SHORT_VIBRATE, - VibrationEffect.DEFAULT_AMPLITUDE - ) - ) + Mockito.verify(mockVibrator) + .vibrate( + VibrationEffect + .createOneShot( + VibrationUtils.SHORT_VIBRATE, + VibrationEffect.DEFAULT_AMPLITUDE + ) + ) } } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.kt b/app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.kt index d823c5d10..1c477f1fb 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.kt @@ -166,10 +166,7 @@ class ContactItem( } } - private fun setGenericAvatar( - holder: ContactItemViewHolder, - roundPlaceholderDrawable: Int - ) { + private fun setGenericAvatar(holder: ContactItemViewHolder, roundPlaceholderDrawable: Int) { val avatar = viewThemeUtils.talk.themePlaceholderAvatar( holder.binding.avatarView, diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt index 51b80ce82..e047be397 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt @@ -194,12 +194,12 @@ class ConversationItem( } ConversationEnums.ObjectType.FILE -> { - holder.binding.dialogAvatar.loadUserAvatar( - viewThemeUtils.talk.themePlaceholderAvatar( - holder.binding.dialogAvatar, - R.drawable.ic_avatar_document - ) + holder.binding.dialogAvatar.loadUserAvatar( + viewThemeUtils.talk.themePlaceholderAvatar( + holder.binding.dialogAvatar, + R.drawable.ic_avatar_document ) + ) false } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.kt b/app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.kt index fa85c2f59..4fffdd120 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.kt @@ -116,22 +116,22 @@ class MentionAutocompleteItem( SOURCE_CALLS -> { run {} run { - holder.binding.avatarView.loadUserAvatar( - viewThemeUtils.talk.themePlaceholderAvatar( - holder.binding.avatarView, - R.drawable.ic_avatar_group - ) - ) - } - } - - SOURCE_GROUPS -> { holder.binding.avatarView.loadUserAvatar( viewThemeUtils.talk.themePlaceholderAvatar( holder.binding.avatarView, R.drawable.ic_avatar_group ) ) + } + } + + SOURCE_GROUPS -> { + holder.binding.avatarView.loadUserAvatar( + viewThemeUtils.talk.themePlaceholderAvatar( + holder.binding.avatarView, + R.drawable.ic_avatar_group + ) + ) } SOURCE_FEDERATION -> { diff --git a/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt b/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt index 78b83250b..ef43da5f8 100644 --- a/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt +++ b/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt @@ -206,11 +206,10 @@ fun ImageView.loadThumbnail(url: String, user: User): io.reactivex.disposables.D .target(this) .transformations(CircleCropTransformation()) - - val layers = arrayOfNulls(2) - layers[0] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_background) - layers[1] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_foreground) - requestBuilder.placeholder(LayerDrawable(layers)) + val layers = arrayOfNulls(2) + layers[0] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_background) + layers[1] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_foreground) + requestBuilder.placeholder(LayerDrawable(layers)) if (url.startsWith(user.baseUrl!!) && (url.contains("index.php/core/preview") || url.contains("/avatar/")) @@ -271,12 +270,11 @@ fun ImageView.loadUserAvatar(any: Any?): io.reactivex.disposables.Disposable { } fun ImageView.loadSystemAvatar(): io.reactivex.disposables.Disposable { - - val layers = arrayOfNulls(2) - layers[0] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_background) - layers[1] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_foreground) - val layerDrawable = LayerDrawable(layers) - val data: Any = layerDrawable + val layers = arrayOfNulls(2) + layers[0] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_background) + layers[1] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_foreground) + val layerDrawable = LayerDrawable(layers) + val data: Any = layerDrawable return DisposableWrapper( load(data) { @@ -286,13 +284,11 @@ fun ImageView.loadSystemAvatar(): io.reactivex.disposables.Disposable { } fun ImageView.loadNoteToSelfAvatar(): io.reactivex.disposables.Disposable { - - val layers = arrayOfNulls(2) - layers[0] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_background) - layers[1] = ContextCompat.getDrawable(context, R.drawable.ic_note_to_self) - val layerDrawable = LayerDrawable(layers) - val data: Any = layerDrawable - + val layers = arrayOfNulls(2) + layers[0] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_background) + layers[1] = ContextCompat.getDrawable(context, R.drawable.ic_note_to_self) + val layerDrawable = LayerDrawable(layers) + val data: Any = layerDrawable return DisposableWrapper( load(data) { @@ -306,12 +302,11 @@ fun ImageView.loadChangelogBotAvatar(): io.reactivex.disposables.Disposable { } fun ImageView.loadBotsAvatar(): io.reactivex.disposables.Disposable { - - val layers = arrayOfNulls(2) - layers[0] = ColorDrawable(context.getColor(R.color.black)) - layers[1] = TextDrawable(context, ">") - val layerDrawable = LayerDrawable(layers) - val data: Any = layerDrawable + val layers = arrayOfNulls(2) + layers[0] = ColorDrawable(context.getColor(R.color.black)) + layers[1] = TextDrawable(context, ">") + val layerDrawable = LayerDrawable(layers) + val data: Any = layerDrawable return DisposableWrapper( load(data) { diff --git a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt index d7a30f236..50687cea7 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt +++ b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt @@ -535,18 +535,18 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor notificationBuilder.setExtras(notificationInfoBundle) - when (pushMessage.type) { - TYPE_CHAT, - TYPE_ROOM, - TYPE_RECORDING, - TYPE_REMINDER, - TYPE_ADMIN_NOTIFICATIONS, - TYPE_REMOTE_TALK_SHARE -> { - notificationBuilder.setChannelId( - NotificationUtils.NotificationChannels.NOTIFICATION_CHANNEL_MESSAGES_V4.name - ) - } + when (pushMessage.type) { + TYPE_CHAT, + TYPE_ROOM, + TYPE_RECORDING, + TYPE_REMINDER, + TYPE_ADMIN_NOTIFICATIONS, + TYPE_REMOTE_TALK_SHARE -> { + notificationBuilder.setChannelId( + NotificationUtils.NotificationChannels.NOTIFICATION_CHANNEL_MESSAGES_V4.name + ) } + } notificationBuilder.setContentIntent(pendingIntent) val groupName = signatureVerification.user!!.id.toString() + "@" + pushMessage.id diff --git a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt index 43bea239b..72a7e9795 100644 --- a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt @@ -256,8 +256,8 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu private fun setupNotificationSettings() { binding.settingsNotificationsTitle.text = resources!!.getString( - R.string.nc_settings_notification_sounds_post_oreo - ) + R.string.nc_settings_notification_sounds_post_oreo + ) setupNotificationSoundsSettings() setupNotificationPermissionSettings() } @@ -359,26 +359,25 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu binding.messagesRingtone.text = resources!!.getString(R.string.nc_common_disabled) } - binding.settingsCallSound.setOnClickListener { - val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) - intent.putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID) - intent.putExtra( - Settings.EXTRA_CHANNEL_ID, - NotificationUtils.NotificationChannels.NOTIFICATION_CHANNEL_CALLS_V4.name - ) - - startActivity(intent) - } - binding.settingsMessageSound.setOnClickListener { - val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) - intent.putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID) - intent.putExtra( - Settings.EXTRA_CHANNEL_ID, - NotificationUtils.NotificationChannels.NOTIFICATION_CHANNEL_MESSAGES_V4.name - ) - startActivity(intent) - } + binding.settingsCallSound.setOnClickListener { + val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) + intent.putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID) + intent.putExtra( + Settings.EXTRA_CHANNEL_ID, + NotificationUtils.NotificationChannels.NOTIFICATION_CHANNEL_CALLS_V4.name + ) + startActivity(intent) + } + binding.settingsMessageSound.setOnClickListener { + val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) + intent.putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID) + intent.putExtra( + Settings.EXTRA_CHANNEL_ID, + NotificationUtils.NotificationChannels.NOTIFICATION_CHANNEL_MESSAGES_V4.name + ) + startActivity(intent) + } } private fun setTroubleshootingClickListenersIfNecessary() { @@ -860,9 +859,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu private fun setupCheckables() { binding.settingsScreenSecuritySwitch.isChecked = appPreferences.isScreenSecured - - binding.settingsIncognitoKeyboardSwitch.isChecked = appPreferences.isKeyboardIncognito - + binding.settingsIncognitoKeyboardSwitch.isChecked = appPreferences.isKeyboardIncognito if (CapabilitiesUtil.isReadStatusAvailable(currentUser!!.capabilities!!.spreedCapability!!)) { binding.settingsReadPrivacySwitch.isChecked = !CapabilitiesUtil.isReadStatusPrivate(currentUser!!) diff --git a/app/src/main/java/com/nextcloud/talk/utils/FileUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/FileUtils.kt index f7b709c05..8f4c40690 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/FileUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/FileUtils.kt @@ -99,8 +99,7 @@ object FileUtils { val cachedFile = File(context.cacheDir, filename) val aboveOrEqualAPI26Check = - !cachedFile.toPath().normalize().startsWith(context.cacheDir.toPath()) - + !cachedFile.toPath().normalize().startsWith(context.cacheDir.toPath()) val isOutsideCacheDir = aboveOrEqualAPI26Check diff --git a/app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.kt index 79ac88610..64efd89b1 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.kt @@ -54,7 +54,6 @@ object NotificationUtils { const val KEY_UPLOAD_GROUP = "com.nextcloud.talk.utils.KEY_UPLOAD_GROUP" const val GROUP_SUMMARY_NOTIFICATION_ID = -1 - private fun createNotificationChannel( context: Context, notificationChannel: Channel, @@ -151,29 +150,26 @@ object NotificationUtils { } fun removeOldNotificationChannels(context: Context) { + val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + // Current version does not use notification channel groups - delete all groups + for (channelGroup in notificationManager.notificationChannelGroups) { + notificationManager.deleteNotificationChannelGroup(channelGroup.id) + } - // Current version does not use notification channel groups - delete all groups - for (channelGroup in notificationManager.notificationChannelGroups) { - notificationManager.deleteNotificationChannelGroup(channelGroup.id) + val channelsToKeep = NotificationChannels.values().map { it.name } + + // Delete all notification channels created by previous versions + for (channel in notificationManager.notificationChannels) { + if (!channelsToKeep.contains(channel.id)) { + notificationManager.deleteNotificationChannel(channel.id) } - - val channelsToKeep = NotificationChannels.values().map { it.name } - - // Delete all notification channels created by previous versions - for (channel in notificationManager.notificationChannels) { - if (!channelsToKeep.contains(channel.id)) { - notificationManager.deleteNotificationChannel(channel.id) - } - } - + } } - private fun getNotificationChannel(context: Context, channelId: String): NotificationChannel? { - val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - return notificationManager.getNotificationChannel(channelId) + val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + return notificationManager.getNotificationChannel(channelId) } private inline fun scanNotifications( @@ -283,13 +279,12 @@ object NotificationUtils { defaultRingtoneUri: String, channelId: String ): Uri? { - - val channel = getNotificationChannel(context, channelId) - if (channel != null) { - return channel.sound - } - // Notification channel will not be available when starting the application for the first time. - // Ringtone uris are required to register the notification channels -> get uri from preferences. + val channel = getNotificationChannel(context, channelId) + if (channel != null) { + return channel.sound + } + // Notification channel will not be available when starting the application for the first time. + // Ringtone uris are required to register the notification channels -> get uri from preferences. return if (TextUtils.isEmpty(ringtonePreferencesString)) { Uri.parse(defaultRingtoneUri) diff --git a/app/src/main/java/com/nextcloud/talk/utils/VibrationUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/VibrationUtils.kt index a12fe0025..f73a92661 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/VibrationUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/VibrationUtils.kt @@ -7,7 +7,6 @@ package com.nextcloud.talk.utils import android.content.Context -import android.os.Build import android.os.VibrationEffect import android.os.Vibrator