private void LoadGifOfChatItem(GifViewHolder holder, int position, GetChatConversationsObject.Messages item) { try { // G_fixed_height_small_url, // UrlGif - view >> mediaFileName // G_fixed_height_small_mp4, //MediaGif - sent >> media if (!string.IsNullOrEmpty(item.Sticker)) { Glide.With(ActivityContext).Load(item.Sticker).Apply(new RequestOptions().Placeholder(Resource.Drawable.ImagePlacholder)).Into(holder.ImageGifView); } holder.LytParent.Activated = SelectedItems.Get(position, false); if (!holder.LytParent.HasOnClickListeners) { holder.LytParent.Click += delegate { try { if (ClickListener == null) { return; } ClickListener.ItemClick(holder.LytParent, item, position); } catch (Exception e) { Console.WriteLine(e); } }; holder.LytParent.LongClick += delegate { try { if (ClickListener == null) { return; } ClickListener.ItemLongClick(holder.LytParent, item, position); } catch (Exception e) { Console.WriteLine(e); } }; } ToggleCheckedBackground(holder, position); } catch (Exception e) { Console.WriteLine(e); } }
public override void OnBindViewHolder(RecyclerView.ViewHolder vh, int position) { try { int type = GetItemViewType(position); var item = MessageList[type]; if (item == null) { return; } switch (item.MessageType) { case "text": { TextViewHolder holder = vh as TextViewHolder; LoadTextOfChatItem(holder, position, item); break; } case "media": { ImageViewHolder holder = vh as ImageViewHolder; LoadImageOfChatItem(holder, position, item); break; } case "sticker" when item.Sticker.Contains(".gif"): { GifViewHolder holder = vh as GifViewHolder; LoadGifOfChatItem(holder, position, item); break; } case "sticker": { StickerViewHolder holder = vh as StickerViewHolder; LoadStickerOfChatItem(holder, position, item); break; } } } catch (Exception exception) { Console.WriteLine(exception); } }
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { try { //Setup your layout here >> var itemView = MessageList[viewType]; if (itemView != null) { if (itemView.From == UserDetails.UserId && itemView.MessageType == "text") { View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Right_MS_view, parent, false); TextViewHolder textViewHolder = new TextViewHolder(row, ActivityContext); return(textViewHolder); } if (itemView.To == UserDetails.UserId && itemView.MessageType == "text") { View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Left_MS_view, parent, false); TextViewHolder textViewHolder = new TextViewHolder(row, ActivityContext); return(textViewHolder); } if (itemView.From == UserDetails.UserId && itemView.MessageType == "media") { View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Right_MS_image, parent, false); ImageViewHolder imageViewHolder = new ImageViewHolder(row); return(imageViewHolder); } if (itemView.To == UserDetails.UserId && itemView.MessageType == "media") { View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Left_MS_image, parent, false); ImageViewHolder imageViewHolder = new ImageViewHolder(row); return(imageViewHolder); } if (itemView.From == UserDetails.UserId && itemView.MessageType == "sticker") { if (itemView.Sticker.Contains(".gif")) { View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Right_MS_gif, parent, false); GifViewHolder viewHolder = new GifViewHolder(row); return(viewHolder); } else { View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Right_MS_sticker, parent, false); StickerViewHolder stickerViewHolder = new StickerViewHolder(row); return(stickerViewHolder); } } if (itemView.To == UserDetails.UserId && itemView.MessageType == "sticker") { if (itemView.Sticker.Contains(".gif")) { View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Left_MS_gif, parent, false); GifViewHolder viewHolder = new GifViewHolder(row); return(viewHolder); } else { View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Left_MS_sticker, parent, false); StickerViewHolder stickerViewHolder = new StickerViewHolder(row); return(stickerViewHolder); } } return(null); } return(null); } catch (Exception exception) { Console.WriteLine(exception); return(null); } }
private void LoadGifOfChatItem(GifViewHolder holder, int position, GetChatConversationsObject.Messages item) { try { if (string.IsNullOrEmpty(item.Sticker)) { return; } string imageUrl = item.Sticker; string fileSavedPath; // G_fixed_height_small_url, // UrlGif - view >> mediaFileName // G_fixed_height_small_mp4, //MediaGif - sent >> media if (imageUrl.Contains("http://") || imageUrl.Contains("https://")) { var fileName = imageUrl.Split('_').Last(); string imageFile = Methods.MultiMedia.GetMediaFrom_Disk(Methods.Path.FolderDiskGif, fileName); if (imageFile == "File Dont Exists") { holder.LoadingProgressView.Indeterminate = false; holder.LoadingProgressView.Visibility = ViewStates.Visible; string filePath = Path.Combine(Methods.Path.FolderDiskGif); string mediaFile = filePath + "/" + fileName; fileSavedPath = mediaFile; var url = imageUrl.Contains("media3.giphy.com/"); if (url) { imageUrl = imageUrl.Replace(Client.WebsiteUrl, ""); } WebClient webClient = new WebClient(); webClient.DownloadDataAsync(new System.Uri(imageUrl)); webClient.DownloadProgressChanged += (sender, args) => { var progress = args.ProgressPercentage; }; webClient.DownloadDataCompleted += (s, e) => { try { if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } File.WriteAllBytes(mediaFile, e.Result); //var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile); //mediaScanIntent.SetData(Android.Net.Uri.FromFile(new Java.IO.File(mediaFile))); //ActivityContext.SendBroadcast(mediaScanIntent); // Tell the media scanner about the new file so that it is // immediately available to the user. MediaScannerConnection.ScanFile(Application.Context, new[] { mediaFile }, null, null); var file = Android.Net.Uri.FromFile(new Java.IO.File(mediaFile)); Glide.With(ActivityContext).Load(file.Path).Apply(new RequestOptions().Placeholder(Resource.Drawable.ImagePlacholder)).Into(holder.ImageGifView); holder.LoadingProgressView.Indeterminate = false; holder.LoadingProgressView.Visibility = ViewStates.Gone; } catch (Exception ex) { Console.WriteLine(ex); } }; } else { fileSavedPath = imageFile; Glide.With(ActivityContext).Load(fileSavedPath).Apply(new RequestOptions().Placeholder(Resource.Drawable.ImagePlacholder)).Into(holder.ImageGifView); //GlideImageLoader.LoadImage(ActivityContext,fileSavedPath, holder.ImageView, ImageStyle.CenterCrop, ImagePlaceholders.Drawable); holder.LoadingProgressView.Indeterminate = false; holder.LoadingProgressView.Visibility = ViewStates.Gone; } } else { fileSavedPath = imageUrl; Glide.With(ActivityContext).Load(fileSavedPath).Apply(new RequestOptions().Placeholder(Resource.Drawable.ImagePlacholder)).Into(holder.ImageGifView); //GlideImageLoader.LoadImage(ActivityContext,fileSavedPath, holder.ImageView, ImageStyle.CenterCrop, ImagePlaceholders.Drawable); holder.LoadingProgressView.Indeterminate = false; holder.LoadingProgressView.Visibility = ViewStates.Gone; } if (!holder.ImageGifView.HasOnClickListeners) { holder.ImageGifView.Click += (sender, args) => { try { string imageFile = Methods.MultiMedia.CheckFileIfExits(fileSavedPath); if (imageFile != "File Dont Exists") { Java.IO.File file2 = new Java.IO.File(fileSavedPath); var photoUri = FileProvider.GetUriForFile(ActivityContext, ActivityContext.PackageName + ".fileprovider", file2); Intent intent = new Intent(); intent.SetAction(Intent.ActionView); intent.AddFlags(ActivityFlags.GrantReadUriPermission); intent.SetDataAndType(photoUri, "image/*"); ActivityContext.StartActivity(intent); } else { Intent intent = new Intent(Intent.ActionView, Uri.Parse(imageUrl)); ActivityContext.StartActivity(intent); } } catch (Exception e) { Console.WriteLine(e); } }; } holder.LytParent.Activated = SelectedItems.Get(position, false); if (!holder.LytParent.HasOnClickListeners) { holder.LytParent.Click += delegate { try { if (ClickListener == null) { return; } ClickListener.ItemClick(holder.LytParent, item, position); } catch (Exception e) { Console.WriteLine(e); } }; holder.LytParent.LongClick += delegate { try { if (ClickListener == null) { return; } ClickListener.ItemLongClick(holder.LytParent, item, position); } catch (Exception e) { Console.WriteLine(e); } }; } ToggleCheckedBackground(holder, position); } catch (Exception e) { Console.WriteLine(e); } }