private void OpenCamera_click() { try { ImagePicker((string file, MediaFile mediafile) => { if (string.IsNullOrEmpty(file)) { return; } else { imageUrlMediaFile = mediafile; imageUrlfile = file; ImageUrl = ImageSource.FromFile(file); App.FrameImage = ImageUrl; byte[] b = File.ReadAllBytes(file); base64String = Convert.ToBase64String(b); if (!string.IsNullOrEmpty(base64String)) { App.base64String = "<img src=\"data:image/png;base64," + base64String + "\" alt=\"\">"; } } }); } catch (Exception ex) { Debug.WriteLine($"Exception: { ex.Message}"); } }
public override object ConvertFromInvariantString(string value) { if (value != null) { return(Uri.TryCreate(value, UriKind.Absolute, out Uri uri) && uri.Scheme != "file" ? ImageSource.FromUri(uri) : ImageSource.FromFile(value)); } throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(ImageSource))); }
public async Task <string> GetChatContacts() { #region Client Respone try { using (var client = new HttpClient()) { var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("user_id", Settings.User_id), new KeyValuePair <string, string>("user_profile_id", Settings.User_id), new KeyValuePair <string, string>("s", Settings.Session), new KeyValuePair <string, string>("after_user_id", Aftercontact), new KeyValuePair <string, string>("list_type", "all") }); var response = await client.PostAsync(Settings.Website + "/app_api.php?application=phone&type=get_users_friends", formContent).ConfigureAwait(false); response.EnsureSuccessStatusCode(); string json = await response.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <Dictionary <string, object> >(json); string apiStatus = data["api_status"].ToString(); string ThemeUrl = data["theme_url"].ToString(); #endregion if (apiStatus == "200") { var users = JObject.Parse(json).SelectToken("users").ToString(); var usersOnline = JObject.Parse(json).SelectToken("online").ToString(); JArray ChatusersOnlineGroup = JArray.Parse(usersOnline); JArray Chatusers = JArray.Parse(users); if (Chatusers.Count == 0) { Aftercontact = "0"; Device.BeginInvokeOnMainThread(() => { ContactListview.IsVisible = false; EmptyContactPage.IsVisible = true; }); UserDialogs.Instance.HideLoading(); return(null); } ChatContactsList.Clear(); foreach (var Onlines in ChatusersOnlineGroup) { JObject ChatlistUserdata = JObject.FromObject(Onlines); var ChatUser_User_ID = ChatlistUserdata["user_id"].ToString(); var ChatUser_avatar = ChatlistUserdata["profile_picture"].ToString(); var ChatUser_name = ChatlistUserdata["name"].ToString(); var ChatUser_lastseen = ChatlistUserdata["lastseen"].ToString(); var ChatUser_lastseen_Time_Text = ChatlistUserdata["lastseen_time_text"].ToString(); var ChatUser_verified = ChatlistUserdata["verified"].ToString(); var UserPlatform = ChatlistUserdata["user_platform"].ToString(); Aftercontact = ChatUser_User_ID; if (UserPlatform == "phone") { UserPlatform = "Mobile"; } if (UserPlatform == "web") { UserPlatform = "Web"; } if (UserPlatform == "windows") { UserPlatform = "Desktop"; } #region Saving image var ImageMediaFile = ImageSource.FromFile(DependencyService.Get <IPicture>() .GetPictureFromDisk(ChatUser_avatar, ChatUser_User_ID)); if (DependencyService.Get <IPicture>().GetPictureFromDisk(ChatUser_avatar, ChatUser_User_ID) == "File Dont Exists") { //ImageMediaFile = "loading.jpg"; DependencyService.Get <IPicture>().SavePictureToDisk(ChatUser_avatar, ChatUser_User_ID); } var OnlineOfflineIcon = ImageSource.FromFile(""); if (Settings.Show_Online_Oflline_Icon) { if (ChatUser_lastseen == "on") { OnlineOfflineIcon = ImageSource.FromFile( DependencyService.Get <IPicture>() .GetPictureFromDisk(ThemeUrl + "/img/windows_app/online.png", "Icons")); if ( DependencyService.Get <IPicture>() .GetPictureFromDisk(ThemeUrl + "/img/windows_app/online.png", "Icons") == "File Dont Exists") { OnlineOfflineIcon = new UriImageSource { Uri = new Uri(ThemeUrl + "/img/windows_app/online.png") }; DependencyService.Get <IPicture>() .SavePictureToDisk(ThemeUrl + "/img/windows_app/online.png", "Icons"); } } else { OnlineOfflineIcon = ImageSource.FromFile( DependencyService.Get <IPicture>() .GetPictureFromDisk(ThemeUrl + "/img/windows_app/offline.png", "Icons")); if ( DependencyService.Get <IPicture>() .GetPictureFromDisk(ThemeUrl + "/img/windows_app/offline.png", "Icons") == "File Dont Exists") { OnlineOfflineIcon = new UriImageSource { Uri = new Uri(ThemeUrl + "/img/windows_app/offline.png") }; DependencyService.Get <IPicture>() .SavePictureToDisk(ThemeUrl + "/img/windows_app/offline.png", "Icons"); } } } #endregion if (ChatUser_lastseen == "on") { ChatContactsList.Add(new ChatContacts() { Username = ChatUser_name, lastseen = OnlineOfflineIcon, Name = ChatUser_name, SeenMessageOrNo = ChatUser_lastseen, profile_picture = ImageMediaFile, LastMessageDateTime = AppResources.Label_Online, //verified = ChatUser_verified_bitmap, UserID = ChatUser_User_ID, Platform = UserPlatform }); } #region adding to Sqlite table var contact = SQL_Commander.GetContactUser(ChatUser_User_ID); #region Update contact information if (contact != null) { if (contact.UserID == ChatUser_User_ID && ((contact.Name != ChatUser_name) || (contact.ProfilePicture != ChatUser_avatar) || (contact.Username != ChatUser_name) || (contact.LastMessageDateTime != ChatUser_lastseen_Time_Text) || (contact.Platform != UserPlatform))) { if ((contact.ProfilePicture != ChatUser_avatar)) { SQL_Commander.DeleteContactRow(contact); DependencyService.Get <IPicture>() .DeletePictureFromDisk(contact.ProfilePicture, ChatUser_User_ID); SQL_Commander.InsertContactUsers(new ContactsTableDB() { UserID = ChatUser_User_ID, Name = ChatUser_name, ProfilePicture = ChatUser_avatar, SeenMessageOrNo = ChatUser_lastseen, LastMessageDateTime = ChatUser_lastseen_Time_Text, Username = ChatUser_name, Platform = UserPlatform }); } contact.UserID = ChatUser_User_ID; contact.Name = ChatUser_name; contact.ProfilePicture = ChatUser_avatar; contact.SeenMessageOrNo = ChatUser_lastseen; contact.LastMessageDateTime = ChatUser_lastseen_Time_Text; contact.Username = ChatUser_name; contact.Platform = UserPlatform; SQL_Commander.UpdateContactUsers(contact); } } #endregion #region Add contact if dont exits else { SQL_Commander.InsertContactUsers(new ContactsTableDB() { UserID = ChatUser_User_ID, Name = ChatUser_name, ProfilePicture = ChatUser_avatar, SeenMessageOrNo = ChatUser_lastseen, LastMessageDateTime = ChatUser_lastseen_Time_Text, Username = ChatUser_name, Platform = UserPlatform }); } #endregion #endregion } foreach (var Offline in Chatusers) { JObject ChatlistUserdata = JObject.FromObject(Offline); var ChatUser_User_ID = ChatlistUserdata["user_id"].ToString(); var ChatUser_avatar = ChatlistUserdata["profile_picture"].ToString(); var ChatUser_name = ChatlistUserdata["name"].ToString(); var ChatUser_lastseen = ChatlistUserdata["lastseen"].ToString(); var ChatUser_lastseen_Time_Text = ChatlistUserdata["lastseen_time_text"].ToString(); var ChatUser_verified = ChatlistUserdata["verified"].ToString(); var UserPlatform = ChatlistUserdata["user_platform"].ToString(); Aftercontact = ChatUser_User_ID; if (UserPlatform == "phone") { UserPlatform = "Mobile"; } if (UserPlatform == "web") { UserPlatform = "Web"; } if (UserPlatform == "windows") { UserPlatform = "Desktop"; } #region Saving image var ImageMediaFile = ImageSource.FromFile(DependencyService.Get <IPicture>() .GetPictureFromDisk(ChatUser_avatar, ChatUser_User_ID)); if (DependencyService.Get <IPicture>().GetPictureFromDisk(ChatUser_avatar, ChatUser_User_ID) == "File Dont Exists") { //ImageMediaFile = "loading.jpg"; DependencyService.Get <IPicture>().SavePictureToDisk(ChatUser_avatar, ChatUser_User_ID); } var OnlineOfflineIcon = ImageSource.FromFile(""); if (Settings.Show_Online_Oflline_Icon) { if (ChatUser_lastseen == "on") { OnlineOfflineIcon = ImageSource.FromFile( DependencyService.Get <IPicture>() .GetPictureFromDisk(ThemeUrl + "/img/windows_app/online.png", "Icons")); if ( DependencyService.Get <IPicture>() .GetPictureFromDisk(ThemeUrl + "/img/windows_app/online.png", "Icons") == "File Dont Exists") { OnlineOfflineIcon = new UriImageSource { Uri = new Uri(ThemeUrl + "/img/windows_app/online.png") }; DependencyService.Get <IPicture>() .SavePictureToDisk(ThemeUrl + "/img/windows_app/online.png", "Icons"); } } else { OnlineOfflineIcon = ImageSource.FromFile( DependencyService.Get <IPicture>() .GetPictureFromDisk(ThemeUrl + "/img/windows_app/offline.png", "Icons")); if ( DependencyService.Get <IPicture>() .GetPictureFromDisk(ThemeUrl + "/img/windows_app/offline.png", "Icons") == "File Dont Exists") { OnlineOfflineIcon = new UriImageSource { Uri = new Uri(ThemeUrl + "/img/windows_app/offline.png") }; DependencyService.Get <IPicture>() .SavePictureToDisk(ThemeUrl + "/img/windows_app/offline.png", "Icons"); } } } #endregion #region Data Adding ChatContactsList.Add(new ChatContacts() { Username = ChatUser_name, lastseen = OnlineOfflineIcon, Name = ChatUser_name, SeenMessageOrNo = ChatUser_lastseen, profile_picture = ImageMediaFile, LastMessageDateTime = AppResources.Label_LastSeen + " " + ChatUser_lastseen_Time_Text, //verified = ChatUser_verified_bitmap, UserID = ChatUser_User_ID, Platform = UserPlatform }); #region adding to Sqlite table var contact = SQL_Commander.GetContactUser(ChatUser_User_ID); #region Update contact information if (contact != null) { if (contact.UserID == ChatUser_User_ID && ((contact.Name != ChatUser_name) || (contact.ProfilePicture != ChatUser_avatar) || (contact.Username != ChatUser_name) || (contact.LastMessageDateTime != ChatUser_lastseen_Time_Text) || (contact.Platform != UserPlatform))) { if ((contact.ProfilePicture != ChatUser_avatar)) { SQL_Commander.DeleteContactRow(contact); DependencyService.Get <IPicture>() .DeletePictureFromDisk(contact.ProfilePicture, ChatUser_User_ID); SQL_Commander.InsertContactUsers(new ContactsTableDB() { UserID = ChatUser_User_ID, Name = ChatUser_name, ProfilePicture = ChatUser_avatar, SeenMessageOrNo = ChatUser_lastseen, LastMessageDateTime = ChatUser_lastseen_Time_Text, Username = ChatUser_name, Platform = UserPlatform }); } contact.UserID = ChatUser_User_ID; contact.Name = ChatUser_name; contact.ProfilePicture = ChatUser_avatar; contact.SeenMessageOrNo = ChatUser_lastseen; contact.LastMessageDateTime = ChatUser_lastseen_Time_Text; contact.Username = ChatUser_name; contact.Platform = UserPlatform; SQL_Commander.UpdateContactUsers(contact); } #endregion #region Add contact if dont exits else { SQL_Commander.InsertContactUsers(new ContactsTableDB() { UserID = ChatUser_User_ID, Name = ChatUser_name, ProfilePicture = ChatUser_avatar, SeenMessageOrNo = ChatUser_lastseen, LastMessageDateTime = ChatUser_lastseen_Time_Text, Username = ChatUser_name, Platform = UserPlatform }); } #endregion } #endregion #endregion } UserDialogs.Instance.HideLoading(); if (ContactListview.IsVisible == false) { Device.BeginInvokeOnMainThread(() => { ContactListview.IsVisible = true; EmptyContactPage.IsVisible = false; }); } } else if (apiStatus == "400") { json = AppResources.Label_Error; } return(json); } } catch (Exception) { ContactListview.EndRefresh(); return(AppResources.Label_Error); } }