public static async Task <ProfileObject> GetInfoData(Activity context, string userId) { if (Methods.CheckConnectivity()) { int apiStatus; dynamic respond; if (userId == UserDetails.UserId.ToString()) { (apiStatus, respond) = await RequestsAsync.Users.ProfileAsync(userId); } else { (apiStatus, respond) = await RequestsAsync.Users.ProfileAsync(userId, "data,media"); } if (apiStatus == 200) { if (respond is ProfileObject result) { if (userId == UserDetails.UserId.ToString()) { UserDetails.Avatar = result.Data.Avater; UserDetails.Username = result.Data.Username; UserDetails.FullName = result.Data.Fullname; UserDetails.IsPro = result.Data.IsPro; UserDetails.Url = Client.WebsiteUrl + "@" + result.Data?.Username; ListUtils.MyUserInfo.Clear(); ListUtils.MyUserInfo.Add(result.Data); SqLiteDatabase dbDatabase = new SqLiteDatabase(); dbDatabase.InsertOrUpdate_DataMyInfo(result.Data); dbDatabase.Dispose(); await Task.Factory.StartNew(() => { try { var respondList = result.Data.Mediafiles.Count; if (respondList > 0) { foreach (var item in result.Data.Mediafiles) { Glide.With(context).Load(item.Avater).Apply(new RequestOptions().SetDiskCacheStrategy(DiskCacheStrategy.All).CenterCrop()).Preload(); var newPath = item.VideoFile; if (!string.IsNullOrEmpty(newPath) && !newPath.Contains(Client.WebsiteUrl)) { newPath = Client.WebsiteUrl + item.VideoFile; } else { newPath = item.Full; } var type = Methods.AttachmentFiles.Check_FileExtension(newPath); if (type == "Video" || item.Avater.Contains("video_thumb")) { var fileName = newPath.Split('/').Last(); item.UrlFile = QuickDateTools.GetFile(UserDetails.UserId.ToString(), Methods.Path.FolderDiskVideo, fileName, newPath); } else if (type == "Image") { var fileName = item.Full.Split('/').Last(); item.UrlFile = QuickDateTools.GetFile(UserDetails.UserId.ToString(), Methods.Path.FolderDiskImage, fileName, item.Full); } } } } catch (Exception e) { Console.WriteLine(e); } }).ConfigureAwait(false); return(result); } else { return(result); } } } //else Methods.DisplayReportResult(context, respond); } return(null); }
//Open private void MAdapterOnItemClick(object sender, AllMediaAdapterClickEventArgs e) { try { var position = e.Position; if (position > -1) { var item = MAdapter.GetItem(position); if (item != null) { if (string.IsNullOrEmpty(item.UrlFile)) { item.UrlFile = item.Full; } var type = Methods.AttachmentFiles.Check_FileExtension(item.UrlFile); var fileName = item.UrlFile.Split('/').Last(); if (type == "Video") { item.UrlFile = QuickDateTools.GetFile(UserDetails.UserId.ToString(), Methods.Path.FolderDiskVideo, fileName, item.UrlFile); if (!string.IsNullOrEmpty(item.UrlFile) && (item.UrlFile.Contains("file://") || item.UrlFile.Contains("content://") || item.UrlFile.Contains("storage") || item.UrlFile.Contains("/data/user/0/"))) { File file2 = new File(item.UrlFile); var mediaUri = FileProvider.GetUriForFile(this, PackageName + ".fileprovider", file2); Intent intent = new Intent(); intent.SetAction(Intent.ActionView); intent.AddFlags(ActivityFlags.GrantReadUriPermission); intent.SetDataAndType(mediaUri, "video/*"); StartActivity(intent); } else { Intent intent = new Intent(Intent.ActionView, Uri.Parse(item.UrlFile)); StartActivity(intent); } } else { item.UrlFile = QuickDateTools.GetFile(UserDetails.UserId.ToString(), Methods.Path.FolderDiskImage, fileName, item.UrlFile); if (!string.IsNullOrEmpty(item.UrlFile) && (item.UrlFile.Contains("file://") || item.UrlFile.Contains("content://") || item.UrlFile.Contains("storage") || item.UrlFile.Contains("/data/user/0/"))) { File file2 = new File(item.UrlFile); var photoUri = FileProvider.GetUriForFile(this, PackageName + ".fileprovider", file2); Intent intent = new Intent(); intent.SetAction(Intent.ActionView); intent.AddFlags(ActivityFlags.GrantReadUriPermission); intent.SetDataAndType(photoUri, "image/*"); StartActivity(intent); } else { Intent intent = new Intent(Intent.ActionView, Uri.Parse(item.UrlFile)); StartActivity(intent); } } } } } catch (Exception exception) { Console.WriteLine(exception); } }
private async Task LoadMediaFilesAsync() { if (Methods.CheckConnectivity()) { int countList = MAdapter.MediaList.Count; var(apiStatus, respond) = await RequestsAsync.Users.ProfileAsync(UserDetails.UserId.ToString(), "data,media"); if (apiStatus != 200 || !(respond is ProfileObject result) || result.Data == null) { Methods.DisplayReportResult(this, respond); } else { var respondList = result.Data.Mediafiles.Count; if (respondList > 0) { foreach (var item in from item in result.Data.Mediafiles let check = MAdapter.MediaList.FirstOrDefault(a => a.Id == item.Id) where check == null select item) { MAdapter.MediaList.Add(item); await Task.Factory.StartNew(() => { try { var newPath = item.VideoFile; if (!string.IsNullOrEmpty(newPath) && !newPath.Contains(Client.WebsiteUrl)) { newPath = Client.WebsiteUrl + item.VideoFile; } else { newPath = item.Full; } var type = Methods.AttachmentFiles.Check_FileExtension(newPath); if (type == "Video" || item.Avater.Contains("video_thumb")) { var fileName = newPath.Split('/').Last(); item.UrlFile = QuickDateTools.GetFile(UserDetails.UserId.ToString(), Methods.Path.FolderDiskVideo, fileName, newPath); } else if (type == "Image") { var fileName = item.Full.Split('/').Last(); item.UrlFile = QuickDateTools.GetFile(UserDetails.UserId.ToString(), Methods.Path.FolderDiskImage, fileName, item.Full); } } catch (Exception e) { Console.WriteLine(e); } }).ConfigureAwait(false); } if (countList > 0) { RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList - 1, MAdapter.MediaList.Count - countList); }); } else { RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); }); } } } RunOnUiThread(ShowEmptyPage); } 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(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show(); } }
public static async Task <ProfileObject> GetInfoData(Activity context, string userId) { if (Methods.CheckConnectivity()) { int apiStatus; dynamic respond; if (userId == UserDetails.UserId.ToString()) { (apiStatus, respond) = await RequestsAsync.Users.ProfileAsync(userId); } else { (apiStatus, respond) = await RequestsAsync.Users.ProfileAsync(userId, "data,media"); } if (apiStatus == 200) { if (respond is ProfileObject result) { if (userId == UserDetails.UserId.ToString()) { UserDetails.Avatar = result.Data.Avater; UserDetails.Username = result.Data.Username; UserDetails.FullName = result.Data.Fullname; UserDetails.IsPro = result.Data.IsPro; UserDetails.Email = result.Data.Email; UserDetails.Url = Client.WebsiteUrl + "@" + result.Data?.Username; ListUtils.MyUserInfo.Clear(); ListUtils.MyUserInfo.Add(result.Data); SqLiteDatabase dbDatabase = new SqLiteDatabase(); dbDatabase.InsertOrUpdate_DataMyInfo(result.Data); dbDatabase.Dispose(); try { GlideImageLoader.LoadImage(context, UserDetails.Avatar, HomeActivity.GetInstance()?.FragmentBottomNavigator?.ProfileImage, ImageStyle.CircleCrop, ImagePlaceholders.Drawable); }catch (Exception e) { Console.WriteLine(e); } await Task.Factory.StartNew(async() => { try { var respondList = result.Data.Mediafiles.Count; if (respondList > 0) { foreach (var item in result.Data.Mediafiles) { Glide.With(context).Load(item.Avater).Apply(new RequestOptions().SetDiskCacheStrategy(DiskCacheStrategy.All).CenterCrop()).Preload(); if (item.IsVideo == "1") { var fileName = item.VideoFile.Split('/').Last(); item.UrlFile = await QuickDateTools.GetFile(UserDetails.UserId.ToString(), Methods.Path.FolderDiskVideo, fileName, item.VideoFile); } else { var fileName = item.Full.Split('/').Last(); item.UrlFile = await QuickDateTools.GetFile(UserDetails.UserId.ToString(), Methods.Path.FolderDiskImage, fileName, item.Full); } } } } catch (Exception e) { Console.WriteLine(e); } }).ConfigureAwait(false); return(result); } else { return(result); } } } //else Methods.DisplayReportResult(context, respond); } return(null); }