@@ -28,10 +28,13 @@ import androidx.annotation.StringRes
2828import androidx.appcompat.app.AppCompatActivity
2929import androidx.appcompat.widget.AppCompatImageView
3030import androidx.core.content.ContextCompat
31+ import com.contusfly.activities.DashboardActivity
3132import com.mirrorflysdk.flycommons.*
3233import com.mirrorflysdk.flycall.webrtc.api.CallManager
3334import com.contusfly.chat.AndroidUtils
3435import com.contusfly.models.Chat
36+ import com.contusfly.notification.AppNotificationManager
37+ import com.contusfly.notification.NotificationBuilder
3538import com.contusfly.utils.*
3639import com.contusfly.utils.Constants
3740import com.contusfly.utils.SharedPreferenceManager.getCurrentUserJid
@@ -46,6 +49,7 @@ import com.mirrorflysdk.api.contacts.ProfileDetails
4649import com.mirrorflysdk.api.models.ChatMessage
4750import com.mirrorflysdk.api.models.RecentChat
4851import com.mirrorflysdk.api.models.ReplyParentChatMessage
52+ import com.mirrorflysdk.flycommons.LogMessage
4953import com.mirrorflysdk.utils.Utils
5054import com.mirrorflysdk.views.CustomToast
5155import java.io.IOException
@@ -258,19 +262,24 @@ val Any.TAG: String
258262
259263fun AppCompatImageView.loadUserProfileImage (context : Context , recentChat : RecentChat ) {
260264 val drawable: Drawable ?
265+
261266 var imageUrl = if (! recentChat.profileThumbImage.isNullOrEmpty()) {
262267 recentChat.profileThumbImage
263268 } else recentChat.profileImage ? : Constants .EMPTY_STRING
264- if (recentChat.isBlockedMe || recentChat.isAdminBlocked) {
265- imageUrl = Constants .EMPTY_STRING
266- drawable = CustomDrawable (context).getDefaultDrawable(recentChat)
267- } else if (recentChat.isDeletedContact()) {
268- imageUrl = recentChat.profileImage ? : Constants .EMPTY_STRING
269- drawable = CustomDrawable (context).getDefaultDrawable(recentChat)
270- } else if (TextUtils .isEmpty(imageUrl) || this .drawable == null )
271- drawable = CustomDrawable (context).getDefaultDrawable(recentChat)
272- else
273- drawable = CustomDrawable (context).getDefaultDrawable(recentChat)
269+
270+ drawable = when {
271+ recentChat.isBlockedMe || recentChat.isAdminBlocked -> {
272+ imageUrl = Constants .EMPTY_STRING
273+ CustomDrawable (context).getDefaultDrawable(recentChat)
274+ }
275+ recentChat.isDeletedContact() -> {
276+ imageUrl = recentChat.profileImage ? : Constants .EMPTY_STRING
277+ CustomDrawable (context).getDefaultDrawable(recentChat)
278+ }
279+ TextUtils .isEmpty(imageUrl) || this .drawable == null -> CustomDrawable (context).getDefaultDrawable(recentChat)
280+ else -> CustomDrawable (context).getDefaultDrawable(recentChat)
281+ }
282+
274283 if (imageUrl.startsWith(Constants .STORAGE ))
275284 MediaUtils .loadImageWithGlide(context, imageUrl, this , drawable)
276285 else
@@ -279,19 +288,24 @@ fun AppCompatImageView.loadUserProfileImage(context: Context, recentChat: Recent
279288
280289fun ImageView.loadUserProfileImage (context : Context , userProfileDetails : ProfileDetails ) {
281290 val drawable: Drawable ?
282- var imageUrl = if (! userProfileDetails.thumbImage.isNullOrEmpty()) {
291+
292+ var imageUrl = if (! userProfileDetails.thumbImage.isNullOrEmpty() && ! userProfileDetails.image.isNullOrEmpty()) {
283293 userProfileDetails.thumbImage
284294 } else userProfileDetails.image ? : Constants .EMPTY_STRING
285- if (userProfileDetails.isBlockedMe || userProfileDetails.isAdminBlocked) {
286- imageUrl = Constants .EMPTY_STRING
287- drawable = CustomDrawable (context).getDefaultDrawable(userProfileDetails)
288- } else if (userProfileDetails.isDeletedContact()) {
289- imageUrl = userProfileDetails.image ? : Constants .EMPTY_STRING
290- drawable = CustomDrawable (context).getDefaultDrawable(userProfileDetails)
291- } else if (TextUtils .isEmpty(imageUrl) || this .drawable == null )
292- drawable = CustomDrawable (context).getDefaultDrawable(userProfileDetails)
293- else
294- drawable = CustomDrawable (context).getDefaultDrawable(userProfileDetails)
295+
296+ drawable = when {
297+ userProfileDetails.isBlockedMe || userProfileDetails.isAdminBlocked -> {
298+ imageUrl = Constants .EMPTY_STRING
299+ CustomDrawable (context).getDefaultDrawable(userProfileDetails)
300+ }
301+ userProfileDetails.isDeletedContact() -> {
302+ imageUrl = userProfileDetails.image ? : Constants .EMPTY_STRING
303+ CustomDrawable (context).getDefaultDrawable(userProfileDetails)
304+ }
305+ TextUtils .isEmpty(imageUrl) || this .drawable == null -> CustomDrawable (context).getDefaultDrawable(userProfileDetails)
306+ else -> CustomDrawable (context).getDefaultDrawable(userProfileDetails)
307+ }
308+
295309 if (imageUrl.startsWith(Constants .STORAGE ))
296310 MediaUtils .loadImageWithGlide(context, imageUrl, this , drawable)
297311 else
@@ -300,17 +314,23 @@ fun ImageView.loadUserProfileImage(context: Context, userProfileDetails: Profile
300314
301315fun ImageView.loadUserInfoProfileImage (context : Context , profileDetails : ProfileDetails ) {
302316 val drawable: Drawable ?
303- var imageUrl = profileDetails.image ? : Constants .EMPTY_STRING
304- if (profileDetails.isBlockedMe || profileDetails.isAdminBlocked) {
305- imageUrl = Constants .EMPTY_STRING
306- drawable = CustomDrawable (context).getDefaultDrawable(profileDetails)
307- } else if (profileDetails.isDeletedContact()) {
308- imageUrl = profileDetails.image ? : Constants .EMPTY_STRING
309- drawable = CustomDrawable (context).getDefaultDrawable(profileDetails)
310- } else if (TextUtils .isEmpty(imageUrl) || this .drawable == null )
311- drawable = CustomDrawable (context).getDefaultDrawable(profileDetails)
312- else
313- drawable = CustomDrawable (context).getDefaultDrawable(profileDetails)
317+ var imageUrl = if (! profileDetails.thumbImage.isNullOrEmpty() && ! profileDetails.image.isNullOrEmpty()) {
318+ profileDetails.thumbImage
319+ } else profileDetails.image ? : Constants .EMPTY_STRING
320+
321+ drawable = when {
322+ profileDetails.isBlockedMe || profileDetails.isAdminBlocked -> {
323+ imageUrl = Constants .EMPTY_STRING
324+ CustomDrawable (context).getDefaultDrawable(profileDetails)
325+ }
326+ profileDetails.isDeletedContact() -> {
327+ imageUrl = profileDetails.image ? : Constants .EMPTY_STRING
328+ CustomDrawable (context).getDefaultDrawable(profileDetails)
329+ }
330+ TextUtils .isEmpty(imageUrl) || this .drawable == null -> CustomDrawable (context).getDefaultDrawable(profileDetails)
331+ else -> CustomDrawable (context).getDefaultDrawable(profileDetails)
332+ }
333+
314334 if (imageUrl.startsWith(Constants .STORAGE ))
315335 MediaUtils .loadImageWithGlide(context, imageUrl, this , drawable)
316336 else {
@@ -529,18 +549,26 @@ fun Chat.getUsername(): String {
529549 return profileDetails?.getDisplayName() ? : toUser
530550}
531551
532- fun ProfileDetails.getDisplayName () : String {
533- return if (BuildConfig .CONTACT_SYNC_ENABLED ) {
534- when {
535- jid.equals(getCurrentUserJid()) -> Constants .YOU
536- isUnknownContact() || nickName.isNullOrBlank() -> Utils .getFormattedPhoneNumber(ChatUtils .getUserFromJid(jid))
537- else -> nickName
552+ fun ProfileDetails.getDisplayName (): String {
553+ try {
554+ return if (BuildConfig .CONTACT_SYNC_ENABLED ) {
555+ when {
556+ jid.equals(getCurrentUserJid()) -> Constants .YOU
557+ isUnknownContact() || nickName.isNullOrBlank() -> Utils .getFormattedPhoneNumber(
558+ ChatUtils .getUserFromJid(jid)
559+ )
560+
561+ else -> nickName
562+ }
563+ } else {
564+ if ((name ? : jid).isNotBlank())
565+ name ? : ChatUtils .getUserFromJid(jid)
566+ else
567+ ChatUtils .getUserFromJid(jid)
538568 }
539- } else {
540- if ((name ? : jid).isNotBlank())
541- name ? : ChatUtils .getUserFromJid(jid)
542- else
543- ChatUtils .getUserFromJid(jid)
569+ } catch (e: Exception ) {
570+ com.contusfly.utils.LogMessage .e(TAG , " Exception in getdisplay name: $e " )
571+ return " "
544572 }
545573}
546574
@@ -758,7 +786,7 @@ fun HashMap<String, Any>.getParams(key: String? = null): Any {
758786
759787}
760788
761- fun HashMap <String , Any >.getHttpStatusCode (): Int = if (this .containsKey(FlyConstants .HTTP_STATUS_CODE )) this [FlyConstants .HTTP_STATUS_CODE ]!! as Int else 500
789+ fun HashMap <String , Any >.getHttpStatusCode (): Int = if (this .containsKey(FlyConstants .HTTP_STATUS_CODE )) ( this [FlyConstants .HTTP_STATUS_CODE ]!! as ? Int ) !! else 500
762790
763791
764792fun <T > returnEmptyListIfNull (nullableList : List <T >? ): List <T > {
@@ -846,4 +874,27 @@ fun View.visibilityChanged(action: (View) -> Unit) {
846874 action(this )
847875 }
848876 }
877+ }
878+
879+ fun checkEqualString (first : String , second : String ) : Boolean {
880+ return first.lowercase() == second.lowercase()
881+ }
882+
883+ fun startDashboardActivity (context : Context ) {
884+ val dashboardIntent = Intent (context, DashboardActivity ::class .java)
885+ dashboardIntent.flags = Intent .FLAG_ACTIVITY_CLEAR_TOP
886+ context.startActivity(dashboardIntent)
887+ }
888+
889+
890+ fun clearDeletedGroupChatNotification (groupJid : String , context : Context ? ){
891+ try {
892+ if (AppNotificationManager .checkGroupHasNotification(groupJid, context!! )) {
893+ val jidList = ArrayList <String >()
894+ jidList.add(groupJid)
895+ NotificationBuilder .clearNotificationTray(jidList, context)
896+ }
897+ } catch (e: Exception ) {
898+ LogMessage .e(" clearDeletedGroupChatNotification" , " Exception in clearDeletedGroupChatNotification: $e " )
899+ }
849900}
0 commit comments