Created
August 4, 2018 12:19
-
-
Save Dobermensch/83a7a739468b1f202231659c2031a151 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Net; | |
using Chatfer.Shared; | |
using Xamarin.Forms; | |
using System.Diagnostics; | |
using Xamarin.Forms.Xaml; | |
namespace Chatfer.Pages | |
{ | |
[XamlCompilation(XamlCompilationOptions.Compile)] | |
public partial class PersonPage : ContentPage | |
{ | |
private string name { get; set; } | |
private string image { get; set; } | |
private string status { get; set; } | |
private int matchUID; | |
private bool last; | |
public int page; | |
public CarouselPage parent; | |
public PersonPage(string displayName, string Status, string profileimage, int uID, bool flag, int pageNum, CarouselPage parentRef) | |
{ | |
InitializeComponent(); | |
this.name = displayName; | |
this.image = profileimage; | |
this.matchUID = uID; | |
this.status = Status; | |
this.last = flag; | |
this.page = pageNum; | |
this.parent = parentRef; | |
profileImage.Source = image; | |
nameLabel.Text = name; | |
statusLabel.Text = status; | |
AddGestureRecognizer(); | |
} | |
protected override void OnAppearing() | |
{ | |
base.OnAppearing(); | |
if (last) | |
{ | |
last = false; | |
LoadMorePages(); | |
} | |
} | |
public async void LoadMorePages() | |
{ | |
try | |
{ | |
int nextPage = page + 1; | |
List<Match> matches = await API.Matches.Find(nextPage); | |
List<Response> peopleInformation = new List<Response>(); | |
List<int> matchU2IDs = new List<int>(); | |
foreach (var match in matches) | |
{ | |
Response resp = await API.Account.QueryOther(match.u2ID); | |
if (resp.Status == HttpStatusCode.OK) | |
{ | |
peopleInformation.Add(resp); | |
matchU2IDs.Add(match.u2ID); | |
} | |
} | |
foreach (var resp in peopleInformation) | |
{ | |
bool flag = false; | |
//Why? | |
if (peopleInformation.IndexOf(resp) == peopleInformation.Count - 3) | |
{ | |
flag = true; | |
} | |
int secondPersonID = matchU2IDs[peopleInformation.IndexOf(resp)]; | |
parent.Children.Add(new PersonPage(resp.Account.DisplayName, resp.Account.Status, API.Account.GetImage(secondPersonID.ToString()), secondPersonID, flag, nextPage, parent)); | |
} | |
} | |
catch (Exception e) | |
{ | |
} | |
} | |
public void AddGestureRecognizer() | |
{ | |
var tapGestureRecognizer = new TapGestureRecognizer(); | |
tapGestureRecognizer.Tapped += async (s, e) => | |
{ | |
var action = await DisplayActionSheet("Add to Chat List?", "Cancel", null, "Yes"); | |
switch (action) | |
{ | |
case "Yes": | |
Response resp = await API.Matches.Add(matchUID); | |
if (resp.Status == System.Net.HttpStatusCode.OK) | |
{ | |
var disp = await DisplayAlert("Hooray!", "You may now message this person", "OK", "cancel"); | |
//API.personContacted = true; | |
} | |
if (resp.Status == System.Net.HttpStatusCode.InternalServerError) | |
{ | |
var disp = await DisplayAlert("Hang on", "This person is already in your Chat List", "OK", "cancel"); | |
} | |
break; | |
default: | |
break; | |
} | |
}; | |
profileImage.GestureRecognizers.Add(tapGestureRecognizer); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment