private void DisplayRecordings() { RecordingPane.Children.Clear(); //string[] recordings = Directory.GetFiles(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "*.mp3"); using (var db = new Persistence.SQLiteDb()) { records = db.GetUserAudioRecordings(user.ID); } if (records.Count == 0) { RecordingPane.Children.Clear(); Frame f = new Frame { BorderColor = Color.Silver }; Label l = new Label { Text = "There are no Recordings yet!", FontSize = 20 }; f.Content = l; RecordingPane.Children.Add(f); } else { CreateRecordingsStack(); } CreateGroupRecordingsStack(); }
private void B_Clicked(object sender, EventArgs e) { int index = ContactList.Children.IndexOf(((StackLayout)((Button)sender).Parent)); if (!user.Contacts.Contains(Contacts[index])) { bool addSuccessful = false; this.user.Contacts.Add(Contacts[index]); using (var sq = new Persistence.SQLiteDb()) { if (user.ID < Contacts[index].ID) { addSuccessful = sq.CreateContact(user.ID, Contacts[index].ID); sq.UpdateUser(user); var records = sq.GetContact(user.ID, Contacts[index].ID); } else { addSuccessful = sq.CreateContact(Contacts[index].ID, user.ID); sq.UpdateUser(user); } } string retMsg = addSuccessful ? "User Added" : "Something went wrong"; DisplayAlert("", retMsg, "Okay"); ((StackLayout)((Button)sender).Parent).Children.Clear(); } else { DisplayAlert("", "That user is already in your contact's list", "Okay"); } }
public RecordingsPage(User user) { InitializeComponent(); this.user = user; using (var db = new Persistence.SQLiteDb()) { user.Recordings = db.GetUserAudioRecordings(user.ID); user.Groups = db.GetUserGroups(user.ID); } Picker p = new Picker { WidthRequest = 50, VerticalOptions = LayoutOptions.CenterAndExpand }; foreach (Group g in user.Groups) { p.Items.Add(g.GroupName); } if (p.Items.Count() == 0) { p.Items.Add("You are not currently in any groups"); } p.SelectedIndex = 0; RecordingsStackLayout.Children.Add(p); DisplayRecordings(); }
/// <summary> /// Creates a new user on Create Account button click /// </summary> void CreateAccountBtn_Clicked(object sender, System.EventArgs e) { // do data field validation here? or can we automagically do it somehow via bindings/something else // since the User class has MaxLength constraints, // will it raise exception if we try to create a user with a field longer than the maxlength? // if the password can be confirmed matching if (PasswordEntry.Text == null || CPasswordEntry.Text == null) { DisplayAlert("User Creation Error", "You must supply matching passwords", "Okay"); } else { if (PasswordEntry.Text.Equals(CPasswordEntry.Text)) { var user = CreateNewUser(); // create db class instance var db = new Persistence.SQLiteDb(); try { // try to add user to db if (db.CreateUser(user)) { // go to home page Navigation.PushAsync(new HomePage(user)); // pop this page off the nav stack Navigation.RemovePage(this); } } catch (System.ArgumentException ae) { // if a user already exists with the given email if (ae.ParamName == "Models.User.Email") { // complain to user and re-direct back this.EmailEntry.TextColor = Color.Red; DisplayAlert("User Creation Error", "A user already exists with that Email", "Okay"); } // if a user already exists with the given username else if (ae.ParamName == "Models.User.UserName") { // complain to user and re-direct back this.UsernameEntry.TextColor = Color.Red; DisplayAlert("User Creation Error", "A user already exists with that User Name", "Okay"); } } } else { // complain to user about password confirmation DisplayAlert("User Creation Error", "You must supply matching passwords", "Okay"); } } }
private void CreateGroupRecordingsStack() { RecordingPane.Children.Add(new Label { Text = "Recordings Shared With You" }); List <Group> groups = new List <Group>(); using (var db = new Persistence.SQLiteDb()) { groups = db.GetGroupbyUserID(user.ID); } foreach (Group group in groups) { List <GroupAudioRecord> gar; using (var db = new Persistence.SQLiteDb()) { gar = db.GetGroupAudioRecordByGroup(group.ID); } foreach (GroupAudioRecord groupAudio in gar) { //string[] splitPath = recording.Split('/'); //string path = splitPath[4].Substring(0, splitPath[4].Length - 4); Models.AudioRecord recording; using (var db = new Persistence.SQLiteDb()) { recording = db.GetAudioByID(groupAudio.AudioRecordId); } if (recording.CreatorId != user.ID) { StackLayout sl = new StackLayout { Orientation = StackOrientation.Horizontal }; Frame f = new Frame { BorderColor = Color.Silver }; Label l = new Label { Text = recording.Title, FontSize = 10, Margin = new Thickness(0, 0, 10, 0), BindingContext = recording }; TapGestureRecognizer g = new TapGestureRecognizer(); g.Tapped += PlayRecording; l.GestureRecognizers.Add(g); sl.Children.Add(l); f.Content = sl; RecordingPane.Children.Add(sl); } } } }
public AddToGroupPage(User user) { this.user = user; InitializeComponent(); using (var sq = new Persistence.SQLiteDb()) { user.Contacts.Clear(); sq.GetContactList(user); } DisplayContacts(); }
private void SearchButton_Clicked(object sender, EventArgs e) { ContactList.Children.Clear(); Contacts.Clear(); using (var sq = new Persistence.SQLiteDb()) { var users = sq.GetUsers(); var searchedUsers = users.Where(x => x.Email.Contains(SearchBarEntry.Text)).ToList(); if (searchedUsers.Count > 0) { foreach (var user in searchedUsers) { if (this.user.Contacts.Where(x => x.ID == user.ID).ToList().Count == 0 && this.user.ID != user.ID) { StackLayout sl = new StackLayout { Orientation = StackOrientation.Horizontal }; Contacts.Add(user); Label l = new Label { Text = $"{user.FirstName} {user.LastName}", FontSize = 15, Margin = new Thickness(0, 3, 0, 0) }; sl.Children.Add(l); Button b = new Button { Text = "ADD", FontSize = 9, WidthRequest = 60, HeightRequest = 30, HorizontalOptions = LayoutOptions.End }; b.Clicked += B_Clicked; sl.Children.Add(b); ContactList.Children.Add(sl); } } //if no users are added. this will hit when only contacts already in the contact list and the user are found. if (ContactList.Children.Count == 0) { DisplayAlert("", "No Users Found", "Okay"); } } else // user not found by email nor username { DisplayAlert("", "No Users Found", "Okay"); } } }
private void DeleteGroupButton_Clicked(object sender, EventArgs e) { Label l = ((Label)((StackLayout)((Image)sender).Parent).Children[0]); using (var db = new Persistence.SQLiteDb()) { Group group = db.GetGroupByName(l.Text); db.DeleteGroup(group.ID); DisplayAlert("", "Group Deleted", "Okay"); Navigation.PopAsync(); Navigation.PushAsync(new GroupsPage(user)); }; }
private void DeleteContact(object sender, EventArgs e) { bool hasDeleted = false; using (var sq = new Persistence.SQLiteDb()) { string[] holder = ((Image)sender).ClassId.Split('-'); hasDeleted = sq.DeleteContact(int.Parse(holder[0]), int.Parse(holder[1])); } string retVal = hasDeleted ? "Contact Deleted" : "Something went wrong"; DisplayAlert("", retVal, "Okay"); Navigation.PopAsync(); Navigation.PushAsync(new ContactsPage(user)); }
private void DisplayContacts() { ContactsPane.Children.Clear(); using (var sq = new Persistence.SQLiteDb()) { user.Contacts.Clear(); sq.GetContactList(user); } if (user.Contacts.Count == 0) { Label noContactsLabel = new Label { HorizontalTextAlignment = TextAlignment.Center, FontSize = 10, Text = "No Contacts" }; ContactsPane.Children.Add(noContactsLabel); } else { foreach (User u in user.Contacts) { StackLayout sl = new StackLayout { Orientation = StackOrientation.Horizontal }; Label l = new Label { Text = $"{u.FirstName} {u.LastName}" }; Image i = new Image() { WidthRequest = 20, HeightRequest = 20 }; i.Source = "redX.png"; i.ClassId = $"{user.ID}-{u.ID}"; TapGestureRecognizer g2 = new TapGestureRecognizer(); g2.Tapped += DeleteContact; i.Margin = 0; i.GestureRecognizers.Add(g2); sl.Children.Add(l); sl.Children.Add(i); ContactpageStackLayout.Children.Insert(1, sl); } } }
private void DisplayGroups() { using (var sq = new Persistence.SQLiteDb()) { user.Groups = sq.GetUserGroups(user.ID); } if (user.Groups.Count == 0) { Label noGroupsLabel = new Label { Text = "You have currently have no groups", FontSize = 10.0 }; GroupsStackLayout.Children.Add(noGroupsLabel); } else { foreach (Group g in user.Groups) { StackLayout sl = new StackLayout { Orientation = StackOrientation.Horizontal }; Label l = new Label { Text = g.GroupName }; sl.Children.Add(l); Image i = new Image() { WidthRequest = 20, HeightRequest = 20 }; i.Source = "redX.png"; i.ClassId = $"{g.ID}"; TapGestureRecognizer g2 = new TapGestureRecognizer(); g2.Tapped += DeleteGroupButton_Clicked; i.Margin = 0; i.GestureRecognizers.Add(g2); sl.Children.Add(l); sl.Children.Add(i); sl.Children.Add(i); GroupsStackLayout.Children.Add(sl); } } }
private void ChangeRecordingName(object sender, EventArgs e) { if (string.IsNullOrEmpty(EditEntry.Text.Trim())) { DisplayAlert("Error", "Invalid Name", "Ok"); } else { StackLayout parent = (StackLayout)((Label)sender).Parent; int index = RecordingPane.Children.IndexOf(parent); string newName = EditEntry.Text; user.Recordings[index].Title = newName; using (var db = new Persistence.SQLiteDb()) { db.UpdateRecording(user.Recordings[index]); } DisplayRecordings(); } }
private void DeleteRecording(object sender, EventArgs e) { StackLayout parent = (StackLayout)((Xamarin.Forms.Image)sender).Parent; int index = RecordingPane.Children.IndexOf(parent); string newName = EditEntry.Text; Models.AudioRecord ar = user.Recordings[index]; user.Recordings.RemoveAt(index); bool hasDeleted = false; using (var db = new Persistence.SQLiteDb()) { db.DeleteGroupAudioRecordByAudioID(ar.ID); hasDeleted = db.DeleteRecording(ar); } string retVal = hasDeleted ? "Audio Deleted" : "Something went wrong"; DisplayAlert("", retVal, "Okay"); DisplayRecordings(); }
public void DisplayGroupMemberships() { Label label = new Label { Text = "Outside groups you belong to" }; GroupsStackLayout.Children.Add(label); List <Group> groups = new List <Group>(); using (var sq = new Persistence.SQLiteDb()) { groups = sq.GetAllGroups().Where(x => x.LeadUserId != user.ID).ToList(); } if (groups.Count == 0) { Label noGroupsLabel = new Label { Text = "You belong to no outside groups", FontSize = 10.0 }; GroupsStackLayout.Children.Add(noGroupsLabel); } else { foreach (Group g in groups) { StackLayout sl = new StackLayout { Orientation = StackOrientation.Horizontal }; Label l = new Label { Text = g.GroupName }; sl.Children.Add(l); sl.Children.Add(l); GroupsStackLayout.Children.Add(sl); } } }
private void StopRecording() { if (recorder != null && recordClicked) { RecordButton.Source = "recordbutton.png"; recorder.Stop(); recorder.Release(); recorder.Dispose(); recorder = null; recordClicked = false; time.Reset(); using (var db = new Persistence.SQLiteDb()) { byte[] audioBytes = System.IO.File.ReadAllBytes(audioFilePath); Models.AudioRecord ar = new Models.AudioRecord() { AudioClip = audioBytes, Title = DateTime.Now.ToString("MM-dd-yyyy-HH;mm;ss"), ID = db.GetRecordings().Count + 1, CreatorId = user.ID }; user.Recordings.Add(ar); db.UpdateUser(user); if (db.CreateRecording(ar)) { Android.Util.Log.WriteLine(Android.Util.LogPriority.Info, "Audio Save", $"Audio saved for user {user.ID}"); } else { DisplayAlert("", "Did not save audio", "OK"); } } } }
public void CreateGroupButton_Clicked(object sender, EventArgs args) { if (!string.IsNullOrWhiteSpace(GroupNameEntry.Text)) { string name = GroupNameEntry.Text; group.GroupName = name; group.LeadUserId = user.ID; using (var db = new Persistence.SQLiteDb()) { db.CreateGroup(group); group = db.GetGroupByName(name); GroupUser gu = new GroupUser(); gu.GroupId = group.ID; gu.IsUserGroupLeader = true; gu.UserId = user.ID; db.CreateGroupUser(gu); foreach (User groupUser in addedUsers) { GroupUser groupu = new GroupUser { GroupId = group.ID, IsUserGroupLeader = true, UserId = groupUser.ID }; db.CreateGroupUser(groupu); } }; DisplayAlert("", "Group Created", "Okay"); Navigation.PopAsync(); Navigation.PushAsync(new GroupsPage(user)); } else { DisplayAlert("", "You need to name the group", "Okay"); } }
private void B_Clicked(object sender, EventArgs e) { //get recordID, groupID and create list on int index = RecordingPane.Children.IndexOf((StackLayout)((Button)sender).Parent); Models.AudioRecord record = user.Recordings[index]; string groupName = ((Picker)RecordingsStackLayout.Children[2]).SelectedItem.ToString(); if (user.Groups.Where(x => x.GroupName == groupName).ToList().Count() > 0) { Group g; int count = 0; using (var db = new Persistence.SQLiteDb()) { g = db.GetGroupByName(groupName); count = db.GetGroupAudioRecords().Count(); } GroupAudioRecord gar = new GroupAudioRecord { AudioRecordId = record.ID, GroupId = g.ID, IsGroupAudioCreator = true }; bool hasShared = false; using (var db = new Persistence.SQLiteDb()) { hasShared = db.CreateGroupAudioRecord(gar); } string retVal = hasShared ? "Audio shared" : "Something went wrong"; DisplayAlert("", retVal, "Okay"); } else { DisplayAlert("", "That group doesn't exist", "Okay"); } }