private async Task SetStory(FetchStoriesObject.Story story) { try { StoryId = story.Id.ToString(); LastSeenTextView.Text = Methods.Time.ReplaceTime(story.TimeText); if (string.IsNullOrEmpty(story.Caption) || string.IsNullOrWhiteSpace(story.Caption)) { StoryaboutLayout.Visibility = ViewStates.Gone; } else { StoryaboutLayout.Visibility = ViewStates.Visible; CaptionStoryTextView.Text = Methods.FunString.DecodeString(story.Caption); } MediaFile = story.MediaFile; if (StoryVideoView == null) { InitVideoView(); } var type = Methods.AttachmentFiles.Check_FileExtension(MediaFile); if (type == "Video") { //Show a progress //RunOnUiThread(() => { try { AndHUD.Shared.Show(this, GetText(Resource.String.Lbl_Loading)); }catch (Exception e) { Console.WriteLine(e); } }); var fileName = MediaFile.Split('/').Last(); MediaFile = AppTools.GetFile(DateTime.Now.Day.ToString(), Methods.Path.FolderDiskStory, fileName, MediaFile); StoryImageView.Visibility = ViewStates.Gone; StoryVideoView.Visibility = ViewStates.Visible; if (MediaFile.Contains("http")) { StoryVideoView.SetVideoURI(Uri.Parse(MediaFile)); StoryVideoView.Start(); } else { var file = Uri.FromFile(new File(MediaFile)); StoryVideoView.SetVideoPath(file.Path); StoryVideoView.Start(); } await Task.Delay(500); } else { StoryImageView.Visibility = ViewStates.Visible; StoryVideoView.Visibility = ViewStates.Gone; Glide.With(this).Load(story.MediaFile).Apply(new RequestOptions()).Into(StoryImageView); // GlideImageLoader.LoadImage(this,story.MediaFile, StoryImageView, ImageStyle.CenterCrop, ImagePlaceholders.Drawable); } } catch (Exception e) { Console.WriteLine(e); } }
private async Task LoadStory() { try { Activity.RunOnUiThread(() => { try { var dataOwner = StoryAdapter.StoryList.FirstOrDefault(a => a.Type == "Your"); if (dataOwner == null) { StoryAdapter.StoryList.Insert(0, new FetchStoriesObject.Data() { Avatar = UserDetails.Avatar, Type = "Your", Username = Context.GetText(Resource.String.Lbl_YourStory), Owner = true, }); } } catch (Exception e) { Console.WriteLine(e); } }); if (Methods.CheckConnectivity()) { int countList = StoryAdapter.StoryList.Count; (int apiStatus, var respond) = await RequestsAsync.Story.FetchStories(); if (apiStatus != 200 || !(respond is FetchStoriesObject result) || result.data == null) { Methods.DisplayReportResult(Activity, respond); } else { var respondList = result.data.Count; if (respondList > 0) { foreach (var item in result.data) { var check = StoryAdapter.StoryList.FirstOrDefault(a => a.UserId == item.UserId); if (check == null) { foreach (var item1 in item.Stories) { if (item.DurationsList == null) { item.DurationsList = new List <long>(); } var type1 = Methods.AttachmentFiles.Check_FileExtension(item1.MediaFile); if (type1 != "Video") { Glide.With(Context).Load(item1.MediaFile).Apply(new RequestOptions().SetDiskCacheStrategy(DiskCacheStrategy.All).CenterCrop()).Preload(); item.DurationsList.Add(10000L); } else { var fileName = item1.MediaFile.Split('/').Last(); item1.MediaFile = AppTools.GetFile(DateTime.Now.Day.ToString(), Methods.Path.FolderDiskStory, fileName, item1.MediaFile); if (Long.ParseLong(item1.Duration) == 0) { item1.Duration = AppTools.GetDuration(item1.MediaFile); item.DurationsList.Add(Long.ParseLong(item1.Duration)); } else { item.DurationsList.Add(Long.ParseLong(item1.Duration)); } } } StoryAdapter.StoryList.Add(item); } else { foreach (var item2 in item.Stories) { if (item.DurationsList == null) { item.DurationsList = new List <long>(); } var type = Methods.AttachmentFiles.Check_FileExtension(item2.MediaFile); if (type != "Video") { Glide.With(Context).Load(item2.MediaFile).Apply(new RequestOptions().SetDiskCacheStrategy(DiskCacheStrategy.All).CenterCrop()).Preload(); item.DurationsList.Add(10000L); } else { var fileName = item2.MediaFile.Split('/').Last(); item2.MediaFile = AppTools.GetFile(DateTime.Now.Day.ToString(), Methods.Path.FolderDiskStory, fileName, item2.MediaFile); if (Long.ParseLong(item2.Duration) == 0) { item2.Duration = AppTools.GetDuration(item2.MediaFile); item.DurationsList.Add(Long.ParseLong(item2.Duration)); } else { item.DurationsList.Add(Long.ParseLong(item2.Duration)); } } } check.Stories = item.Stories; } } if (countList > 0) { Activity.RunOnUiThread(() => { StoryAdapter.NotifyItemRangeInserted(countList - 1, StoryAdapter.StoryList.Count - countList); }); } else { Activity.RunOnUiThread(() => { StoryAdapter.NotifyDataSetChanged(); }); } } } } else { Inflated = EmptyStateLayout.Inflate(); EmptyStateInflater x = new EmptyStateInflater(); x.InflateLayout(Inflated, EmptyStateInflater.Type.NoConnection); if (!x.EmptyStateButton.HasOnClickListeners) { x.EmptyStateButton.Click += null; x.EmptyStateButton.Click += EmptyStateButtonOnClick; } Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show(); } } catch (Exception e) { Console.WriteLine(e.Message); } }