From 095456dc7d3aa8318ff90152fcea08f3e07039ea Mon Sep 17 00:00:00 2001 From: vivekCometChat Date: Tue, 2 Apr 2024 18:47:22 +0530 Subject: [PATCH] 3.0.14-2 --- uikit-kotlin/build.gradle | 2 +- uikit-kotlin/src/main/AndroidManifest.xml | 22 +- .../message_list/CometChatMessageList.kt | 1555 ++++++----- .../messages/message_list/MessageAdapter.kt | 2478 +++++++++++++---- .../CometChatThreadMessageList.kt | 46 +- .../CometChatComposeBox.kt | 278 +- .../uikit/ui_resources/utils/MediaUtils.kt | 153 +- .../sticker_header/StickyHeaderDecoration.kt | 44 +- .../layout/message_left_audio_item.xml | 230 +- .../layout/message_left_file_item.xml | 162 +- .../layout/message_left_group_call_item.xml | 17 +- .../layout/message_left_link_item.xml | 341 +-- .../layout/message_left_list_image_item.xml | 274 +- .../layout/message_left_list_video_item.xml | 247 +- .../layout/message_left_location_item.xml | 310 ++- .../layout/message_left_polls_item.xml | 134 +- .../layout/message_left_sticker_item.xml | 178 +- .../layout/message_left_text_item.xml | 132 +- .../layout/message_left_whiteboard_item.xml | 15 +- .../layout/message_left_writeboard_item.xml | 247 +- .../layout/message_right_audio_item.xml | 188 +- .../layout/message_right_file_item.xml | 141 +- .../layout/message_right_group_call_item.xml | 103 +- .../layout/message_right_link_item.xml | 12 +- .../layout/message_right_list_image_item.xml | 11 +- .../layout/message_right_list_video_item.xml | 209 +- .../layout/message_right_location_item.xml | 278 +- .../layout/message_right_polls_item.xml | 135 +- .../layout/message_right_sticker_item.xml | 139 +- .../layout/message_right_text_item.xml | 112 +- .../layout/message_right_whiteboard_item.xml | 214 +- .../layout/message_right_writeboard_item.xml | 215 +- 32 files changed, 5297 insertions(+), 3325 deletions(-) diff --git a/uikit-kotlin/build.gradle b/uikit-kotlin/build.gradle index eb872f8..9962144 100644 --- a/uikit-kotlin/build.gradle +++ b/uikit-kotlin/build.gradle @@ -82,7 +82,7 @@ dependencies { //cometchat compileOnly 'com.cometchat:pro-android-chat-sdk:3.0.14' compileOnly 'com.cometchat:pro-android-calls-sdk:2.3.0' - + implementation 'com.google.android.flexbox:flexbox:3.0.0' def activityKtxVersion = "1.3.1" implementation "androidx.activity:activity-ktx:$activityKtxVersion" def fragmentKtxVersion = "1.4.0-alpha06" diff --git a/uikit-kotlin/src/main/AndroidManifest.xml b/uikit-kotlin/src/main/AndroidManifest.xml index b3e2637..69ead86 100644 --- a/uikit-kotlin/src/main/AndroidManifest.xml +++ b/uikit-kotlin/src/main/AndroidManifest.xml @@ -3,14 +3,24 @@ xmlns:tools="http://schemas.android.com/tools" package="com.cometchat.pro.uikit"> - - - - - - + + + + + + + + + + + + + () { override fun onSuccess(mediaMessage: MediaMessage?) { @@ -711,17 +778,25 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } override fun onAudioActionClicked() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - audioPermission.launch(permission.WRITE_EXTERNAL_STORAGE) - } else { - if (Utils.hasPermissions(context,WRITE_EXTERNAL_STORAGE)) { - (context as Activity).startActivityForResult( - MediaUtils.openAudio(activity!!), + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { + if (Utils.hasPermissions(context, WRITE_EXTERNAL_STORAGE)) { + MediaUtils.openAudio( + activity!! + ) + } else { + requestPermissions( + arrayOf(WRITE_EXTERNAL_STORAGE), UIKitConstants.RequestCode.AUDIO ) + } + } else { + if (Utils.hasPermissions(context, permission.READ_MEDIA_AUDIO)) { + MediaUtils.openAudio( + activity!! + ) } else { requestPermissions( - arrayOf(WRITE_EXTERNAL_STORAGE), + arrayOf(permission.READ_MEDIA_AUDIO), UIKitConstants.RequestCode.AUDIO ) } @@ -729,11 +804,12 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } override fun onCameraActionClicked() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) - cameraPermission.launch(Manifest.permission.CAMERA) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) cameraPermission.launch(Manifest.permission.CAMERA) else { if (Utils.hasPermissions(context, *CAMERA_PERMISSION)) { - (context as Activity).startActivityForResult(MediaUtils.openCamera(context!!), UIKitConstants.RequestCode.CAMERA) + (context as Activity).startActivityForResult( + MediaUtils.openCamera(context!!), UIKitConstants.RequestCode.CAMERA + ) } else { requestPermissions(CAMERA_PERMISSION, UIKitConstants.RequestCode.CAMERA) } @@ -741,47 +817,49 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } override fun onGalleryActionClicked() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - galleryPermission.launch(WRITE_EXTERNAL_STORAGE) - } - else { - if (Utils.hasPermissions(context, WRITE_EXTERNAL_STORAGE)) { - startActivityForResult( - MediaUtils.openGallery(activity!!), - UIKitConstants.RequestCode.GALLERY - ) - } else { + + if (Utils.hasPermissions( + context, + permission.READ_MEDIA_IMAGES + ) || Utils.hasPermissions( + context, permission.READ_MEDIA_VIDEO + ) || Utils.hasPermissions( + context, WRITE_EXTERNAL_STORAGE + ) + ) { + MediaUtils.openGallery( + activity!! + ) + } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { requestPermissions( - arrayOf(WRITE_EXTERNAL_STORAGE), - UIKitConstants.RequestCode.GALLERY + arrayOf( + permission.READ_MEDIA_IMAGES, + permission.READ_MEDIA_VIDEO + ), UIKitConstants.RequestCode.GALLERY ) - } + } else requestPermissions( + arrayOf(WRITE_EXTERNAL_STORAGE), + UIKitConstants.RequestCode.GALLERY + ) } } override fun onFileActionClicked() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - if (!checkPermission()) { - requestFilePermission() - } else { - (context as Activity).startActivityForResult( - MediaUtils.getFileIntent( - UIKitConstants.IntentStrings.EXTRA_MIME_DOC - ), UIKitConstants.RequestCode.FILE - ) - } - }else { - if (Utils.hasPermissions(context, WRITE_EXTERNAL_STORAGE)) { - (context as Activity).startActivityForResult( - MediaUtils.getFileIntent(UIKitConstants.IntentStrings.EXTRA_MIME_DOC), - UIKitConstants.RequestCode.FILE - ) - } else { - requestPermissions( - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), - UIKitConstants.RequestCode.FILE - ) - } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU || Utils.hasPermissions( + context, WRITE_EXTERNAL_STORAGE + ) + ) { + startActivityForResult( + MediaUtils.getFileIntent(UIKitConstants.IntentStrings.EXTRA_MIME_DOC), + UIKitConstants.RequestCode.FILE + ) + } else { + requestPermissions( + arrayOf(WRITE_EXTERNAL_STORAGE), + UIKitConstants.RequestCode.FILE + ) } } @@ -806,18 +884,28 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } override fun onLocationActionClicked() { - if (Utils.hasPermissions(context, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)) { - initLocation() - //locationManager = (LocationManager) Objects.requireNonNull(getContext()).getSystemService(Context.LOCATION_SERVICE); - val provider: Boolean = - locationManager!!.isProviderEnabled(LocationManager.GPS_PROVIDER) - if (!provider) { - turnOnLocation() - } else { - getLocation() - } + if (Utils.hasPermissions( + context, + Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION + ) + ) { + initLocation() + //locationManager = (LocationManager) Objects.requireNonNull(getContext()).getSystemService(Context.LOCATION_SERVICE); + val provider: Boolean = + locationManager!!.isProviderEnabled(LocationManager.GPS_PROVIDER) + if (!provider) { + turnOnLocation() + } else { + getLocation() + } } else { - requestPermissions(arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION), UIKitConstants.RequestCode.LOCATION) + requestPermissions( + arrayOf( + Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION + ), UIKitConstants.RequestCode.LOCATION + ) } } @@ -829,7 +917,9 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic Extensions.fetchStickers(object : ExtensionResponseListener() { override fun onResponseSuccess(vararg: Any?) { val stickersJSON = vararg as JSONObject - stickersView?.setData(Id, type, Extensions.extractStickersFromJSON(stickersJSON)) + stickersView?.setData( + Id, type, Extensions.extractStickersFromJSON(stickersJSON) + ) } override fun onResponseFailed(e: CometChatException?) { @@ -849,28 +939,34 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } override fun onWhiteBoardClicked() { - Extensions.callExtensions("whiteboard", Id, type, object : ExtensionResponseListener() { - override fun onResponseSuccess(vararg: Any?) { - var jasonObject: JSONObject = vararg as JSONObject - } + Extensions.callExtensions("whiteboard", + Id, + type, + object : ExtensionResponseListener() { + override fun onResponseSuccess(vararg: Any?) { + var jasonObject: JSONObject = vararg as JSONObject + } - override fun onResponseFailed(e: CometChatException?) { - ErrorMessagesUtils.cometChatErrorMessage(context, e?.code) - } - }) + override fun onResponseFailed(e: CometChatException?) { + ErrorMessagesUtils.cometChatErrorMessage(context, e?.code) + } + }) } override fun onWriteBoardClicked() { - Extensions.callExtensions("document", Id, type, object : ExtensionResponseListener() { - override fun onResponseSuccess(vararg: Any?) { - var jasonObject: JSONObject = vararg as JSONObject - } + Extensions.callExtensions("document", + Id, + type, + object : ExtensionResponseListener() { + override fun onResponseSuccess(vararg: Any?) { + var jasonObject: JSONObject = vararg as JSONObject + } - override fun onResponseFailed(e: CometChatException?) { - ErrorMessagesUtils.cometChatErrorMessage(context, e?.code) - } - }) + override fun onResponseFailed(e: CometChatException?) { + ErrorMessagesUtils.cometChatErrorMessage(context, e?.code) + } + }) } // override fun onStartCallClicked() { @@ -885,40 +981,8 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic }) } -// private fun registerGalleryLauncher() : File { -// val galleryLauncher = -// registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> -// if (result.resultCode == Activity.RESULT_OK) { -// val data: Intent? = result.data -// if (data == null) { -// return null -// } -// val uri = data?.data -// var imageLocalPath = File(FileUtils.getPathReal(requireActivity(), uri!!)) -// -// file = imageLocalPath.absoluteFile -// -// } -// } -// } - private fun checkPermission(): Boolean { - return Environment.isExternalStorageManager() - - // else { -// if (Utils.hasPermissions(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { -// startActivityForResult( -// MediaUtils.openGallery(requireActivity()), -// UIKitConstants.RequestCode.GALLERY -// ) -// } else { -// requestPermissions( -// arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), -// UIKitConstants.RequestCode.GALLERY -// ) -// } -// } -// return false + return Environment.isExternalStorageManager() } @TargetApi(30) @@ -927,8 +991,13 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic when { granted -> { // Toast.makeText(context, "Permission granted!", Toast.LENGTH_SHORT).show() - (context as Activity).startActivityForResult(MediaUtils.openCamera(requireActivity()), UIKitConstants.RequestCode.CAMERA) + (context as Activity).startActivityForResult( + MediaUtils.openCamera( + requireActivity() + ), UIKitConstants.RequestCode.CAMERA + ) } + else -> { requestCameraPermission() } @@ -940,9 +1009,9 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted -> when { granted -> { - Toast.makeText(context, "Permission granted!", Toast.LENGTH_SHORT).show() - (context as Activity).startActivityForResult(MediaUtils.openGallery(requireActivity()), - UIKitConstants.RequestCode.GALLERY) + Toast.makeText(context, "Permission granted!", Toast.LENGTH_SHORT).show() + (context as Activity) + MediaUtils.openGallery(requireActivity()) } else -> { Toast.makeText(context, "Permission denied!", Toast.LENGTH_SHORT).show() @@ -950,15 +1019,16 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } } } + @TargetApi(30) private val audioPermission = registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted -> when { granted -> { Toast.makeText(context, "Permission granted!", Toast.LENGTH_SHORT).show() - (context as Activity).startActivityForResult(MediaUtils.openAudio(requireActivity()), - UIKitConstants.RequestCode.AUDIO) + MediaUtils.openAudio(requireActivity()) } + else -> { Toast.makeText(context, "Permission denied!", Toast.LENGTH_SHORT).show() requestGalleryPermission() @@ -970,11 +1040,13 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic when { ContextCompat.checkSelfPermission( - requireContext(), - Manifest.permission.CAMERA + requireContext(), Manifest.permission.CAMERA ) == PackageManager.PERMISSION_GRANTED -> { - (context as Activity).startActivityForResult(MediaUtils.openCamera(requireActivity()), UIKitConstants.RequestCode.CAMERA) + (context as Activity).startActivityForResult( + MediaUtils.openCamera(requireActivity()), UIKitConstants.RequestCode.CAMERA + ) } + shouldShowRequestPermissionRationale(Manifest.permission.CAMERA) -> { context?.let { Utils.showPermissionAlert( @@ -986,118 +1058,27 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic ) { cameraPermission.launch(Manifest.permission.CAMERA) } } } - else -> { - context?.let { - Utils.showPermissionAlert(it, - getString(R.string.camera_permission), - getString(R.string.camera_permission_denied), - getString(R.string.setting), - getString(R.string.cancel) - ) { - val intent = Intent() - intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS - val uri = Uri.fromParts( - "package", - context?.packageName, null - ) - intent.data = uri - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK - startActivity(intent) - } - } - - } - } - } - private fun requestFilePermission() { - when { - ContextCompat.checkSelfPermission( - requireContext(), - WRITE_EXTERNAL_STORAGE - ) == PackageManager.PERMISSION_GRANTED -> { - (context as Activity).startActivityForResult( - MediaUtils.getFileIntent(UIKitConstants.IntentStrings.EXTRA_MIME_DOC), - UIKitConstants.RequestCode.FILE - ) - } -// shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE) -> { -// context?.let { -// Utils.showPermissionAlert( -// it, -// getString(R.string.grant_storage_permission), -// getString(R.string.grant_permission_to_access_storage), -// getString(R.string.deny), -// getString(R.string.allow) -// ) { galleryPermission.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) } -// } -// } -// else -> { -// context?.let { -// Utils.showPermissionAlert( -// it, -// getString(R.string.grant_storage_permission), -// getString(R.string.grant_permission_to_access_storage), -// getString(R.string.setting), -// getString(R.string.cancel) -// ) { -// val intent = Intent() -// intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS -// val uri = Uri.fromParts( -// "package", -// context?.packageName, null -// ) -// intent.data = uri -// intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK -// startActivity(intent) -// } -// } -// } - } - } - - private fun requestAudioPermission() { - when { - ContextCompat.checkSelfPermission( - requireContext(), - WRITE_EXTERNAL_STORAGE - ) == PackageManager.PERMISSION_GRANTED -> { - (context as Activity).startActivityForResult( - MediaUtils.openAudio(requireActivity()), - UIKitConstants.RequestCode.AUDIO - ) - } - shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE) -> { - context?.let { - Utils.showPermissionAlert( - it, - getString(R.string.grant_storage_permission), - getString(R.string.grant_permission_to_access_storage), - getString(R.string.deny), - getString(R.string.allow) - ) { galleryPermission.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) } - } - } else -> { context?.let { Utils.showPermissionAlert( it, - getString(R.string.grant_storage_permission), - getString(R.string.grant_permission_to_access_storage), + getString(R.string.camera_permission), + getString(R.string.camera_permission_denied), getString(R.string.setting), getString(R.string.cancel) ) { val intent = Intent() intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS val uri = Uri.fromParts( - "package", - context?.packageName, null + "package", context?.packageName, null ) intent.data = uri intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK startActivity(intent) } } + } } } @@ -1105,51 +1086,15 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic private fun requestGalleryPermission() { when { ContextCompat.checkSelfPermission( - requireContext(), - WRITE_EXTERNAL_STORAGE + requireContext(), WRITE_EXTERNAL_STORAGE ) == PackageManager.PERMISSION_GRANTED -> { - (context as Activity).startActivityForResult( - MediaUtils.openGallery(requireActivity()), - UIKitConstants.RequestCode.GALLERY - ) + (context as Activity) + MediaUtils.openGallery(requireActivity()) } -// shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE) -> { -// context?.let { -// Utils.showPermissionAlert( -// it, -// getString(R.string.grant_storage_permission), -// getString(R.string.grant_permission_to_access_storage), -// getString(R.string.deny), -// getString(R.string.allow) -// ) { galleryPermission.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) } -// } -// } -// else -> { -// context?.let { -// Utils.showPermissionAlert( -// it, -// getString(R.string.grant_storage_permission), -// getString(R.string.grant_permission_to_access_storage), -// getString(R.string.setting), -// getString(R.string.cancel) -// ) { -// val intent = Intent() -// intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS -// val uri = Uri.fromParts( -// "package", -// context?.packageName, null -// ) -// intent.data = uri -// intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK -// startActivity(intent) -// } -// } -// } } } - private fun createPollDialog() { var dialog = AlertDialog.Builder(requireContext(), R.style.dialogTheme) val view: View = LayoutInflater.from(context).inflate(R.layout.create_poll_layout, null) @@ -1180,8 +1125,15 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic etQuestion.requestFocus() val option1Text = option1.findViewById(R.id.et_option) val option2Text = option2.findViewById(R.id.et_option) - if (etQuestion.text.toString().trim { it <= ' ' }.isEmpty()) etQuestion.error = getString(R.string.fill_this_field) else if (option1Text.text.toString().trim { it <= ' ' }.isEmpty()) option1Text.error = getString(R.string.fill_this_field) else if (option2Text.text.toString().trim { it <= ' ' }.isEmpty()) option2Text.error = getString(R.string.fill_this_field) else { - val progressDialog = ProgressDialog.show(context, "", resources.getString(R.string.create_poll)) + if (etQuestion.text.toString().trim { it <= ' ' }.isEmpty()) etQuestion.error = + getString(R.string.fill_this_field) else if (option1Text.text.toString() + .trim { it <= ' ' }.isEmpty() + ) option1Text.error = + getString(R.string.fill_this_field) else if (option2Text.text.toString() + .trim { it <= ' ' }.isEmpty() + ) option2Text.error = getString(R.string.fill_this_field) else { + val progressDialog = + ProgressDialog.show(context, "", resources.getString(R.string.create_poll)) createPoll.isEnabled = false try { val optionJson = JSONArray() @@ -1189,27 +1141,31 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic optionJson.put(option2Text.text.toString()) for (views in pollOptionsArrayList) { val optionsText = views.findViewById(R.id.et_option) - if (optionsText.text.toString().trim { it <= ' ' }.isNotEmpty()) optionJson.put(optionsText.text.toString()) + if (optionsText.text.toString().trim { it <= ' ' } + .isNotEmpty()) optionJson.put(optionsText.text.toString()) } val jsonObject = JSONObject() jsonObject.put("question", etQuestion.text.toString()) jsonObject.put("options", optionJson) jsonObject.put("receiver", Id) jsonObject.put("receiverType", type) - callExtension("polls", "POST", "/v2/create", - jsonObject, object : CallbackListener() { - override fun onSuccess(jsonObject: JSONObject?) { - progressDialog.dismiss() - alertDialog.dismiss() - } + callExtension("polls", + "POST", + "/v2/create", + jsonObject, + object : CallbackListener() { + override fun onSuccess(jsonObject: JSONObject?) { + progressDialog.dismiss() + alertDialog.dismiss() + } - override fun onError(e: CometChatException) { - progressDialog.dismiss() - createPoll.isEnabled = true - Log.e(TAG, "onErrorCallExtension: " + e.message) - Toast.makeText(context, e.message, Toast.LENGTH_LONG).show() - } - }) + override fun onError(e: CometChatException) { + progressDialog.dismiss() + createPoll.isEnabled = true + Log.e(TAG, "onErrorCallExtension: " + e.message) + Toast.makeText(context, e.message, Toast.LENGTH_LONG).show() + } + }) } catch (e: java.lang.Exception) { createPoll.isEnabled = true Log.e(TAG, "onErrorJSON: " + e.message) @@ -1235,7 +1191,9 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } initAlert(customData) } else { - Toast.makeText(context, getString(R.string.unable_to_get_location), Toast.LENGTH_LONG).show() + Toast.makeText( + context, getString(R.string.unable_to_get_location), Toast.LENGTH_LONG + ).show() } } } @@ -1243,7 +1201,11 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic private fun initAlert(customData: JSONObject) { val builder = AlertDialog.Builder(requireContext()) builder.setTitle(getString(R.string.share_location_alert)) - builder.setPositiveButton(getString(R.string.share)) { dialog, which -> sendCustomMessage(UIKitConstants.IntentStrings.LOCATION, customData) }.setNegativeButton(getString(R.string.cancel)) { dialog, which -> dialog.dismiss() } + builder.setPositiveButton(getString(R.string.share)) { dialog, which -> + sendCustomMessage( + UIKitConstants.IntentStrings.LOCATION, customData + ) + }.setNegativeButton(getString(R.string.cancel)) { dialog, which -> dialog.dismiss() } builder.create() builder.show() } @@ -1251,11 +1213,18 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic private fun sendCustomMessage(customType: String, customData: JSONObject) { var progressDialog = ProgressDialog.show(context, "", resources.getString(R.string.sending)) val customMessage: CustomMessage - customMessage = if (type.equals(CometChatConstants.RECEIVER_TYPE_USER, ignoreCase = true)) CustomMessage(Id, CometChatConstants.RECEIVER_TYPE_USER, customType, customData) else CustomMessage(Id, CometChatConstants.RECEIVER_TYPE_GROUP, customType, customData) + customMessage = if (type.equals( + CometChatConstants.RECEIVER_TYPE_USER, ignoreCase = true + ) + ) CustomMessage( + Id, CometChatConstants.RECEIVER_TYPE_USER, customType, customData + ) else CustomMessage(Id, CometChatConstants.RECEIVER_TYPE_GROUP, customType, customData) val incrementCountObject = JSONObject() val pushNotificationObject = JSONObject() if (customType == UIKitConstants.IntentStrings.LOCATION) { - pushNotificationObject.put("pushNotification", loggedInUser.name+" has shared his location") + pushNotificationObject.put( + "pushNotification", loggedInUser.name + " has shared his location" + ) customMessage.metadata = pushNotificationObject } if (customType == UIKitConstants.IntentStrings.STICKERS || customType == UIKitConstants.IntentStrings.LOCATION) { @@ -1268,8 +1237,9 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic if (messageAdapter != null) { messageAdapter?.addMessage(customMessage) scrollToBottom() - if (customMessage.customData.has("sessionID")) - Utils.startVideoCallIntent(context!!, customMessage.customData.getString("sessionID")) + if (customMessage.customData.has("sessionID")) Utils.startVideoCallIntent( + context!!, customMessage.customData.getString("sessionID") + ) } } @@ -1285,13 +1255,19 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic private fun turnOnLocation() { val builder = AlertDialog.Builder(requireContext()) builder.setTitle(getString(R.string.turn_on_gps)) - builder.setPositiveButton(getString(R.string.on)) { dialog, which -> startActivityForResult(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), UIKitConstants.RequestCode.LOCATION) }.setNegativeButton(getString(R.string.cancel)) { dialog, which -> dialog.dismiss() } + builder.setPositiveButton(getString(R.string.on)) { dialog, which -> + startActivityForResult( + Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), + UIKitConstants.RequestCode.LOCATION + ) + }.setNegativeButton(getString(R.string.cancel)) { dialog, which -> dialog.dismiss() } builder.create() builder.show() } private fun initLocation() { - fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(requireActivity()) + fusedLocationProviderClient = + LocationServices.getFusedLocationProviderClient(requireActivity()) locationListener = object : LocationListener { override fun onLocationChanged(location: Location) {} override fun onStatusChanged(provider: String, status: Int, extras: Bundle) {} @@ -1300,37 +1276,58 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } locationManager = context?.getSystemService(Context.LOCATION_SERVICE) as LocationManager try { - locationListener?.let { locationManager?.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DIST.toFloat(), it) } - locationListener?.let { locationManager?.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, MIN_DIST.toFloat(), it) } + locationListener?.let { + locationManager?.requestLocationUpdates( + LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DIST.toFloat(), it + ) + } + locationListener?.let { + locationManager?.requestLocationUpdates( + LocationManager.GPS_PROVIDER, MIN_TIME, MIN_DIST.toFloat(), it + ) + } } catch (e: java.lang.Exception) { e.printStackTrace() } } - override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + override fun onRequestPermissionsResult( + requestCode: Int, permissions: Array, grantResults: IntArray + ) { Log.d(TAG, "onRequestPermissionsResult: ") when (requestCode) { - UIKitConstants.RequestCode.CAMERA -> - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED && - grantResults[1] == PackageManager.PERMISSION_GRANTED) - startActivityForResult(MediaUtils.openCamera(requireActivity()), - UIKitConstants.RequestCode.CAMERA) - else showSnackBar(view?.findViewById(R.id.message_box), - resources.getString(R.string.grant_camera_permission)) + UIKitConstants.RequestCode.CAMERA -> if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) startActivityForResult( + MediaUtils.openCamera(requireActivity()), UIKitConstants.RequestCode.CAMERA + ) + else showSnackBar( + view?.findViewById(R.id.message_box), + resources.getString(R.string.grant_camera_permission) + ) + UIKitConstants.RequestCode.GALLERY -> if (grantResults[0] == PackageManager.PERMISSION_GRANTED) - startActivityForResult(MediaUtils.openGallery(requireActivity()), - UIKitConstants.RequestCode.GALLERY) - else showSnackBar(view?.findViewById(R.id.message_box), - resources.getString(R.string.grant_storage_permission)) - UIKitConstants.RequestCode.FILE -> - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) - startActivityForResult(MediaUtils.getFileIntent( - UIKitConstants.IntentStrings.EXTRA_MIME_DOC), UIKitConstants.RequestCode.FILE) - else showSnackBar(view?.findViewById(R.id.message_box), - resources.getString(R.string.grant_storage_permission)) - UIKitConstants.RequestCode.LOCATION -> - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + + MediaUtils.openGallery(requireActivity()) +// startActivityForResult( +// +// MediaUtils.openGallery(requireActivity()), UIKitConstants.RequestCode.GALLERY +// ) + else showSnackBar( + view?.findViewById(R.id.message_box), + resources.getString(R.string.grant_storage_permission) + ) + + UIKitConstants.RequestCode.FILE -> if (grantResults[0] == PackageManager.PERMISSION_GRANTED) startActivityForResult( + MediaUtils.getFileIntent( + UIKitConstants.IntentStrings.EXTRA_MIME_DOC + ), UIKitConstants.RequestCode.FILE + ) + else showSnackBar( + view?.findViewById(R.id.message_box), + resources.getString(R.string.grant_storage_permission) + ) + + UIKitConstants.RequestCode.LOCATION -> if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { initLocation() //locationManager = (LocationManager) Objects.requireNonNull(getContext()).getSystemService(Context.LOCATION_SERVICE); val provider = locationManager!!.isProviderEnabled(LocationManager.GPS_PROVIDER) @@ -1339,8 +1336,10 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } else { getLocation() } - } else - showSnackBar(view?.findViewById(R.id.message_box), resources.getString(R.string.grant_location_permission)) + } else showSnackBar( + view?.findViewById(R.id.message_box), + resources.getString(R.string.grant_location_permission) + ) } } @@ -1441,44 +1440,35 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic if (type != null) { if (type == CometChatConstants.RECEIVER_TYPE_USER) { messagesRequest = if (!FeatureRestriction.isHideDeletedMessagesEnabled()) { - MessagesRequestBuilder().setLimit(LIMIT).setUID(Id) - .hideReplies(true) - .setTypes(UIKitConstants.MessageRequest.messageTypesForUser) - .setCategories(UIKitConstants.MessageRequest.messageCategoriesForUser) - .build() + MessagesRequestBuilder().setLimit(LIMIT).setUID(Id).hideReplies(true) + .setTypes(UIKitConstants.MessageRequest.messageTypesForUser) + .setCategories(UIKitConstants.MessageRequest.messageCategoriesForUser) + .build() } else { - MessagesRequestBuilder().setLimit(LIMIT).setUID(Id) - .hideReplies(true) - .hideDeletedMessages(true) - .setTypes(UIKitConstants.MessageRequest.messageTypesForUser) - .setCategories(UIKitConstants.MessageRequest.messageCategoriesForUser) - .build() + MessagesRequestBuilder().setLimit(LIMIT).setUID(Id).hideReplies(true) + .hideDeletedMessages(true) + .setTypes(UIKitConstants.MessageRequest.messageTypesForUser) + .setCategories(UIKitConstants.MessageRequest.messageCategoriesForUser) + .build() } - } - else { + } else { messagesRequest = if (!FeatureRestriction.isHideDeletedMessagesEnabled()) { - MessagesRequestBuilder().setLimit(LIMIT).setGUID(Id) - .hideReplies(true) - .setTypes(UIKitConstants.MessageRequest.messageTypesForGroup) - .setCategories(UIKitConstants.MessageRequest.messageCategoriesForGroup) - .build() + MessagesRequestBuilder().setLimit(LIMIT).setGUID(Id).hideReplies(true) + .setTypes(UIKitConstants.MessageRequest.messageTypesForGroup) + .setCategories(UIKitConstants.MessageRequest.messageCategoriesForGroup) + .build() } else { - MessagesRequestBuilder().setLimit(LIMIT).setGUID(Id) - .hideReplies(true) - .hideDeletedMessages(true) - .hideMessagesFromBlockedUsers(true) - .setTypes(UIKitConstants.MessageRequest.messageTypesForGroup) - .setCategories(UIKitConstants.MessageRequest.messageCategoriesForGroup) - .build() + MessagesRequestBuilder().setLimit(LIMIT).setGUID(Id).hideReplies(true) + .hideDeletedMessages(true).hideMessagesFromBlockedUsers(true) + .setTypes(UIKitConstants.MessageRequest.messageTypesForGroup) + .setCategories(UIKitConstants.MessageRequest.messageCategoriesForGroup) + .build() } } } } messagesRequest?.fetchPrevious(object : CallbackListener>() { override fun onSuccess(baseMessages: List) { - for (i in baseMessages) { - Log.d(TAG, "onSuccess: basemsgtype " + i.type) - } isInProgress = false initMessageAdapter(baseMessages) if (baseMessages.isNotEmpty()) { @@ -1524,7 +1514,6 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic private fun setSmartReplyAdapter(replyList: List?) { rvSmartReply?.setSmartReplyList(replyList) - scrollToBottom() } /** @@ -1535,7 +1524,11 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic */ private fun initMessageAdapter(messageList: List) { if (messageAdapter == null) { - messageAdapter = activity?.let { MessageAdapter(it, messageList, CometChatMessageList::class.java.name) } + messageAdapter = activity?.let { + MessageAdapter( + it, messageList, CometChatMessageList::class.java.name + ) + } rvChatListView?.adapter = messageAdapter stickyHeaderDecoration = StickyHeaderDecoration(messageAdapter!!) rvChatListView?.addItemDecoration(stickyHeaderDecoration!!, 0) @@ -1585,7 +1578,7 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode,resultCode,data) + super.onActivityResult(requestCode, resultCode, data) Log.d(TAG, "onActivityResult: " + data?.data) when (requestCode) { UIKitConstants.RequestCode.AUDIO -> if (data != null) { @@ -1594,6 +1587,7 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic val cr = activity?.contentResolver sendMediaMessage(file, CometChatConstants.MESSAGE_TYPE_AUDIO) } + UIKitConstants.RequestCode.GALLERY -> if (data != null) { intentRequestCode = UIKitConstants.RequestCode.GALLERY Log.v(TAG, "onActivityResult:intent $data") @@ -1602,11 +1596,20 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic val mimeType = cr?.getType(data.data!!) Log.v(TAG, "onActivityResult:file $file") if (mimeType != null && mimeType.contains("image")) { - if (file.exists()) sendMediaMessage(file, CometChatConstants.MESSAGE_TYPE_IMAGE) else Snackbar.make(rvChatListView!!, R.string.file_not_exist, Snackbar.LENGTH_LONG).show() + if (file.exists()) sendMediaMessage( + file, CometChatConstants.MESSAGE_TYPE_IMAGE + ) else Snackbar.make( + rvChatListView!!, R.string.file_not_exist, Snackbar.LENGTH_LONG + ).show() } else { - if (file.exists()) sendMediaMessage(file, CometChatConstants.MESSAGE_TYPE_VIDEO) else Snackbar.make(rvChatListView!!, R.string.file_not_exist, Snackbar.LENGTH_LONG).show() + if (file.exists()) sendMediaMessage( + file, CometChatConstants.MESSAGE_TYPE_VIDEO + ) else Snackbar.make( + rvChatListView!!, R.string.file_not_exist, Snackbar.LENGTH_LONG + ).show() } } + UIKitConstants.RequestCode.CAMERA -> { intentRequestCode = UIKitConstants.RequestCode.CAMERA val file: File @@ -1615,20 +1618,32 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } else { File(MediaUtils.pictureImagePath) } - if (file.exists()) sendMediaMessage(file, CometChatConstants.MESSAGE_TYPE_IMAGE) else Snackbar.make(rvChatListView!!, R.string.file_not_exist, Snackbar.LENGTH_LONG).show() + if (file.exists()) sendMediaMessage( + file, CometChatConstants.MESSAGE_TYPE_IMAGE + ) else Snackbar.make( + rvChatListView!!, R.string.file_not_exist, Snackbar.LENGTH_LONG + ).show() } + UIKitConstants.RequestCode.FILE -> { intentRequestCode = UIKitConstants.RequestCode.FILE - if (data != null) sendMediaMessage(MediaUtils.getRealPath(activity, data.data), CometChatConstants.MESSAGE_TYPE_FILE) + if (data != null) sendMediaMessage( + MediaUtils.getRealPath(activity, data.data), + CometChatConstants.MESSAGE_TYPE_FILE + ) } + UIKitConstants.RequestCode.BLOCK_USER -> name = data?.getStringExtra("") UIKitConstants.RequestCode.LOCATION -> { - locationManager = context?.getSystemService(Context.LOCATION_SERVICE) as LocationManager + locationManager = + context?.getSystemService(Context.LOCATION_SERVICE) as LocationManager if (locationManager!!.isProviderEnabled(LocationManager.GPS_PROVIDER)) { - Toast.makeText(context, getString(R.string.gps_enabled), Toast.LENGTH_SHORT).show() + Toast.makeText(context, getString(R.string.gps_enabled), Toast.LENGTH_SHORT) + .show() getLocation() } else { - Toast.makeText(context, getString(R.string.gps_disabled), Toast.LENGTH_SHORT).show() + Toast.makeText(context, getString(R.string.gps_disabled), Toast.LENGTH_SHORT) + .show() } } } @@ -1646,7 +1661,10 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic // val progressDialog: ProgressDialog // progressDialog = ProgressDialog.show(context, "", "Sending Media Message") val mediaMessage: MediaMessage - mediaMessage = if (type.equals(CometChatConstants.RECEIVER_TYPE_USER, ignoreCase = true)) MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_USER) else MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_GROUP) + mediaMessage = + if (type.equals(CometChatConstants.RECEIVER_TYPE_USER, ignoreCase = true)) MediaMessage( + Id, file, filetype, CometChatConstants.RECEIVER_TYPE_USER + ) else MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_GROUP) val jsonObject = JSONObject() try { jsonObject.put("path", file.absolutePath) @@ -1657,6 +1675,7 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic mediaMessage.sender = loggedInUser mediaMessage.muid = System.currentTimeMillis().toString() mediaMessage.category = CometChatConstants.CATEGORY_MESSAGE + mediaMessage.sentAt = System.currentTimeMillis() / 1000 if (messageAdapter != null) { messageAdapter?.addMessage(mediaMessage) scrollToBottom() @@ -1698,11 +1717,13 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic isBlockedByMe = false blockUserLayout?.visibility = View.GONE avatarUrl = user.avatar - FeatureRestriction.isUserPresenceEnabled(object : FeatureRestriction.OnSuccessListener { + FeatureRestriction.isUserPresenceEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { - if (user.status == CometChatConstants.USER_STATUS_ONLINE) - tvStatus!!.setTextColor(activity!!.resources.getColor(R.color.colorPrimary)) + if (user.status == CometChatConstants.USER_STATUS_ONLINE) tvStatus!!.setTextColor( + activity!!.resources.getColor(R.color.colorPrimary) + ) status = user.status.toString() tvStatus!!.text = status } @@ -1740,7 +1761,7 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic private get() { getGroup(Id, object : CallbackListener() { override fun onSuccess(group: Group) { - Log.v(TAG, "getGroup: "+group.toString() ) + Log.v(TAG, "getGroup: " + group.toString()) if (activity != null) { name = group.name avatarUrl = group.icon @@ -1767,11 +1788,15 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic */ private fun sendMessage(message: String) { val textMessage: TextMessage - textMessage = if (type.equals(CometChatConstants.RECEIVER_TYPE_USER, ignoreCase = true)) TextMessage(Id, message, CometChatConstants.RECEIVER_TYPE_USER) else TextMessage(Id, message, CometChatConstants.RECEIVER_TYPE_GROUP) + textMessage = + if (type.equals(CometChatConstants.RECEIVER_TYPE_USER, ignoreCase = true)) TextMessage( + Id, message, CometChatConstants.RECEIVER_TYPE_USER + ) else TextMessage(Id, message, CometChatConstants.RECEIVER_TYPE_GROUP) sendTypingIndicator(true) textMessage.category = CometChatConstants.CATEGORY_MESSAGE textMessage.sender = loggedInUser textMessage.muid = System.currentTimeMillis().toString() + textMessage.sentAt = System.currentTimeMillis() / 1000 if (messageAdapter != null) { MediaUtils.playSendSound(context, R.raw.outgoing_message) messageAdapter?.addMessage(textMessage) @@ -1792,8 +1817,9 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic // ErrorMessagesUtils.cometChatErrorMessage(context, e.code) textMessage.sentAt = -1 if (e.code.equals("ERROR_INTERNET_UNAVAILABLE", ignoreCase = true)) { - ErrorMessagesUtils.showCometChatErrorDialog(context, - getString(R.string.please_check_your_internet_connection)) + ErrorMessagesUtils.showCometChatErrorDialog( + context, getString(R.string.please_check_your_internet_connection) + ) } else if (!e.code.equals("ERR_BLOCKED_BY_EXTENSION", ignoreCase = true)) { if (messageAdapter == null) { Log.e(TAG, "onError: MessageAdapter is null") @@ -1845,7 +1871,14 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic private fun editMessage(baseMessage: BaseMessage?, message: String) { isEdit = false val textMessage: TextMessage - textMessage = if (baseMessage?.receiverType.equals(CometChatConstants.RECEIVER_TYPE_USER, ignoreCase = true)) TextMessage(baseMessage!!.receiverUid, message, CometChatConstants.RECEIVER_TYPE_USER) else TextMessage(baseMessage!!.receiverUid, message, CometChatConstants.RECEIVER_TYPE_GROUP) + textMessage = if (baseMessage?.receiverType.equals( + CometChatConstants.RECEIVER_TYPE_USER, ignoreCase = true + ) + ) TextMessage( + baseMessage!!.receiverUid, message, CometChatConstants.RECEIVER_TYPE_USER + ) else TextMessage( + baseMessage!!.receiverUid, message, CometChatConstants.RECEIVER_TYPE_GROUP + ) sendTypingIndicator(true) textMessage.id = baseMessage.id editMessage(textMessage, object : CallbackListener() { @@ -1871,22 +1904,27 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic isReply = false try { var textMessage: TextMessage - textMessage = if (type.equals(CometChatConstants.RECEIVER_TYPE_USER, ignoreCase = true)) TextMessage(Id, message, CometChatConstants.RECEIVER_TYPE_USER) else TextMessage(Id!!, message, CometChatConstants.RECEIVER_TYPE_GROUP) + textMessage = if (type.equals( + CometChatConstants.RECEIVER_TYPE_USER, ignoreCase = true + ) + ) TextMessage(Id, message, CometChatConstants.RECEIVER_TYPE_USER) else TextMessage( + Id!!, message, CometChatConstants.RECEIVER_TYPE_GROUP + ) textMessage.category = CometChatConstants.CATEGORY_MESSAGE textMessage.sender = loggedInUser textMessage.muid = System.currentTimeMillis().toString() var jsonObject = JSONObject() var replyObject = JSONObject() - if (isReplyPrivately) - jsonObject.put("replyToMessage", baseMessage?.rawMessage) - else - jsonObject.put("reply-message", baseMessage?.rawMessage) + if (isReplyPrivately) jsonObject.put("replyToMessage", baseMessage?.rawMessage) + else jsonObject.put("reply-message", baseMessage?.rawMessage) textMessage.metadata = jsonObject sendTypingIndicator(true) if (messageAdapter != null) { - if (UIKitConstants.Sounds.enableMessageSounds) MediaUtils.playSendSound(context, R.raw.outgoing_message) + if (UIKitConstants.Sounds.enableMessageSounds) MediaUtils.playSendSound( + context, R.raw.outgoing_message + ) messageAdapter?.addMessage(textMessage) scrollToBottom() } @@ -1905,8 +1943,9 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic Log.e(TAG, "onError: " + e.message) textMessage.sentAt = -1 if (e.code.equals("ERROR_INTERNET_UNAVAILABLE", ignoreCase = true)) { - ErrorMessagesUtils.showCometChatErrorDialog(context, - getString(R.string.please_check_your_internet_connection)) + ErrorMessagesUtils.showCometChatErrorDialog( + context, getString(R.string.please_check_your_internet_connection) + ) } else if (!e.code.equals("ERR_BLOCKED_BY_EXTENSION", ignoreCase = true)) { if (messageAdapter == null) { Log.e(TAG, "onError: MessageAdapter is null") @@ -1949,22 +1988,28 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic super.onGroupMemberLeft(action, leftUser, leftGroup) Log.d(TAG, "onGroupMemberLeft: " + leftUser.name) if (leftGroup.guid == Id) { - if (memberNames != null) tvStatus?.text = memberNames?.replace("," + leftUser.name, "") + if (memberNames != null) tvStatus?.text = + memberNames?.replace("," + leftUser.name, "") } onMessageReceived(action) } - override fun onGroupMemberKicked(action: Action, kickedUser: User, kickedBy: User, kickedFrom: Group) { + override fun onGroupMemberKicked( + action: Action, kickedUser: User, kickedBy: User, kickedFrom: Group + ) { super.onGroupMemberKicked(action, kickedUser, kickedBy, kickedFrom) Log.d(TAG, "onGroupMemberKicked: " + kickedUser.name) if (kickedUser.uid == getLoggedInUser().uid) { if (activity != null) activity?.finish() } - if (kickedFrom.guid == Id) tvStatus?.text = memberNames?.replace("," + kickedUser.name, "") + if (kickedFrom.guid == Id) tvStatus?.text = + memberNames?.replace("," + kickedUser.name, "") onMessageReceived(action) } - override fun onGroupMemberBanned(action: Action, bannedUser: User, bannedBy: User, bannedFrom: Group) { + override fun onGroupMemberBanned( + action: Action, bannedUser: User, bannedBy: User, bannedFrom: Group + ) { if (bannedUser.uid == getLoggedInUser().uid) { if (activity != null) { activity?.onBackPressed() @@ -1974,15 +2019,26 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic onMessageReceived(action) } - override fun onGroupMemberUnbanned(action: Action, unbannedUser: User, unbannedBy: User, unbannedFrom: Group) { + override fun onGroupMemberUnbanned( + action: Action, unbannedUser: User, unbannedBy: User, unbannedFrom: Group + ) { onMessageReceived(action) } - override fun onGroupMemberScopeChanged(action: Action, updatedBy: User, updatedUser: User, scopeChangedTo: String, scopeChangedFrom: String, group: Group) { + override fun onGroupMemberScopeChanged( + action: Action, + updatedBy: User, + updatedUser: User, + scopeChangedTo: String, + scopeChangedFrom: String, + group: Group + ) { onMessageReceived(action) } - override fun onMemberAddedToGroup(action: Action, addedby: User, userAdded: User, addedTo: Group) { + override fun onMemberAddedToGroup( + action: Action, addedby: User, userAdded: User, addedTo: Group + ) { if (addedTo.guid == Id) tvStatus?.text = memberNames + "," + userAdded.name onMessageReceived(action) } @@ -2008,7 +2064,9 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic override fun onUserOffline(user: User) { Log.d(TAG, "onUserOffline: $user") if (user.uid == Id) { - if (Utils.isDarkMode(context!!)) tvStatus?.setTextColor(resources.getColor(R.color.textColorWhite)) else tvStatus?.setTextColor(resources.getColor(android.R.color.black)) + if (Utils.isDarkMode(context!!)) tvStatus?.setTextColor(resources.getColor(R.color.textColorWhite)) else tvStatus?.setTextColor( + resources.getColor(android.R.color.black) + ) tvStatus?.text = user.status } } @@ -2022,7 +2080,9 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic * @param baseMessage is object of BaseMessage.class. It is message which is been marked as read. */ private fun markMessageAsRead(baseMessage: BaseMessage) { - if (type == CometChatConstants.RECEIVER_TYPE_USER) markAsRead(baseMessage.id, baseMessage.sender.uid, baseMessage.receiverType) else markAsRead(baseMessage.id, baseMessage.receiverUid, baseMessage.receiverType) + if (type == CometChatConstants.RECEIVER_TYPE_USER) markAsRead( + baseMessage.id, baseMessage.sender.uid, baseMessage.receiverType + ) else markAsRead(baseMessage.id, baseMessage.receiverUid, baseMessage.receiverType) } /** @@ -2086,18 +2146,18 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } private fun setTransientMessage(transientMessage: TransientMessage?) { - Log.e(TAG, "setTransientMessage: "+transientMessage) - Log.e(TAG, "setTransientMessage: "+Id) + Log.e(TAG, "setTransientMessage: " + transientMessage) + Log.e(TAG, "setTransientMessage: " + Id) - if (transientMessage?.data != null) { - try { - val reaction = transientMessage.data.getString("reaction") - val type = transientMessage.data.getString("type") - if (reaction.equals("heart") && type.equals("live_reaction")) setReaction() - } catch (e: java.lang.Exception) { - e.printStackTrace() - } + if (transientMessage?.data != null) { + try { + val reaction = transientMessage.data.getString("reaction") + val type = transientMessage.data.getString("type") + if (reaction.equals("heart") && type.equals("live_reaction")) setReaction() + } catch (e: java.lang.Exception) { + e.printStackTrace() } + } } @@ -2105,30 +2165,43 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic if (messageAdapter != null) { if (messageReceipt.receivertype == CometChatConstants.RECEIVER_TYPE_USER) { if (Id != null && messageReceipt.sender.uid == Id) { - if (messageReceipt.receiptType == MessageReceipt.RECEIPT_TYPE_DELIVERED) messageAdapter?.setDeliveryReceipts(messageReceipt) else messageAdapter?.setReadReceipts(messageReceipt) + if (messageReceipt.receiptType == MessageReceipt.RECEIPT_TYPE_DELIVERED) messageAdapter?.setDeliveryReceipts( + messageReceipt + ) else messageAdapter?.setReadReceipts(messageReceipt) } } } } private fun setTypingIndicator(typingIndicator: TypingIndicator, isShow: Boolean) { - if (typingIndicator.receiverType.equals(CometChatConstants.RECEIVER_TYPE_USER, ignoreCase = true)) { + if (typingIndicator.receiverType.equals( + CometChatConstants.RECEIVER_TYPE_USER, ignoreCase = true + ) + ) { Log.v(TAG, "onTypingStarted: $typingIndicator") - if (Id != null && Id.equals(typingIndicator.sender.uid, ignoreCase = true)) typingIndicator(typingIndicator, isShow) + if (Id != null && Id.equals( + typingIndicator.sender.uid, ignoreCase = true + ) + ) typingIndicator(typingIndicator, isShow) } else { - if (Id != null && Id.equals(typingIndicator.receiverId, ignoreCase = true)) typingIndicator(typingIndicator, isShow) + if (Id != null && Id.equals( + typingIndicator.receiverId, ignoreCase = true + ) + ) typingIndicator(typingIndicator, isShow) } } private fun onMessageReceived(message: BaseMessage) { MediaUtils.playSendSound(context, R.raw.incoming_message) if (message.receiverType == CometChatConstants.RECEIVER_TYPE_USER) { - if (Id != null && Id.equals(message.sender.uid, ignoreCase = true)) { + if (Id != null && Id.equals(message.sender.uid, ignoreCase = true)) { + setMessage(message) + } else if (Id != null && Id.equals( + message.receiverUid, ignoreCase = true + ) && message.sender.uid.equals(loggedInUser.uid, ignoreCase = true) + ) { setMessage(message) } - else if (Id != null && Id.equals(message.receiverUid, ignoreCase = true) && message.sender.uid.equals(loggedInUser.uid, ignoreCase = true)) { - setMessage(message) - } } else { if (Id != null && Id.equals(message.receiverUid, ignoreCase = true)) { setMessage(message) @@ -2186,39 +2259,43 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic if (show) { if (typingIndicator.receiverType == CometChatConstants.RECEIVER_TYPE_USER) { // if (typingIndicator.metadata == null) { - FeatureRestriction.isTypingIndicatorsEnabled(object : FeatureRestriction.OnSuccessListener{ - override fun onSuccess(p0: Boolean) { - if (p0) { - tvStatus?.visibility = View.VISIBLE - tvStatus?.text = "is Typing..." - } + FeatureRestriction.isTypingIndicatorsEnabled(object : + FeatureRestriction.OnSuccessListener { + override fun onSuccess(p0: Boolean) { + if (p0) { + tvStatus?.visibility = View.VISIBLE + tvStatus?.text = "is Typing..." } + } - }) + }) // } // else // setLiveReaction() } else { // if (typingIndicator.metadata == null) { - FeatureRestriction.isTypingIndicatorsEnabled(object : FeatureRestriction.OnSuccessListener{ - override fun onSuccess(p0: Boolean) { - if (p0) { - tvStatus?.visibility = View.VISIBLE - tvStatus?.text = typingIndicator.sender.name + " is Typing..." - } + FeatureRestriction.isTypingIndicatorsEnabled(object : + FeatureRestriction.OnSuccessListener { + override fun onSuccess(p0: Boolean) { + if (p0) { + tvStatus?.visibility = View.VISIBLE + tvStatus?.text = typingIndicator.sender.name + " is Typing..." } + } - }) + }) // } // else // setLiveReaction() } } else { - if (typingIndicator.receiverType == CometChatConstants.RECEIVER_TYPE_USER){ + if (typingIndicator.receiverType == CometChatConstants.RECEIVER_TYPE_USER) { if (typingIndicator.metadata == null) { - FeatureRestriction.isUserPresenceEnabled(object : FeatureRestriction.OnSuccessListener { + FeatureRestriction.isUserPresenceEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { - if (p0) tvStatus!!.text = status else tvStatus?.visibility = View.GONE + if (p0) tvStatus!!.text = status else tvStatus?.visibility = + View.GONE } }) } @@ -2235,10 +2312,8 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic // } // }) // } - } - else{ - if (typingIndicator.metadata == null) - tvStatus?.text = memberNames + } else { + if (typingIndicator.metadata == null) tvStatus?.text = memberNames // else{ // val animator = ObjectAnimator.ofFloat(liveReactionLayout!!, "alpha", 0.2f) // animator.duration = 700 @@ -2291,14 +2366,10 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } override fun onResume() { -// onCloseAction() super.onResume() - Log.d(TAG, "onResume: ") - Log.v(TAG, "onResume: " + intentRequestCode) checkOnGoingCall() stickyHeaderDecoration?.let { this.rvChatListView?.removeItemDecoration(it) } - if (!(intentRequestCode == UIKitConstants.RequestCode.AUDIO || intentRequestCode == UIKitConstants.RequestCode.GALLERY || - intentRequestCode == UIKitConstants.RequestCode.FILE || intentRequestCode == UIKitConstants.RequestCode.CAMERA)) { + if (!(intentRequestCode == UIKitConstants.RequestCode.AUDIO || intentRequestCode == UIKitConstants.RequestCode.GALLERY || intentRequestCode == UIKitConstants.RequestCode.FILE || intentRequestCode == UIKitConstants.RequestCode.CAMERA)) { messageAdapter = null messagesRequest = null fetchMessage() @@ -2309,7 +2380,8 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic if (type != null) { if (type == CometChatConstants.RECEIVER_TYPE_USER) { - FeatureRestriction.isUserPresenceEnabled(object : FeatureRestriction.OnSuccessListener { + FeatureRestriction.isUserPresenceEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { addUserListener() @@ -2319,8 +2391,7 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic }) Thread(Runnable { user }).start() } else { - if (!FeatureRestriction.isGroupActionMessagesEnabled()) - addGroupListener() + if (!FeatureRestriction.isGroupActionMessagesEnabled()) addGroupListener() Thread(Runnable { group }).start() Thread(Runnable { member }).start() } @@ -2334,7 +2405,9 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic userAvatar?.visibility = View.VISIBLE ivCloseMessageAction?.visibility = View.GONE // ivCopyMessageAction?.visibility = View.GONE - if (activity != null && (activity as AppCompatActivity?)?.supportActionBar != null) (activity as AppCompatActivity?)?.supportActionBar?.setDisplayHomeAsUpEnabled(true) + if (activity != null && (activity as AppCompatActivity?)?.supportActionBar != null) (activity as AppCompatActivity?)?.supportActionBar?.setDisplayHomeAsUpEnabled( + true + ) } override fun onAttach(context: Context) { @@ -2425,8 +2498,7 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic isReply = false baseMessage = null replyMessageLayout?.visibility = View.GONE - } - else if (id == R.id.btn_unblock_user) { + } else if (id == R.id.btn_unblock_user) { unblockUser() } else if (id == R.id.iv_user_info) { if (type == CometChatConstants.RECEIVER_TYPE_USER) { @@ -2513,8 +2585,7 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic if (basemessage != null && basemessage.sender != null) { if (basemessage !is Action && basemessage.deletedAt == 0L) { baseMessage = basemessage - if (basemessage.replyCount > 0) - threadVisible = false + if (basemessage.replyCount > 0) threadVisible = false else { threadVisible } @@ -2525,7 +2596,8 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } else { editVisible = false // forwardVisible = true - deleteVisible = if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) else false + deleteVisible = + if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) else false } } } @@ -2536,24 +2608,28 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic if (basemessage != null && basemessage.sender != null) { if (basemessage !is Action && basemessage.deletedAt == 0L) { baseMessage = basemessage - if (basemessage.replyCount > 0) - threadVisible = false + if (basemessage.replyCount > 0) threadVisible = false else { threadVisible } copyVisible = false - if (baseMessage?.type.equals(CometChatConstants.MESSAGE_TYPE_AUDIO,true) || - baseMessage?.type.equals(CometChatConstants.MESSAGE_TYPE_VIDEO,true) || - baseMessage?.type.equals(CometChatConstants.MESSAGE_TYPE_FILE,true)) - shareVisible = false + if (baseMessage?.type.equals( + CometChatConstants.MESSAGE_TYPE_AUDIO, + true + ) || baseMessage?.type.equals( + CometChatConstants.MESSAGE_TYPE_VIDEO, + true + ) || baseMessage?.type.equals(CometChatConstants.MESSAGE_TYPE_FILE, true) + ) shareVisible = false if (basemessage.sender.uid == getLoggedInUser().uid) { deleteVisible = FeatureRestriction.isDeleteMessageEnabled() editVisible = false // forwardVisible = true } else { - deleteVisible = if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) else false + deleteVisible = + if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) else false // forwardVisible = true editVisible = false } @@ -2565,8 +2641,7 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic if (basemessage != null && basemessage.sender != null) { if (basemessage !is Action && basemessage.deletedAt == 0L) { baseMessage = basemessage - if (basemessage.replyCount > 0) - threadVisible = false + if (basemessage.replyCount > 0) threadVisible = false else { threadVisible } @@ -2578,32 +2653,33 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic deleteVisible = FeatureRestriction.isDeleteMessageEnabled() editVisible = false } else { - deleteVisible = if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) else false + deleteVisible = + if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) else false editVisible = false } } } } - if (stickerMessageList.size == 1){ + if (stickerMessageList.size == 1) { shareVisible = false forwardVisible = false editVisible = false copyVisible = false replyVisible val basemessage = stickerMessageList[0] - if (basemessage != null && basemessage.sender != null){ - if (basemessage !is Action && basemessage.deletedAt == 0L){ + if (basemessage != null && basemessage.sender != null) { + if (basemessage !is Action && basemessage.deletedAt == 0L) { baseMessage = basemessage - if (basemessage.replyCount > 0) - threadVisible = false + if (basemessage.replyCount > 0) threadVisible = false else { threadVisible } - if (basemessage.sender.uid == loggedInUser.uid){ + if (basemessage.sender.uid == loggedInUser.uid) { deleteVisible = FeatureRestriction.isDeleteMessageEnabled() - } else{ - deleteVisible = if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) else false + } else { + deleteVisible = + if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) else false } @@ -2621,16 +2697,16 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic if (basemessage != null && basemessage.sender != null) { if (basemessage.deletedAt == 0L) { baseMessage = basemessage - if (basemessage.replyCount > 0) - threadVisible = false + if (basemessage.replyCount > 0) threadVisible = false else { threadVisible } - if (basemessage.sender.uid == getLoggedInUser().uid) - deleteVisible = FeatureRestriction.isDeleteMessageEnabled() + if (basemessage.sender.uid == getLoggedInUser().uid) deleteVisible = + FeatureRestriction.isDeleteMessageEnabled() else { - if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN|| loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) { - deleteVisible = (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) + if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) { + deleteVisible = + (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) } else { deleteVisible = false } @@ -2648,16 +2724,16 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic if (basemessage != null && basemessage.sender != null) { if (basemessage.deletedAt == 0L) { baseMessage = basemessage - if (basemessage.replyCount > 0) - threadVisible = false + if (basemessage.replyCount > 0) threadVisible = false else { threadVisible } - if (basemessage.sender.uid == getLoggedInUser().uid) - deleteVisible = FeatureRestriction.isDeleteMessageEnabled() + if (basemessage.sender.uid == getLoggedInUser().uid) deleteVisible = + FeatureRestriction.isDeleteMessageEnabled() else { if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) { - deleteVisible = (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) + deleteVisible = + (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) } else { deleteVisible = false } @@ -2678,11 +2754,12 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic if (basemessage != null && basemessage.sender != null) { if (basemessage.deletedAt == 0L) { baseMessage = basemessage - if (basemessage.sender.uid == getLoggedInUser().uid) - deleteVisible = FeatureRestriction.isDeleteMessageEnabled() + if (basemessage.sender.uid == getLoggedInUser().uid) deleteVisible = + FeatureRestriction.isDeleteMessageEnabled() else { if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) { - deleteVisible = (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) + deleteVisible = + (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) } else { deleteVisible = false } @@ -2700,19 +2777,19 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic if (basemessage.sender != null) { if (basemessage !is Action && basemessage.deletedAt == 0L) { baseMessage = basemessage - if (basemessage.replyCount > 0) - threadVisible = false + if (basemessage.replyCount > 0) threadVisible = false else { threadVisible } // threadVisible = if (basemessage.replyCount > 0) false else FeatureRestriction.isThreadedMessagesEnabled() - deleteVisible = if (basemessage.sender.uid == getLoggedInUser().uid) FeatureRestriction.isDeleteMessageEnabled() else { - if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) { - (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) - } else { - false + deleteVisible = + if (basemessage.sender.uid == getLoggedInUser().uid) FeatureRestriction.isDeleteMessageEnabled() else { + if (loggedInUserScope != null && (loggedInUserScope == CometChatConstants.SCOPE_ADMIN || loggedInUserScope == CometChatConstants.SCOPE_MODERATOR)) { + (FeatureRestriction.isDeleteMessageEnabled() || isDeleteMemberMessageVisible) + } else { + false + } } - } } } } @@ -2762,10 +2839,12 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic bundle.putString("type", CometChatMessageListActivity::class.java.name) cometChatMessageActions?.arguments = bundle - if (editVisible || copyVisible || threadVisible || shareVisible || deleteVisible - || replyVisible || forwardVisible || reactionVisible || messageInfoVisible || sendMessagePrivatelyVisible || replyPrivatelyVisible) - cometChatMessageActions?.show(requireFragmentManager(), cometChatMessageActions?.tag) - cometChatMessageActions?.setMessageActionListener(object : CometChatMessageActions.MessageActionListener { + if (editVisible || copyVisible || threadVisible || shareVisible || deleteVisible || replyVisible || forwardVisible || reactionVisible || messageInfoVisible || sendMessagePrivatelyVisible || replyPrivatelyVisible) cometChatMessageActions?.show( + requireFragmentManager(), + cometChatMessageActions?.tag + ) + cometChatMessageActions?.setMessageActionListener(object : + CometChatMessageActions.MessageActionListener { override fun onEditMessageClick() { if (baseMessage != null && baseMessage?.type == CometChatConstants.MESSAGE_TYPE_TEXT) { @@ -2808,14 +2887,18 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic var message = "" for (bMessage in baseMessages!!) { if (bMessage.deletedAt == 0L && bMessage is TextMessage) { - message = message + "[" + Utils.getLastMessageDate(bMessage.getSentAt()) + "] " + bMessage.getSender().name + ": " + bMessage.text + message = + message + "[" + Utils.getLastMessageDate(bMessage.getSentAt()) + "] " + bMessage.getSender().name + ": " + bMessage.text } } Log.v(TAG, "onCopy: $message") - val clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clipboardManager = + context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val clipData = ClipData.newPlainText("MessageAdapter", message) clipboardManager.setPrimaryClip(clipData) - Toast.makeText(context, resources.getString(R.string.text_copied), Toast.LENGTH_LONG).show() + Toast.makeText( + context, resources.getString(R.string.text_copied), Toast.LENGTH_LONG + ).show() if (messageAdapter != null) { messageAdapter?.clearLongClickSelectedItem() messageAdapter?.notifyDataSetChanged() @@ -2832,45 +2915,77 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage?.type) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage?.sentAt) if (baseMessage?.type == CometChatConstants.MESSAGE_TYPE_TEXT) { - intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getProfanityFilter(baseMessage!!)) + intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + Extensions.getProfanityFilter(baseMessage!!) + ) } else if (baseMessage?.category == CometChatConstants.CATEGORY_CUSTOM) { - if ((baseMessage as CustomMessage).customData != null) - intent.putExtra(UIKitConstants.IntentStrings.CUSTOM_MESSAGE, - (baseMessage as CustomMessage).customData.toString()) + if ((baseMessage as CustomMessage).customData != null) intent.putExtra( + UIKitConstants.IntentStrings.CUSTOM_MESSAGE, + (baseMessage as CustomMessage).customData.toString() + ) if (baseMessage?.type == UIKitConstants.IntentStrings.LOCATION) { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, - UIKitConstants.IntentStrings.LOCATION) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.LOCATION + ) } else if (baseMessage?.type == UIKitConstants.IntentStrings.STICKERS) { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.STICKERS) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.STICKERS + ) } else if (baseMessage?.type == UIKitConstants.IntentStrings.WHITEBOARD) { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, - UIKitConstants.IntentStrings.WHITEBOARD) - intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWhiteBoardUrl(baseMessage!!)) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.WHITEBOARD + ) + intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + Extensions.getWhiteBoardUrl(baseMessage!!) + ) } else if (baseMessage?.type == UIKitConstants.IntentStrings.WRITEBOARD) { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, - UIKitConstants.IntentStrings.WRITEBOARD) - intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWriteBoardUrl(baseMessage!!)) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.WRITEBOARD + ) + intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + Extensions.getWriteBoardUrl(baseMessage!!) + ) } else if (baseMessage?.type == UIKitConstants.IntentStrings.MEETING) { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, - UIKitConstants.IntentStrings.MEETING) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.MEETING + ) } else { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, - UIKitConstants.IntentStrings.POLLS) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.POLLS + ) } } else { - FeatureRestriction.isImageModerationEnabled(object : FeatureRestriction.OnSuccessListener{ + FeatureRestriction.isImageModerationEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { isImageNotSafe = Extensions.getImageModeration(context, baseMessage) } }) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, - (baseMessage as MediaMessage).attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, - (baseMessage as MediaMessage).attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, - (baseMessage as MediaMessage).attachment.fileSize) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, - (baseMessage as MediaMessage).attachment.fileExtension) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + (baseMessage as MediaMessage).attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + (baseMessage as MediaMessage).attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + (baseMessage as MediaMessage).attachment.fileSize + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + (baseMessage as MediaMessage).attachment.fileExtension + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage?.sentAt) intent.putExtra(UIKitConstants.IntentStrings.IMAGE_MODERATION, isImageNotSafe) } @@ -2898,7 +3013,9 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage?.sender?.avatar) intent.putExtra(UIKitConstants.IntentStrings.STATUS, baseMessage?.sender?.status) intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage?.sender?.name) - intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER) + intent.putExtra( + UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER + ) startActivity(intent) activity?.finish() } @@ -2907,20 +3024,20 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic val intent = Intent(context, CometChatMessageListActivity::class.java) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage?.sender?.uid) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage?.sender?.avatar) - intent.putExtra(UIKitConstants.IntentStrings.STATUS, baseMessage?.sender?.status) + intent.putExtra(UIKitConstants.IntentStrings.STATUS, baseMessage?.sender?.status) intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage?.sender?.name) intent.putExtra("isReply", true) intent.putExtra("baseMessageMetadata", baseMessage?.rawMessage.toString()) - intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER) + intent.putExtra( + UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER + ) startActivity(intent) activity?.finish() } }) - - // val textMessageList: MutableList = ArrayList() // val mediaMessageList: MutableList = ArrayList() // for (baseMessage in baseMessagesList!!) { @@ -3003,18 +3120,22 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic e.printStackTrace() } - callExtension("reactions", "POST", "/v1/react", body, - object : CallbackListener() { - override fun onSuccess(responseObject: JSONObject) { - Log.v(TAG, "onSuccess: $responseObject") - // ReactionModel added successfully. - } + callExtension( + "reactions", + "POST", + "/v1/react", + body, + object : CallbackListener() { + override fun onSuccess(responseObject: JSONObject) { + Log.v(TAG, "onSuccess: $responseObject") + // ReactionModel added successfully. + } - override fun onError(e: CometChatException) { - Toast.makeText(context, e.message, Toast.LENGTH_LONG).show() - Log.e(TAG, "onError: " + e.code + e.message + e.details) - } - }) + override fun onError(e: CometChatException) { + Toast.makeText(context, e.message, Toast.LENGTH_LONG).show() + Log.e(TAG, "onError: " + e.code + e.message + e.details) + } + }) // var body = JSONObject() // try { // body.put("msgId", baseMessage!!.id) @@ -3045,41 +3166,102 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage?.id) intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage?.replyCount) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage?.sentAt) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage!!)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage!!) + ) if (baseMessage?.category.equals(CometChatConstants.CATEGORY_MESSAGE, ignoreCase = true)) { intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage?.type) - if (baseMessage?.type == CometChatConstants.MESSAGE_TYPE_TEXT) intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getProfanityFilter(baseMessage!!)) else { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, (baseMessage as MediaMessage).attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, (baseMessage as MediaMessage).attachment.fileExtension) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, (baseMessage as MediaMessage).attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, (baseMessage as MediaMessage).attachment.fileSize) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_MIME_TYPE, (baseMessage as MediaMessage).attachment.fileMimeType) + if (baseMessage?.type == CometChatConstants.MESSAGE_TYPE_TEXT) intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + Extensions.getProfanityFilter(baseMessage!!) + ) else { + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + (baseMessage as MediaMessage).attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + (baseMessage as MediaMessage).attachment.fileExtension + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + (baseMessage as MediaMessage).attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + (baseMessage as MediaMessage).attachment.fileSize + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_MIME_TYPE, + (baseMessage as MediaMessage).attachment.fileMimeType + ) } } else { try { if (baseMessage?.type == UIKitConstants.IntentStrings.LOCATION) { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.LOCATION) - intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LATITUDE, - (baseMessage as CustomMessage).customData.getDouble("latitude")) - intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LONGITUDE, - (baseMessage as CustomMessage).customData.getDouble("longitude")) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.LOCATION + ) + intent.putExtra( + UIKitConstants.IntentStrings.LOCATION_LATITUDE, + (baseMessage as CustomMessage).customData.getDouble("latitude") + ) + intent.putExtra( + UIKitConstants.IntentStrings.LOCATION_LONGITUDE, + (baseMessage as CustomMessage).customData.getDouble("longitude") + ) } else if (baseMessage?.type == UIKitConstants.IntentStrings.STICKERS) { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, (baseMessage as CustomMessage).customData.getString("name")) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, (baseMessage as CustomMessage).customData.getString("url")) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.STICKERS) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + (baseMessage as CustomMessage).customData.getString("name") + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + (baseMessage as CustomMessage).customData.getString("url") + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.STICKERS + ) } else if (baseMessage?.type == UIKitConstants.IntentStrings.WHITEBOARD) { - intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWhiteBoardUrl(baseMessage!!)) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.WHITEBOARD) + intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + Extensions.getWhiteBoardUrl(baseMessage!!) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.WHITEBOARD + ) } else if (baseMessage?.type == UIKitConstants.IntentStrings.WRITEBOARD) { - intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWriteBoardUrl(baseMessage!!)) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.WRITEBOARD) + intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + Extensions.getWriteBoardUrl(baseMessage!!) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.WRITEBOARD + ) } else if (baseMessage?.type == UIKitConstants.IntentStrings.POLLS) { val options = (baseMessage as CustomMessage).customData.getJSONObject("options") - intent.putExtra(UIKitConstants.IntentStrings.POLL_QUESTION, (baseMessage as CustomMessage).customData.getString("question")) + intent.putExtra( + UIKitConstants.IntentStrings.POLL_QUESTION, + (baseMessage as CustomMessage).customData.getString("question") + ) intent.putExtra(UIKitConstants.IntentStrings.POLL_OPTION, options.toString()) - intent.putExtra(UIKitConstants.IntentStrings.POLL_VOTE_COUNT, Extensions.getVoteCount(baseMessage!!)) - intent.putExtra(UIKitConstants.IntentStrings.POLL_RESULT, Extensions.getVoterInfo(baseMessage!!, options.length())) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.POLLS) + intent.putExtra( + UIKitConstants.IntentStrings.POLL_VOTE_COUNT, + Extensions.getVoteCount(baseMessage!!) + ) + intent.putExtra( + UIKitConstants.IntentStrings.POLL_RESULT, + Extensions.getVoterInfo(baseMessage!!, options.length()) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.POLLS + ) } } catch (e: java.lang.Exception) { Log.e(TAG, "startThreadActivityError: " + e.message) @@ -3098,29 +3280,55 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic private fun startForwardMessageActivity() { val intent = Intent(context, CometChatForwardMessageActivity::class.java) if (baseMessage?.category == CometChatConstants.CATEGORY_MESSAGE) { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, CometChatConstants.CATEGORY_MESSAGE) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, CometChatConstants.CATEGORY_MESSAGE + ) if (baseMessage?.type == CometChatConstants.MESSAGE_TYPE_TEXT) { - intent.putExtra(CometChatConstants.MESSAGE_TYPE_TEXT, (baseMessage as TextMessage).text) - intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.MESSAGE_TYPE_TEXT) - } else if (baseMessage?.type == CometChatConstants.MESSAGE_TYPE_IMAGE || - baseMessage?.type == CometChatConstants.MESSAGE_TYPE_AUDIO || - baseMessage?.type == CometChatConstants.MESSAGE_TYPE_VIDEO || - baseMessage?.type == CometChatConstants.MESSAGE_TYPE_FILE) { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, (baseMessage as MediaMessage).attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, (baseMessage as MediaMessage).attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_MIME_TYPE, (baseMessage as MediaMessage).attachment.fileMimeType) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, (baseMessage as MediaMessage).attachment.fileExtension) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, (baseMessage as MediaMessage).attachment.fileSize) + intent.putExtra( + CometChatConstants.MESSAGE_TYPE_TEXT, (baseMessage as TextMessage).text + ) + intent.putExtra( + UIKitConstants.IntentStrings.TYPE, CometChatConstants.MESSAGE_TYPE_TEXT + ) + } else if (baseMessage?.type == CometChatConstants.MESSAGE_TYPE_IMAGE || baseMessage?.type == CometChatConstants.MESSAGE_TYPE_AUDIO || baseMessage?.type == CometChatConstants.MESSAGE_TYPE_VIDEO || baseMessage?.type == CometChatConstants.MESSAGE_TYPE_FILE) { + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + (baseMessage as MediaMessage).attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + (baseMessage as MediaMessage).attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_MIME_TYPE, + (baseMessage as MediaMessage).attachment.fileMimeType + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + (baseMessage as MediaMessage).attachment.fileExtension + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + (baseMessage as MediaMessage).attachment.fileSize + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage?.type) } } else if (baseMessage?.category == CometChatConstants.CATEGORY_CUSTOM) { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, CometChatConstants.CATEGORY_CUSTOM) - intent.putExtra(UIKitConstants.IntentStrings.TYPE, UIKitConstants.IntentStrings.LOCATION) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, CometChatConstants.CATEGORY_CUSTOM + ) + intent.putExtra( + UIKitConstants.IntentStrings.TYPE, UIKitConstants.IntentStrings.LOCATION + ) try { - intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LATITUDE, - (baseMessage as CustomMessage).customData.getDouble("latitude")) - intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LONGITUDE, - (baseMessage as CustomMessage).customData.getDouble("longitude")) + intent.putExtra( + UIKitConstants.IntentStrings.LOCATION_LATITUDE, + (baseMessage as CustomMessage).customData.getDouble("latitude") + ) + intent.putExtra( + UIKitConstants.IntentStrings.LOCATION_LONGITUDE, + (baseMessage as CustomMessage).customData.getDouble("longitude") + ) } catch (e: java.lang.Exception) { Log.e(TAG, "startForwardMessageActivityError: " + e.message) } @@ -3141,21 +3349,30 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic shareIntent.putExtra(Intent.EXTRA_TITLE, resources.getString(R.string.app_name)) shareIntent.putExtra(Intent.EXTRA_TEXT, (baseMessage as TextMessage).text) shareIntent.type = "text/plain" - val intent = Intent.createChooser(shareIntent, resources.getString(R.string.share_message)) + val intent = + Intent.createChooser(shareIntent, resources.getString(R.string.share_message)) startActivity(intent) } else if (baseMessage != null && baseMessage?.type == CometChatConstants.MESSAGE_TYPE_IMAGE) { val mediaName = (baseMessage as MediaMessage).attachment.fileName - Glide.with(requireContext()).asBitmap().load((baseMessage as MediaMessage).attachment.fileUrl).into(object : SimpleTarget() { - override fun onResourceReady(resource: Bitmap, transition: Transition?) { - val path = MediaStore.Images.Media.insertImage(context?.contentResolver, resource, mediaName, null) - val shareIntent = Intent() - shareIntent.action = Intent.ACTION_SEND - shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path)) - shareIntent.type = (baseMessage as MediaMessage).attachment.fileMimeType - val intent = Intent.createChooser(shareIntent, resources.getString(R.string.share_message)) - startActivity(intent) - } - }) + Glide.with(requireContext()).asBitmap() + .load((baseMessage as MediaMessage).attachment.fileUrl) + .into(object : SimpleTarget() { + override fun onResourceReady( + resource: Bitmap, transition: Transition? + ) { + val path = MediaStore.Images.Media.insertImage( + context?.contentResolver, resource, mediaName, null + ) + val shareIntent = Intent() + shareIntent.action = Intent.ACTION_SEND + shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path)) + shareIntent.type = (baseMessage as MediaMessage).attachment.fileMimeType + val intent = Intent.createChooser( + shareIntent, resources.getString(R.string.share_message) + ) + startActivity(intent) + } + }) } } @@ -3170,29 +3387,42 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic replyMessage?.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) } else if (baseMessage?.type == CometChatConstants.MESSAGE_TYPE_IMAGE) { replyMessage?.text = resources.getString(R.string.shared_a_image) - Glide.with(requireContext()).load((baseMessage as MediaMessage).attachment.fileUrl).into(replyMedia!!) + Glide.with(requireContext()).load((baseMessage as MediaMessage).attachment.fileUrl) + .into(replyMedia!!) replyMessage?.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) } else if (baseMessage?.type == CometChatConstants.MESSAGE_TYPE_AUDIO) { - val messageStr = String.format(resources.getString(R.string.shared_a_audio), - Utils.getFileSize((baseMessage as MediaMessage).attachment.fileSize)) + val messageStr = String.format( + resources.getString(R.string.shared_a_audio), + Utils.getFileSize((baseMessage as MediaMessage).attachment.fileSize) + ) replyMessage?.text = messageStr - replyMessage?.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_library_music_24dp, 0, 0, 0) + replyMessage?.setCompoundDrawablesWithIntrinsicBounds( + R.drawable.ic_library_music_24dp, 0, 0, 0 + ) replyMedia?.visibility = View.GONE } else if (baseMessage?.type == CometChatConstants.MESSAGE_TYPE_VIDEO) { replyMessage?.text = resources.getString(R.string.shared_a_video) - Glide.with(requireContext()).load((baseMessage as MediaMessage).attachment.fileUrl).into(replyMedia!!) + Glide.with(requireContext()).load((baseMessage as MediaMessage).attachment.fileUrl) + .into(replyMedia!!) } else if (baseMessage?.type == CometChatConstants.MESSAGE_TYPE_FILE) { - val messageStr = String.format(resources.getString(R.string.shared_a_file), - Utils.getFileSize((baseMessage as MediaMessage).attachment.fileSize)) + val messageStr = String.format( + resources.getString(R.string.shared_a_file), + Utils.getFileSize((baseMessage as MediaMessage).attachment.fileSize) + ) replyMessage?.text = messageStr - replyMessage?.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_insert_drive_file_black_24dp, 0, 0, 0) - } - else if (baseMessage?.type == UIKitConstants.IntentStrings.LOCATION) { + replyMessage?.setCompoundDrawablesWithIntrinsicBounds( + R.drawable.ic_insert_drive_file_black_24dp, 0, 0, 0 + ) + } else if (baseMessage?.type == UIKitConstants.IntentStrings.LOCATION) { try { val jsonObject = (baseMessage as CustomMessage).customData - val messageStr = java.lang.String.format(getString(R.string.shared_location), - Utils.getAddress(context, jsonObject.getDouble("latitude"), - jsonObject.getDouble("longitude"))) + val messageStr = java.lang.String.format( + getString(R.string.shared_location), Utils.getAddress( + context, + jsonObject.getDouble("latitude"), + jsonObject.getDouble("longitude") + ) + ) replyMessage?.text = messageStr replyMedia?.visibility = View.GONE replyMessage?.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) @@ -3202,25 +3432,32 @@ class CometChatMessageList : Fragment(), View.OnClickListener, OnMessageLongClic } else if (baseMessage?.type == UIKitConstants.IntentStrings.POLLS) { try { val jsonObject = (baseMessage as CustomMessage).customData - val messageStr = String.format(getString(R.string.shared_a_polls), jsonObject.getString("question")) + val messageStr = String.format( + getString(R.string.shared_a_polls), jsonObject.getString("question") + ) replyMessage?.text = messageStr } catch (e: Exception) { Log.e(TAG, "replyMessageError: " + e.message) } - } - else if (baseMessage?.type == UIKitConstants.IntentStrings.STICKERS) { + } else if (baseMessage?.type == UIKitConstants.IntentStrings.STICKERS) { replyMessage?.text = resources.getString(R.string.shared_a_sticker) try { - Glide.with(requireContext()).load((baseMessage as CustomMessage).customData.getString("url")).into(replyMedia!!) + Glide.with(requireContext()) + .load((baseMessage as CustomMessage).customData.getString("url")) + .into(replyMedia!!) } catch (e: JSONException) { e.printStackTrace() } } else if (baseMessage?.type == UIKitConstants.IntentStrings.WHITEBOARD) { replyMessage?.text = getString(R.string.shared_a_whiteboard) - replyMessage?.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_whiteboard_24dp, 0, 0, 0) + replyMessage?.setCompoundDrawablesWithIntrinsicBounds( + R.drawable.ic_whiteboard_24dp, 0, 0, 0 + ) } else if (baseMessage?.type == UIKitConstants.IntentStrings.WRITEBOARD) { replyMessage?.text = getString(R.string.shared_a_writeboard) - replyMessage?.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_writeboard_24dp, 0, 0, 0) + replyMessage?.setCompoundDrawablesWithIntrinsicBounds( + R.drawable.ic_writeboard_24dp, 0, 0, 0 + ) } composeBox?.ivMic?.visibility = View.GONE composeBox?.ivSend?.visibility = View.VISIBLE diff --git a/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/MessageAdapter.kt b/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/MessageAdapter.kt index f7a8c7e..b6301a6 100644 --- a/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/MessageAdapter.kt +++ b/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/MessageAdapter.kt @@ -23,6 +23,7 @@ import android.widget.LinearLayout import android.widget.TextView import android.widget.Toast import androidx.cardview.widget.CardView +import androidx.core.view.marginTop import androidx.databinding.DataBindingUtil import androidx.emoji.text.EmojiCompat import androidx.emoji.text.EmojiSpan @@ -51,6 +52,7 @@ import com.cometchat.pro.uikit.ui_resources.utils.Utils import com.cometchat.pro.uikit.ui_resources.utils.sticker_header.StickyHeaderAdapter import com.cometchat.pro.uikit.ui_settings.FeatureRestriction import com.cometchat.pro.uikit.ui_settings.UIKitSettings +import com.google.android.flexbox.FlexboxLayout import com.google.android.material.chip.Chip import com.google.android.material.chip.ChipGroup import org.json.JSONException @@ -69,13 +71,14 @@ import kotlin.math.roundToInt * Modified on - 23rd March 2020 * */ -class MessageAdapter(context: Context, messageList: List, type: String?) : RecyclerView.Adapter(), StickyHeaderAdapter { +class MessageAdapter(context: Context, messageList: List, type: String?) : + RecyclerView.Adapter(), StickyHeaderAdapter { private var isDataMasking: Boolean = false private var isImageNotSafe: Boolean = false private var isProfanityFilter: Boolean = false private var isLinkPreview: Boolean = false private var isThreadVisible: Boolean = false - private var thumbnailUrl : String? = null + private var thumbnailUrl: String? = null var isReplyVisible: Boolean = false private val messageList: MutableList = ArrayList() var context: Context @@ -130,9 +133,10 @@ class MessageAdapter(context: Context, messageList: List, type: Str var LATITUDE = 0.0 var LONGITUDE = 0.0 - private lateinit var textMessage :String + private lateinit var textMessage: String } + /** * It is used to initialize the adapter wherever we needed. It has parameter like messageList * which contains list of messages and it will be used in adapter and paramter type is a String @@ -209,199 +213,414 @@ class MessageAdapter(context: Context, messageList: List, type: Str return when (i) { LEFT_DELETE_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val deleteMessageItemBinding: MessageLeftDeleteItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_delete_item, parent, false) + val deleteMessageItemBinding: MessageLeftDeleteItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_delete_item, + parent, + false + ) deleteMessageItemBinding.root.tag = LEFT_DELETE_MESSAGE LeftDeleteMessageViewHolder(deleteMessageItemBinding) } + RIGHT_DELETE_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val deleteMessageItemBinding: MessageRightDeleteItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_delete_item, parent, false) + val deleteMessageItemBinding: MessageRightDeleteItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_delete_item, + parent, + false + ) deleteMessageItemBinding.root.tag = RIGHT_DELETE_MESSAGE RightDeleteMessageViewHolder(deleteMessageItemBinding) } + LEFT_TEXT_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val textMessageItemBinding: MessageLeftTextItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_text_item, parent, false) + val textMessageItemBinding: MessageLeftTextItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_text_item, + parent, + false + ) textMessageItemBinding.root.tag = LEFT_TEXT_MESSAGE LeftTextMessageViewHolder(textMessageItemBinding) } + RIGHT_TEXT_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val textMessageItemBinding: MessageRightTextItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_text_item, parent, false) + val textMessageItemBinding: MessageRightTextItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_text_item, + parent, + false + ) textMessageItemBinding.root.tag = RIGHT_TEXT_MESSAGE RightTextMessageViewHolder(textMessageItemBinding) } + LEFT_REPLY_TEXT_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val textMessageItemBinding: MessageLeftTextItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_text_item, parent, false) + val textMessageItemBinding: MessageLeftTextItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_text_item, + parent, + false + ) textMessageItemBinding.root.tag = LEFT_REPLY_TEXT_MESSAGE LeftTextMessageViewHolder(textMessageItemBinding) } + RIGHT_REPLY_TEXT_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val textMessageItemBinding: MessageRightTextItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_text_item, parent, false) + val textMessageItemBinding: MessageRightTextItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_text_item, + parent, + false + ) textMessageItemBinding.root.tag = RIGHT_REPLY_TEXT_MESSAGE RightTextMessageViewHolder(textMessageItemBinding) } + RIGHT_LINK_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val linkMessageItemBinding: MessageRightLinkItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_link_item, parent, false) + val linkMessageItemBinding: MessageRightLinkItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_link_item, + parent, + false + ) linkMessageItemBinding.root.tag = RIGHT_LINK_MESSAGE RightLinkMessageViewHolder(linkMessageItemBinding) } + LEFT_LINK_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val linkMessageItemBinding: MessageLeftLinkItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_link_item, parent, false) + val linkMessageItemBinding: MessageLeftLinkItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_link_item, + parent, + false + ) linkMessageItemBinding.root.tag = LEFT_LINK_MESSAGE LeftLinkMessageViewHolder(linkMessageItemBinding) } + RIGHT_AUDIO_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val audioMessageItemBinding: MessageRightAudioItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_audio_item, parent, false) + val audioMessageItemBinding: MessageRightAudioItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_audio_item, + parent, + false + ) audioMessageItemBinding.root.tag = RIGHT_AUDIO_MESSAGE RightAudioMessageViewHolder(audioMessageItemBinding) } + LEFT_AUDIO_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val audioMessageItemBinding: MessageLeftAudioItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_audio_item, parent, false) + val audioMessageItemBinding: MessageLeftAudioItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_audio_item, + parent, + false + ) audioMessageItemBinding.root.tag = LEFT_AUDIO_MESSAGE LeftAudioMessageViewHolder(audioMessageItemBinding) } + LEFT_IMAGE_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val imageMessageItemBinding: MessageLeftListImageItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_list_image_item, parent, false) + val imageMessageItemBinding: MessageLeftListImageItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_list_image_item, + parent, + false + ) imageMessageItemBinding.root.tag = LEFT_IMAGE_MESSAGE LeftImageMessageViewHolder(imageMessageItemBinding) } + RIGHT_IMAGE_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val imageMessageItemBinding: MessageRightListImageItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_list_image_item, parent, false) + val imageMessageItemBinding: MessageRightListImageItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_list_image_item, + parent, + false + ) imageMessageItemBinding.root.tag = RIGHT_IMAGE_MESSAGE RightImageMessageViewHolder(imageMessageItemBinding) } + LEFT_VIDEO_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val videoMessageItemBinding: MessageLeftListVideoItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_list_video_item, parent, false) + val videoMessageItemBinding: MessageLeftListVideoItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_list_video_item, + parent, + false + ) videoMessageItemBinding.root.tag = LEFT_VIDEO_MESSAGE LeftVideoMessageViewHolder(videoMessageItemBinding) } + RIGHT_VIDEO_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val videoMessageItemBinding: MessageRightListVideoItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_list_video_item, parent, false) + val videoMessageItemBinding: MessageRightListVideoItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_list_video_item, + parent, + false + ) videoMessageItemBinding.root.tag = RIGHT_VIDEO_MESSAGE RightVideoMessageViewHolder(videoMessageItemBinding) } + RIGHT_FILE_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val fileMessageItemBinding: MessageRightFileItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_file_item, parent, false) + val fileMessageItemBinding: MessageRightFileItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_file_item, + parent, + false + ) fileMessageItemBinding.root.tag = RIGHT_FILE_MESSAGE RightFileMessageViewHolder(fileMessageItemBinding) } + LEFT_FILE_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val fileMessageItemBinding: MessageLeftFileItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_file_item, parent, false) + val fileMessageItemBinding: MessageLeftFileItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_file_item, + parent, + false + ) fileMessageItemBinding.root.tag = LEFT_FILE_MESSAGE LeftFileMessageViewHolder(fileMessageItemBinding) } + ACTION_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val actionMessageItemBinding: MessageActionItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_action_item, parent, false) + val actionMessageItemBinding: MessageActionItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_action_item, + parent, + false + ) actionMessageItemBinding.root.tag = ACTION_MESSAGE ActionMessageViewHolder(actionMessageItemBinding) } + CALL_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val callMessageItemBinding: MessageActionItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_action_item, parent, false) + val callMessageItemBinding: MessageActionItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_action_item, + parent, + false + ) callMessageItemBinding.root.tag = CALL_MESSAGE ActionMessageViewHolder(callMessageItemBinding) } + RIGHT_CUSTOM_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val customMessageItemBinding: MessageRightCustomItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_custom_item, parent, false) + val customMessageItemBinding: MessageRightCustomItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_custom_item, + parent, + false + ) customMessageItemBinding.root.tag = RIGHT_CUSTOM_MESSAGE RightCustomMessageViewHolder(customMessageItemBinding) } + LEFT_CUSTOM_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val customMessageItemBinding: MessageLeftCustomItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_custom_item, parent, false) + val customMessageItemBinding: MessageLeftCustomItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_custom_item, + parent, + false + ) customMessageItemBinding.root.tag = LEFT_CUSTOM_MESSAGE LeftCustomMessageViewHolder(customMessageItemBinding) } + RIGHT_LOCATION_CUSTOM_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val locationCustomMessageItemBinding: MessageRightLocationItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_location_item, parent, false) + val locationCustomMessageItemBinding: MessageRightLocationItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_location_item, + parent, + false + ) locationCustomMessageItemBinding.root.tag = RIGHT_LOCATION_CUSTOM_MESSAGE RightLocationMessageViewHolder(locationCustomMessageItemBinding) } + LEFT_LOCATION_CUSTOM_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val locationCustomMessageItemBinding: MessageLeftLocationItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_location_item, parent, false) + val locationCustomMessageItemBinding: MessageLeftLocationItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_location_item, + parent, + false + ) locationCustomMessageItemBinding.root.tag = LEFT_LOCATION_CUSTOM_MESSAGE LeftLocationMessageViewHolder(locationCustomMessageItemBinding) } + LEFT_STICKER_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val messageStickerItemBinding: MessageLeftStickerItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_sticker_item, parent, false) + val messageStickerItemBinding: MessageLeftStickerItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_sticker_item, + parent, + false + ) messageStickerItemBinding.root.tag = LEFT_STICKER_MESSAGE LeftStickerMessageViewHolder(messageStickerItemBinding) } + RIGHT_STICKER_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val messageStickerItemBinding: MessageRightStickerItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_sticker_item, parent, false) + val messageStickerItemBinding: MessageRightStickerItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_sticker_item, + parent, + false + ) messageStickerItemBinding.root.tag = RIGHT_STICKER_MESSAGE RightStickerMessageViewHolder(messageStickerItemBinding) } + LEFT_WHITEBOARD_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val messageWhiteBoardItemBinding: MessageLeftWhiteboardItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_whiteboard_item, parent, false) + val messageWhiteBoardItemBinding: MessageLeftWhiteboardItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_whiteboard_item, + parent, + false + ) messageWhiteBoardItemBinding.root.tag = LEFT_WHITEBOARD_MESSAGE LeftWhiteBoardMessageViewHolder(messageWhiteBoardItemBinding) } + RIGHT_WHITEBOARD_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val messageWhiteBoardItemBinding: MessageRightWhiteboardItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_whiteboard_item, parent, false) + val messageWhiteBoardItemBinding: MessageRightWhiteboardItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_whiteboard_item, + parent, + false + ) messageWhiteBoardItemBinding.root.tag = RIGHT_WHITEBOARD_MESSAGE RightWhiteBoardMessageViewHolder(messageWhiteBoardItemBinding) } + LEFT_WRITEBOARD_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val messageWriteBoardItemBinding: MessageLeftWriteboardItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_writeboard_item, parent, false) + val messageWriteBoardItemBinding: MessageLeftWriteboardItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_writeboard_item, + parent, + false + ) messageWriteBoardItemBinding.root.tag = LEFT_WRITEBOARD_MESSAGE LeftWriteBoardMessageViewHolder(messageWriteBoardItemBinding) } + RIGHT_WRITEBOARD_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val messageWriteBoardItemBinding: MessageRightWriteboardItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_writeboard_item, parent, false) + val messageWriteBoardItemBinding: MessageRightWriteboardItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_writeboard_item, + parent, + false + ) messageWriteBoardItemBinding.root.tag = RIGHT_WRITEBOARD_MESSAGE RightWriteBoardMessageViewHolder(messageWriteBoardItemBinding) } + LEFT_CONFERENCE_CALL_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val messageConferenceCallItemBinding: MessageLeftGroupCallItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_group_call_item, parent, false) + val messageConferenceCallItemBinding: MessageLeftGroupCallItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_group_call_item, + parent, + false + ) messageConferenceCallItemBinding.root.tag = LEFT_CONFERENCE_CALL_MESSAGE LeftConferenceCallMessageViewHolder(messageConferenceCallItemBinding) } + RIGHT_CONFERENCE_CALL_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val messageConferenceCallItemBinding: MessageRightGroupCallItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_group_call_item, parent, false) + val messageConferenceCallItemBinding: MessageRightGroupCallItemBinding = + DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_group_call_item, + parent, + false + ) messageConferenceCallItemBinding.root.tag = RIGHT_CONFERENCE_CALL_MESSAGE RightConferenceCallMessageViewHolder(messageConferenceCallItemBinding) } + LEFT_POLLS_CUSTOM_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val messagePollsItemBinding: MessageLeftPollsItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_left_polls_item, parent, false) + val messagePollsItemBinding: MessageLeftPollsItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_left_polls_item, + parent, + false + ) messagePollsItemBinding.root.tag = LEFT_POLLS_CUSTOM_MESSAGE LeftPollsMessageViewHolder(messagePollsItemBinding) } + RIGHT_POLLS_CUSTOM_MESSAGE -> { val layoutInflater = LayoutInflater.from(parent.context) - val messagePollsItemBinding: MessageRightPollsItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_right_polls_item, parent, false) + val messagePollsItemBinding: MessageRightPollsItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_right_polls_item, + parent, + false + ) messagePollsItemBinding.root.tag = RIGHT_POLLS_CUSTOM_MESSAGE RightPollsMessageViewHolder(messagePollsItemBinding) } + else -> { val layoutInflater = LayoutInflater.from(parent.context) - val actionMessageItemBinding : MessageActionItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.message_action_item, parent, false) + val actionMessageItemBinding: MessageActionItemBinding = DataBindingUtil.inflate( + layoutInflater, + R.layout.message_action_item, + parent, + false + ) actionMessageItemBinding.root.tag = -1 ActionMessageViewHolder(actionMessageItemBinding) } @@ -409,8 +628,6 @@ class MessageAdapter(context: Context, messageList: List, type: Str } - - /** * This method is used to bind the various ViewHolder content with their respective view types. * Here different methods are being called for different view type and in each method different @@ -439,7 +656,8 @@ class MessageAdapter(context: Context, messageList: List, type: Str if (i - 1 >= 0) { if (messageList[i - 1].sender != null) prevMessage = messageList[i - 1] } - isPrevActionMessage = prevMessage != null && (prevMessage.category == CometChatConstants.CATEGORY_ACTION || prevMessage.category == CometChatConstants.CATEGORY_CALL) + isPrevActionMessage = + prevMessage != null && (prevMessage.category == CometChatConstants.CATEGORY_ACTION || prevMessage.category == CometChatConstants.CATEGORY_CALL) isNextMessage = nextMessage != null && baseMessage.sender.uid == nextMessage.sender.uid isPreviousMessage = prevMessage != null && baseMessage.sender.uid == prevMessage.sender.uid if (!isPreviousMessage && isNextMessage) { @@ -475,16 +693,48 @@ class MessageAdapter(context: Context, messageList: List, type: Str ACTION_MESSAGE, CALL_MESSAGE -> setActionData(viewHolder as ActionMessageViewHolder, i) LEFT_CUSTOM_MESSAGE -> setCustomData(viewHolder as LeftCustomMessageViewHolder, i) RIGHT_CUSTOM_MESSAGE -> setCustomData(viewHolder as RightCustomMessageViewHolder, i) - LEFT_LOCATION_CUSTOM_MESSAGE -> setLocationData(viewHolder as LeftLocationMessageViewHolder, i) - RIGHT_LOCATION_CUSTOM_MESSAGE -> setLocationData(viewHolder as RightLocationMessageViewHolder, i) + LEFT_LOCATION_CUSTOM_MESSAGE -> setLocationData( + viewHolder as LeftLocationMessageViewHolder, + i + ) + + RIGHT_LOCATION_CUSTOM_MESSAGE -> setLocationData( + viewHolder as RightLocationMessageViewHolder, + i + ) + LEFT_STICKER_MESSAGE -> setStickerData(viewHolder as LeftStickerMessageViewHolder, i) RIGHT_STICKER_MESSAGE -> setStickerData(viewHolder as RightStickerMessageViewHolder, i) - LEFT_WHITEBOARD_MESSAGE -> setWhiteBoardData(viewHolder as LeftWhiteBoardMessageViewHolder, i) - RIGHT_WHITEBOARD_MESSAGE -> setWhiteBoardData(viewHolder as RightWhiteBoardMessageViewHolder, i) - LEFT_WRITEBOARD_MESSAGE -> setWriteBoardData(viewHolder as LeftWriteBoardMessageViewHolder, i) - RIGHT_WRITEBOARD_MESSAGE -> setWriteBoardData(viewHolder as RightWriteBoardMessageViewHolder, i) - LEFT_CONFERENCE_CALL_MESSAGE -> setMeetingData(viewHolder as LeftConferenceCallMessageViewHolder, i) - RIGHT_CONFERENCE_CALL_MESSAGE -> setMeetingData(viewHolder as RightConferenceCallMessageViewHolder, i) + LEFT_WHITEBOARD_MESSAGE -> setWhiteBoardData( + viewHolder as LeftWhiteBoardMessageViewHolder, + i + ) + + RIGHT_WHITEBOARD_MESSAGE -> setWhiteBoardData( + viewHolder as RightWhiteBoardMessageViewHolder, + i + ) + + LEFT_WRITEBOARD_MESSAGE -> setWriteBoardData( + viewHolder as LeftWriteBoardMessageViewHolder, + i + ) + + RIGHT_WRITEBOARD_MESSAGE -> setWriteBoardData( + viewHolder as RightWriteBoardMessageViewHolder, + i + ) + + LEFT_CONFERENCE_CALL_MESSAGE -> setMeetingData( + viewHolder as LeftConferenceCallMessageViewHolder, + i + ) + + RIGHT_CONFERENCE_CALL_MESSAGE -> setMeetingData( + viewHolder as RightConferenceCallMessageViewHolder, + i + ) + LEFT_POLLS_CUSTOM_MESSAGE -> setPollsData(viewHolder as LeftPollsMessageViewHolder, i) RIGHT_POLLS_CUSTOM_MESSAGE -> setPollsData(viewHolder as RightPollsMessageViewHolder, i) } @@ -506,17 +756,23 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } } if (baseMessage.replyCount != 0) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -528,29 +784,56 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.type) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) try { - val option = (baseMessage as CustomMessage).customData.getJSONObject("options") - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.POLLS) - intent.putExtra(UIKitConstants.IntentStrings.POLL_QUESTION, - baseMessage.customData.getString("question")) + val option = + (baseMessage as CustomMessage).customData.getJSONObject("options") + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.POLLS + ) + intent.putExtra( + UIKitConstants.IntentStrings.POLL_QUESTION, + baseMessage.customData.getString("question") + ) intent.putExtra(UIKitConstants.IntentStrings.POLL_OPTION, option.toString()) - intent.putExtra(UIKitConstants.IntentStrings.POLL_VOTE_COUNT, Extensions.getVoteCount(baseMessage)) - intent.putExtra(UIKitConstants.IntentStrings.POLL_RESULT, Extensions.getVoterInfo(baseMessage, option.length())) + intent.putExtra( + UIKitConstants.IntentStrings.POLL_VOTE_COUNT, + Extensions.getVoteCount(baseMessage) + ) + intent.putExtra( + UIKitConstants.IntentStrings.POLL_RESULT, + Extensions.getVoterInfo(baseMessage, option.length()) + ) } catch (e: java.lang.Exception) { Log.e(TAG, "startThreadActivityError: " + e.message) } - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.category) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.category + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.receiverType) if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.receiverUid) } else { - if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.receiverUid) + if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.sender.uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.receiverUid + ) } context.startActivity(intent) }) @@ -567,22 +850,32 @@ class MessageAdapter(context: Context, messageList: List, type: Str var voteText = Extensions.getVoteCount(baseMessage).toString() + " Votes" viewHolder.view.totalVotes.text = voteText val linearLayout = LinearLayout(context) - val layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT) + val layoutParams = LinearLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) linearLayout.setPadding(8, 8, 8, 8) linearLayout.setBackgroundColor(Color.parseColor(UIKitSettings.color)) linearLayout.background = context.resources - .getDrawable(R.drawable.cc_message_bubble_right) - linearLayout.backgroundTintList = ColorStateList.valueOf(context.resources - .getColor(R.color.textColorWhite)) + .getDrawable(R.drawable.cc_message_bubble_right) + linearLayout.backgroundTintList = ColorStateList.valueOf( + context.resources + .getColor(R.color.textColorWhite) + ) layoutParams.bottomMargin = Utils.dpToPx(context, 8f).toInt() linearLayout.layoutParams = layoutParams val textViewPercentage = TextView(context) val textViewOption = TextView(context) textViewPercentage.setPadding(16, 4, 0, 4) textViewOption.setPadding(16, 4, 0, 4) - textViewOption.setTextAppearance(context, androidx.appcompat.R.style.TextAppearance_AppCompat_Medium) - textViewPercentage.setTextAppearance(context, androidx.appcompat.R.style.TextAppearance_AppCompat_Medium) + textViewOption.setTextAppearance( + context, + androidx.appcompat.R.style.TextAppearance_AppCompat_Medium + ) + textViewPercentage.setTextAppearance( + context, + androidx.appcompat.R.style.TextAppearance_AppCompat_Medium + ) textViewPercentage.setTextColor(context.resources.getColor(R.color.primaryTextColor)) textViewOption.setTextColor(context.resources.getColor(R.color.primaryTextColor)) val optionStr = options.getString((k + 1).toString()) @@ -593,9 +886,19 @@ class MessageAdapter(context: Context, messageList: List, type: Str voteCount.toFloat()).roundToInt() if (percentage > 0) textViewPercentage.text = "$percentage% " } - if (k + 1 == Extensions.userVotedOn(baseMessage, optionList.size + 1, loggedInUser.uid)) { + if (k + 1 == Extensions.userVotedOn( + baseMessage, + optionList.size + 1, + loggedInUser.uid + ) + ) { textViewPercentage.compoundDrawablePadding = 8 - textViewPercentage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_baseline_check_circle_24, 0, 0, 0) + textViewPercentage.setCompoundDrawablesWithIntrinsicBounds( + R.drawable.ic_baseline_check_circle_24, + 0, + 0, + 0 + ) } if (viewHolder.view.optionsGroup.childCount != options.length()) { viewHolder.view.loadingProgressBar.visibility = View.GONE @@ -606,25 +909,35 @@ class MessageAdapter(context: Context, messageList: List, type: Str linearLayout.setOnClickListener { try { var pollsId: String? = null - pollsId = if (jsonObject.has("id")) jsonObject.getString("id") else baseMessage.getId().toString() + "" + pollsId = + if (jsonObject.has("id")) jsonObject.getString("id") else baseMessage.getId() + .toString() + "" val pollsJsonObject = JSONObject() pollsJsonObject.put("vote", k + 1) pollsJsonObject.put("id", pollsId) CometChat.callExtension("polls", "POST", "/v2/vote", - pollsJsonObject, object : CallbackListener() { - override fun onSuccess(jsonObject: JSONObject) { - // Voted successfully - viewHolder.view.loadingProgressBar.visibility = View.VISIBLE - viewHolder.view.totalVotes.text = "0 Votes" - Log.v(TAG, "onSuccess: $jsonObject") - Toast.makeText(context, "Voted Successfully", Toast.LENGTH_LONG).show() - } - - override fun onError(e: CometChatException) { - // Some error occured - Log.e(TAG, "onErrorExtension: ${e.message}${e.code}".trimIndent()) - } - }) + pollsJsonObject, object : CallbackListener() { + override fun onSuccess(jsonObject: JSONObject) { + // Voted successfully + viewHolder.view.loadingProgressBar.visibility = + View.VISIBLE + viewHolder.view.totalVotes.text = "0 Votes" + Log.v(TAG, "onSuccess: $jsonObject") + Toast.makeText( + context, + "Voted Successfully", + Toast.LENGTH_LONG + ).show() + } + + override fun onError(e: CometChatException) { + // Some error occured + Log.e( + TAG, + "onErrorExtension: ${e.message}${e.code}".trimIndent() + ) + } + }) } catch (e: Exception) { Log.e(TAG, "onError: " + e.message) } @@ -632,7 +945,10 @@ class MessageAdapter(context: Context, messageList: List, type: Str optionList.add(options.getString((k + 1).toString())) } } catch (e: Exception) { - Log.e(TAG, "setPollsData: ${e.message}${viewHolder.view.totalVotes.text}".trimIndent()) + Log.e( + TAG, + "setPollsData: ${e.message}${viewHolder.view.totalVotes.text}".trimIndent() + ) } showMessageTime(viewHolder, baseMessage) // if (messageList.get(messageList.size()-1).equals(baseMessage)) @@ -658,12 +974,14 @@ class MessageAdapter(context: Context, messageList: List, type: Str } else { viewHolder as RightPollsMessageViewHolder - if (baseMessage.replyCount != 0 ){ - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + if (baseMessage.replyCount != 0) { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -676,29 +994,56 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.type) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) try { - val option = (baseMessage as CustomMessage).customData.getJSONObject("options") - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.POLLS) - intent.putExtra(UIKitConstants.IntentStrings.POLL_QUESTION, - baseMessage.customData.getString("question")) + val option = + (baseMessage as CustomMessage).customData.getJSONObject("options") + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.POLLS + ) + intent.putExtra( + UIKitConstants.IntentStrings.POLL_QUESTION, + baseMessage.customData.getString("question") + ) intent.putExtra(UIKitConstants.IntentStrings.POLL_OPTION, option.toString()) - intent.putExtra(UIKitConstants.IntentStrings.POLL_VOTE_COUNT, Extensions.getVoteCount(baseMessage)) - intent.putExtra(UIKitConstants.IntentStrings.POLL_RESULT, Extensions.getVoterInfo(baseMessage, option.length())) + intent.putExtra( + UIKitConstants.IntentStrings.POLL_VOTE_COUNT, + Extensions.getVoteCount(baseMessage) + ) + intent.putExtra( + UIKitConstants.IntentStrings.POLL_RESULT, + Extensions.getVoterInfo(baseMessage, option.length()) + ) } catch (e: java.lang.Exception) { Log.e(TAG, "startThreadActivityError: " + e.message) } - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.category) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.category + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.receiverType) if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.receiverUid) } else { - if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.receiverUid) + if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.sender.uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.receiverUid + ) } context.startActivity(intent) }) @@ -713,24 +1058,35 @@ class MessageAdapter(context: Context, messageList: List, type: Str val voterInfo = Extensions.getVoterInfo(baseMessage, options.length()) viewHolder.view.tvQuestion.text = jsonObject.getString("question") for (k in 0 until options.length()) { - viewHolder.view.totalVotes.text = Extensions.getVoteCount(baseMessage).toString() + " Votes" + viewHolder.view.totalVotes.text = + Extensions.getVoteCount(baseMessage).toString() + " Votes" val linearLayout = LinearLayout(context) - val layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT) + val layoutParams = LinearLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) linearLayout.setPadding(8, 8, 8, 8) linearLayout.setBackgroundColor(Color.parseColor(UIKitSettings.color)) linearLayout.background = context.resources - .getDrawable(R.drawable.cc_message_bubble_right) - linearLayout.backgroundTintList = ColorStateList.valueOf(context.resources - .getColor(R.color.textColorWhite)) + .getDrawable(R.drawable.cc_message_bubble_right) + linearLayout.backgroundTintList = ColorStateList.valueOf( + context.resources + .getColor(R.color.textColorWhite) + ) layoutParams.bottomMargin = Utils.dpToPx(context, 8f).toInt() linearLayout.layoutParams = layoutParams val textViewPercentage = TextView(context) val textViewOption = TextView(context) textViewPercentage.setPadding(16, 4, 0, 4) textViewOption.setPadding(16, 4, 0, 4) - textViewOption.setTextAppearance(context, androidx.appcompat.R.style.TextAppearance_AppCompat_Medium) - textViewPercentage.setTextAppearance(context, androidx.appcompat.R.style.TextAppearance_AppCompat_Medium) + textViewOption.setTextAppearance( + context, + androidx.appcompat.R.style.TextAppearance_AppCompat_Medium + ) + textViewPercentage.setTextAppearance( + context, + androidx.appcompat.R.style.TextAppearance_AppCompat_Medium + ) textViewPercentage.setTextColor(context.resources.getColor(R.color.primaryTextColor)) textViewOption.setTextColor(context.resources.getColor(R.color.primaryTextColor)) val optionStr = options.getString((k + 1).toString()) @@ -741,9 +1097,19 @@ class MessageAdapter(context: Context, messageList: List, type: Str voteCount.toFloat()).roundToInt() if (percentage > 0) textViewPercentage.text = "$percentage% " } - if (k + 1 == Extensions.userVotedOn(baseMessage, optionList.size + 1, loggedInUser.uid)) { + if (k + 1 == Extensions.userVotedOn( + baseMessage, + optionList.size + 1, + loggedInUser.uid + ) + ) { textViewPercentage.compoundDrawablePadding = 8 - textViewPercentage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_baseline_check_circle_24, 0, 0, 0) + textViewPercentage.setCompoundDrawablesWithIntrinsicBounds( + R.drawable.ic_baseline_check_circle_24, + 0, + 0, + 0 + ) } if (viewHolder.view.optionsGroup.childCount != options.length()) { viewHolder.view.loadingProgressBar.visibility = View.GONE @@ -754,25 +1120,35 @@ class MessageAdapter(context: Context, messageList: List, type: Str linearLayout.setOnClickListener { try { var pollsId: String? = null - pollsId = if (jsonObject.has("id")) jsonObject.getString("id") else baseMessage.getId().toString() + "" + pollsId = + if (jsonObject.has("id")) jsonObject.getString("id") else baseMessage.getId() + .toString() + "" val pollsJsonObject = JSONObject() pollsJsonObject.put("vote", k + 1) pollsJsonObject.put("id", pollsId) CometChat.callExtension("polls", "POST", "/v2/vote", - pollsJsonObject, object : CallbackListener() { - override fun onSuccess(jsonObject: JSONObject) { - // Voted successfully - viewHolder.view.loadingProgressBar.visibility = View.VISIBLE - viewHolder.view.totalVotes.text = "0 Votes" - Log.v(TAG, "onSuccess: $jsonObject") - Toast.makeText(context, "Voted Successfully", Toast.LENGTH_LONG).show() - } - - override fun onError(e: CometChatException) { - // Some error occured - Log.e(TAG, "onErrorExtension: ${e.message}${e.code}".trimIndent()) - } - }) + pollsJsonObject, object : CallbackListener() { + override fun onSuccess(jsonObject: JSONObject) { + // Voted successfully + viewHolder.view.loadingProgressBar.visibility = + View.VISIBLE + viewHolder.view.totalVotes.text = "0 Votes" + Log.v(TAG, "onSuccess: $jsonObject") + Toast.makeText( + context, + "Voted Successfully", + Toast.LENGTH_LONG + ).show() + } + + override fun onError(e: CometChatException) { + // Some error occured + Log.e( + TAG, + "onErrorExtension: ${e.message}${e.code}".trimIndent() + ) + } + }) } catch (e: Exception) { Log.e(TAG, "onError: " + e.message) } @@ -780,7 +1156,10 @@ class MessageAdapter(context: Context, messageList: List, type: Str optionList.add(options.getString((k + 1).toString())) } } catch (e: Exception) { - Log.e(TAG, "setPollsData: ${e.message}${viewHolder.view.totalVotes.text}".trimIndent()) + Log.e( + TAG, + "setPollsData: ${e.message}${viewHolder.view.totalVotes.text}".trimIndent() + ) } showMessageTime(viewHolder, baseMessage) // if (messageList.get(messageList.size()-1).equals(baseMessage)) @@ -823,13 +1202,21 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } - viewHolder.view.callMessage.text = baseMessage.sender.name + " " + context.getString(R.string.has_shared_group_call) + viewHolder.view.callMessage.text = + baseMessage.sender.name + " " + context.getString(R.string.has_shared_group_call) } viewHolder.view.joinCall.setOnClickListener(View.OnClickListener { - Utils.startVideoCallIntent(context, (baseMessage as CustomMessage).customData.getString("sessionID")) + Utils.startVideoCallIntent( + context, + (baseMessage as CustomMessage).customData.getString("sessionID") + ) }) viewHolder.view.cvMessageContainer.setOnClickListener(View.OnClickListener { @@ -854,9 +1241,13 @@ class MessageAdapter(context: Context, messageList: List, type: Str }) } else { viewHolder as RightConferenceCallMessageViewHolder - viewHolder.view.callMessage.text = context.getString(R.string.you_created_group_call) + viewHolder.view.callMessage.text = + context.getString(R.string.you_created_group_call) viewHolder.view.joinCall.setOnClickListener(View.OnClickListener { - Utils.startVideoCallIntent(context, (baseMessage as CustomMessage).customData.getString("sessionID")) + Utils.startVideoCallIntent( + context, + (baseMessage as CustomMessage).customData.getString("sessionID") + ) }) viewHolder.view.cvMessageContainer.setOnClickListener(View.OnClickListener { if (baseMessage.sender.uid == loggedInUser.uid) { @@ -898,18 +1289,30 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } - viewHolder.view.writeboardMessage.text = baseMessage.sender.name + " " + context.getString(R.string.has_shared_document) + viewHolder.view.writeboardMessage.text = + baseMessage.sender.name + " " + context.getString(R.string.has_shared_document) } - viewHolder.view.joinWriteboard.setOnClickListener(View.OnClickListener { Extensions.openWriteBoard(baseMessage, context) }) - if (baseMessage.replyCount != 0 ) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + viewHolder.view.joinWriteboard.setOnClickListener(View.OnClickListener { + Extensions.openWriteBoard( + baseMessage, + context + ) + }) + if (baseMessage.replyCount != 0) { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -921,19 +1324,37 @@ class MessageAdapter(context: Context, messageList: List, type: Str val intent = Intent(context, CometChatThreadMessageListActivity::class.java) intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.type) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) - intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWriteBoardUrl(baseMessage)) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.category) + intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + Extensions.getWriteBoardUrl(baseMessage) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.category + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.receiverType) if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.receiverUid) } else { - if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.receiverUid) + if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.sender.uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.receiverUid + ) } context.startActivity(intent) }) @@ -967,31 +1388,56 @@ class MessageAdapter(context: Context, messageList: List, type: Str } else { viewHolder as RightWriteBoardMessageViewHolder - viewHolder.view.writeboardMessage.text = context.getString(R.string.you_created_document) - viewHolder.view.joinWriteboard.setOnClickListener(View.OnClickListener { Extensions.openWriteBoard(baseMessage, context) }) - if (baseMessage.replyCount !=0) { - viewHolder.view.threadReplyCount.visibility = View.VISIBLE; - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() +" Replies" - } else { - viewHolder.view.threadReplyCount.visibility = View.GONE + viewHolder.view.writeboardMessage.text = + context.getString(R.string.you_created_document) + viewHolder.view.joinWriteboard.setOnClickListener(View.OnClickListener { + Extensions.openWriteBoard( + baseMessage, + context + ) + }) + if (baseMessage.replyCount != 0) { + viewHolder.view.threadReplyCount.visibility = View.VISIBLE; + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" + } else { + viewHolder.view.threadReplyCount.visibility = View.GONE } viewHolder.view.threadReplyCount.setOnClickListener(View.OnClickListener { val intent = Intent(context, CometChatThreadMessageListActivity::class.java) intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.type) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) - intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWriteBoardUrl(baseMessage)) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.category) + intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + Extensions.getWriteBoardUrl(baseMessage) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.category + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.receiverType) if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.receiverUid) } else { - if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.receiverUid) + if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.sender.uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.receiverUid + ) } context.startActivity(intent) }) @@ -1027,7 +1473,7 @@ class MessageAdapter(context: Context, messageList: List, type: Str private fun setWhiteBoardData(viewHolder: RecyclerView.ViewHolder, i: Int) { val baseMessage = messageList[i] - if (baseMessage != null && baseMessage.deletedAt == 0L){ + if (baseMessage != null && baseMessage.deletedAt == 0L) { if (viewHolder is LeftWhiteBoardMessageViewHolder) { if (baseMessage.sender.uid != loggedInUser.uid) { if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_USER) { @@ -1041,20 +1487,27 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } - viewHolder.view.whiteboardMessage.text = baseMessage.sender.name + " " + context.getString(R.string.has_shared_whiteboard) + viewHolder.view.whiteboardMessage.text = + baseMessage.sender.name + " " + context.getString(R.string.has_shared_whiteboard) } viewHolder.view.joinWhiteboard.setOnClickListener(View.OnClickListener { Extensions.openWhiteBoard(baseMessage, context) }) - if (baseMessage.replyCount != 0 ) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + if (baseMessage.replyCount != 0) { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -1065,19 +1518,37 @@ class MessageAdapter(context: Context, messageList: List, type: Str val intent = Intent(context, CometChatThreadMessageListActivity::class.java) intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.type) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) - intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWhiteBoardUrl(baseMessage)) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.category) + intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + Extensions.getWhiteBoardUrl(baseMessage) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.category + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.receiverType) if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.receiverUid) } else { - if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.receiverUid) + if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.sender.uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.receiverUid + ) } context.startActivity(intent) }) @@ -1110,14 +1581,22 @@ class MessageAdapter(context: Context, messageList: List, type: Str } else { viewHolder as RightWhiteBoardMessageViewHolder - viewHolder.view.whiteboardMessage.text = context.getString(R.string.you_created_whiteboard) - viewHolder.view.joinWhiteboard.setOnClickListener(View.OnClickListener { Extensions.openWhiteBoard(baseMessage, context) }) - if (baseMessage.replyCount != 0 ) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + viewHolder.view.whiteboardMessage.text = + context.getString(R.string.you_created_whiteboard) + viewHolder.view.joinWhiteboard.setOnClickListener(View.OnClickListener { + Extensions.openWhiteBoard( + baseMessage, + context + ) + }) + if (baseMessage.replyCount != 0) { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -1129,19 +1608,37 @@ class MessageAdapter(context: Context, messageList: List, type: Str val intent = Intent(context, CometChatThreadMessageListActivity::class.java) intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.type) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) - intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWhiteBoardUrl(baseMessage)) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.category) + intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + Extensions.getWhiteBoardUrl(baseMessage) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.category + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.receiverType) if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.receiverUid) } else { - if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.receiverUid) + if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.sender.uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.receiverUid + ) } context.startActivity(intent) }) @@ -1178,9 +1675,9 @@ class MessageAdapter(context: Context, messageList: List, type: Str private fun setStickerData(viewHolder: RecyclerView.ViewHolder, i: Int) { val baseMessage = messageList[i] - if (baseMessage != null && baseMessage.deletedAt == 0L){ + if (baseMessage != null && baseMessage.deletedAt == 0L) { // var viewHolder : RecyclerView.ViewHolder - if (viewHolder is LeftStickerMessageViewHolder){ + if (viewHolder is LeftStickerMessageViewHolder) { if (baseMessage.sender.uid != loggedInUser.uid) { if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_USER) { viewHolder.view.tvUser.visibility = View.GONE @@ -1193,22 +1690,30 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } } viewHolder.view.stickerView.setImageDrawable(context.resources.getDrawable(R.drawable.ic_defaulf_image)) try { - Glide.with(context).load((baseMessage as CustomMessage).customData.getString("url")).into(viewHolder.view.stickerView) + Glide.with(context) + .load((baseMessage as CustomMessage).customData.getString("url")) + .into(viewHolder.view.stickerView) } catch (e: JSONException) { e.printStackTrace() } if (baseMessage.replyCount != 0) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -1220,24 +1725,48 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.STICKERS) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.STICKERS + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) try { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, (baseMessage as CustomMessage).customData.getString("name")) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, baseMessage.customData.getString("url")) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + (baseMessage as CustomMessage).customData.getString("name") + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + baseMessage.customData.getString("url") + ) } catch (e: JSONException) { e.printStackTrace() } intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.receiverType) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.category) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.category + ) if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.receiverUid) } else { - if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.receiverUid) + if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.sender.uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.receiverUid + ) } context.startActivity(intent) } @@ -1266,21 +1795,24 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.reactionsLayout.visibility = View.GONE setReactionSupport(baseMessage, viewHolder.view.reactionsLayout) - } - else{ + } else { viewHolder as RightStickerMessageViewHolder viewHolder.view.stickerView.setImageDrawable(context.resources.getDrawable(R.drawable.ic_defaulf_image)) try { - Glide.with(context).load((baseMessage as CustomMessage).customData.getString("url")).into(viewHolder.view.stickerView) + Glide.with(context) + .load((baseMessage as CustomMessage).customData.getString("url")) + .into(viewHolder.view.stickerView) } catch (e: JSONException) { e.printStackTrace() } - if (baseMessage.replyCount != 0 ) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + if (baseMessage.replyCount != 0) { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -1292,24 +1824,48 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.STICKERS) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.STICKERS + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) try { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, (baseMessage as CustomMessage).customData.getString("name")) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, baseMessage.customData.getString("url")) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + (baseMessage as CustomMessage).customData.getString("name") + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + baseMessage.customData.getString("url") + ) } catch (e: JSONException) { e.printStackTrace() } intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.receiverType) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.category) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.category + ) if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.receiverUid) } else { - if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.receiverUid) + if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.sender.uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.receiverUid + ) } context.startActivity(intent) } @@ -1344,11 +1900,11 @@ class MessageAdapter(context: Context, messageList: List, type: Str private fun setLocationData(viewHolder: RecyclerView.ViewHolder, i: Int) { val baseMessage = messageList[i] if (baseMessage != null && baseMessage.deletedAt == 0L) { - if (viewHolder is LeftLocationMessageViewHolder){ + if (viewHolder is LeftLocationMessageViewHolder) { if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_USER) { viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.GONE - } else if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP){ + } else if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { if (isUserDetailVisible) { viewHolder.view.tvUser.visibility = View.VISIBLE viewHolder.view.ivUser.visibility = View.VISIBLE @@ -1356,15 +1912,21 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } - if (baseMessage.replyCount != 0 ) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + if (baseMessage.replyCount != 0) { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -1376,27 +1938,49 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.type) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) try { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.LOCATION) - intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LATITUDE, - (baseMessage as CustomMessage).customData.getDouble("latitude")) - intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LONGITUDE, - baseMessage.customData.getDouble("longitude")) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.LOCATION + ) + intent.putExtra( + UIKitConstants.IntentStrings.LOCATION_LATITUDE, + (baseMessage as CustomMessage).customData.getDouble("latitude") + ) + intent.putExtra( + UIKitConstants.IntentStrings.LOCATION_LONGITUDE, + baseMessage.customData.getDouble("longitude") + ) } catch (e: java.lang.Exception) { Log.e(TAG, "startThreadActivityError: " + e.message) } - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.category) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.category + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.receiverType) if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.receiverUid) } else { - if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.receiverUid) + if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.sender.uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.receiverUid + ) } context.startActivity(intent) }) @@ -1404,8 +1988,10 @@ class MessageAdapter(context: Context, messageList: List, type: Str setLocationData(baseMessage, viewHolder.view.tvPlaceName, viewHolder.view.ivMap) viewHolder.view.ivMap.setOnClickListener(View.OnClickListener { try { - val latitude = (baseMessage as CustomMessage).customData.getDouble("latitude") - val longitude = (baseMessage as CustomMessage).customData.getDouble("longitude") + val latitude = + (baseMessage as CustomMessage).customData.getDouble("latitude") + val longitude = + (baseMessage as CustomMessage).customData.getDouble("longitude") val label = Utils.getAddress(context, latitude, longitude) val uriBegin = "geo:$latitude,$longitude" val encodedQuery = Uri.encode(label) @@ -1441,8 +2027,7 @@ class MessageAdapter(context: Context, messageList: List, type: Str }) viewHolder.view.reactionsLayout.visibility = View.GONE setReactionSupport(baseMessage, viewHolder.view.reactionsLayout) - } - else { + } else { viewHolder as RightLocationMessageViewHolder // if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_USER) { // viewHolder.view.tvUser.visibility = View.GONE @@ -1459,12 +2044,14 @@ class MessageAdapter(context: Context, messageList: List, type: Str // viewHolder.view.tvUser.setText(baseMessage.sender.name) // } - if (baseMessage.replyCount != 0 ) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + if (baseMessage.replyCount != 0) { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -1476,35 +2063,59 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.type) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) try { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.LOCATION) - intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LATITUDE, - (baseMessage as CustomMessage).customData.getDouble("latitude")) - intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LONGITUDE, - baseMessage.customData.getDouble("longitude")) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + UIKitConstants.IntentStrings.LOCATION + ) + intent.putExtra( + UIKitConstants.IntentStrings.LOCATION_LATITUDE, + (baseMessage as CustomMessage).customData.getDouble("latitude") + ) + intent.putExtra( + UIKitConstants.IntentStrings.LOCATION_LONGITUDE, + baseMessage.customData.getDouble("longitude") + ) } catch (e: java.lang.Exception) { Log.e(TAG, "startThreadActivityError: " + e.message) } - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.category) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.category + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.receiverType) if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.receiverUid) } else { - if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.receiverUid) + if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.sender.uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.receiverUid + ) } context.startActivity(intent) }) setLocationData(baseMessage, viewHolder.view.tvPlaceName, viewHolder.view.ivMap) viewHolder.view.ivMap.setOnClickListener(View.OnClickListener { try { - val latitude = (baseMessage as CustomMessage).customData.getDouble("latitude") - val longitude = (baseMessage as CustomMessage).customData.getDouble("longitude") + val latitude = + (baseMessage as CustomMessage).customData.getDouble("latitude") + val longitude = + (baseMessage as CustomMessage).customData.getDouble("longitude") val label = Utils.getAddress(context, latitude, longitude) val uriBegin = "geo:$latitude,$longitude" val encodedQuery = Uri.encode(label) @@ -1543,17 +2154,19 @@ class MessageAdapter(context: Context, messageList: List, type: Str } } } + private fun setLocationData(baseMessage: BaseMessage, tvAddress: TextView, ivMap: ImageView) { try { LATITUDE = (baseMessage as CustomMessage).customData.getDouble("latitude") LONGITUDE = baseMessage.customData.getDouble("longitude") tvAddress.text = Utils.getAddress(context, LATITUDE, LONGITUDE) - val mapUrl = UIKitConstants.MapUrl.MAPS_URL + LATITUDE + "," + LONGITUDE + "&key=" + UIKitConstants.MapUrl.MAP_ACCESS_KEY + val mapUrl = + UIKitConstants.MapUrl.MAPS_URL + LATITUDE + "," + LONGITUDE + "&key=" + UIKitConstants.MapUrl.MAP_ACCESS_KEY Glide.with(context) - .load(mapUrl) - .placeholder(R.drawable.location_map) - .diskCacheStrategy(DiskCacheStrategy.ALL) - .into(ivMap) + .load(mapUrl) + .placeholder(R.drawable.location_map) + .diskCacheStrategy(DiskCacheStrategy.ALL) + .into(ivMap) } catch (e: JSONException) { e.printStackTrace() } @@ -1574,7 +2187,11 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } showMessageTime(viewHolder, baseMessage) @@ -1582,16 +2199,18 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.txtTime.visibility = View.VISIBLE // else viewHolder.view.txtTime.visibility = View.GONE - if (baseMessage.replyCount != 0 ) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + if (baseMessage.replyCount != 0) { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) - }else { + } else { viewHolder.view.replyAvatarLayout.visibility = View.GONE viewHolder.view.threadReplyCount.visibility = View.GONE } @@ -1600,27 +2219,61 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.type) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, (baseMessage as MediaMessage).attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, baseMessage.attachment.fileExtension) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, baseMessage.attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, baseMessage.attachment.fileSize) - intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory()) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + (baseMessage as MediaMessage).attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + baseMessage.attachment.fileExtension + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + baseMessage.attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + baseMessage.attachment.fileSize + ) + intent.putExtra( + UIKitConstants.IntentStrings.TYPE, + baseMessage.getReceiverType() + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.getCategory() + ) if (baseMessage.getReceiverType() == CometChatConstants.RECEIVER_TYPE_GROUP) { - intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid()) + intent.putExtra( + UIKitConstants.IntentStrings.GUID, + baseMessage.getReceiverUid() + ) } else { - if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid()) + if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getSender().uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getReceiverUid() + ) } context.startActivity(intent) }) if ((baseMessage as MediaMessage).attachment != null) { - viewHolder.view.audiolengthTv.text = Utils.getFileSize((baseMessage as MediaMessage).attachment.fileSize) + viewHolder.view.audiolengthTv.text = + Utils.getFileSize((baseMessage as MediaMessage).attachment.fileSize) viewHolder.view.playBtn.visibility = View.VISIBLE } else { viewHolder.view.audiolengthTv.text = "-" @@ -1638,7 +2291,11 @@ class MessageAdapter(context: Context, messageList: List, type: Str try { mediaPlayer?.setDataSource(baseMessage.attachment.fileUrl) mediaPlayer?.prepare() - mediaPlayer?.setOnCompletionListener { (viewHolder as LeftAudioMessageViewHolder).view.playBtn.setImageResource(R.drawable.ic_play_arrow_black_24dp) } + mediaPlayer?.setOnCompletionListener { + (viewHolder as LeftAudioMessageViewHolder).view.playBtn.setImageResource( + R.drawable.ic_play_arrow_black_24dp + ) + } } catch (e: Exception) { Log.e(TAG, "MediaPlayerError: " + e.message) } @@ -1661,18 +2318,20 @@ class MessageAdapter(context: Context, messageList: List, type: Str } viewHolder.view.reactionsLayout.visibility = View.GONE setReactionSupport(baseMessage, viewHolder.view.reactionsLayout) - } else{ + } else { viewHolder as RightAudioMessageViewHolder showMessageTime(viewHolder, baseMessage) // if (selectedItemList.contains(baseMessage.id)) viewHolder.view.txtTime.visibility = View.VISIBLE // else viewHolder.view.txtTime.visibility = View.GONE - if (baseMessage.replyCount != 0 ) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + if (baseMessage.replyCount != 0) { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -1685,27 +2344,61 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.type) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, (baseMessage as MediaMessage).attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, baseMessage.attachment.fileExtension) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, baseMessage.attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, baseMessage.attachment.fileSize) - intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory()) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + (baseMessage as MediaMessage).attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + baseMessage.attachment.fileExtension + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + baseMessage.attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + baseMessage.attachment.fileSize + ) + intent.putExtra( + UIKitConstants.IntentStrings.TYPE, + baseMessage.getReceiverType() + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.getCategory() + ) if (baseMessage.getReceiverType() == CometChatConstants.RECEIVER_TYPE_GROUP) { - intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid()) + intent.putExtra( + UIKitConstants.IntentStrings.GUID, + baseMessage.getReceiverUid() + ) } else { - if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid()) + if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getSender().uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getReceiverUid() + ) } context.startActivity(intent) }) if ((baseMessage as MediaMessage).attachment != null) { - viewHolder.view.audiolengthTv.text = Utils.getFileSize((baseMessage as MediaMessage).attachment.fileSize) + viewHolder.view.audiolengthTv.text = + Utils.getFileSize((baseMessage as MediaMessage).attachment.fileSize) viewHolder.view.playBtn.visibility = View.VISIBLE } else { viewHolder.view.audiolengthTv.text = "-" @@ -1723,7 +2416,11 @@ class MessageAdapter(context: Context, messageList: List, type: Str try { mediaPlayer?.setDataSource(baseMessage.attachment.fileUrl) mediaPlayer?.prepare() - mediaPlayer?.setOnCompletionListener { (viewHolder as RightAudioMessageViewHolder).view.playBtn.setImageResource(R.drawable.ic_play_arrow_black_24dp) } + mediaPlayer?.setOnCompletionListener { + (viewHolder as RightAudioMessageViewHolder).view.playBtn.setImageResource( + R.drawable.ic_play_arrow_black_24dp + ) + } } catch (e: Exception) { Log.e(TAG, "MediaPlayerError: " + e.message) } @@ -1769,7 +2466,7 @@ class MessageAdapter(context: Context, messageList: List, type: Str private fun setFileData(view: RecyclerView.ViewHolder, i: Int) { val baseMessage = messageList[i] if (baseMessage != null && baseMessage.deletedAt == 0L) { - var viewHolder : RecyclerView.ViewHolder + var viewHolder: RecyclerView.ViewHolder if (view is LeftFileMessageViewHolder) { viewHolder = view as LeftFileMessageViewHolder if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_USER) { @@ -1783,7 +2480,11 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } if ((baseMessage as MediaMessage).attachment != null) { @@ -1802,7 +2503,8 @@ class MessageAdapter(context: Context, messageList: List, type: Str // else viewHolder.view.txtTime.visibility = View.GONE if (baseMessage.getReplyCount() != 0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.getReplyCount().toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.getReplyCount().toString() + " Replies" } else { viewHolder.view.replyAvatarLayout.visibility = View.GONE viewHolder.view.threadReplyCount.visibility = View.GONE @@ -1811,23 +2513,62 @@ class MessageAdapter(context: Context, messageList: List, type: Str val intent = Intent(context, CometChatThreadMessageListActivity::class.java) // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().name) - intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount()) + intent.putExtra( + UIKitConstants.IntentStrings.AVATAR, + baseMessage.getSender().avatar + ) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.getReplyCount() + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType()) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + baseMessage.getType() + ) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, baseMessage.attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, baseMessage.attachment.fileExtension) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, baseMessage.attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, baseMessage.attachment.fileSize) - intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory()) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + baseMessage.attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + baseMessage.attachment.fileExtension + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + baseMessage.attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + baseMessage.attachment.fileSize + ) + intent.putExtra( + UIKitConstants.IntentStrings.TYPE, + baseMessage.getReceiverType() + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.getCategory() + ) if (baseMessage.getReceiverType() == CometChatConstants.RECEIVER_TYPE_GROUP) { - intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid()) + intent.putExtra( + UIKitConstants.IntentStrings.GUID, + baseMessage.getReceiverUid() + ) } else { - if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid()) + if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getSender().uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getReceiverUid() + ) } context.startActivity(intent) }) @@ -1840,7 +2581,12 @@ class MessageAdapter(context: Context, messageList: List, type: Str // } notifyDataSetChanged() } - viewHolder.view.tvFileName.setOnClickListener { view: View? -> MediaUtils.openFile(baseMessage.attachment.fileUrl, context) } + viewHolder.view.tvFileName.setOnClickListener { view: View? -> + MediaUtils.openFile( + baseMessage.attachment.fileUrl, + context + ) + } viewHolder.view.cvMessageContainer.setOnLongClickListener { if (!isLongClickEnabled && !isTextMessageClick) { isImageMessageClick = true @@ -1870,7 +2616,8 @@ class MessageAdapter(context: Context, messageList: List, type: Str // else viewHolder.view.txtTime.visibility = View.GONE if (baseMessage.getReplyCount() != 0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.getReplyCount().toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.getReplyCount().toString() + " Replies" } else { viewHolder.view.replyAvatarLayout.visibility = View.GONE viewHolder.view.threadReplyCount.visibility = View.GONE @@ -1879,23 +2626,62 @@ class MessageAdapter(context: Context, messageList: List, type: Str val intent = Intent(context, CometChatThreadMessageListActivity::class.java) // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().name) - intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount()) + intent.putExtra( + UIKitConstants.IntentStrings.AVATAR, + baseMessage.getSender().avatar + ) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.getReplyCount() + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType()) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + baseMessage.getType() + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt()) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, baseMessage.attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, baseMessage.attachment.fileExtension) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, baseMessage.attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, baseMessage.attachment.fileSize) - intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory()) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + baseMessage.attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + baseMessage.attachment.fileExtension + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + baseMessage.attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + baseMessage.attachment.fileSize + ) + intent.putExtra( + UIKitConstants.IntentStrings.TYPE, + baseMessage.getReceiverType() + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.getCategory() + ) if (baseMessage.getReceiverType() == CometChatConstants.RECEIVER_TYPE_GROUP) { - intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid()) + intent.putExtra( + UIKitConstants.IntentStrings.GUID, + baseMessage.getReceiverUid() + ) } else { - if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid()) + if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getSender().uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getReceiverUid() + ) } context.startActivity(intent) }) @@ -1908,7 +2694,12 @@ class MessageAdapter(context: Context, messageList: List, type: Str // } notifyDataSetChanged() } - viewHolder.view.tvFileName.setOnClickListener { view: View? -> MediaUtils.openFile(baseMessage.attachment.fileUrl, context) } + viewHolder.view.tvFileName.setOnClickListener { view: View? -> + MediaUtils.openFile( + baseMessage.attachment.fileUrl, + context + ) + } viewHolder.view.cvMessageContainer.setOnLongClickListener { if (!isLongClickEnabled && !isTextMessageClick) { isImageMessageClick = true @@ -1938,7 +2729,7 @@ class MessageAdapter(context: Context, messageList: List, type: Str private fun setImageData(view: RecyclerView.ViewHolder, i: Int) { val baseMessage = messageList[i] Log.d(TAG, "setImageData: imgBasemsg " + baseMessage) - var viewHolder : RecyclerView.ViewHolder + var viewHolder: RecyclerView.ViewHolder if (view is LeftImageMessageViewHolder) { viewHolder = view as LeftImageMessageViewHolder if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_USER) { @@ -1952,17 +2743,23 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } viewHolder.view.goImgMessage.setImageDrawable(context.resources.getDrawable(R.drawable.ic_defaulf_image)) - FeatureRestriction.isImageModerationEnabled(object : FeatureRestriction.OnSuccessListener { + FeatureRestriction.isImageModerationEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { isImageNotSafe = Extensions.getImageModeration(context, baseMessage) } }) - FeatureRestriction.isThumbnailGenerationEnabled(object : FeatureRestriction.OnSuccessListener { + FeatureRestriction.isThumbnailGenerationEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) thumbnailUrl = Extensions.getThumbnailGeneration(context, baseMessage) @@ -1985,7 +2782,12 @@ class MessageAdapter(context: Context, messageList: List, type: Str if (baseMessage.attachment.fileExtension.equals(".gif", ignoreCase = true)) setImageDrawable(viewHolder, baseMessage.attachment.fileUrl, true, false) else - setImageDrawable(viewHolder, baseMessage.attachment.fileUrl, false, isImageNotSafe) + setImageDrawable( + viewHolder, + baseMessage.attachment.fileUrl, + false, + isImageNotSafe + ) } } if (isImageNotSafe) { @@ -2001,7 +2803,8 @@ class MessageAdapter(context: Context, messageList: List, type: Str if (baseMessage.getReplyCount() != 0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.getReplyCount().toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.getReplyCount().toString() + " Replies" } else { viewHolder.view.replyAvatarLayout.visibility = View.GONE viewHolder.view.threadReplyCount.visibility = View.GONE @@ -2011,22 +2814,49 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount()) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.getReplyCount() + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId()) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType()) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, (baseMessage as MediaMessage).attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, baseMessage.attachment.fileExtension) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, baseMessage.attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, baseMessage.attachment.fileSize) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + (baseMessage as MediaMessage).attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + baseMessage.attachment.fileExtension + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + baseMessage.attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + baseMessage.attachment.fileSize + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory()) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.getCategory() + ) if (baseMessage.getReceiverType() == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid()) } else { - if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid()) + if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getSender().uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getReceiverUid() + ) } context.startActivity(intent) }) @@ -2036,7 +2866,12 @@ class MessageAdapter(context: Context, messageList: List, type: Str alert.setTitle("Unsafe Content") alert.setIcon(R.drawable.ic_hand) alert.setMessage("Are you surely want to see this unsafe content") - alert.setPositiveButton("Yes") { dialog, which -> MediaUtils.openFile((baseMessage as MediaMessage).attachment.fileUrl, context) } + alert.setPositiveButton("Yes") { dialog, which -> + MediaUtils.openFile( + (baseMessage as MediaMessage).attachment.fileUrl, + context + ) + } alert.setNegativeButton("No") { dialog, which -> dialog.dismiss() } alert.create().show() } else { @@ -2062,12 +2897,14 @@ class MessageAdapter(context: Context, messageList: List, type: Str // if (FeatureRestriction.isImageModerationEnabled()) // isImageNotSafe = Extensions.getImageModeration(context, baseMessage) - FeatureRestriction.isImageModerationEnabled(object : FeatureRestriction.OnSuccessListener { + FeatureRestriction.isImageModerationEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { isImageNotSafe = Extensions.getImageModeration(context, baseMessage) } }) - FeatureRestriction.isThumbnailGenerationEnabled(object : FeatureRestriction.OnSuccessListener { + FeatureRestriction.isThumbnailGenerationEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) thumbnailUrl = Extensions.getThumbnailGeneration(context, baseMessage) @@ -2088,7 +2925,12 @@ class MessageAdapter(context: Context, messageList: List, type: Str if (baseMessage.attachment.fileExtension.equals(".gif", ignoreCase = true)) setImageDrawable(viewHolder, baseMessage.attachment.fileUrl, true, false) else - setImageDrawable(viewHolder, baseMessage.attachment.fileUrl, false, isImageNotSafe) + setImageDrawable( + viewHolder, + baseMessage.attachment.fileUrl, + false, + isImageNotSafe + ) } } if (isImageNotSafe) { @@ -2101,12 +2943,14 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.txtTime.visibility = View.VISIBLE // else viewHolder.view.txtTime.visibility = View.GONE // - if (baseMessage.replyCount != 0 ) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + if (baseMessage.replyCount != 0) { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -2119,22 +2963,49 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount()) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.getReplyCount() + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId()) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType()) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, (baseMessage as MediaMessage).attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, baseMessage.attachment.fileExtension) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, baseMessage.attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, baseMessage.attachment.fileSize) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + (baseMessage as MediaMessage).attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + baseMessage.attachment.fileExtension + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + baseMessage.attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + baseMessage.attachment.fileSize + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory()) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.getCategory() + ) if (baseMessage.getReceiverType() == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid()) } else { - if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid()) + if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getSender().uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getReceiverUid() + ) } context.startActivity(intent) }) @@ -2144,7 +3015,12 @@ class MessageAdapter(context: Context, messageList: List, type: Str alert.setTitle("Unsafe Content") alert.setIcon(R.drawable.ic_hand) alert.setMessage("Are you surely want to see this unsafe content") - alert.setPositiveButton("Yes") { dialog, which -> MediaUtils.openFile((baseMessage as MediaMessage).attachment.fileUrl, context) } + alert.setPositiveButton("Yes") { dialog, which -> + MediaUtils.openFile( + (baseMessage as MediaMessage).attachment.fileUrl, + context + ) + } alert.setNegativeButton("No") { dialog, which -> dialog.dismiss() } alert.create().show() } else { @@ -2167,16 +3043,29 @@ class MessageAdapter(context: Context, messageList: List, type: Str } } - private fun setImageDrawable(viewHolder: RecyclerView.ViewHolder, url: String?, isGif: Boolean, isImageNotSafe: Boolean) { + private fun setImageDrawable( + viewHolder: RecyclerView.ViewHolder, + url: String?, + isGif: Boolean, + isImageNotSafe: Boolean + ) { if (viewHolder is LeftImageMessageViewHolder) { if (isGif) { Glide.with(context).asGif().diskCacheStrategy(DiskCacheStrategy.NONE) - .skipMemoryCache(true).load(url).into(viewHolder.view.goImgMessage) + .skipMemoryCache(true).load(url).into(viewHolder.view.goImgMessage) } else { Glide.with(context).asBitmap().load(url).into(object : CustomTarget() { - override fun onResourceReady(resource: Bitmap, transition: Transition?) { + override fun onResourceReady( + resource: Bitmap, + transition: Transition? + ) { if (isImageNotSafe) - viewHolder.view.goImgMessage.setImageBitmap(Utils.blur(context, resource)) + viewHolder.view.goImgMessage.setImageBitmap( + Utils.blur( + context, + resource + ) + ) else viewHolder.view.goImgMessage.setImageBitmap(resource) } @@ -2187,17 +3076,24 @@ class MessageAdapter(context: Context, messageList: List, type: Str }) } - } - else { + } else { viewHolder as RightImageMessageViewHolder if (isGif) { Glide.with(context).asGif().diskCacheStrategy(DiskCacheStrategy.NONE) - .skipMemoryCache(true).load(url).into(viewHolder.view.goImgMessage) + .skipMemoryCache(true).load(url).into(viewHolder.view.goImgMessage) } else { Glide.with(context).asBitmap().load(url).into(object : CustomTarget() { - override fun onResourceReady(resource: Bitmap, transition: Transition?) { + override fun onResourceReady( + resource: Bitmap, + transition: Transition? + ) { if (isImageNotSafe) - viewHolder.view.goImgMessage.setImageBitmap(Utils.blur(context, resource)) + viewHolder.view.goImgMessage.setImageBitmap( + Utils.blur( + context, + resource + ) + ) else viewHolder.view.goImgMessage.setImageBitmap(resource) } @@ -2228,7 +3124,7 @@ class MessageAdapter(context: Context, messageList: List, type: Str private fun setVideoData(view: RecyclerView.ViewHolder, i: Int) { val baseMessage = messageList[i] - var viewHolder : RecyclerView.ViewHolder + var viewHolder: RecyclerView.ViewHolder if (view is LeftVideoMessageViewHolder) { viewHolder = view as LeftVideoMessageViewHolder if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_USER) { @@ -2242,10 +3138,15 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } - if ((baseMessage as MediaMessage).attachment != null) Glide.with(context).load(baseMessage.attachment.fileUrl).into(viewHolder.view.goVideoMessage) + if ((baseMessage as MediaMessage).attachment != null) Glide.with(context) + .load(baseMessage.attachment.fileUrl).into(viewHolder.view.goVideoMessage) showMessageTime(viewHolder, baseMessage) // if (selectedItemList.contains(baseMessage.getId())) viewHolder.view.txtTime.visibility = View.VISIBLE @@ -2253,7 +3154,9 @@ class MessageAdapter(context: Context, messageList: List, type: Str // if (baseMessage.getReplyCount() != 0) { viewHolder.view.threadReplyCount.setVisibility(View.VISIBLE) - viewHolder.view.threadReplyCount.setText(baseMessage.getReplyCount().toString() + " Replies") + viewHolder.view.threadReplyCount.setText( + baseMessage.getReplyCount().toString() + " Replies" + ) } else { viewHolder.view.replyAvatarLayout.setVisibility(View.GONE) viewHolder.view.threadReplyCount.setVisibility(View.GONE) @@ -2263,22 +3166,49 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount()) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.getReplyCount() + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId()) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType()) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, baseMessage.attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, baseMessage.attachment.fileExtension) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, baseMessage.attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, baseMessage.attachment.fileSize) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + baseMessage.attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + baseMessage.attachment.fileExtension + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + baseMessage.attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + baseMessage.attachment.fileSize + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory()) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.getCategory() + ) if (baseMessage.getReceiverType() == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid()) } else { - if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid()) + if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getSender().uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getReceiverUid() + ) } context.startActivity(intent) }) @@ -2295,12 +3225,18 @@ class MessageAdapter(context: Context, messageList: List, type: Str } true } - viewHolder.view.playBtn.setOnClickListener { MediaUtils.openFile(baseMessage.attachment.fileUrl, context) } + viewHolder.view.playBtn.setOnClickListener { + MediaUtils.openFile( + baseMessage.attachment.fileUrl, + context + ) + } viewHolder.view.reactionsLayout.visibility = View.GONE setReactionSupport(baseMessage, viewHolder.view.reactionsLayout) } else { viewHolder = view as RightVideoMessageViewHolder - if ((baseMessage as MediaMessage).attachment != null) Glide.with(context).load(baseMessage.attachment.fileUrl).into(viewHolder.view.goVideoMessage) + if ((baseMessage as MediaMessage).attachment != null) Glide.with(context) + .load(baseMessage.attachment.fileUrl).into(viewHolder.view.goVideoMessage) showMessageTime(viewHolder, baseMessage) // if (selectedItemList.contains(baseMessage.getId())) viewHolder.view.txtTime.visibility = View.VISIBLE @@ -2308,7 +3244,8 @@ class MessageAdapter(context: Context, messageList: List, type: Str // if (baseMessage.getReplyCount() != 0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.getReplyCount().toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.getReplyCount().toString() + " Replies" } else { viewHolder.view.replyAvatarLayout.visibility = View.GONE viewHolder.view.threadReplyCount.visibility = View.GONE @@ -2318,22 +3255,49 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount()) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.getReplyCount() + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId()) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType()) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt()) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, baseMessage.attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, baseMessage.attachment.fileExtension) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, baseMessage.attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, baseMessage.attachment.fileSize) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + baseMessage.attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + baseMessage.attachment.fileExtension + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + baseMessage.attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + baseMessage.attachment.fileSize + ) intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory()) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.getCategory() + ) if (baseMessage.getReceiverType() == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid()) } else { - if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid()) + if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getSender().uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getReceiverUid() + ) } context.startActivity(intent) }) @@ -2350,8 +3314,13 @@ class MessageAdapter(context: Context, messageList: List, type: Str } true } - if(baseMessage.attachment!=null) - viewHolder.view.playBtn.setOnClickListener { MediaUtils.openFile(baseMessage?.attachment?.fileUrl, context) } + if (baseMessage.attachment != null) + viewHolder.view.playBtn.setOnClickListener { + MediaUtils.openFile( + baseMessage?.attachment?.fileUrl, + context + ) + } viewHolder.view.reactionsLayout.visibility = View.GONE setReactionSupport(baseMessage, viewHolder.view.reactionsLayout) } @@ -2373,18 +3342,24 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } viewHolder.view.goTxtMessage.setTypeface(null, Typeface.ITALIC) showMessageTime(viewHolder, baseMessage) - if (selectedItemList.contains(baseMessage.id)) viewHolder.view.txtTime.visibility = View.VISIBLE else viewHolder.view.txtTime.visibility = View.GONE + if (selectedItemList.contains(baseMessage.id)) viewHolder.view.txtTime.visibility = + View.VISIBLE else viewHolder.view.txtTime.visibility = View.GONE } else { viewHolder = view as RightDeleteMessageViewHolder viewHolder.view.goTxtMessage.setTypeface(null, Typeface.ITALIC) showMessageTime(viewHolder, baseMessage) - if (selectedItemList.contains(baseMessage.id)) viewHolder.view.txtTime.visibility = View.VISIBLE else viewHolder.view.txtTime.visibility = View.GONE + if (selectedItemList.contains(baseMessage.id)) viewHolder.view.txtTime.visibility = + View.VISIBLE else viewHolder.view.txtTime.visibility = View.GONE } } @@ -2404,35 +3379,44 @@ class MessageAdapter(context: Context, messageList: List, type: Str private fun setActionData(view: ActionMessageViewHolder, i: Int) { val baseMessage = messageList[i] val viewHolder = view as ActionMessageViewHolder - if (Utils.isDarkMode(context)) viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.textColorWhite)) else viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.primaryTextColor)) + if (Utils.isDarkMode(context)) viewHolder.view.goTxtMessage.setTextColor( + context.resources.getColor( + R.color.textColorWhite + ) + ) else viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.primaryTextColor)) viewHolder.view.goTxtMessage.typeface = fontUtils.getTypeFace(FontUtils.robotoMedium) if (baseMessage is Action) { var actionMessage: String? = "" if (baseMessage.action == CometChatConstants.ActionKeys.ACTION_JOINED) - actionMessage = (baseMessage.actioBy as User).name + " " + context.getString(R.string.joined) - else if (baseMessage.action == CometChatConstants.ActionKeys.ACTION_MEMBER_ADDED) actionMessage = ((baseMessage.actioBy as User).name + " " - + context.getString(R.string.added) + " " + (baseMessage.actionOn as User).name) - else if (baseMessage.action == CometChatConstants.ActionKeys.ACTION_KICKED) actionMessage = ((baseMessage.actioBy as User).name + " " - + context.getString(R.string.kicked_by) + " " + (baseMessage.actionOn as User).name) - else if (baseMessage.action == CometChatConstants.ActionKeys.ACTION_BANNED) actionMessage = ((baseMessage.actioBy as User).name + " " - + context.getString(R.string.ban) + " " + (baseMessage.actionOn as User).name) - else if (baseMessage.action == CometChatConstants.ActionKeys.ACTION_UNBANNED) actionMessage = ((baseMessage.actioBy as User).name + " " - + context.getString(R.string.unban) + " " + (baseMessage.actionOn as User).name) - else if (baseMessage.action == CometChatConstants.ActionKeys.ACTION_LEFT) actionMessage = (baseMessage.actioBy as User).name + " " + context.getString(R.string.left) + actionMessage = + (baseMessage.actioBy as User).name + " " + context.getString(R.string.joined) + else if (baseMessage.action == CometChatConstants.ActionKeys.ACTION_MEMBER_ADDED) actionMessage = + ((baseMessage.actioBy as User).name + " " + + context.getString(R.string.added) + " " + (baseMessage.actionOn as User).name) + else if (baseMessage.action == CometChatConstants.ActionKeys.ACTION_KICKED) actionMessage = + ((baseMessage.actioBy as User).name + " " + + context.getString(R.string.kicked_by) + " " + (baseMessage.actionOn as User).name) + else if (baseMessage.action == CometChatConstants.ActionKeys.ACTION_BANNED) actionMessage = + ((baseMessage.actioBy as User).name + " " + + context.getString(R.string.ban) + " " + (baseMessage.actionOn as User).name) + else if (baseMessage.action == CometChatConstants.ActionKeys.ACTION_UNBANNED) actionMessage = + ((baseMessage.actioBy as User).name + " " + + context.getString(R.string.unban) + " " + (baseMessage.actionOn as User).name) + else if (baseMessage.action == CometChatConstants.ActionKeys.ACTION_LEFT) actionMessage = + (baseMessage.actioBy as User).name + " " + context.getString(R.string.left) else if (baseMessage.action == CometChatConstants.ActionKeys.ACTION_SCOPE_CHANGED) actionMessage = if (baseMessage.newScope == CometChatConstants.SCOPE_MODERATOR) { - ((baseMessage.actioBy as User).name + " " + context.getString(R.string.made) + " " - + (baseMessage.actionOn as User).name + " " + context.getString(R.string.moderator)) - } else if (baseMessage.newScope == CometChatConstants.SCOPE_ADMIN) { - ((baseMessage.actioBy as User).name + " " + context.getString(R.string.made) + " " - + (baseMessage.actionOn as User).name + " " + context.getString(R.string.admin)) - } else if (baseMessage.newScope == CometChatConstants.SCOPE_PARTICIPANT) { - ((baseMessage.actioBy as User).name + " " + context.getString(R.string.made) + " " - + (baseMessage.actionOn as User).name + " " + context.getString(R.string.participant)) - } else baseMessage.message + ((baseMessage.actioBy as User).name + " " + context.getString(R.string.made) + " " + + (baseMessage.actionOn as User).name + " " + context.getString(R.string.moderator)) + } else if (baseMessage.newScope == CometChatConstants.SCOPE_ADMIN) { + ((baseMessage.actioBy as User).name + " " + context.getString(R.string.made) + " " + + (baseMessage.actionOn as User).name + " " + context.getString(R.string.admin)) + } else if (baseMessage.newScope == CometChatConstants.SCOPE_PARTICIPANT) { + ((baseMessage.actioBy as User).name + " " + context.getString(R.string.made) + " " + + (baseMessage.actionOn as User).name + " " + context.getString(R.string.participant)) + } else baseMessage.message viewHolder.view.goTxtMessage.text = actionMessage - } - else if (baseMessage is Call) { + } else if (baseMessage is Call) { // val call = baseMessage // if (call.callStatus == CometChatConstants.CALL_STATUS_INITIATED) viewHolder.view.goTxtMessage.text = call.sender.name + " " + call.callStatus + " " + call.type + " " + context.resources.getString(R.string.call).toLowerCase() else viewHolder.view.goTxtMessage.text = context.resources.getString(R.string.call) + " " + baseMessage.callStatus @@ -2457,10 +3441,12 @@ class MessageAdapter(context: Context, messageList: List, type: Str } if (call.type == CometChatConstants.CALL_TYPE_VIDEO) { - callMessageText = callMessageText + " " + context.resources.getString(R.string.video_call) + callMessageText = + callMessageText + " " + context.resources.getString(R.string.video_call) isVideo = true } else { - callMessageText = callMessageText + " " + context.resources.getString(R.string.audio_call) + callMessageText = + callMessageText + " " + context.resources.getString(R.string.audio_call) isVideo = false } viewHolder.view.goTxtMessage.text = callMessageText @@ -2487,11 +3473,11 @@ class MessageAdapter(context: Context, messageList: List, type: Str setStatusIcon(viewHolder.view.txtTime, baseMessage) } else if (viewHolder is LeftFileMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) - } else if (viewHolder is LeftAudioMessageViewHolder){ + } else if (viewHolder is LeftAudioMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) - } else if (viewHolder is LeftVideoMessageViewHolder){ + } else if (viewHolder is LeftVideoMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) - } else if (viewHolder is LeftLocationMessageViewHolder){ + } else if (viewHolder is LeftLocationMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) } else if (viewHolder is LeftCustomMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) @@ -2503,10 +3489,7 @@ class MessageAdapter(context: Context, messageList: List, type: Str setStatusIcon(viewHolder.view.txtTime, baseMessage) } else if (viewHolder is LeftPollsMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) - } - - - else if (viewHolder is RightTextMessageViewHolder) { + } else if (viewHolder is RightTextMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) } else if (viewHolder is RightLinkMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) @@ -2514,11 +3497,11 @@ class MessageAdapter(context: Context, messageList: List, type: Str setStatusIcon(viewHolder.view.txtTime, baseMessage) } else if (viewHolder is RightFileMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) - } else if (viewHolder is RightAudioMessageViewHolder){ + } else if (viewHolder is RightAudioMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) - } else if (viewHolder is RightVideoMessageViewHolder){ + } else if (viewHolder is RightVideoMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) - } else if (viewHolder is RightLocationMessageViewHolder){ + } else if (viewHolder is RightLocationMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) } else if (viewHolder is RightCustomMessageViewHolder) { setStatusIcon(viewHolder.view.txtTime, baseMessage) @@ -2550,22 +3533,47 @@ class MessageAdapter(context: Context, messageList: List, type: Str if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_USER) { if (baseMessage.readAt != 0L) { txtTime.text = Utils.getHeaderDate(baseMessage.readAt * 1000) - txtTime.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_message_read, 0) + txtTime.setCompoundDrawablesWithIntrinsicBounds( + 0, + 0, + R.drawable.ic_message_read, + 0 + ) txtTime.compoundDrawablePadding = 10 } else if (baseMessage.deliveredAt != 0L) { txtTime.text = Utils.getHeaderDate(baseMessage.deliveredAt * 1000) - txtTime.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_message_delivered, 0) + txtTime.setCompoundDrawablesWithIntrinsicBounds( + 0, + 0, + R.drawable.ic_message_delivered, + 0 + ) txtTime.compoundDrawablePadding = 10 } else if (baseMessage.sentAt > 0) { txtTime.text = Utils.getHeaderDate(baseMessage.sentAt * 1000) - txtTime.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_message_sent, 0) + txtTime.setCompoundDrawablesWithIntrinsicBounds( + 0, + 0, + R.drawable.ic_message_sent, + 0 + ) txtTime.compoundDrawablePadding = 10 } else if (baseMessage.sentAt == -1L) { txtTime.text = "" - txtTime.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_error, 0) + txtTime.setCompoundDrawablesWithIntrinsicBounds( + 0, + 0, + R.drawable.ic_error, + 0 + ) } else { txtTime.text = Utils.getHeaderDate(baseMessage.sentAt * 1000) - txtTime.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_message_sent, 0) + txtTime.setCompoundDrawablesWithIntrinsicBounds( + 0, + 0, + R.drawable.ic_message_sent, + 0 + ) txtTime.compoundDrawablePadding = 10 } } else { @@ -2574,7 +3582,12 @@ class MessageAdapter(context: Context, messageList: List, type: Str txtTime.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) } else { txtTime.text = "" - txtTime.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_wait, 0) + txtTime.setCompoundDrawablesWithIntrinsicBounds( + 0, + 0, + R.drawable.ic_wait, + 0 + ) txtTime.compoundDrawablePadding = 10 } } @@ -2617,7 +3630,11 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } } @@ -2626,19 +3643,23 @@ class MessageAdapter(context: Context, messageList: List, type: Str // val txtMessage = baseMessage.text.trim { it <= ' ' } var message = txtMessage - if(isProfanityFilter) { + if (isProfanityFilter) { message = Extensions.getProfanityFilter(baseMessage) } - if(isDataMasking) { + if (isDataMasking) { message = Extensions.checkDataMasking(baseMessage) } - viewHolder.view.goTxtMessage.text = Html.fromHtml(message,Html.FROM_HTML_MODE_COMPACT) + viewHolder.view.goTxtMessage.text = + Html.fromHtml(message, Html.FROM_HTML_MODE_COMPACT) viewHolder.view.goTxtMessage.movementMethod = LinkMovementMethod.getInstance() - viewHolder.view.goTxtMessage.typeface = fontUtils.getTypeFace(FontUtils.robotoRegular) - if (baseMessage.getSender().uid == loggedInUser.uid) viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.textColorWhite)) else viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.primaryTextColor)) + viewHolder.view.goTxtMessage.typeface = + fontUtils.getTypeFace(FontUtils.robotoRegular) + if (baseMessage.getSender().uid == loggedInUser.uid) viewHolder.view.goTxtMessage.setTextColor( + context.resources.getColor(R.color.textColorWhite) + ) else viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.primaryTextColor)) showMessageTime(viewHolder, baseMessage) // if (messageList[messageList.size - 1] == baseMessage) { // selectedItemList.add(baseMessage.getId()) @@ -2655,21 +3676,22 @@ class MessageAdapter(context: Context, messageList: List, type: Str } else { setSelectedMessage(baseMessage.getId()) } - notifyDataSetChanged() } - viewHolder.view.rlMessage.setOnLongClickListener { + viewHolder.view.goTxtMessage.setOnLongClickListener { if (!isImageMessageClick) { isLongClickEnabled = true isTextMessageClick = true setLongClickSelectedItem(baseMessage) messageLongClick?.setLongMessageClick(longselectedItemList) - notifyDataSetChanged() } true } viewHolder.view.root.setTag(R.string.message, baseMessage) - if ((baseMessage.metadata != null && baseMessage.metadata.has("reply-message")) || (baseMessage.metadata != null && baseMessage.metadata.has("replyToMessage"))) { + if ((baseMessage.metadata != null && baseMessage.metadata.has("reply-message")) || (baseMessage.metadata != null && baseMessage.metadata.has( + "replyToMessage" + )) + ) { try { var metaData = JSONObject() if (baseMessage.metadata.has("reply-message")) @@ -2688,44 +3710,65 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.replyItem.replyMessage.text = replyMessage viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + CometChatConstants.MESSAGE_TYPE_IMAGE -> { - viewHolder.view.replyItem.replyMessage.text = context.resources.getString(R.string.message_image) + viewHolder.view.replyItem.replyMessage.text = + context.resources.getString(R.string.message_image) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + CometChatConstants.MESSAGE_TYPE_AUDIO -> { - viewHolder.view.replyItem.replyMessage.text = context.resources.getString(R.string.message_audio) + viewHolder.view.replyItem.replyMessage.text = + context.resources.getString(R.string.message_audio) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + CometChatConstants.MESSAGE_TYPE_VIDEO -> { - viewHolder.view.replyItem.replyMessage.text = context.resources.getString(R.string.message_video) + viewHolder.view.replyItem.replyMessage.text = + context.resources.getString(R.string.message_video) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + CometChatConstants.MESSAGE_TYPE_FILE -> { - viewHolder.view.replyItem.replyMessage.text = context.resources.getString(R.string.message_file) + viewHolder.view.replyItem.replyMessage.text = + context.resources.getString(R.string.message_file) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + UIKitConstants.IntentStrings.LOCATION -> { - viewHolder.view.replyItem.replyMessage.text = context.resources.getString(R.string.custom_message_location) - viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.VISIBLE + viewHolder.view.replyItem.replyMessage.text = + context.resources.getString(R.string.custom_message_location) + viewHolder.view.replyItem.replyMediaThumbnail.visibility = + View.VISIBLE } + UIKitConstants.IntentStrings.STICKERS -> { - viewHolder.view.replyItem.replyMessage.text = context.getString(R.string.custom_message_sticker) + viewHolder.view.replyItem.replyMessage.text = + context.getString(R.string.custom_message_sticker) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + UIKitConstants.IntentStrings.WHITEBOARD -> { - viewHolder.view.replyItem.replyMessage.text = context.getString(R.string.custom_message_whiteboard) + viewHolder.view.replyItem.replyMessage.text = + context.getString(R.string.custom_message_whiteboard) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + UIKitConstants.IntentStrings.WRITEBOARD -> { - viewHolder.view.replyItem.replyMessage.text = context.getString(R.string.custom_message_document); + viewHolder.view.replyItem.replyMessage.text = + context.getString(R.string.custom_message_document); viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + UIKitConstants.IntentStrings.POLLS -> { - viewHolder.view.replyItem.replyMessage.text = context.getString(R.string.custom_message_poll) + viewHolder.view.replyItem.replyMessage.text = + context.getString(R.string.custom_message_poll) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + UIKitConstants.IntentStrings.MEETING -> { - viewHolder.view.replyItem.replyMessage.text = context.getString(R.string.custom_message_meeting) + viewHolder.view.replyItem.replyMessage.text = + context.getString(R.string.custom_message_meeting) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } } @@ -2735,7 +3778,8 @@ class MessageAdapter(context: Context, messageList: List, type: Str } if (baseMessage.getReplyCount() != 0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.getReplyCount().toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.getReplyCount().toString() + " Replies" } else { viewHolder.view.replyAvatarLayout.visibility = View.GONE viewHolder.view.threadReplyCount.visibility = View.GONE @@ -2744,28 +3788,60 @@ class MessageAdapter(context: Context, messageList: List, type: Str val intent = Intent(context, CometChatThreadMessageListActivity::class.java) // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().name) - intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount()) + intent.putExtra( + UIKitConstants.IntentStrings.AVATAR, + baseMessage.getSender().avatar + ) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.getReplyCount() + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType()) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + baseMessage.getType() + ) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt()) - intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, (baseMessage as TextMessage).text) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory()) - intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType()) + intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + (baseMessage as TextMessage).text + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.getCategory() + ) + intent.putExtra( + UIKitConstants.IntentStrings.TYPE, + baseMessage.getReceiverType() + ) if (baseMessage.getReceiverType() == CometChatConstants.RECEIVER_TYPE_GROUP) { - intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid()) + intent.putExtra( + UIKitConstants.IntentStrings.GUID, + baseMessage.getReceiverUid() + ) } else { - if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid()) + if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getSender().uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getReceiverUid() + ) } context.startActivity(intent) }) // val txtMessage = baseMessage.text.trim { it <= ' ' } viewHolder.view.goTxtMessage.textSize = 16f var count = 0 - val processed = EmojiCompat.get().process(txtMessage, 0, - txtMessage.length - 1, Int.MAX_VALUE, EmojiCompat.REPLACE_STRATEGY_ALL) + val processed = EmojiCompat.get().process( + txtMessage, 0, + txtMessage.length - 1, Int.MAX_VALUE, EmojiCompat.REPLACE_STRATEGY_ALL + ) if (processed is Spannable) { val spannable = processed count = spannable.getSpans(0, spannable.length - 1, EmojiSpan::class.java).size @@ -2800,11 +3876,15 @@ class MessageAdapter(context: Context, messageList: List, type: Str message = Extensions.checkDataMasking(baseMessage) } - viewHolder.view.goTxtMessage.text = Html.fromHtml(message,Html.FROM_HTML_MODE_COMPACT) + viewHolder.view.goTxtMessage.text = + Html.fromHtml(message, Html.FROM_HTML_MODE_COMPACT) viewHolder.view.goTxtMessage.autoLinkMask = Linkify.ALL viewHolder.view.goTxtMessage.linksClickable = true - viewHolder.view.goTxtMessage.typeface = fontUtils.getTypeFace(FontUtils.robotoRegular) - if (baseMessage.getSender().uid == loggedInUser.uid) viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.textColorWhite)) else viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.primaryTextColor)) + viewHolder.view.goTxtMessage.typeface = + fontUtils.getTypeFace(FontUtils.robotoRegular) + if (baseMessage.getSender().uid == loggedInUser.uid) viewHolder.view.goTxtMessage.setTextColor( + context.resources.getColor(R.color.textColorWhite) + ) else viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.primaryTextColor)) showMessageTime(viewHolder, baseMessage) // if (messageList[messageList.size - 1] == baseMessage) { // selectedItemList.add(baseMessage.getId()) @@ -2828,13 +3908,16 @@ class MessageAdapter(context: Context, messageList: List, type: Str isTextMessageClick = true setLongClickSelectedItem(baseMessage) messageLongClick?.setLongMessageClick(longselectedItemList) - notifyDataSetChanged() +// notifyDataSetChanged() } true } viewHolder.view.root.setTag(R.string.message, baseMessage) - if ((baseMessage.metadata != null && baseMessage.metadata.has("reply-message")) || (baseMessage.metadata != null && baseMessage.metadata.has("replyToMessage"))) { + if ((baseMessage.metadata != null && baseMessage.metadata.has("reply-message")) || (baseMessage.metadata != null && baseMessage.metadata.has( + "replyToMessage" + )) + ) { try { var metaData = JSONObject() if (baseMessage.metadata.has("reply-message")) @@ -2853,44 +3936,65 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.replyItem.replyMessage.text = replyMessage viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + CometChatConstants.MESSAGE_TYPE_IMAGE -> { - viewHolder.view.replyItem.replyMessage.text = context.resources.getString(R.string.message_image) + viewHolder.view.replyItem.replyMessage.text = + context.resources.getString(R.string.message_image) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + CometChatConstants.MESSAGE_TYPE_AUDIO -> { - viewHolder.view.replyItem.replyMessage.text = context.resources.getString(R.string.message_audio) + viewHolder.view.replyItem.replyMessage.text = + context.resources.getString(R.string.message_audio) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + CometChatConstants.MESSAGE_TYPE_VIDEO -> { - viewHolder.view.replyItem.replyMessage.text = context.resources.getString(R.string.message_video) + viewHolder.view.replyItem.replyMessage.text = + context.resources.getString(R.string.message_video) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + CometChatConstants.MESSAGE_TYPE_FILE -> { - viewHolder.view.replyItem.replyMessage.text = context.resources.getString(R.string.message_file) + viewHolder.view.replyItem.replyMessage.text = + context.resources.getString(R.string.message_file) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + UIKitConstants.IntentStrings.LOCATION -> { - viewHolder.view.replyItem.replyMessage.text = context.resources.getString(R.string.custom_message_location) - viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.VISIBLE + viewHolder.view.replyItem.replyMessage.text = + context.resources.getString(R.string.custom_message_location) + viewHolder.view.replyItem.replyMediaThumbnail.visibility = + View.VISIBLE } + UIKitConstants.IntentStrings.STICKERS -> { - viewHolder.view.replyItem.replyMessage.text = context.getString(R.string.custom_message_sticker) + viewHolder.view.replyItem.replyMessage.text = + context.getString(R.string.custom_message_sticker) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + UIKitConstants.IntentStrings.WHITEBOARD -> { - viewHolder.view.replyItem.replyMessage.text = context.getString(R.string.custom_message_whiteboard) + viewHolder.view.replyItem.replyMessage.text = + context.getString(R.string.custom_message_whiteboard) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + UIKitConstants.IntentStrings.WRITEBOARD -> { - viewHolder.view.replyItem.replyMessage.text = context.getString(R.string.custom_message_document) + viewHolder.view.replyItem.replyMessage.text = + context.getString(R.string.custom_message_document) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + UIKitConstants.IntentStrings.POLLS -> { - viewHolder.view.replyItem.replyMessage.text = context.getString(R.string.custom_message_poll) + viewHolder.view.replyItem.replyMessage.text = + context.getString(R.string.custom_message_poll) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } + UIKitConstants.IntentStrings.MEETING -> { - viewHolder.view.replyItem.replyMessage.text = context.getString(R.string.custom_message_meeting) + viewHolder.view.replyItem.replyMessage.text = + context.getString(R.string.custom_message_meeting) viewHolder.view.replyItem.replyMediaThumbnail.visibility = View.GONE } } @@ -2900,7 +4004,8 @@ class MessageAdapter(context: Context, messageList: List, type: Str } if (baseMessage.getReplyCount() != 0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.getReplyCount().toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.getReplyCount().toString() + " Replies" } else { viewHolder.view.replyAvatarLayout.visibility = View.GONE viewHolder.view.threadReplyCount.visibility = View.GONE @@ -2909,28 +4014,57 @@ class MessageAdapter(context: Context, messageList: List, type: Str val intent = Intent(context, CometChatThreadMessageListActivity::class.java) // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().name) - intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount()) + intent.putExtra( + UIKitConstants.IntentStrings.AVATAR, + baseMessage.getSender().avatar + ) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.getReplyCount() + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId()) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType()) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE, + baseMessage.getType() + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt()) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, baseMessage.text) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory()) - intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType()) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.getCategory() + ) + intent.putExtra( + UIKitConstants.IntentStrings.TYPE, + baseMessage.getReceiverType() + ) if (baseMessage.getReceiverType() == CometChatConstants.RECEIVER_TYPE_GROUP) { - intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid()) + intent.putExtra( + UIKitConstants.IntentStrings.GUID, + baseMessage.getReceiverUid() + ) } else { - if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid()) + if (baseMessage.getReceiverUid() == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getSender().uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.getReceiverUid() + ) } context.startActivity(intent) }) val txtMessage = baseMessage.text.trim { it <= ' ' } viewHolder.view.goTxtMessage.textSize = 16f var count = 0 - val processed = EmojiCompat.get().process(txtMessage, 0, - txtMessage.length - 1, Int.MAX_VALUE, EmojiCompat.REPLACE_STRATEGY_ALL) + val processed = EmojiCompat.get().process( + txtMessage, 0, + txtMessage.length - 1, Int.MAX_VALUE, EmojiCompat.REPLACE_STRATEGY_ALL + ) if (processed is Spannable) { val spannable = processed count = spannable.getSpans(0, spannable.length - 1, EmojiSpan::class.java).size @@ -2950,22 +4084,41 @@ class MessageAdapter(context: Context, messageList: List, type: Str } - private fun setReactionSupport(baseMessage: BaseMessage, reactionsLayout: ChipGroup) { - val reactionsOnMessage: HashMap = Extensions.getReactionsOnMessage(baseMessage) + private fun setReactionSupport(baseMessage: BaseMessage, reactionsLayout: FlexboxLayout) { + val reactionsOnMessage: HashMap = + Extensions.getReactionsOnMessage(baseMessage) if (reactionsOnMessage.size > 0) { reactionsLayout.visibility = View.VISIBLE reactionsLayout.removeAllViews() for ((k, v) in reactionsOnMessage) { val chip = Chip(context) chip.chipStrokeWidth = 2f - chip.chipBackgroundColor = ColorStateList.valueOf(context.resources.getColor(android.R.color.transparent)) + chip.chipBackgroundColor = + ColorStateList.valueOf(context.resources.getColor(android.R.color.transparent)) // chip.chipStrokeColor = ColorStateList.valueOf(context.resources.getColor(R.color.colorPrimaryDark)) chip.chipStrokeColor = ColorStateList.valueOf(Color.parseColor(UIKitSettings.color)) chip.text = k + " " + reactionsOnMessage[k] + // Create new flexbox layout params + + + reactionsLayout.addView(chip) + val lp = FlexboxLayout.LayoutParams( + FlexboxLayout.LayoutParams.WRAP_CONTENT, + FlexboxLayout.LayoutParams.WRAP_CONTENT + ) + + // Set the margins + lp.setMargins(1, 1, 2, -10) + lp.topMargin = -30 + // Set the new params to the chip + chip.layoutParams = lp chip.setOnLongClickListener { val intent = Intent(context, CometChatReactionInfoActivity::class.java) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, baseMessage.metadata.toString()) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + baseMessage.metadata.toString() + ) context.startActivity(intent) true } @@ -2978,15 +4131,15 @@ class MessageAdapter(context: Context, messageList: List, type: Str e.printStackTrace() } CometChat.callExtension("reactions", "POST", "/v1/react", body, - object : CallbackListener() { - override fun onSuccess(responseObject: JSONObject?) { - // ReactionModel added successfully. - } + object : CallbackListener() { + override fun onSuccess(responseObject: JSONObject?) { + // ReactionModel added successfully. + } - override fun onError(e: CometChatException) { - // Some error occured. - } - }) + override fun onError(e: CometChatException) { + // Some error occured. + } + }) } } } @@ -3010,13 +4163,20 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } - viewHolder.view.goTxtMessage.text = context.resources.getString(R.string.custom_message) + viewHolder.view.goTxtMessage.text = + context.resources.getString(R.string.custom_message) viewHolder.view.goTxtMessage.typeface = fontUtils.getTypeFace(FontUtils.robotoLight) - if (baseMessage.sender.uid == loggedInUser.uid) viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.textColorWhite)) else viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.primaryTextColor)) + if (baseMessage.sender.uid == loggedInUser.uid) viewHolder.view.goTxtMessage.setTextColor( + context.resources.getColor(R.color.textColorWhite) + ) else viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.primaryTextColor)) showMessageTime(viewHolder, baseMessage) // if (messageList[messageList.size - 1] == baseMessage) { // selectedItemList.add(baseMessage.id) @@ -3032,14 +4192,18 @@ class MessageAdapter(context: Context, messageList: List, type: Str } else { viewHolder = view as RightCustomMessageViewHolder viewHolder.view.customMessage = baseMessage as CustomMessage - viewHolder.view.goTxtMessage.text = context.resources.getString(R.string.custom_message) + viewHolder.view.goTxtMessage.text = + context.resources.getString(R.string.custom_message) viewHolder.view.goTxtMessage.typeface = fontUtils.getTypeFace(FontUtils.robotoLight) - if (baseMessage.sender.uid == loggedInUser.uid) viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.textColorWhite)) else viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.primaryTextColor)) + if (baseMessage.sender.uid == loggedInUser.uid) viewHolder.view.goTxtMessage.setTextColor( + context.resources.getColor(R.color.textColorWhite) + ) else viewHolder.view.goTxtMessage.setTextColor(context.resources.getColor(R.color.primaryTextColor)) showMessageTime(viewHolder, baseMessage) if (messageList[messageList.size - 1] == baseMessage) { selectedItemList.add(baseMessage.id) } - if (selectedItemList.contains(baseMessage.id)) viewHolder.view.txtTime.visibility = View.VISIBLE else viewHolder.view.txtTime.visibility = View.GONE + if (selectedItemList.contains(baseMessage.id)) viewHolder.view.txtTime.visibility = + View.VISIBLE else viewHolder.view.txtTime.visibility = View.GONE viewHolder.view.rlMessage.setOnClickListener { view: View? -> setSelectedMessage(baseMessage.id) notifyDataSetChanged() @@ -3057,33 +4221,55 @@ class MessageAdapter(context: Context, messageList: List, type: Str view.setCardBackgroundColor(Color.parseColor(UIKitSettings.color)) } else { if (Build.VERSION.SDK_INT >= 29) { - view.background.colorFilter = PorterDuffColorFilter(Color.parseColor(UIKitSettings.color), PorterDuff.Mode.SRC_ATOP) + view.background.colorFilter = PorterDuffColorFilter( + Color.parseColor(UIKitSettings.color), + PorterDuff.Mode.SRC_ATOP + ) } else { - view.background.setColorFilter(Color.parseColor(UIKitSettings.color), PorterDuff.Mode.SRC_ATOP) + view.background.setColorFilter( + Color.parseColor(UIKitSettings.color), + PorterDuff.Mode.SRC_ATOP + ) } } } else { if (view !is CardView) { - if (Build.VERSION.SDK_INT >= 29) view.background.colorFilter = PorterDuffColorFilter(context.getColor(R.color.message_bubble_grey), PorterDuff.Mode.SRC_ATOP) else view.background.setColorFilter(context.resources.getColor(R.color.message_bubble_grey), PorterDuff.Mode.SRC_ATOP) + if (Build.VERSION.SDK_INT >= 29) view.background.colorFilter = + PorterDuffColorFilter( + context.getColor(R.color.message_bubble_grey), + PorterDuff.Mode.SRC_ATOP + ) else view.background.setColorFilter( + context.resources.getColor(R.color.message_bubble_grey), + PorterDuff.Mode.SRC_ATOP + ) } } } else { if (baseMessage.sentAt > 0 && FeatureRestriction.isEditMessageEnabled() && - FeatureRestriction.isDeleteMessageEnabled() || - FeatureRestriction.isShareCopyForwardMessageEnabled() || - isReplyVisible || - isThreadVisible) { - if (baseMessage.sender == CometChat.getLoggedInUser()) view.background.setColorFilter(context.resources.getColor(R.color.colorPrimaryDark), PorterDuff.Mode.SRC_ATOP) else view.background.setColorFilter(context.resources.getColor(R.color.secondaryTextColor), PorterDuff.Mode.SRC_ATOP) + FeatureRestriction.isDeleteMessageEnabled() || + FeatureRestriction.isShareCopyForwardMessageEnabled() || + isReplyVisible || + isThreadVisible + ) { + if (baseMessage.sender == CometChat.getLoggedInUser()) view.background.setColorFilter( + context.resources.getColor(R.color.colorPrimaryDark), + PorterDuff.Mode.SRC_ATOP + ) else view.background.setColorFilter( + context.resources.getColor(R.color.secondaryTextColor), + PorterDuff.Mode.SRC_ATOP + ) } - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { isThreadVisible = p0 } } }) - FeatureRestriction.isMessageRepliesEnabled(object : FeatureRestriction.OnSuccessListener { + FeatureRestriction.isMessageRepliesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) isReplyVisible = p0 @@ -3115,7 +4301,11 @@ class MessageAdapter(context: Context, messageList: List, type: Str viewHolder.view.tvUser.visibility = View.GONE viewHolder.view.ivUser.visibility = View.INVISIBLE } - setAvatar(viewHolder.view.ivUser, baseMessage.sender.avatar, baseMessage.sender.name) + setAvatar( + viewHolder.view.ivUser, + baseMessage.sender.avatar, + baseMessage.sender.name + ) viewHolder.view.tvUser.text = baseMessage.sender.name } @@ -3129,16 +4319,25 @@ class MessageAdapter(context: Context, messageList: List, type: Str val image = linkPreviewJsonObject?.getString("image") val title = linkPreviewJsonObject?.getString("title") url = linkPreviewJsonObject?.getString("url") - Log.v("setLinkData: ", baseMessage.toString() + "\n\n" + url + "\n" + description + "\n" + image) + Log.v( + "setLinkData: ", + baseMessage.toString() + "\n\n" + url + "\n" + description + "\n" + image + ) viewHolder.view.linkTitle.text = title viewHolder.view.linkSubtitle.text = description - Glide.with(context).load(Uri.parse(image)).timeout(1000).into(viewHolder.view.linkImg) - if ((url != null && url.contains("youtu.be")) || (url != null && url.contains("youtube"))) { + Glide.with(context).load(Uri.parse(image)).timeout(1000) + .into(viewHolder.view.linkImg) + if ((url != null && url.contains("youtu.be")) || (url != null && url.contains( + "youtube" + )) + ) { viewHolder.view.videoLink.visibility = View.VISIBLE - viewHolder.view.visitLink.text = context.resources.getString(R.string.view_on_youtube) + viewHolder.view.visitLink.text = + context.resources.getString(R.string.view_on_youtube) } else { viewHolder.view.videoLink.visibility = View.GONE - viewHolder.view.visitLink.text = context.resources.getString(R.string.visit) + viewHolder.view.visitLink.text = + context.resources.getString(R.string.visit) } val messageStr = (baseMessage as TextMessage).text if (baseMessage.text == url || baseMessage.text == "$url/") { @@ -3153,12 +4352,14 @@ class MessageAdapter(context: Context, messageList: List, type: Str } } } - if (baseMessage.replyCount != 0 ) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + if (baseMessage.replyCount != 0) { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -3171,24 +4372,54 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.type) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.category) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.category + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) - if (baseMessage.type == CometChatConstants.MESSAGE_TYPE_TEXT) intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, (baseMessage as TextMessage).text) else { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, (baseMessage as MediaMessage).attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, baseMessage.attachment.fileExtension) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, baseMessage.attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, baseMessage.attachment.fileSize) + if (baseMessage.type == CometChatConstants.MESSAGE_TYPE_TEXT) intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + (baseMessage as TextMessage).text + ) else { + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + (baseMessage as MediaMessage).attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + baseMessage.attachment.fileExtension + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + baseMessage.attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + baseMessage.attachment.fileSize + ) } intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.receiverType) if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.receiverUid) } else { - if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.receiverUid) + if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.sender.uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.receiverUid + ) } context.startActivity(intent) }) @@ -3243,16 +4474,25 @@ class MessageAdapter(context: Context, messageList: List, type: Str val image = linkPreviewJsonObject?.getString("image") val title = linkPreviewJsonObject?.getString("title") url = linkPreviewJsonObject?.getString("url") - Log.v("setLinkData: ", baseMessage.toString() + "\n\n" + url + "\n" + description + "\n" + image) + Log.v( + "setLinkData: ", + baseMessage.toString() + "\n\n" + url + "\n" + description + "\n" + image + ) viewHolder.view.linkTitle.text = title viewHolder.view.linkSubtitle.text = description - Glide.with(context).load(Uri.parse(image)).timeout(1000).into(viewHolder.view.linkImg) - if ((url != null && url.contains("youtu.be")) || (url != null && url.contains("youtube"))) { + Glide.with(context).load(Uri.parse(image)).timeout(1000) + .into(viewHolder.view.linkImg) + if ((url != null && url.contains("youtu.be")) || (url != null && url.contains( + "youtube" + )) + ) { viewHolder.view.videoLink.visibility = View.VISIBLE - viewHolder.view.visitLink.text = context.resources.getString(R.string.view_on_youtube) + viewHolder.view.visitLink.text = + context.resources.getString(R.string.view_on_youtube) } else { viewHolder.view.videoLink.visibility = View.GONE - viewHolder.view.visitLink.text = context.resources.getString(R.string.visit) + viewHolder.view.visitLink.text = + context.resources.getString(R.string.visit) } val messageStr = (baseMessage as TextMessage).text if (baseMessage.text == url || baseMessage.text == "$url/") { @@ -3267,12 +4507,14 @@ class MessageAdapter(context: Context, messageList: List, type: Str } } } - if (baseMessage.replyCount != 0 ) { - FeatureRestriction.isThreadedMessagesEnabled(object : FeatureRestriction.OnSuccessListener { + if (baseMessage.replyCount != 0) { + FeatureRestriction.isThreadedMessagesEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { if (p0) { viewHolder.view.threadReplyCount.visibility = View.VISIBLE - viewHolder.view.threadReplyCount.text = baseMessage.replyCount.toString() + " Replies" + viewHolder.view.threadReplyCount.text = + baseMessage.replyCount.toString() + " Replies" } } }) @@ -3285,24 +4527,54 @@ class MessageAdapter(context: Context, messageList: List, type: Str // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString()); intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.sender.avatar) - intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.replyCount) + intent.putExtra( + UIKitConstants.IntentStrings.REPLY_COUNT, + baseMessage.replyCount + ) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.name) intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.id) intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.type) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.category) - intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage)) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_CATEGORY, + baseMessage.category + ) + intent.putExtra( + UIKitConstants.IntentStrings.REACTION_INFO, + Extensions.getReactionsOnMessage(baseMessage) + ) intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.sentAt) - if (baseMessage.type == CometChatConstants.MESSAGE_TYPE_TEXT) intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, (baseMessage as TextMessage).text) else { - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, (baseMessage as MediaMessage).attachment.fileName) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, baseMessage.attachment.fileExtension) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, baseMessage.attachment.fileUrl) - intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, baseMessage.attachment.fileSize) + if (baseMessage.type == CometChatConstants.MESSAGE_TYPE_TEXT) intent.putExtra( + UIKitConstants.IntentStrings.TEXTMESSAGE, + (baseMessage as TextMessage).text + ) else { + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, + (baseMessage as MediaMessage).attachment.fileName + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, + baseMessage.attachment.fileExtension + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, + baseMessage.attachment.fileUrl + ) + intent.putExtra( + UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, + baseMessage.attachment.fileSize + ) } intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.receiverType) if (baseMessage.receiverType == CometChatConstants.RECEIVER_TYPE_GROUP) { intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.receiverUid) } else { - if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.sender.uid) else intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.receiverUid) + if (baseMessage.receiverUid == loggedInUser.uid) intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.sender.uid + ) else intent.putExtra( + UIKitConstants.IntentStrings.UID, + baseMessage.receiverUid + ) } context.startActivity(intent) }) @@ -3353,7 +4625,9 @@ class MessageAdapter(context: Context, messageList: List, type: Str } fun setLongClickSelectedItem(baseMessage: BaseMessage) { - if (longselectedItemList.contains(baseMessage)) longselectedItemList.remove(baseMessage) else longselectedItemList.add(baseMessage) + if (longselectedItemList.contains(baseMessage)) longselectedItemList.remove(baseMessage) else longselectedItemList.add( + baseMessage + ) } /** @@ -3367,7 +4641,8 @@ class MessageAdapter(context: Context, messageList: List, type: Str * @see CometChatAvatar */ private fun setAvatar(avatar: CometChatAvatar, avatarUrl: String?, name: String) { - if (avatarUrl != null && avatarUrl.isNotEmpty()) Glide.with(context).load(avatarUrl).into(avatar) else avatar.setInitials(name) + if (avatarUrl != null && avatarUrl.isNotEmpty()) Glide.with(context).load(avatarUrl) + .into(avatar) else avatar.setInitials(name) } override fun getItemCount(): Int { @@ -3381,17 +4656,21 @@ class MessageAdapter(context: Context, messageList: List, type: Str } override fun onCreateHeaderViewHolder(var1: ViewGroup?): DateItemHolder? { - val view = LayoutInflater.from(var1?.context).inflate(R.layout.cometchat_messagedate_header, - var1, false) + val view = LayoutInflater.from(var1?.context).inflate( + R.layout.cometchat_messagedate_header, + var1, false + ) return DateItemHolder(view) } override fun onBindHeaderViewHolder(var1: Any, var2: Int, var3: Long) { val baseMessage = messageList[var2] + Log.e(TAG, "onBindHeaderViewHolder: " + baseMessage) val date = Date(baseMessage.sentAt * 1000L) val formattedDate = Utils.getDate(date.time) var dateItemHolder = var1 as DateItemHolder; - dateItemHolder.txtMessageDate.background = context.resources.getDrawable(R.drawable.cc_rounded_date_button) + dateItemHolder.txtMessageDate.background = + context.resources.getDrawable(R.drawable.cc_rounded_date_button) dateItemHolder.txtMessageDate.text = formattedDate } @@ -3418,36 +4697,47 @@ class MessageAdapter(context: Context, messageList: List, type: Str return when (baseMessage.type) { CometChatConstants.MESSAGE_TYPE_TEXT -> if (baseMessage.sender.uid == loggedInUser.uid) { if (isLinkPreview && extensionList != null && extensionList.containsKey("linkPreview") && extensionList["linkPreview"] != null) RIGHT_LINK_MESSAGE - else if (baseMessage.metadata != null && baseMessage.metadata.has("reply-message") || baseMessage.metadata != null && baseMessage.metadata.has("replyToMessage")) + else if (baseMessage.metadata != null && baseMessage.metadata.has("reply-message") || baseMessage.metadata != null && baseMessage.metadata.has( + "replyToMessage" + ) + ) return RIGHT_REPLY_TEXT_MESSAGE else RIGHT_TEXT_MESSAGE } else { if (isLinkPreview && extensionList != null && extensionList.containsKey("linkPreview") && extensionList["linkPreview"] != null) LEFT_LINK_MESSAGE - else if (baseMessage.metadata != null && baseMessage.metadata.has("reply-message") || baseMessage.metadata != null && baseMessage.metadata.has("replyToMessage")) + else if (baseMessage.metadata != null && baseMessage.metadata.has("reply-message") || baseMessage.metadata != null && baseMessage.metadata.has( + "replyToMessage" + ) + ) return LEFT_REPLY_TEXT_MESSAGE else LEFT_TEXT_MESSAGE } + CometChatConstants.MESSAGE_TYPE_AUDIO -> if (baseMessage.sender.uid == loggedInUser.uid) { RIGHT_AUDIO_MESSAGE } else { LEFT_AUDIO_MESSAGE } + CometChatConstants.MESSAGE_TYPE_IMAGE -> if (baseMessage.sender.uid == loggedInUser.uid) { RIGHT_IMAGE_MESSAGE } else { LEFT_IMAGE_MESSAGE } + CometChatConstants.MESSAGE_TYPE_VIDEO -> if (baseMessage.sender.uid == loggedInUser.uid) { RIGHT_VIDEO_MESSAGE } else { LEFT_VIDEO_MESSAGE } + CometChatConstants.MESSAGE_TYPE_FILE -> if (baseMessage.sender.uid == loggedInUser.uid) { RIGHT_FILE_MESSAGE } else { LEFT_FILE_MESSAGE } + else -> -1 } } else { @@ -3459,7 +4749,7 @@ class MessageAdapter(context: Context, messageList: List, type: Str return CALL_MESSAGE } else if (baseMessage.category == CometChatConstants.CATEGORY_CUSTOM) { if (baseMessage.sender.uid == loggedInUser.uid) { - return when (baseMessage.type){ + return when (baseMessage.type) { UIKitConstants.IntentStrings.LOCATION -> RIGHT_LOCATION_CUSTOM_MESSAGE UIKitConstants.IntentStrings.STICKERS -> RIGHT_STICKER_MESSAGE UIKitConstants.IntentStrings.WHITEBOARD -> RIGHT_WHITEBOARD_MESSAGE @@ -3468,9 +4758,8 @@ class MessageAdapter(context: Context, messageList: List, type: Str UIKitConstants.IntentStrings.POLLS -> RIGHT_POLLS_CUSTOM_MESSAGE else -> RIGHT_CUSTOM_MESSAGE } - } - else { - return when (baseMessage.type){ + } else { + return when (baseMessage.type) { UIKitConstants.IntentStrings.LOCATION -> LEFT_LOCATION_CUSTOM_MESSAGE UIKitConstants.IntentStrings.STICKERS -> LEFT_STICKER_MESSAGE UIKitConstants.IntentStrings.WHITEBOARD -> LEFT_WHITEBOARD_MESSAGE @@ -3566,7 +4855,7 @@ class MessageAdapter(context: Context, messageList: List, type: Str val index = messageList.indexOf(baseMessage) messageList.remove(baseMessage) messageList.add(index, baseMessage) - notifyItemChanged(index) + notifyItemChanged(index, baseMessage) } } @@ -3605,93 +4894,113 @@ class MessageAdapter(context: Context, messageList: List, type: Str for (i in messageList.indices.reversed()) { val muid = messageList[i].muid if (muid != null && muid == baseMessage?.muid) { - messageList.removeAt(i) - messageList.add(i, baseMessage) - notifyItemChanged(i) + messageList[i] = baseMessage + notifyItemChanged(i, baseMessage) + break } } } -// fun remove(basemessage: BaseMessage) { -// val index = messageList.indexOf(basemessage) -// messageList.remove(basemessage) -// notifyItemRemoved(index) -// } - + inner class LeftDeleteMessageViewHolder(val view: MessageLeftDeleteItemBinding) : + RecyclerView.ViewHolder(view.root) - //delete - inner class LeftDeleteMessageViewHolder(val view: MessageLeftDeleteItemBinding) : RecyclerView.ViewHolder(view.root) - - inner class RightDeleteMessageViewHolder(val view: MessageRightDeleteItemBinding) : RecyclerView.ViewHolder(view.root) + inner class RightDeleteMessageViewHolder(val view: MessageRightDeleteItemBinding) : + RecyclerView.ViewHolder(view.root) //text - inner class LeftTextMessageViewHolder(val view: MessageLeftTextItemBinding) : RecyclerView.ViewHolder(view.root) + inner class LeftTextMessageViewHolder(val view: MessageLeftTextItemBinding) : + RecyclerView.ViewHolder(view.root) - inner class RightTextMessageViewHolder(val view: MessageRightTextItemBinding) : RecyclerView.ViewHolder(view.root) + inner class RightTextMessageViewHolder(val view: MessageRightTextItemBinding) : + RecyclerView.ViewHolder(view.root) // - inner class LeftCustomMessageViewHolder(val view: MessageLeftCustomItemBinding) : RecyclerView.ViewHolder(view.root) + inner class LeftCustomMessageViewHolder(val view: MessageLeftCustomItemBinding) : + RecyclerView.ViewHolder(view.root) - inner class RightCustomMessageViewHolder(val view: MessageRightCustomItemBinding) : RecyclerView.ViewHolder(view.root) + inner class RightCustomMessageViewHolder(val view: MessageRightCustomItemBinding) : + RecyclerView.ViewHolder(view.root) //image - inner class LeftImageMessageViewHolder(val view: MessageLeftListImageItemBinding) : RecyclerView.ViewHolder(view.root) + inner class LeftImageMessageViewHolder(val view: MessageLeftListImageItemBinding) : + RecyclerView.ViewHolder(view.root) - inner class RightImageMessageViewHolder(val view: MessageRightListImageItemBinding) : RecyclerView.ViewHolder(view.root) + inner class RightImageMessageViewHolder(val view: MessageRightListImageItemBinding) : + RecyclerView.ViewHolder(view.root) //video - inner class LeftVideoMessageViewHolder(val view: MessageLeftListVideoItemBinding) : RecyclerView.ViewHolder(view.root) + inner class LeftVideoMessageViewHolder(val view: MessageLeftListVideoItemBinding) : + RecyclerView.ViewHolder(view.root) - inner class RightVideoMessageViewHolder(val view: MessageRightListVideoItemBinding) : RecyclerView.ViewHolder(view.root) + inner class RightVideoMessageViewHolder(val view: MessageRightListVideoItemBinding) : + RecyclerView.ViewHolder(view.root) //file - inner class LeftFileMessageViewHolder(val view: MessageLeftFileItemBinding) : RecyclerView.ViewHolder(view.root) + inner class LeftFileMessageViewHolder(val view: MessageLeftFileItemBinding) : + RecyclerView.ViewHolder(view.root) - inner class RightFileMessageViewHolder(val view: MessageRightFileItemBinding) : RecyclerView.ViewHolder(view.root) + inner class RightFileMessageViewHolder(val view: MessageRightFileItemBinding) : + RecyclerView.ViewHolder(view.root) //audio - inner class LeftAudioMessageViewHolder(val view: MessageLeftAudioItemBinding) : RecyclerView.ViewHolder(view.root) + inner class LeftAudioMessageViewHolder(val view: MessageLeftAudioItemBinding) : + RecyclerView.ViewHolder(view.root) - inner class RightAudioMessageViewHolder(val view: MessageRightAudioItemBinding) : RecyclerView.ViewHolder(view.root) + inner class RightAudioMessageViewHolder(val view: MessageRightAudioItemBinding) : + RecyclerView.ViewHolder(view.root) //link - inner class LeftLinkMessageViewHolder(val view: MessageLeftLinkItemBinding) : RecyclerView.ViewHolder(view.root) + inner class LeftLinkMessageViewHolder(val view: MessageLeftLinkItemBinding) : + RecyclerView.ViewHolder(view.root) - inner class RightLinkMessageViewHolder(val view: MessageRightLinkItemBinding) : RecyclerView.ViewHolder(view.root) + inner class RightLinkMessageViewHolder(val view: MessageRightLinkItemBinding) : + RecyclerView.ViewHolder(view.root) //action - inner class ActionMessageViewHolder(val view: MessageActionItemBinding) : RecyclerView.ViewHolder(view.root) + inner class ActionMessageViewHolder(val view: MessageActionItemBinding) : + RecyclerView.ViewHolder(view.root) //location - inner class LeftLocationMessageViewHolder(val view: MessageLeftLocationItemBinding): RecyclerView.ViewHolder(view.root) + inner class LeftLocationMessageViewHolder(val view: MessageLeftLocationItemBinding) : + RecyclerView.ViewHolder(view.root) - inner class RightLocationMessageViewHolder(val view: MessageRightLocationItemBinding) : RecyclerView.ViewHolder(view.root) + inner class RightLocationMessageViewHolder(val view: MessageRightLocationItemBinding) : + RecyclerView.ViewHolder(view.root) //sticker - inner class LeftStickerMessageViewHolder(val view: MessageLeftStickerItemBinding): RecyclerView.ViewHolder(view.root) + inner class LeftStickerMessageViewHolder(val view: MessageLeftStickerItemBinding) : + RecyclerView.ViewHolder(view.root) - inner class RightStickerMessageViewHolder(val view: MessageRightStickerItemBinding): RecyclerView.ViewHolder(view.root) + inner class RightStickerMessageViewHolder(val view: MessageRightStickerItemBinding) : + RecyclerView.ViewHolder(view.root) //WhiteBoard - inner class LeftWhiteBoardMessageViewHolder(val view: MessageLeftWhiteboardItemBinding): RecyclerView.ViewHolder(view.root) + inner class LeftWhiteBoardMessageViewHolder(val view: MessageLeftWhiteboardItemBinding) : + RecyclerView.ViewHolder(view.root) - inner class RightWhiteBoardMessageViewHolder(val view: MessageRightWhiteboardItemBinding) : RecyclerView.ViewHolder(view.root) + inner class RightWhiteBoardMessageViewHolder(val view: MessageRightWhiteboardItemBinding) : + RecyclerView.ViewHolder(view.root) //WriteBoard - inner class LeftWriteBoardMessageViewHolder(val view: MessageLeftWriteboardItemBinding) : RecyclerView.ViewHolder(view.root) + inner class LeftWriteBoardMessageViewHolder(val view: MessageLeftWriteboardItemBinding) : + RecyclerView.ViewHolder(view.root) - inner class RightWriteBoardMessageViewHolder(val view: MessageRightWriteboardItemBinding) : RecyclerView.ViewHolder(view.root) + inner class RightWriteBoardMessageViewHolder(val view: MessageRightWriteboardItemBinding) : + RecyclerView.ViewHolder(view.root) //GroupCall - inner class LeftConferenceCallMessageViewHolder(val view: MessageLeftGroupCallItemBinding) :RecyclerView.ViewHolder(view.root) + inner class LeftConferenceCallMessageViewHolder(val view: MessageLeftGroupCallItemBinding) : + RecyclerView.ViewHolder(view.root) - inner class RightConferenceCallMessageViewHolder(val view: MessageRightGroupCallItemBinding) :RecyclerView.ViewHolder(view.root) + inner class RightConferenceCallMessageViewHolder(val view: MessageRightGroupCallItemBinding) : + RecyclerView.ViewHolder(view.root) //Poll - inner class LeftPollsMessageViewHolder(val view: MessageLeftPollsItemBinding) : RecyclerView.ViewHolder(view.root) - - inner class RightPollsMessageViewHolder(val view: MessageRightPollsItemBinding): RecyclerView.ViewHolder(view.root) + inner class LeftPollsMessageViewHolder(val view: MessageLeftPollsItemBinding) : + RecyclerView.ViewHolder(view.root) + inner class RightPollsMessageViewHolder(val view: MessageRightPollsItemBinding) : + RecyclerView.ViewHolder(view.root) // class WhiteBoardMessageViewHolder(val view: RecyclerView.ViewHolder) @@ -3807,7 +5116,8 @@ class MessageAdapter(context: Context, messageList: List, type: Str // } // } - inner class DateItemHolder internal constructor(itemView: View) : RecyclerView.ViewHolder(itemView) { + inner class DateItemHolder internal constructor(itemView: View) : + RecyclerView.ViewHolder(itemView) { var txtMessageDate: TextView init { diff --git a/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_components/messages/threaded_message_list/CometChatThreadMessageList.kt b/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_components/messages/threaded_message_list/CometChatThreadMessageList.kt index a44efa1..6ab7622 100644 --- a/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_components/messages/threaded_message_list/CometChatThreadMessageList.kt +++ b/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_components/messages/threaded_message_list/CometChatThreadMessageList.kt @@ -774,10 +774,29 @@ class CometChatThreadMessageList : Fragment(), View.OnClickListener, OnMessageLo } override fun onAudioActionClicked() { - if (Utils.hasPermissions(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - startActivityForResult(MediaUtils.openAudio(activity!!), UIKitConstants.RequestCode.AUDIO) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { + if (Utils.hasPermissions(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + MediaUtils.openAudio( + activity!! + ) + } else { + requestPermissions( + arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), + UIKitConstants.RequestCode.AUDIO + ) + } } else { - requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), UIKitConstants.RequestCode.AUDIO) + if (Utils.hasPermissions(context, Manifest.permission.READ_MEDIA_AUDIO)) { + MediaUtils.openAudio( + activity!! + ) + + } else { + requestPermissions( + arrayOf(Manifest.permission.READ_MEDIA_AUDIO), + UIKitConstants.RequestCode.AUDIO + ) + } } } @@ -791,17 +810,26 @@ class CometChatThreadMessageList : Fragment(), View.OnClickListener, OnMessageLo override fun onGalleryActionClicked() { if (Utils.hasPermissions(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - startActivityForResult(MediaUtils.openGallery(activity!!), UIKitConstants.RequestCode.GALLERY) + MediaUtils.openGallery(activity!!) } else { requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), UIKitConstants.RequestCode.GALLERY) } } override fun onFileActionClicked() { - if (Utils.hasPermissions(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - startActivityForResult(MediaUtils.getFileIntent(UIKitConstants.IntentStrings.EXTRA_MIME_DOC), UIKitConstants.RequestCode.FILE) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU || Utils.hasPermissions( + context, Manifest.permission.WRITE_EXTERNAL_STORAGE + ) + ) { + startActivityForResult( + MediaUtils.getFileIntent(UIKitConstants.IntentStrings.EXTRA_MIME_DOC), + UIKitConstants.RequestCode.FILE + ) } else { - requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), UIKitConstants.RequestCode.FILE) + requestPermissions( + arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), + UIKitConstants.RequestCode.FILE + ) } } @@ -948,8 +976,8 @@ class CometChatThreadMessageList : Fragment(), View.OnClickListener, OnMessageLo override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { Log.d(Companion.TAG, "onRequestPermissionsResult: ") when (requestCode) { - UIKitConstants.RequestCode.CAMERA -> if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) startActivityForResult(MediaUtils.openCamera(activity!!), UIKitConstants.RequestCode.CAMERA) else showSnackBar(view!!.findViewById(R.id.message_box), resources.getString(R.string.grant_camera_permission)) - UIKitConstants.RequestCode.GALLERY -> if (grantResults[0] == PackageManager.PERMISSION_GRANTED) startActivityForResult(MediaUtils.openGallery(activity!!), UIKitConstants.RequestCode.GALLERY) else showSnackBar(view!!.findViewById(R.id.message_box), resources.getString(R.string.grant_storage_permission)) + UIKitConstants.RequestCode.CAMERA -> if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) MediaUtils.openCamera(activity!!)else showSnackBar(view!!.findViewById(R.id.message_box), resources.getString(R.string.grant_camera_permission)) + UIKitConstants.RequestCode.GALLERY -> if (grantResults[0] == PackageManager.PERMISSION_GRANTED) MediaUtils.openGallery(activity!!) else showSnackBar(view!!.findViewById(R.id.message_box), resources.getString(R.string.grant_storage_permission)) UIKitConstants.RequestCode.FILE -> if (grantResults[0] == PackageManager.PERMISSION_GRANTED) startActivityForResult(MediaUtils.getFileIntent(UIKitConstants.IntentStrings.EXTRA_MIME_DOC), UIKitConstants.RequestCode.FILE) else showSnackBar(view!!.findViewById(R.id.message_box), resources.getString(R.string.grant_storage_permission)) UIKitConstants.RequestCode.LOCATION -> if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { } else showSnackBar(view!!.findViewById(R.id.message_box), resources.getString(R.string.grant_location_permission)) diff --git a/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatComposeBox/CometChatComposeBox.kt b/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatComposeBox/CometChatComposeBox.kt index b4baf6c..0b6bc54 100644 --- a/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatComposeBox/CometChatComposeBox.kt +++ b/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatComposeBox/CometChatComposeBox.kt @@ -1,26 +1,47 @@ package com.cometchat.pro.uikit.ui_components.shared.cometchatComposeBox import android.Manifest -import android.Manifest.permission -import android.Manifest.permission.* +import android.Manifest.permission.MANAGE_EXTERNAL_STORAGE +import android.Manifest.permission.RECORD_AUDIO +import android.Manifest.permission.WRITE_EXTERNAL_STORAGE +import android.annotation.TargetApi import android.app.Activity import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager import android.content.res.ColorStateList import android.graphics.Color import android.media.AudioManager import android.media.MediaPlayer import android.media.MediaRecorder -import android.os.* +import android.net.Uri +import android.os.Build +import android.os.Build.VERSION.SDK_INT +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.os.SystemClock +import android.provider.Settings import android.text.Editable import android.text.TextWatcher import android.util.AttributeSet import android.util.Log import android.view.View import android.view.ViewGroup -import android.widget.* -import androidx.annotation.RequiresApi +import android.widget.Chronometer +import android.widget.ImageView +import android.widget.RelativeLayout +import android.widget.SeekBar +import android.widget.Toast +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity +import androidx.core.app.ActivityCompat +import androidx.core.app.ActivityCompat.requestPermissions +import androidx.core.app.ActivityCompat.startActivityForResult +import androidx.core.content.ContextCompat import androidx.core.view.inputmethod.InputContentInfoCompat +import androidx.fragment.app.FragmentActivity import com.cometchat.pro.uikit.R import com.cometchat.pro.uikit.ui_components.shared.cometchatComposeBox.CometChatComposeBoxActions.ComposeBoxActionListener import com.cometchat.pro.uikit.ui_components.shared.cometchatComposeBox.CometChatEditText.OnEditTextMediaListener @@ -30,28 +51,11 @@ import com.cometchat.pro.uikit.ui_resources.utils.Utils import com.cometchat.pro.uikit.ui_resources.utils.audio_visualizer.AudioRecordView import com.cometchat.pro.uikit.ui_settings.FeatureRestriction import com.cometchat.pro.uikit.ui_settings.UIKitSettings +import com.google.android.material.snackbar.Snackbar import java.io.File import java.io.IOException -import java.util.* -import android.annotation.TargetApi - -import androidx.core.app.ActivityCompat - -import androidx.core.app.ActivityCompat.startActivityForResult - -import android.content.Intent -import android.content.pm.PackageManager -import android.net.Uri - -import android.os.Build -import android.os.Build.VERSION - -import android.os.Build.VERSION.SDK_INT -import android.provider.Settings -import androidx.appcompat.app.AlertDialog -import androidx.core.app.ActivityCompat.requestPermissions -import androidx.core.content.ContextCompat -import com.cometchat.pro.uikit.ui_components.messages.message_list.CometChatMessageListActivity +import java.util.Timer +import java.util.TimerTask class CometChatComposeBox : RelativeLayout, View.OnClickListener { @@ -98,8 +102,10 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { var isStickerVisible = true var isWhiteBoardVisible = true var isWriteBoardVisible = true -// var isStartVideoCall = true + + // var isStartVideoCall = true var isPollVisible = true + private lateinit var permissions: Array constructor(context: Context) : super(context) { initViewComponent(context, null, -1, -1) @@ -109,14 +115,24 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { initViewComponent(context, attrs, -1, -1) } - constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super( + context, + attrs, + defStyleAttr + ) { initViewComponent(context, attrs, defStyleAttr, -1) } - private fun initViewComponent(context: Context, attributeSet: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) { + private fun initViewComponent( + context: Context, + attributeSet: AttributeSet?, + defStyleAttr: Int, + defStyleRes: Int + ) { var view = View.inflate(context, R.layout.cometchat_compose_box, null) - var a = getContext().theme.obtainStyledAttributes(attributeSet, R.styleable.ComposeBox, 0, 0) + var a = + getContext().theme.obtainStyledAttributes(attributeSet, R.styleable.ComposeBox, 0, 0) color = a.getColor(R.styleable.ComposeBox_color, resources.getColor(R.color.colorPrimary)) addView(view) @@ -134,11 +150,59 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { }, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN) } btnLiveReaction = findViewById(R.id.btn_live_reaction) - FeatureRestriction.isLiveReactionsEnabled(object : FeatureRestriction.OnSuccessListener{ + FeatureRestriction.isLiveReactionsEnabled(object : FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { - if (p0) btnLiveReaction?.visibility = View.VISIBLE else btnLiveReaction?.visibility = View.GONE + if (p0) btnLiveReaction?.visibility = + View.VISIBLE else btnLiveReaction?.visibility = View.GONE } }) + permissions = + arrayOf(RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE) + + activityResultLauncher = (context as FragmentActivity).registerForActivityResult( + ActivityResultContracts.RequestMultiplePermissions() + ) { permissionGrantedHashMap -> + var permissionGranted = true + for (entry in permissionGrantedHashMap.entries) { + val key = entry.key + val value = entry.value + if (permissions.contains(key) && !value) { + permissionGranted = false + break + } + } + if (!permissionGranted) { + Snackbar.make( + view!!, + "Please Grant Permissions", + Snackbar.LENGTH_SHORT + ).show() + } else { + if (!isRecording) { + startRecord() + ivMic!!.setImageDrawable(resources.getDrawable(R.drawable.ic_stop_24dp)) + isRecording = true + isPlaying = false + } else { + if (isRecording && !isPlaying) { + isPlaying = true + stopRecording(false) + recordTime!!.stop() + } + voiceSeekbar!!.visibility = View.VISIBLE + voiceMessage = true + ivMic!!.setImageDrawable(resources.getDrawable(R.drawable.ic_pause_24dp)) + audioRecordView!!.visibility = View.GONE + ivSend!!.visibility = View.VISIBLE + ivDelete!!.visibility = View.VISIBLE + if (audioFileNameWithPath != null) startPlayingAudio(audioFileNameWithPath!!) else Toast.makeText( + context, + "No File Found. Please", + Toast.LENGTH_LONG + ).show() + } + } + } composeBox = findViewById(R.id.message_box) flBox = findViewById(R.id.flBox) ivMic = findViewById(R.id.ivMic) @@ -254,26 +318,35 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { }) if (Utils.isDarkMode(context)) { composeBox!!.setBackgroundColor(resources.getColor(R.color.darkModeBackground)) - ivAudio!!.imageTintList = ColorStateList.valueOf(resources.getColor(R.color.textColorWhite)) + ivAudio!!.imageTintList = + ColorStateList.valueOf(resources.getColor(R.color.textColorWhite)) // ivMic!!.setImageDrawable(resources.getDrawable(R.drawable.ic_mic_white_24dp)) - flBox!!.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.textColorWhite)) + flBox!!.backgroundTintList = + ColorStateList.valueOf(resources.getColor(R.color.textColorWhite)) etComposeBox!!.setTextColor(resources.getColor(R.color.textColorWhite)) // ivArrow!!.imageTintList = ColorStateList.valueOf(resources.getColor(R.color.textColorWhite)) // ivSend!!.imageTintList = ColorStateList.valueOf(resources.getColor(R.color.textColorWhite)) - ivCamera!!.imageTintList = ColorStateList.valueOf(resources.getColor(R.color.textColorWhite)) - ivGallery!!.imageTintList = ColorStateList.valueOf(resources.getColor(R.color.textColorWhite)) - ivFile!!.imageTintList = ColorStateList.valueOf(resources.getColor(R.color.textColorWhite)) + ivCamera!!.imageTintList = + ColorStateList.valueOf(resources.getColor(R.color.textColorWhite)) + ivGallery!!.imageTintList = + ColorStateList.valueOf(resources.getColor(R.color.textColorWhite)) + ivFile!!.imageTintList = + ColorStateList.valueOf(resources.getColor(R.color.textColorWhite)) } else { composeBox!!.setBackgroundColor(resources.getColor(R.color.textColorWhite)) - ivAudio!!.imageTintList = ColorStateList.valueOf(resources.getColor(R.color.colorPrimary)) + ivAudio!!.imageTintList = + ColorStateList.valueOf(resources.getColor(R.color.colorPrimary)) // ivMic!!.setImageDrawable(resources.getDrawable(R.drawable.ic_mic_grey_24dp)) etComposeBox!!.setTextColor(resources.getColor(R.color.primaryTextColor)) // ivSend!!.imageTintList = ColorStateList.valueOf(resources.getColor(R.color.colorPrimary)) flBox!!.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.grey)) // ivArrow!!.imageTintList = ColorStateList.valueOf(resources.getColor(R.color.grey)) - ivCamera!!.imageTintList = ColorStateList.valueOf(resources.getColor(R.color.colorPrimary)) - ivFile!!.imageTintList = ColorStateList.valueOf(resources.getColor(R.color.colorPrimary)) - ivFile!!.imageTintList = ColorStateList.valueOf(resources.getColor(R.color.colorPrimary)) + ivCamera!!.imageTintList = + ColorStateList.valueOf(resources.getColor(R.color.colorPrimary)) + ivFile!!.imageTintList = + ColorStateList.valueOf(resources.getColor(R.color.colorPrimary)) + ivFile!!.imageTintList = + ColorStateList.valueOf(resources.getColor(R.color.colorPrimary)) } if (UIKitSettings.color != null) { val settingsColor = Color.parseColor(UIKitSettings.color) @@ -282,14 +355,16 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { isLocationVisible = FeatureRestriction.isLocationSharingEnabled() - FeatureRestriction.isCollaborativeWhiteBoardEnabled(object : FeatureRestriction.OnSuccessListener { + FeatureRestriction.isCollaborativeWhiteBoardEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { - Log.e("CometChatComposeBox", "onSuccess: "+p0.toString() ) + Log.e("CometChatComposeBox", "onSuccess: " + p0.toString()) isWhiteBoardVisible = p0 bundle.putBoolean("isWhiteBoardVisible", isWhiteBoardVisible) } }) - FeatureRestriction.isCollaborativeDocumentEnabled(object : FeatureRestriction.OnSuccessListener{ + FeatureRestriction.isCollaborativeDocumentEnabled(object : + FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { isWriteBoardVisible = p0 bundle.putBoolean("isWriteBoardVisible", isWriteBoardVisible) @@ -330,7 +405,7 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { bundle.putBoolean("isCameraVisible", isCameraVisible) } }) - FeatureRestriction.isFilesEnabled(object: FeatureRestriction.OnSuccessListener{ + FeatureRestriction.isFilesEnabled(object : FeatureRestriction.OnSuccessListener { override fun onSuccess(p0: Boolean) { isFileVisible = p0 isAudioVisible = p0 @@ -341,7 +416,7 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { }) - if (!isLocationVisible && !isWhiteBoardVisible && !isWriteBoardVisible && !isAudioVisible && !isFileVisible && !isCameraVisible && !isGalleryVisible && !isPollVisible && !isStickerVisible ){ + if (!isLocationVisible && !isWhiteBoardVisible && !isWriteBoardVisible && !isAudioVisible && !isFileVisible && !isCameraVisible && !isGalleryVisible && !isPollVisible && !isStickerVisible) { ivArrow!!.visibility = GONE } a.recycle() @@ -366,7 +441,7 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { this.composeActionListener.getFileActionView(ivFile!!) } -// @RequiresApi(Build.VERSION_CODES.M) + // @RequiresApi(Build.VERSION_CODES.M) override fun onClick(view: View) { if (view.id == R.id.ivDelete) { stopRecording(true) @@ -468,25 +543,31 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { // rlActionContainer!!.startAnimation(leftAnim) // rlActionContainer!!.visibility = View.GONE // } - if (!isRecording) { - startRecord() - ivMic!!.setImageDrawable(resources.getDrawable(R.drawable.ic_stop_24dp)) - isRecording = true - isPlaying = false - } else { - if (isRecording && !isPlaying) { - isPlaying = true - stopRecording(false) - recordTime!!.stop() - } - voiceSeekbar!!.visibility = View.VISIBLE - voiceMessage = true - ivMic!!.setImageDrawable(resources.getDrawable(R.drawable.ic_pause_24dp)) - audioRecordView!!.visibility = View.GONE - ivSend!!.visibility = View.VISIBLE - ivDelete!!.visibility = View.VISIBLE - if (audioFileNameWithPath != null) startPlayingAudio(audioFileNameWithPath!!) else Toast.makeText(context, "No File Found. Please", Toast.LENGTH_LONG).show() - } + + if (SDK_INT > Build.VERSION_CODES.Q) { + permissions = arrayOf(RECORD_AUDIO) + } + activityResultLauncher?.launch(permissions) + +// if (!isRecording) { +// startRecord() +// ivMic!!.setImageDrawable(resources.getDrawable(R.drawable.ic_stop_24dp)) +// isRecording = true +// isPlaying = false +// } else { +// if (isRecording && !isPlaying) { +// isPlaying = true +// stopRecording(false) +// recordTime!!.stop() +// } +// voiceSeekbar!!.visibility = View.VISIBLE +// voiceMessage = true +// ivMic!!.setImageDrawable(resources.getDrawable(R.drawable.ic_pause_24dp)) +// audioRecordView!!.visibility = View.GONE +// ivSend!!.visibility = View.VISIBLE +// ivDelete!!.visibility = View.VISIBLE +// if (audioFileNameWithPath != null) startPlayingAudio(audioFileNameWithPath!!) else Toast.makeText(context, "No File Found. Please", Toast.LENGTH_LONG).show() +// } // } else { // //// requestPermission() @@ -501,21 +582,25 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { } } + private var activityResultLauncher: ActivityResultLauncher>? = null + + @TargetApi(30) - private fun checkRecordAudioPermissionAPI30(recordAudioRequestCode: Int) : Boolean{ - if (checkSinglePermission(Manifest.permission.RECORD_AUDIO) && - checkSinglePermission(MANAGE_EXTERNAL_STORAGE)) return true + private fun checkRecordAudioPermissionAPI30(recordAudioRequestCode: Int): Boolean { + if (checkSinglePermission(RECORD_AUDIO) && + checkSinglePermission(MANAGE_EXTERNAL_STORAGE) + ) return true else { // AlertDialog.Builder(context) // .setTitle(R.string.background_location_permission_title) // .setMessage(R.string.background_location_permission_message) // .setPositiveButton(R.string.yes) { _, _ -> - // this request will take user to Application's Setting page - requestPermissions( - context as Activity, - arrayOf(Manifest.permission.RECORD_AUDIO, MANAGE_EXTERNAL_STORAGE), - recordAudioRequestCode - ) + // this request will take user to Application's Setting page + requestPermissions( + context as Activity, + arrayOf(RECORD_AUDIO, MANAGE_EXTERNAL_STORAGE), + recordAudioRequestCode + ) // } // .setNegativeButton(R.string.no) { dialog, _ -> // dialog.dismiss() @@ -525,8 +610,12 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { } return false } - fun checkSinglePermission(permission: String) : Boolean { - return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED + + fun checkSinglePermission(permission: String): Boolean { + return ContextCompat.checkSelfPermission( + context, + permission + ) == PackageManager.PERMISSION_GRANTED } private fun requestPermission() { @@ -541,15 +630,26 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { context.packageName ) ) - startActivityForResult(context as Activity, intent, UIKitConstants.RequestCode.RECORD, null) + startActivityForResult( + context as Activity, + intent, + UIKitConstants.RequestCode.RECORD, + null + ) } catch (e: java.lang.Exception) { val intent = Intent() intent.action = Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION - startActivityForResult(context as Activity, intent, UIKitConstants.RequestCode.RECORD, null) + startActivityForResult( + context as Activity, + intent, + UIKitConstants.RequestCode.RECORD, + null + ) } } else { //below android 11 - ActivityCompat.requestPermissions(context as Activity, arrayOf(RECORD_AUDIO, WRITE_EXTERNAL_STORAGE), + ActivityCompat.requestPermissions( + context as Activity, arrayOf(RECORD_AUDIO, WRITE_EXTERNAL_STORAGE), UIKitConstants.RequestCode.RECORD ) } @@ -573,7 +673,7 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { } -// @RequiresApi(Build.VERSION_CODES.M) + // @RequiresApi(Build.VERSION_CODES.M) private fun startPlayingAudio(path: String) { try { if (timerRunnable != null) { @@ -581,13 +681,22 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { timerRunnable = null } mediaPlayer?.reset() - if (Utils.hasPermissions(context, *arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE))) { + if (Utils.hasPermissions( + context, + *arrayOf( + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE + ) + ) + ) { mediaPlayer?.setDataSource(path) mediaPlayer?.prepare() mediaPlayer?.start() } else { - requestPermissions(context as Activity, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), - UIKitConstants.RequestCode.READ_STORAGE) + requestPermissions( + context as Activity, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), + UIKitConstants.RequestCode.READ_STORAGE + ) } val duration = mediaPlayer?.duration voiceSeekbar?.max = duration!! @@ -647,7 +756,8 @@ class CometChatComposeBox : RelativeLayout, View.OnClickListener { override fun run() { var currentMaxAmp = 0 try { - currentMaxAmp = if (mediaRecorder != null) mediaRecorder!!.maxAmplitude else 0 + currentMaxAmp = + if (mediaRecorder != null) mediaRecorder!!.maxAmplitude else 0 audioRecordView!!.update(currentMaxAmp) if (mediaRecorder == null) timer = null } catch (e: Exception) { diff --git a/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_resources/utils/MediaUtils.kt b/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_resources/utils/MediaUtils.kt index cab00d9..eab9677 100644 --- a/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_resources/utils/MediaUtils.kt +++ b/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_resources/utils/MediaUtils.kt @@ -1,13 +1,11 @@ package com.cometchat.pro.uikit.ui_resources.utils -import android.annotation.SuppressLint import android.app.Activity import android.content.* import android.content.pm.ApplicationInfo import android.content.pm.PackageManager import android.database.Cursor import android.graphics.Bitmap -import android.graphics.BitmapFactory import android.hardware.Camera import android.hardware.Camera.CameraInfo import android.media.AudioManager @@ -23,10 +21,8 @@ import android.util.Log import android.widget.Toast import androidx.annotation.RequiresApi import androidx.core.content.FileProvider -import androidx.loader.content.CursorLoader -import com.cometchat.pro.constants.CometChatConstants import com.cometchat.pro.uikit.BuildConfig -import com.cometchat.pro.uikit.R +import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants import com.cometchat.pro.uikit.ui_resources.utils.Utils.Companion.generateFileName import com.cometchat.pro.uikit.ui_resources.utils.Utils.Companion.getDocumentCacheDir import com.cometchat.pro.uikit.ui_resources.utils.Utils.Companion.getFileName @@ -36,7 +32,7 @@ import java.text.SimpleDateFormat import java.util.* import kotlin.math.min - class MediaUtils { +class MediaUtils { companion object { private var activity: Activity? = null @@ -57,7 +53,8 @@ import kotlin.math.min val listCam = packageManager.queryIntentActivities(captureIntent, 0) for (res in listCam) { val intent = Intent(captureIntent) - intent.component = ComponentName(res.activityInfo.packageName, res.activityInfo.name) + intent.component = + ComponentName(res.activityInfo.packageName, res.activityInfo.name) intent.setPackage(res.activityInfo.packageName) if (outputFileUri != null) { intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri) @@ -71,7 +68,8 @@ import kotlin.math.min val listGallery = packageManager.queryIntentActivities(galleryIntent, 0) for (res in listGallery) { val intent = Intent(galleryIntent) - intent.component = ComponentName(res.activityInfo.packageName, res.activityInfo.name) + intent.component = + ComponentName(res.activityInfo.packageName, res.activityInfo.name) intent.setPackage(res.activityInfo.packageName) allIntents.add(intent) } @@ -114,14 +112,18 @@ import kotlin.math.min val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date()) val imageFileName = "$timeStamp.jpg" val storageDir = Environment.getExternalStoragePublicDirectory( - Environment.DIRECTORY_PICTURES) + Environment.DIRECTORY_PICTURES + ) pictureImagePath = storageDir.absolutePath + "/" + imageFileName val file: File = File(pictureImagePath) var outputFileUri: Uri? var app: ApplicationInfo? = null var provider: String? = null try { - app = context.packageManager.getApplicationInfo(context.packageName, PackageManager.GET_META_DATA) + app = context.packageManager.getApplicationInfo( + context.packageName, + PackageManager.GET_META_DATA + ) val bundle = app.metaData provider = bundle.getString(BuildConfig.LIBRARY_PACKAGE_NAME) Log.d("openCamera", "openCamera: $provider") @@ -135,7 +137,8 @@ import kotlin.math.min contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, timeStamp) contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg") contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, "DCIM") - outputFileUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues) + outputFileUri = + resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues) uri = outputFileUri } else if (Build.VERSION.SDK_INT <= 23) { outputFileUri = Uri.fromFile(file) @@ -147,70 +150,23 @@ import kotlin.math.min return intent } - fun openGallery(a: Activity): Intent? { - activity = a - val allIntents: MutableList = ArrayList() - val packageManager: PackageManager = activity!!.getPackageManager() - val galleryIntent = Intent(Intent.ACTION_GET_CONTENT) - galleryIntent.type = "image/* video/*" - val listGallery = packageManager.queryIntentActivities(galleryIntent, 0) - for (res in listGallery) { - val intent = Intent(galleryIntent) - intent.component = ComponentName(res.activityInfo.packageName, res.activityInfo.name) - intent.setPackage(res.activityInfo.packageName) - allIntents.add(intent) - } - var mainIntent = allIntents[allIntents.size - 1] - for (intent in allIntents) { - if (intent!!.component!!.className == "com.android.documentsui.DocumentsActivity") { - mainIntent = intent - break - } - } - allIntents.remove(mainIntent) - - // Create a chooser from the main intent - val chooserIntent = Intent.createChooser(mainIntent, "Select source") - - // Add all other intents - chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, allIntents.toTypedArray()) - return chooserIntent + fun openGallery(a: Activity) { + val pickPhoto = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) + a.startActivityForResult(pickPhoto, UIKitConstants.RequestCode.GALLERY) } - fun openAudio(a: Activity): Intent? { - activity = a - val allIntents: MutableList = ArrayList() - val packageManager: PackageManager = activity!!.getPackageManager() - val audioIntent = Intent(Intent.ACTION_GET_CONTENT) - audioIntent.type = "audio/*" - val listGallery = packageManager.queryIntentActivities(audioIntent, 0) - for (res in listGallery) { - val intent = Intent(audioIntent) - intent.component = ComponentName(res.activityInfo.packageName, res.activityInfo.name) - intent.setPackage(res.activityInfo.packageName) - allIntents.add(intent) - } - var mainIntent = allIntents[allIntents.size - 1] - for (intent in allIntents) { - if (intent!!.component!!.className == "com.android.documentsui.DocumentsActivity") { - mainIntent = intent - break - } - } - allIntents.remove(mainIntent) - - // Create a chooser from the main intent - val chooserIntent = Intent.createChooser(mainIntent, "Select source") - - // Add all other intents - chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, allIntents.toTypedArray()) - return chooserIntent + fun openAudio(a: Activity){ + var chooseFile = Intent(Intent.ACTION_GET_CONTENT) + chooseFile.type = "audio/*" + chooseFile = Intent.createChooser(chooseFile, "Choose a Audio") + a.startActivityForResult(chooseFile,UIKitConstants.RequestCode.AUDIO) } private fun getCaptureImageOutputUri(): Uri? { val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date()) val imageFileName = "$timeStamp.jpg" - val storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + val storageDir = + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) val file = File(storageDir.absolutePath + "/" + imageFileName) return Uri.fromFile(file) } @@ -226,7 +182,8 @@ import kotlin.math.min if (getPickImageResultUri(data) != null) { picUri = getPickImageResultUri(data)!! try { - bitmap = MediaStore.Images.Media.getBitmap(activity?.contentResolver, picUri) + bitmap = + MediaStore.Images.Media.getBitmap(activity?.contentResolver, picUri) return createFileFromBitmap(bitmap) } catch (e: IOException) { e.printStackTrace() @@ -270,7 +227,7 @@ import kotlin.math.min val realPath: String if (fileUri?.let { isGoogleDrive(it) } == true) { return saveDriveFile(context!!, fileUri) - } else if (Build.VERSION.SDK_INT < 30){ + } else if (Build.VERSION.SDK_INT < 30) { realPath = fileUri?.let { getRealPathFromURI(context!!, it) }!! } else { //(Build.VERSION.SDK_INT == 30) @@ -281,10 +238,12 @@ import kotlin.math.min } @RequiresApi(Build.VERSION_CODES.R) - private fun getRealPathFromN(context: Context?, uri: Uri) : String? { + private fun getRealPathFromN(context: Context?, uri: Uri): String? { val returnUri = uri - val returnCursor = context?.contentResolver?.query(returnUri, - null, null, null, null) + val returnCursor = context?.contentResolver?.query( + returnUri, + null, null, null, null + ) /* * Get the column indexes of the data in the Cursor, * * move to the first row in the Cursor, get the data, @@ -319,7 +278,7 @@ import kotlin.math.min outputStream.write(buffers, 0, read) } Log.e("File Size", "Size " + file.length()) - inputStream?.close() + inputStream.close() outputStream.close() Log.e("File Path", "Path " + file.path) Log.e("File Size", "Size " + file.length()) @@ -330,7 +289,7 @@ import kotlin.math.min } fun saveDriveFile(context: Context?, uri: Uri?): File { - var file : File? = null + var file: File? = null try { if (uri != null) { file = File(context?.cacheDir, getFileName(context, uri)) @@ -396,11 +355,14 @@ import kotlin.math.min } } val contentUriPrefixesToTry = arrayOf( - "content://downloads/public_downloads", - "content://downloads/my_downloads" + "content://downloads/public_downloads", + "content://downloads/my_downloads" ) for (contentUriPrefix in contentUriPrefixesToTry) { - val contentUri = ContentUris.withAppendedId(Uri.parse(contentUriPrefix), java.lang.Long.valueOf(id!!)) + val contentUri = ContentUris.withAppendedId( + Uri.parse(contentUriPrefix), + java.lang.Long.valueOf(id!!) + ) try { val path: String = getDataColumn(context, contentUri, null, null)!! if (path != null) { @@ -434,14 +396,19 @@ import kotlin.math.min } val selection = "_id=?" val selectionArgs = arrayOf( - split[1] + split[1] ) return getDataColumn(context, contentUri, selection, selectionArgs) } } else if ("content".equals(uri.scheme, ignoreCase = true)) { // Return the remote address - return if (isGooglePhotosUri(uri)) uri.lastPathSegment else getDataColumn(context, uri, null, null) + return if (isGooglePhotosUri(uri)) uri.lastPathSegment else getDataColumn( + context, + uri, + null, + null + ) } else if ("file".equals(uri.scheme, ignoreCase = true)) { return uri.path } @@ -481,15 +448,22 @@ import kotlin.math.min * @param selectionArgs (Optional) Selection arguments used in the query. * @return The value of the _data column, which is typically a file path. */ - fun getDataColumn(context: Context, uri: Uri?, selection: String?, selectionArgs: Array?): String? { + fun getDataColumn( + context: Context, + uri: Uri?, + selection: String?, + selectionArgs: Array? + ): String? { var cursor: Cursor? = null val column = "_data" val projection = arrayOf( - column + column ) try { - cursor = context.contentResolver.query(uri!!, projection, selection, selectionArgs, - null) + cursor = context.contentResolver.query( + uri!!, projection, selection, selectionArgs, + null + ) if (cursor != null && cursor.moveToFirst()) { val index = cursor.getColumnIndexOrThrow(column) return cursor.getString(index) @@ -627,15 +601,20 @@ import kotlin.math.min // return file // } - private fun filterExtension(uri: Uri, extensionType : String) : String? { + private fun filterExtension(uri: Uri, extensionType: String): String? { Log.e("TAG", "filterExtension: uri " + uri.toString()) val fileString = uri.toString() //this is your String representing the File val lastDot = fileString.lastIndexOf('.') - Log.e("TAG", "filterExtension: lastdot "+lastDot.toString()) + Log.e("TAG", "filterExtension: lastdot " + lastDot.toString()) if (lastDot > 0) { val extension = fileString.substring(lastDot) Log.e("TAG", "filterExtension: " + extension) - if (extension.contains(".pdf") || extension.contains(".docx") || extension.contains(".msword") || extension.contains(".vnd.ms.excel") || extension.contains(".mspowerpoint") || extension.contains(".zip")) { + if (extension.contains(".pdf") || extension.contains(".docx") || extension.contains( + ".msword" + ) || extension.contains(".vnd.ms.excel") || extension.contains(".mspowerpoint") || extension.contains( + ".zip" + ) + ) { return uri.lastPathSegment } else if (extensionType == "vnd.openxmlformats-officedocument.wordprocessingml.document") { return uri.lastPathSegment + ".docx" diff --git a/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_resources/utils/sticker_header/StickyHeaderDecoration.kt b/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_resources/utils/sticker_header/StickyHeaderDecoration.kt index 5e05653..3644584 100644 --- a/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_resources/utils/sticker_header/StickyHeaderDecoration.kt +++ b/uikit-kotlin/src/main/java/com/cometchat/pro/uikit/ui_resources/utils/sticker_header/StickyHeaderDecoration.kt @@ -2,16 +2,25 @@ package com.cometchat.pro.uikit.ui_resources.utils.sticker_header import android.graphics.Canvas import android.graphics.Rect +import android.util.Log import android.view.View import android.view.ViewGroup import androidx.core.view.ViewCompat import androidx.recyclerview.widget.RecyclerView import kotlin.collections.HashMap -class StickyHeaderDecoration @JvmOverloads constructor(private val mAdapter: StickyHeaderAdapter<*>, var2: Boolean = false) : RecyclerView.ItemDecoration() { +class StickyHeaderDecoration @JvmOverloads constructor( + private val mAdapter: StickyHeaderAdapter<*>, + var2: Boolean = false +) : RecyclerView.ItemDecoration() { private val mHeaderCache: MutableMap private val mRenderInline: Boolean - override fun getItemOffsets(var1: Rect, var2: View, var3: RecyclerView, var4: RecyclerView.State) { + override fun getItemOffsets( + var1: Rect, + var2: View, + var3: RecyclerView, + var4: RecyclerView.State + ) { val var5 = var3.getChildAdapterPosition(var2) var var6 = 0 if (var5 != -1 && hasHeader(var5) && showHeaderAboveItem(var5)) { @@ -62,10 +71,22 @@ class StickyHeaderDecoration @JvmOverloads constructor(private val mAdapter: Sti val var5 = mAdapter.onCreateHeaderViewHolder(var1) val var6 = var5!!.itemView mAdapter.onBindHeaderViewHolder(var5, var2, var3) - val var7 = View.MeasureSpec.makeMeasureSpec(var1.measuredWidth, View.MeasureSpec.getMode(1073741824)) - val var8 = View.MeasureSpec.makeMeasureSpec(var1.measuredHeight, View.MeasureSpec.getMode(0)) - val var9 = ViewGroup.getChildMeasureSpec(var7, var1.paddingLeft + var1.paddingRight, var6.layoutParams.width) - val var10 = ViewGroup.getChildMeasureSpec(var8, var1.paddingTop + var1.paddingBottom, var6.layoutParams.height) + val var7 = View.MeasureSpec.makeMeasureSpec( + var1.measuredWidth, + View.MeasureSpec.getMode(1073741824) + ) + val var8 = + View.MeasureSpec.makeMeasureSpec(var1.measuredHeight, View.MeasureSpec.getMode(0)) + val var9 = ViewGroup.getChildMeasureSpec( + var7, + var1.paddingLeft + var1.paddingRight, + var6.layoutParams.width + ) + val var10 = ViewGroup.getChildMeasureSpec( + var8, + var1.paddingTop + var1.paddingBottom, + var6.layoutParams.height + ) var6.measure(var9, var10) var6.layout(0, 0, var6.measuredWidth, var6.measuredHeight) mHeaderCache[var3] = var5 @@ -97,7 +118,13 @@ class StickyHeaderDecoration @JvmOverloads constructor(private val mAdapter: Sti } } - private fun getHeaderTop(var1: RecyclerView, var2: View, var3: View, var4: Int, var5: Int): Int { + private fun getHeaderTop( + var1: RecyclerView, + var2: View, + var3: View, + var4: Int, + var5: Int + ): Int { val var6 = getHeaderHeightForLayout(var3) var var7 = var2.y.toInt() - var6 if (var5 == 0) { @@ -109,7 +136,8 @@ class StickyHeaderDecoration @JvmOverloads constructor(private val mAdapter: Sti val var13 = mAdapter.getHeaderId(var12) if (var13 != var9) { val var15 = var1.getChildAt(var11) - val var16 = var15.y.toInt() - (var6 + getHeader(var1, var12)!!.itemView.height) + val var16 = + var15.y.toInt() - (var6 + getHeader(var1, var12)!!.itemView.height) if (var16 < 0) { return var16 } diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_audio_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_audio_item.xml index 7a4a2e5..acfc194 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_audio_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_audio_item.xml @@ -1,122 +1,136 @@ + + + type="com.cometchat.pro.models.MediaMessage" /> - - - - - - - - - - + + - - + android:layout_height="wrap_content" + android:layout_marginStart="10dp" + android:layout_marginTop="8dp" + android:layout_toEndOf="@+id/iv_user" + android:textSize="12sp" + tools:text="Iron Man" /> + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:layout_below="@+id/reaction_group" + android:layout_alignStart="@+id/cv_message_container" + android:layout_marginBottom="16dp"> + + + + + + - - - - + android:layout_height="wrap_content" + android:layout_alignBottom="@id/cv_message_container" + android:layout_gravity="center" + android:layout_marginStart="8dp" + android:layout_marginBottom="8dp" + android:layout_toEndOf="@id/cv_message_container" + android:textSize="12sp" + android:textStyle="bold" + android:visibility="gone" + tools:text="11:00 PM" + tools:visibility="visible" /> + \ No newline at end of file diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_file_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_file_item.xml index 63ce41a..74ed2e5 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_file_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_file_item.xml @@ -1,17 +1,20 @@ + + + type="com.cometchat.pro.models.MediaMessage" /> + + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:animateLayoutChanges="true" + android:orientation="vertical"> + android:layout_marginBottom="4dp" + tools:src="@tools:sample/avatars" /> + + android:textSize="12sp" + tools:text="Iron Man" /> + + android:maxWidth="250dp" + android:maxLength="15" + android:paddingTop="3dp" + android:singleLine="true" + android:textColor="@color/primaryTextColor" + tools:text="File Name" /> + + android:layout_height="wrap_content" + android:layout_below="@+id/tvFileName" + android:layout_alignEnd="@+id/tvFileName" + android:textSize="12sp" + tools:text="10MB" /> + + android:padding="5dp"> + + android:layout_height="wrap_content" + android:src="@drawable/ic_insert_drive_file_black_24dp" + android:tint="@color/primaryTextColor" /> + + android:textSize="8sp" + android:textStyle="bold" + android:visibility="visible" + tools:text="PDF" /> - - + + - + android:layout_height="wrap_content" + android:layout_gravity="start" + android:orientation="horizontal" + android:visibility="gone" + app:flexWrap="wrap" + app:singleLine="true" /> + + android:layout_marginBottom="16dp"> + + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:orientation="horizontal" + android:visibility="gone" /> + + android:clickable="true" + android:foreground="?selectableItemBackground" + android:textColor="@color/colorPrimary" + tools:text="2 replies" /> + android:visibility="gone" + tools:text="11:00 PM" + tools:visibility="visible" /> diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_group_call_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_group_call_item.xml index 410869a..80550f8 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_group_call_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_group_call_item.xml @@ -72,8 +72,8 @@ android:layout_marginTop="8dp" android:layout_toEndOf="@+id/icon" android:padding="10dp" - android:textSize="16sp" android:textColor="@color/primaryTextColor" + android:textSize="16sp" tools:text="Someone has shared whiteboard. Click below join button to check whiteboard" /> @@ -86,29 +86,30 @@ android:layout_marginRight="10dp" android:layout_marginBottom="6dp" android:text="@string/join" + android:textAllCaps="false" android:textColor="@color/colorPrimary" app:backgroundTint="@color/textColorWhite" - app:cornerRadius="8dp" - android:textAllCaps="false"/> + app:cornerRadius="8dp" /> - + android:gravity="start"> - - + + + + type="com.cometchat.pro.models.TextMessage" /> - - - - - - - - + android:gravity="start"> - - - - - - - - + + + android:id="@+id/tv_user" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginLeft="10dp" + android:layout_marginTop="8dp" + android:layout_toEndOf="@+id/iv_user" + android:textSize="12sp" + tools:text="Iron Man" /> + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:layout_below="@+id/reaction_group" + android:layout_alignStart="@+id/cv_link_message_container" + android:layout_marginBottom="16dp"> + + + + + + - - + android:layout_height="wrap_content" + android:layout_alignBottom="@+id/cv_link_message_container" + android:layout_gravity="center" + android:layout_toEndOf="@+id/cv_link_message_container" + android:textSize="12sp" + android:textStyle="bold" + android:visibility="gone" + tools:drawableStart="@drawable/ic_double_tick" + tools:text="11:00 PM" + tools:visibility="visible" /> - + - + \ No newline at end of file diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_list_image_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_list_image_item.xml index b506d1a..93e01c9 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_list_image_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_list_image_item.xml @@ -1,158 +1,168 @@ + + + type="com.cometchat.pro.models.MediaMessage" /> - - - - - - - - + android:layout_height="wrap_content"> + - + + + android:layout_height="wrap_content" + android:layout_below="@+id/tv_user" + android:layout_margin="10dp" + android:layout_toEndOf="@+id/iv_user" + app:cardBackgroundColor="@color/colorPrimary" + app:cardCornerRadius="10dp"> + + + + + + - - - - - - - + android:background="@color/grey" + android:gravity="center" + android:paddingLeft="16dp" + android:paddingRight="16dp"> - + - + + - - - - + + + - - + + + + + + + - - + android:layout_height="wrap_content" + android:layout_below="@+id/reaction_group" + android:layout_alignStart="@+id/cv_image_message_container" + android:layout_marginBottom="16dp"> + + + + + + - + diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_list_video_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_list_video_item.xml index 460d075..175d1bc 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_list_video_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_list_video_item.xml @@ -1,137 +1,148 @@ + + + type="com.cometchat.pro.models.MediaMessage" /> - - - - + - - - + android:layout_height="wrap_content"> + - - - - + android:layout_height="wrap_content" + android:layout_marginStart="10dp" + android:layout_marginTop="8dp" + android:layout_toEndOf="@+id/iv_user" + android:textSize="12sp" + tools:text="Iron Man" /> - - - - - - - + android:layout_height="wrap_content" + android:layout_below="@+id/tv_user" + android:layout_margin="10dp" + android:layout_toEndOf="@id/iv_user" + app:cardBackgroundColor="@color/colorPrimary" + app:cardCornerRadius="10dp"> + + + + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:layout_below="@+id/reaction_group" + android:layout_alignStart="@+id/cv_image_message_container" + android:layout_marginBottom="16dp"> + + + + + + - - - - - - - + android:layout_height="wrap_content" + android:layout_alignBottom="@id/cv_image_message_container" + android:layout_gravity="center" + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" + android:layout_toEndOf="@id/cv_image_message_container" + android:textColor="@color/secondaryTextColor" + android:textSize="12sp" + android:textStyle="bold" + android:visibility="gone" + tools:text="11:00 PM" + tools:visibility="visible" /> + + + + + \ No newline at end of file diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_location_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_location_item.xml index 6fad85d..1a96b0f 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_location_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_location_item.xml @@ -1,162 +1,178 @@ + + + type="com.cometchat.pro.models.CustomMessage" /> - - - - - - + + - - - - - - - - - - - - + + - - + android:layout_height="wrap_content" + android:layout_marginStart="10dp" + android:layout_toEndOf="@+id/iv_user" + android:textSize="12sp" + tools:text="Iron Man" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + android:layout_height="wrap_content" + android:layout_alignBottom="@id/cv_message_container" + android:layout_gravity="center" + android:layout_marginBottom="8dp" + android:layout_toEndOf="@id/cv_message_container" + android:textColor="@color/secondaryTextColor" + android:textSize="12sp" + android:textStyle="bold" + android:visibility="gone" + tools:text="11:00 PM" + tools:visibility="visible" /> + - \ No newline at end of file diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_polls_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_polls_item.xml index cef116e..12afd33 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_polls_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_polls_item.xml @@ -1,46 +1,52 @@ + + + + android:layout_marginBottom="8dp" + android:orientation="vertical"> + android:layout_height="wrap_content"> + + android:layout_marginBottom="4dp" + tools:src="@tools:sample/avatars" /> + + android:textSize="12sp" + tools:text="Iron Man" /> + + android:orientation="vertical"> + android:layout_height="24dp" + android:layout_gravity="end" + android:visibility="gone" /> + - + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:orientation="vertical" + android:paddingLeft="8dp" + android:paddingTop="8dp" + android:paddingRight="8dp"/> + + android:textStyle="italic" + tools:text="2 Votes" /> - - + + - + android:layout_height="wrap_content" + android:layout_gravity="start" + android:orientation="horizontal" + android:visibility="gone" + app:flexWrap="wrap" + app:singleLine="true" /> + + + android:orientation="vertical"> + + tools:text="2 replies" /> + android:visibility="gone" + tools:text="11:00 PM" + tools:visibility="visible" /> diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_sticker_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_sticker_item.xml index d23fad8..d6f853c 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_sticker_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_sticker_item.xml @@ -1,103 +1,111 @@ + + - - - - - - - - - - - - - + + - - + android:layout_height="wrap_content" + android:layout_marginStart="10dp" + android:layout_marginTop="8dp" + android:layout_toEndOf="@+id/iv_user" + android:textSize="12sp" + tools:text="Iron Man" /> + + + + + + + + + + + - - + android:layout_height="wrap_content" + android:layout_below="@+id/reaction_group" + android:layout_alignStart="@+id/sticker_view" + android:layout_marginBottom="16dp" + android:gravity="start" + android:orientation="vertical"> + + + + - + diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_text_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_text_item.xml index 4b7cc1a..5417b8b 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_text_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_text_item.xml @@ -1,70 +1,77 @@ + + + type="com.cometchat.pro.models.TextMessage" /> + + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:animateLayoutChanges="true" + android:orientation="vertical"> + android:layout_height="wrap_content" + android:animateLayoutChanges="true"> + + android:layout_marginBottom="4dp" + tools:src="@tools:sample/avatars" /> + + android:textSize="12sp" + tools:text="Iron Man" /> + + android:background="@drawable/cc_message_bubble_left"> + android:layout_marginLeft="8dp" + android:layout_marginTop="8dp" + android:layout_marginRight="8dp" + bind:replyTextMessage="@{textMessage}" /> + + android:maxWidth="250dp" + android:padding="10dp" + android:textColor="@color/primaryTextColor" + tools:text="message" /> @@ -72,69 +79,72 @@ android:id="@+id/img_pending" android:layout_width="15dp" android:layout_height="wrap_content" - android:layout_marginTop="11dp" android:layout_marginStart="-5dp" + android:layout_marginTop="11dp" android:layout_marginEnd="5dp" android:layout_toEndOf="@+id/cv_message_container" android:visibility="visible" /> - - + + - + android:layout_height="wrap_content" + android:layout_gravity="start" + app:flexWrap="wrap" + android:orientation="horizontal" + android:visibility="gone" + app:singleLine="true" /> + + android:layout_alignStart="@+id/cv_message_container" + android:layout_marginBottom="16dp"> + + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:orientation="horizontal" + android:visibility="gone" /> + + android:clickable="true" + android:foreground="?selectableItemBackground" + android:textColor="@color/colorPrimary" + tools:text="2 replies" /> + tools:text="11:00 PM" + tools:visibility="visible" /> diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_whiteboard_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_whiteboard_item.xml index 53fe620..356d80b 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_whiteboard_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_left_whiteboard_item.xml @@ -85,29 +85,30 @@ android:layout_marginRight="8dp" android:layout_marginBottom="16dp" android:text="@string/join" + android:textAllCaps="false" android:textColor="@color/primaryTextColor" app:backgroundTint="@color/textColorWhite" - app:cornerRadius="8dp" - android:textAllCaps="false"/> + app:cornerRadius="8dp" /> - + android:gravity="start"> - - + + + - - - - - + + + - + + + + - - + + + + + + + + + + + + android:layout_below="@id/top_message_layout" + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" + android:layout_marginBottom="16dp" + android:text="@string/join" + android:textAllCaps="false" + android:textColor="@color/primaryTextColor" + app:backgroundTint="@color/textColorWhite" + app:cornerRadius="8dp" /> - - - - + + + + + - - + android:layout_height="wrap_content" + android:layout_below="@+id/reaction_group" + android:layout_alignStart="@+id/cv_message_container" + android:layout_marginBottom="16dp" + android:gravity="start" + android:orientation="vertical"> + + + + - + android:layout_height="wrap_content" + android:layout_alignBottom="@+id/cv_message_container" + android:layout_gravity="center" + android:layout_marginBottom="8dp" + android:layout_toEndOf="@id/cv_message_container" + android:textSize="12sp" + android:textStyle="bold" + android:visibility="gone" + tools:text="11:00 PM" + tools:visibility="visible" /> + - - - - + \ No newline at end of file diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_audio_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_audio_item.xml index 5aea46c..175bd55 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_audio_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_audio_item.xml @@ -2,104 +2,116 @@ + + + type="com.cometchat.pro.models.MediaMessage" /> - - - - - - - - - - + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:layout_below="@+id/reaction_group" + android:layout_alignEnd="@+id/cv_message_container" + android:layout_marginBottom="16dp"> + + + + + - - - - + android:layout_height="wrap_content" + android:layout_alignBottom="@id/cv_message_container" + android:layout_gravity="center" + android:layout_marginEnd="8dp" + android:layout_marginBottom="8dp" + android:layout_toStartOf="@id/cv_message_container" + android:textSize="12sp" + android:textStyle="bold" + android:visibility="gone" + tools:text="11:00 PM" + tools:visibility="visible" /> + \ No newline at end of file diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_file_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_file_item.xml index b24a499..73bba42 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_file_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_file_item.xml @@ -1,18 +1,21 @@ + + + type="com.cometchat.pro.models.MediaMessage" /> + + android:orientation="vertical"> + android:background="@drawable/cc_message_bubble_right" + android:padding="8dp"> + + android:maxWidth="250dp" + android:maxLength="15" + android:paddingTop="3dp" + android:singleLine="true" + android:textColor="@color/textColorWhite" + tools:text="File Name" /> + + android:textColor="@color/textColorWhite" + android:textSize="12sp" + tools:text="File Size" /> + + android:padding="5dp"> + + android:layout_height="wrap_content" + android:src="@drawable/ic_insert_drive_file_black_24dp" + android:tint="@color/textColorWhite" /> + + android:textSize="8sp" + android:textStyle="bold" + android:visibility="visible" + tools:text="PDF" /> - - + + - + android:layout_height="wrap_content" + android:layout_gravity="end" + android:orientation="horizontal" + android:visibility="gone" + app:flexWrap="wrap" + app:singleLine="true" /> + + android:layout_marginBottom="16dp"> + + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:orientation="horizontal" + android:visibility="gone" /> + + android:clickable="true" + android:foreground="?selectableItemBackground" + android:textColor="@color/colorPrimary" + tools:text="2 replies" /> + android:visibility="gone" + tools:text="11:00 PM" + tools:visibility="visible" /> diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_group_call_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_group_call_item.xml index 3bec108..eee13fd 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_group_call_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_group_call_item.xml @@ -2,30 +2,35 @@ + + + + android:layout_marginEnd="8dp" + android:layout_marginBottom="8dp" + android:gravity="end" + android:orientation="vertical"> + android:layout_height="wrap_content"> + + android:layout_height="wrap_content" + android:layout_alignParentEnd="true" + android:background="@drawable/cc_message_bubble_right" + android:backgroundTint="@color/colorPrimary"> + @@ -52,68 +57,76 @@ android:textSize="16sp" tools:text="Someone has shared whiteboard. Click below join button to check whiteboard" /> + + app:cornerRadius="8dp" /> + - + + - + + - + android:layout_height="wrap_content" + android:layout_gravity="end" + android:orientation="horizontal" + android:visibility="gone" + app:flexWrap="wrap" + app:singleLine="true" /> + + + android:orientation="vertical"> + + tools:text="2 replies" /> diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_link_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_link_item.xml index 0ba22c0..aad179b 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_link_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_link_item.xml @@ -109,22 +109,24 @@ - - - + - - - + + + + type="com.cometchat.pro.models.MediaMessage" /> - + - - - + android:layout_height="wrap_content"> - - - + + + - - - - - - - - + android:layout_height="wrap_content"> + + + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:layout_below="@+id/reaction_group" + android:layout_alignEnd="@+id/cv_image_message_container" + android:layout_marginBottom="16dp"> + + + + + + - - - - + android:layout_height="wrap_content" + android:layout_alignBottom="@id/cv_image_message_container" + android:layout_gravity="center" + android:layout_marginBottom="16dp" + android:layout_toStartOf="@id/cv_image_message_container" + android:textColor="@color/secondaryTextColor" + android:textSize="12sp" + android:textStyle="bold" + android:visibility="gone" + tools:drawableEnd="@drawable/ic_double_tick" + tools:text="11:00 PM" + tools:visibility="visible" /> + + \ No newline at end of file diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_location_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_location_item.xml index 30c6020..da1bd34 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_location_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_location_item.xml @@ -2,147 +2,161 @@ + + + type="com.cometchat.pro.models.CustomMessage" /> - - - - - - - - - - - - - - - - - + + - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + android:layout_height="wrap_content" + android:layout_alignBottom="@+id/cv_message_container" + android:layout_marginBottom="8dp" + android:layout_toStartOf="@+id/cv_message_container" + android:gravity="center_vertical" + android:textColor="@color/secondaryTextColor" + android:textSize="12sp" + android:textStyle="bold" + android:visibility="gone" + tools:text="11:00 PM" + tools:visibility="visible" /> + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_polls_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_polls_item.xml index d783600..c1fe0c4 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_polls_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_polls_item.xml @@ -1,119 +1,132 @@ + + + + android:layout_marginBottom="8dp" + android:gravity="end" + android:orientation="vertical"> + android:layout_height="wrap_content"> + + android:layout_height="wrap_content" + android:layout_alignParentEnd="true" + android:layout_marginEnd="8dp" + android:background="@drawable/cc_message_bubble_right" + android:orientation="vertical"> + tools:text="What color is rose ?" /> + + android:layout_height="24dp" + android:layout_gravity="end" + android:visibility="gone" /> + - + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:orientation="vertical" + android:paddingLeft="8dp" + android:paddingTop="8dp" + android:paddingRight="8dp" /> + + android:textStyle="italic" + tools:text="2 Votes" /> + - + + - + + - + android:layout_height="wrap_content" + android:layout_gravity="end" + android:orientation="horizontal" + android:visibility="gone" + app:flexWrap="wrap" + app:singleLine="true" /> + + + android:gravity="end" + android:orientation="vertical"> + + tools:text="2 replies" /> diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_sticker_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_sticker_item.xml index bafe48f..b0ba42c 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_sticker_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_sticker_item.xml @@ -1,82 +1,91 @@ + + - - - - - - - - - + + + + + + + + + + - - + android:layout_height="wrap_content" + android:layout_below="@+id/reaction_group" + android:layout_alignEnd="@+id/sticker_view" + android:layout_marginBottom="16dp" + android:gravity="end" + android:orientation="vertical"> + + + + - + \ No newline at end of file diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_text_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_text_item.xml index 9b9b101..b3e146f 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_text_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_text_item.xml @@ -2,105 +2,125 @@ + + + type="com.cometchat.pro.models.TextMessage" /> + + android:orientation="vertical"> + android:layout_height="wrap_content" + android:animateLayoutChanges="true"> + + android:layout_height="wrap_content" + android:layout_marginLeft="8dp" + android:layout_marginTop="8dp" + android:layout_marginRight="8dp" /> + android:maxWidth="250dp" + android:padding="10dp" + android:textColor="@color/textColorWhite" + tools:text="message" /> - - + + + + + + + + + + - + android:layout_height="wrap_content" + android:layout_gravity="end" + android:orientation="horizontal" + android:visibility="gone" + app:flexWrap="wrap" + app:singleLine="true" /> + + + android:layout_alignEnd="@+id/cv_message_container" + android:layout_marginBottom="16dp"> + + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:orientation="horizontal" + android:visibility="gone" /> + + android:clickable="true" + android:foreground="?selectableItemBackground" + android:textColor="@color/colorPrimary" + tools:text="2 replies" /> + + + - - + android:layout_marginTop="8dp" + android:layout_marginEnd="8dp" + android:layout_marginBottom="8dp" + android:gravity="end" + android:orientation="vertical"> + + - - + + + + + + + + + + android:layout_below="@id/top_message_layout" + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" + android:layout_marginBottom="16dp" + android:text="@string/launch" + android:textAllCaps="false" + android:textColor="@color/primaryTextColor" + app:backgroundTint="@color/textColorWhite" + app:cornerRadius="8dp" /> - - - - - - - - + + + + + + + - - - + android:layout_height="wrap_content" + android:layout_below="@id/reaction_group" + android:layout_alignEnd="@id/cv_message_container" + android:gravity="end" + android:orientation="vertical"> + + + + + \ No newline at end of file diff --git a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_writeboard_item.xml b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_writeboard_item.xml index fa901cb..6b52928 100644 --- a/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_writeboard_item.xml +++ b/uikit-kotlin/src/main/res/layouts/messagebubbles/layout/message_right_writeboard_item.xml @@ -1,117 +1,132 @@ + + - - + android:layout_marginBottom="8dp" + android:gravity="end" + android:orientation="vertical"> + + android:id="@+id/rl_message" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:paddingEnd="8dp"> + - - + + + + + + + + + + android:layout_below="@id/top_message_layout" + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" + android:layout_marginBottom="16dp" + android:text="@string/launch" + android:textAllCaps="false" + android:textColor="@color/primaryTextColor" + app:backgroundTint="@color/textColorWhite" + app:cornerRadius="8dp" /> - - - - - - - - + + + + + + + - - - + android:layout_height="wrap_content" + android:layout_below="@id/reaction_group" + android:layout_alignEnd="@id/cv_message_container" + android:gravity="end" + android:orientation="vertical"> + + + + + \ No newline at end of file