public static RequestOptions GetRequestOptions(ImageStyle style, ImagePlaceholders imagePlaceholders) { try { var options = new RequestOptions(); switch (style) { case ImageStyle.CenterCrop: options.CenterCrop(); break; case ImageStyle.FitCenter: options.FitCenter(); break; case ImageStyle.CircleCrop: options.CircleCrop(); break; case ImageStyle.CircleCropWithBorder: options.CircleCrop(); options.Transform(new GlideCircleWithBorder(2, Color.White)); break; case ImageStyle.RoundedCrop: options.Transform(new MultiTransformation(new CenterCrop(), new RoundedCorners(20))); break; default: options.CenterCrop(); break; } switch (imagePlaceholders) { case ImagePlaceholders.Color: var color = Methods.FunString.RandomColor(); options.Placeholder(new ColorDrawable(Color.ParseColor(color))).Fallback(new ColorDrawable(Color.ParseColor(color))); break; case ImagePlaceholders.Drawable: options.Placeholder(Resource.Drawable.ImagePlacholder).Fallback(Resource.Drawable.ImagePlacholder); break; } return(options); } catch (Exception e) { Methods.DisplayReportResultTrack(e); return(new RequestOptions()); } }
public static RequestOptions GetRequestOptions(ImageStyle style, ImagePlaceholders imagePlaceholders) { try { var options = new RequestOptions(); switch (style) { case ImageStyle.CenterCrop: options.CenterCrop(); break; case ImageStyle.FitCenter: options.FitCenter(); break; case ImageStyle.CircleCrop: options.CircleCrop(); break; case ImageStyle.RoundedCrop: options.Transform(new MultiTransformation(new CenterCrop(), new RoundedCorners(25))) .SetPriority(Priority.High).Override(450) .SetUseAnimationPool(false).SetDiskCacheStrategy(DiskCacheStrategy.All) .Error(Resource.Drawable.ImagePlacholder_circle) .Placeholder(Resource.Drawable.ImagePlacholder_circle); break; default: options.CenterCrop(); break; } switch (imagePlaceholders) { case ImagePlaceholders.Color: var color = Methods.FunString.RandomColor(); options.Placeholder(new ColorDrawable(Color.ParseColor(color))).Fallback(new ColorDrawable(Color.ParseColor(color))); break; case ImagePlaceholders.Drawable: options.Placeholder(Resource.Drawable.ImagePlacholder).Fallback(Resource.Drawable.ImagePlacholder); break; } return(options); } catch (Exception e) { Console.WriteLine(e); return(new RequestOptions()); } }
public static void LoadImage(Activity activity, string imageUri, ImageView image, ImageStyle style, ImagePlaceholders imagePlaceholders, RequestOptions options = null) { try { if (image == null) { return; } if (string.IsNullOrEmpty(imageUri) || string.IsNullOrWhiteSpace(imageUri)) { imageUri = "blackdefault"; } imageUri = imageUri.Replace(" ", ""); var newImage = Glide.With(activity); if (options == null) { options = GetOptions(style, imagePlaceholders); } if (AppSettings.CompressImage && style != ImageStyle.RoundedCrop) { if (imageUri.Contains("avatar") || imageUri.Contains("Avatar")) { options.Override(AppSettings.AvatarSize); } else if (imageUri.Contains("gif")) { options.Override(AppSettings.ImageSize); } else { options.Override(AppSettings.ImageSize); } } if (AppSettings.CompressImage) { options.Override(AppSettings.ImageSize); } if (imageUri.Contains("no_profile_image") || imageUri.Contains("blackdefault") || imageUri.Contains("no_profile_image_circle") || imageUri.Contains("ImagePlacholder") || imageUri.Contains("ImagePlacholder_circle") || imageUri.Contains("Grey_Offline") || imageUri.Contains("d-avatar")) { if (imageUri.Contains("no_profile_image_circle")) { newImage.Load(Resource.Drawable.no_profile_image_circle).Apply(options).Into(image); } else if (imageUri.Contains("no_profile_image") || imageUri.Contains("d-avatar")) { newImage.Load(Resource.Drawable.no_profile_image).Apply(options).Into(image); } else if (imageUri.Contains("ImagePlacholder")) { newImage.Load(Resource.Drawable.ImagePlacholder).Apply(options).Into(image); } else if (imageUri.Contains("ImagePlacholder_circle")) { newImage.Load(Resource.Drawable.ImagePlacholder_circle).Apply(options).Into(image); } else if (imageUri.Contains("blackdefault")) { newImage.Load(Resource.Drawable.blackdefault).Apply(options).Into(image); } else { newImage.Load(Resource.Drawable.ImagePlacholder).Apply(options).Into(image); } } else if (!string.IsNullOrEmpty(imageUri) && imageUri.Contains("http")) { newImage.Load(imageUri).Apply(options).Into(image); } else if (!string.IsNullOrEmpty(imageUri) && (imageUri.Contains("file://") || imageUri.Contains("content://") || imageUri.Contains("storage") || imageUri.Contains("/data/user/0/"))) { File file2 = new File(imageUri); var photoUri = FileProvider.GetUriForFile(activity, activity.PackageName + ".fileprovider", file2); RequestOptions option = style == ImageStyle.CircleCrop ? new RequestOptions().CircleCrop() : new RequestOptions(); newImage.Load(photoUri).Apply(option).Into(image); } else { newImage.Load(Resource.Drawable.no_profile_image).Apply(options).Into(image); } } catch (Exception e) { Console.WriteLine(e); } }
public static void LoadImage(Activity activity, string imageUri, ImageView image, ImageStyle style, ImagePlaceholders imagePlaceholders, bool compress = true, RequestOptions options = null) { try { if (image == null) { return; } if (string.IsNullOrEmpty(imageUri) || string.IsNullOrWhiteSpace(imageUri)) { imageUri = "blackdefault"; } imageUri = imageUri.Replace(" ", ""); var newImage = Glide.With(activity); if (options == null) { options = GetOptions(style, imagePlaceholders); } if (compress) { options.Override(200); } if (imageUri.Contains("no_profile_image") || imageUri.Contains("blackdefault") || imageUri.Contains("no_profile_image_circle") || imageUri.Contains("ImagePlacholder") || imageUri.Contains("ImagePlacholder_circle") || imageUri.Contains("Grey_Offline") || imageUri.Contains("d-avatar")) { if (imageUri.Contains("no_profile_image_circle")) { newImage.Load(Resource.Drawable.no_profile_image_circle).Apply(options).Into(image); } else if (imageUri.Contains("no_profile_image") || imageUri.Contains("d-avatar")) { newImage.Load(Resource.Drawable.no_profile_image).Apply(options).Into(image); } else if (imageUri.Contains("ImagePlacholder")) { newImage.Load(Resource.Drawable.ImagePlacholder).Apply(options).Into(image); } else if (imageUri.Contains("ImagePlacholder_circle")) { newImage.Load(Resource.Drawable.ImagePlacholder_circle).Apply(options).Into(image); } else if (imageUri.Contains("blackdefault")) { newImage.Load(Resource.Drawable.blackdefault).Apply(options).Into(image); } else if (imageUri.Contains("Grey_Offline")) { newImage.Load(Resource.Drawable.Grey_Offline).Apply(options).Into(image); } } else if (!string.IsNullOrEmpty(imageUri) && imageUri.Contains("http")) { newImage.Load(imageUri).Apply(options).Into(image); } else if (!string.IsNullOrEmpty(imageUri) && (imageUri.Contains("file://") || imageUri.Contains("content://") || imageUri.Contains("storage") || imageUri.Contains("/data/user/0/"))) { var file = Uri.FromFile(new File(imageUri)); newImage.Load(file.Path).Apply(options).Into(image); } else { newImage.Load(Resource.Drawable.no_profile_image).Apply(options).Into(image); } } catch (Exception e) { Console.WriteLine(e); } }
public static void LoadImage(Activity activity, string imageUri, ImageView image, ImageStyle style, ImagePlaceholders imagePlaceholders, bool compress = false, RequestOptions options = null) { try { if (string.IsNullOrEmpty(imageUri) || string.IsNullOrWhiteSpace(imageUri) || image == null || activity?.IsDestroyed != false) { return; } imageUri = imageUri.Replace(" ", ""); var newImage = Glide.With(activity); options ??= GetOptions(style, imagePlaceholders); if (compress && style != ImageStyle.RoundedCrop) { if (imageUri.Contains("avatar") || imageUri.Contains("Avatar")) { options.Override(AppSettings.AvatarPostSize); } else if (imageUri.Contains("gif")) { options.Override(AppSettings.ImagePostSize); } else { options.Override(AppSettings.ImagePostSize); } } if (compress) { options.Override(AppSettings.ImagePostSize); } if (imageUri.Contains("no_profile_image") || imageUri.Contains("blackdefault") || imageUri.Contains("no_profile_image_circle") || imageUri.Contains("ImagePlacholder") || imageUri.Contains("ImagePlacholder_circle") || imageUri.Contains("Grey_Offline") || imageUri.Contains("Image_File") || imageUri.Contains("Audio_File") || imageUri.Contains("addImage") || imageUri.Contains("d-group") || imageUri.Contains("d-cover") || imageUri.Contains("d-avatar") || imageUri.Contains("user_anonymous")) { if (imageUri.Contains("no_profile_image_circle")) { newImage.Load(Resource.Drawable.no_profile_image_circle).Apply(options).Into(image); } else if (imageUri.Contains("no_profile_image") || imageUri.Contains("d-avatar")) { newImage.Load(Resource.Drawable.no_profile_image).Apply(options).Into(image); } else if (imageUri.Contains("ImagePlacholder")) { newImage.Load(Resource.Drawable.ImagePlacholder).Apply(options).Into(image); } else if (imageUri.Contains("ImagePlacholder_circle")) { newImage.Load(Resource.Drawable.ImagePlacholder_circle).Apply(options).Into(image); } else if (imageUri.Contains("blackdefault")) { newImage.Load(Resource.Drawable.blackdefault).Apply(options).Into(image); } else if (imageUri.Contains("Grey_Offline")) { newImage.Load(Resource.Drawable.Grey_Offline).Apply(options).Into(image); } else if (imageUri.Contains("Image_File")) { newImage.Load(Resource.Drawable.Image_File).Apply(options).Into(image); } else if (imageUri.Contains("Audio_File")) { newImage.Load(Resource.Drawable.Audio_File).Apply(options).Into(image); } else if (imageUri.Contains("addImage")) { newImage.Load(Resource.Drawable.addImage).Apply(options).Into(image); } else if (imageUri.Contains("d-group")) { newImage.Load(Resource.Drawable.default_group).Apply(options).Into(image); } else if (imageUri.Contains("d-page")) { newImage.Load(Resource.Drawable.default_page).Apply(options).Into(image); } else if (imageUri.Contains("d-cover")) { newImage.Load(Resource.Drawable.Cover_image).Apply(options).Into(image); } else if (imageUri.Contains("user_anonymous")) { newImage.Load(Resource.Drawable.user_anonymous).Apply(options).Into(image); } } else if (!string.IsNullOrEmpty(imageUri) && imageUri.Contains("http")) { newImage.Load(imageUri).Apply(options).Into(image); } else if (!string.IsNullOrEmpty(imageUri) && (imageUri.Contains("file://") || imageUri.Contains("content://") || imageUri.Contains("storage") || imageUri.Contains("/data/user/0/"))) { File file2 = new File(imageUri); var photoUri = FileProvider.GetUriForFile(activity, activity.PackageName + ".fileprovider", file2); RequestOptions option = style == ImageStyle.CircleCrop ? new RequestOptions().CircleCrop() : new RequestOptions(); Glide.With(activity).Load(photoUri).Apply(option).Into(image); } else { newImage.Load(Resource.Drawable.no_profile_image).Apply(options).Into(image); } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
private static RequestOptions GetOptions(ImageStyle style, ImagePlaceholders imagePlaceholders) { try { RequestOptions options = new RequestOptions(); switch (style) { case ImageStyle.CenterCrop: options = new RequestOptions().Apply(RequestOptions.CenterCropTransform() .CenterCrop() .SetPriority(Priority.High) .SetUseAnimationPool(false).SetDiskCacheStrategy(DiskCacheStrategy.All).AutoClone() .Error(Resource.Drawable.ImagePlacholder) .Placeholder(Resource.Drawable.ImagePlacholder)); break; case ImageStyle.FitCenter: options = new RequestOptions().Apply(RequestOptions.CenterCropTransform().AutoClone() .FitCenter() .SetPriority(Priority.High) .SetUseAnimationPool(false).SetDiskCacheStrategy(DiskCacheStrategy.All) .Error(Resource.Drawable.ImagePlacholder) .Placeholder(Resource.Drawable.ImagePlacholder)); break; case ImageStyle.CircleCrop: options = new RequestOptions().Apply(RequestOptions.CircleCropTransform().AutoClone() .CenterCrop().CircleCrop() .SetPriority(Priority.High) .SetUseAnimationPool(false).SetDiskCacheStrategy(DiskCacheStrategy.All) .Error(Resource.Drawable.ImagePlacholder_circle) .Placeholder(Resource.Drawable.ImagePlacholder_circle)); break; case ImageStyle.RoundedCrop: options = new RequestOptions().Apply(RequestOptions.CircleCropTransform().AutoClone() .CenterCrop() .Transform(new MultiTransformation(new CenterCrop(), new RoundedCorners(20))) .SetPriority(Priority.High) .SetUseAnimationPool(false).SetDiskCacheStrategy(DiskCacheStrategy.All) .Error(Resource.Drawable.ImagePlacholder_circle) .Placeholder(Resource.Drawable.ImagePlacholder_circle)); break; default: options.CenterCrop(); break; } switch (imagePlaceholders) { case ImagePlaceholders.Color: var color = Methods.FunString.RandomColor(); options.Placeholder(new ColorDrawable(Color.ParseColor(color))).Fallback(new ColorDrawable(Color.ParseColor(color))); break; case ImagePlaceholders.Drawable: switch (style) { case ImageStyle.CircleCrop: options.Placeholder(Resource.Drawable.ImagePlacholder_circle).Fallback(Resource.Drawable.ImagePlacholder_circle); break; default: options.Placeholder(Resource.Drawable.ImagePlacholder).Fallback(Resource.Drawable.ImagePlacholder); break; } break; } return(options); } catch (Exception e) { Methods.DisplayReportResultTrack(e); return(new RequestOptions().CenterCrop()); } }
public static void LoadImage(Activity activity, int imageUri, ImageView image, ImageStyle style, ImagePlaceholders imagePlaceholders, bool compress = false, RequestOptions options = null) { try { if (image == null || activity?.IsDestroyed != false) { return; } var newImage = Glide.With(activity); options ??= GetOptions(style, imagePlaceholders); switch (compress) { case true when style != ImageStyle.RoundedCrop: options.Override(AppSettings.ImagePostSize); break; } switch (compress) { case true: options.Override(AppSettings.ImagePostSize); break; } newImage.Load(imageUri).Apply(options).Into(image); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
public static void LoadImage(Activity activity, string imageUri, ImageView image, ImageStyle style, ImagePlaceholders imagePlaceholders, RequestOptions options = null) { try { if (string.IsNullOrEmpty(imageUri) || string.IsNullOrWhiteSpace(imageUri) || image == null) { return; } imageUri = imageUri.Replace(" ", ""); var newImage = Glide.With(activity); if (options == null) { options = GetOptions(style, imagePlaceholders); } if (AppSettings.CompressImage && style != ImageStyle.RoundedCrop) { if (imageUri.Contains("avatar") || imageUri.Contains("Avatar")) { options.Override(AppSettings.AvatarSize); } else if (imageUri.Contains("gif")) { options.Override(AppSettings.ImageSize); } else { options.Override(AppSettings.ImageSize); } } if (AppSettings.CompressImage) { options.Override(AppSettings.ImageSize); } if (imageUri.Contains("FirstImageOne") || imageUri.Contains("FirstImageTwo") || imageUri.Contains("no_profile_image") || imageUri.Contains("no_profile_image_circle") || imageUri.Contains("ImagePlacholder") || imageUri.Contains("ImagePlacholder_circle") || imageUri.Contains("d-avatar") || imageUri.Contains("Grey_Offline") || imageUri.Contains("addImage")) { if (imageUri.Contains("no_profile_image_circle") || imageUri.Contains("d-avatar.jpg")) { newImage.Load(Resource.Drawable.no_profile_image_circle).Apply(options).Into(image); } else if (imageUri.Contains("no_profile_image") || imageUri.Contains("d-avatar.jpg")) { newImage.Load(Resource.Drawable.no_profile_image).Apply(options).Into(image); } else if (imageUri.Contains("ImagePlacholder")) { newImage.Load(Resource.Drawable.ImagePlacholder).Apply(options).Into(image); } else if (imageUri.Contains("ImagePlacholder_circle")) { newImage.Load(Resource.Drawable.ImagePlacholder_circle).Apply(options).Into(image); } else if (imageUri.Contains("FirstImageOne")) { newImage.Load(Resource.Drawable.FirstImageOne).Apply(options).Into(image); } else if (imageUri.Contains("FirstImageTwo")) { newImage.Load(Resource.Drawable.FirstImageTwo).Apply(options).Into(image); } else if (imageUri.Contains("addImage.jpg")) { newImage.Load(Resource.Drawable.addImage).Apply(options).Into(image); } else if (imageUri.Contains("Grey_Offline")) { newImage.Load(Resource.Drawable.Grey_Offline).Apply(options).Into(image); } } else if (!string.IsNullOrEmpty(imageUri) && imageUri.Contains("http")) { newImage.Load(imageUri).Apply(options).Into(image); } else if (!string.IsNullOrEmpty(imageUri) && (imageUri.Contains("file://") || imageUri.Contains("content://") || imageUri.Contains("storage") || imageUri.Contains("/data/user/0/"))) { var file = Uri.FromFile(new File(imageUri)); newImage.Load(file.Path).Apply(options).Into(image); } else { newImage.Load(Resource.Drawable.no_profile_image).Apply(options).Into(image); } } catch (Exception e) { Console.WriteLine(e); } }
public static void LoadImage(Activity activity, string imageUri, ImageView image, ImageStyle style, ImagePlaceholders imagePlaceholders, bool compress = true, RequestOptions options = null) { try { if (string.IsNullOrEmpty(imageUri) || string.IsNullOrWhiteSpace(imageUri) || image == null) { return; } imageUri = imageUri.Replace(" ", ""); var newImage = Glide.With(activity); if (options == null) { options = GetOptions(style, imagePlaceholders); } if (compress) { options.Override(AppSettings.ImagePostSize); } if (imageUri.Contains("no_profile_image") || imageUri.Contains("blackdefault") || imageUri.Contains("no_profile_image_circle") || imageUri.Contains("ImagePlacholder") || imageUri.Contains("ImagePlacholder_circle") || imageUri.Contains("Grey_Offline") || imageUri.Contains("d-group") || imageUri.Contains("d-cover") || imageUri.Contains("d-avatar") || imageUri.Contains("EmbedVideo_File") || imageUri.Contains("FirstBackground") || imageUri.Contains("loginBackground") || imageUri.Contains("ForgetPasswordBackground")) { if (imageUri.Contains("no_profile_image")) { newImage.Load(Resource.Drawable.no_profile_image).Apply(options).Into(image); } else if (imageUri.Contains("no_profile_image_circle")) { newImage.Load(Resource.Drawable.no_profile_image_circle).Apply(options).Into(image); } else if (imageUri.Contains("d-avatar")) { newImage.Load(Resource.Drawable.no_profile_image).Apply(options).Into(image); } else if (imageUri.Contains("ImagePlacholder")) { newImage.Load(Resource.Drawable.ImagePlacholder).Apply(options).Into(image); } else if (imageUri.Contains("ImagePlacholder_circle")) { newImage.Load(Resource.Drawable.ImagePlacholder_circle).Apply(options).Into(image); } else if (imageUri.Contains("blackdefault")) { newImage.Load(Resource.Drawable.blackdefault).Apply(options).Into(image); } else if (imageUri.Contains("Grey_Offline")) { newImage.Load(Resource.Drawable.Grey_Offline).Apply(options).Into(image); } else if (imageUri.Contains("d-group")) { newImage.Load(Resource.Drawable.default_group).Apply(options).Into(image); } else if (imageUri.Contains("d-cover")) { newImage.Load(Resource.Drawable.Cover_image).Apply(options).Into(image); } else if (imageUri.Contains("EmbedVideo_File")) { newImage.Load(Resource.Drawable.EmbedVideo_File).Apply(options).Into(image); } else if (imageUri.Contains("FirstBackground")) { newImage.Load(Resource.Drawable.FirstBackground).Apply(options).Into(image); } else if (imageUri.Contains("loginBackground")) { newImage.Load(Resource.Drawable.loginBackground).Apply(options).Into(image); } else if (imageUri.Contains("ForgetPasswordBackground")) { newImage.Load(Resource.Drawable.ForgetPasswordBackground).Apply(options).Into(image); } else { newImage.Load(Resource.Drawable.ImagePlacholder).Apply(options).Into(image); } } else if (!string.IsNullOrEmpty(imageUri) && imageUri.Contains("http")) { newImage.Load(imageUri).Apply(options).Into(image); } else if (!string.IsNullOrEmpty(imageUri) && (imageUri.Contains("file://") || imageUri.Contains("content://") || imageUri.Contains("storage") || imageUri.Contains("/data/user/0/"))) { File file2 = new File(imageUri); var photoUri = FileProvider.GetUriForFile(activity, activity.PackageName + ".fileprovider", file2); RequestOptions option = style == ImageStyle.CircleCrop ? new RequestOptions().CircleCrop() : new RequestOptions(); Glide.With(activity).Load(photoUri).Apply(option).Into(image); } else { newImage.Load(Resource.Drawable.no_profile_image).Apply(options).Into(image); } } catch (Exception e) { Console.WriteLine(e); } }