public async Task GetAllUserPhotos() { UserAPI userAPI = new UserAPI(); string profilePhoto = ""; UIImage Image; foreach (User user in recipients) { Tuple <HttpStatusCode, string> photoResponse = await userAPI.GetUserPhotoForMapObjects(user.id); if (photoResponse.Item1 != HttpStatusCode.OK) { Console.WriteLine("Failed to retrieve profile photo or no profile photo found."); Image = UIImage.FromFile("donationIcon.png"); } else { Console.WriteLine("Successfully retrieved user photo."); profilePhoto = photoResponse.Item2; var imageBytes = Convert.FromBase64String(profilePhoto); var imageData = NSData.FromArray(imageBytes); Image = UIImage.LoadFromData(imageData); } UserPhotos.Add(user.id, Image); } }
///// <summary> ///// Activated whenever focus is on this page ///// </summary> protected override async void OnAppearing() { customMap = new CustomMap { MapType = MapType.Street, WidthRequest = 100, HeightRequest = 100, }; customMap.CustomPins = new Dictionary <Position, CustomPin> { }; customMap.HelicopterPins = new Dictionary <String, CustomPin> { }; //Center on New Zealand var centerPosition = new Position(-41.626217, 172.361873); customMap.MoveToRegion(MapSpan.FromCenterAndRadius( centerPosition, Distance.FromMiles(500.0))); var stack = new StackLayout { Spacing = 0 }; stack.Children.Add(customMap); Content = stack; Title = "Available Donor Map"; //Get all the organs from the database //Create pins for every organ UserAPI userAPI = new UserAPI(); Tuple <HttpStatusCode, List <CustomMapObject> > tuple = await userAPI.GetOrgansForMap(); Console.WriteLine("Initialising hoppis...."); //await InitialiseHospitals(); Console.WriteLine("Adding HeliChopper..."); //AddHelicopter(); Console.WriteLine("HeliChopper success, entering switch"); switch (tuple.Item1) { case HttpStatusCode.OK: Console.WriteLine("Organ Map Objects Successfully received"); users = tuple.Item2; Geocoder geocoder = new Geocoder(); foreach (CustomMapObject user in users) { if (user.organs.Count == 0) { continue; } IEnumerable <Position> position = await geocoder.GetPositionsForAddressAsync(user.cityOfDeath + ", " + user.regionOfDeath + ", " + user.countryOfDeath); Position organPosition = new Position(); using (var sequenceEnum = position.GetEnumerator()) { while (sequenceEnum.MoveNext()) { organPosition = sequenceEnum.Current; } } Random rnd = new Random(); double randomNumberLongitude = rnd.NextDouble() / 50.00; double randomNumberLatitude = rnd.NextDouble() / 50.00; Position finalPosition = new Position(organPosition.Latitude + randomNumberLatitude, organPosition.Longitude + randomNumberLongitude); List <string> organIcons = new List <string>(); foreach (string organ in user.organs) { string organLower = organ.ToLower(); string imageString = ""; switch (organLower) { case ("pancreas"): imageString = "pancreas_icon.png"; break; case ("heart"): imageString = "heart_icon.png"; break; case ("liver"): imageString = "liver_icon.png"; break; case ("connective-tissue"): imageString = "tissue_icon.png"; break; case ("bone-marrow"): imageString = "bone_icon.png"; break; case ("skin"): imageString = "skin_icon.png"; break; case ("lung"): imageString = "lungs_icon.png"; break; case ("cornea"): imageString = "eye_icon.png"; break; case ("kidney"): imageString = "kidney_icon.png"; break; case ("intestine"): imageString = "intestines_icon.png"; break; case ("middle-ear"): imageString = "ear_icon.png"; break; case ("bone"): imageString = "bone_icon.png"; break; } organIcons.Add(imageString); } //Used so that we can get the id when we want to view the user organIcons.Add(user.id.ToString()); //SET GENDER ICON //Randomize man or woman photo //If other then set to a pin //If none then also set to a pin string genderIcon = ""; switch (user.gender) { case ("Male"): int number = rnd.Next(1, 15); genderIcon = "man" + number + ".png"; break; case ("Female"): number = rnd.Next(1, 12); genderIcon = "woman" + number + ".png"; break; case ("Other"): genderIcon = "other.png"; break; default: genderIcon = "other.png"; break; } //SET PROFILE PHOTO //Get profile photo from users uploaded photo (if there is one) string profilePhoto = ""; Tuple <HttpStatusCode, string> photoResponse = await userAPI.GetUserPhotoForMapObjects(user.id); if (photoResponse.Item1 != HttpStatusCode.OK) { Console.WriteLine("Failed to retrieve profile photo or no profile photo found."); Byte[] bytes; if (Device.RuntimePlatform == Device.Android) { } else { bytes = File.ReadAllBytes("donationIcon.png"); profilePhoto = Convert.ToBase64String(bytes); } } else { profilePhoto = photoResponse.Item2; } var pin = new CustomPin { CustomType = ODMSPinType.DONOR, Position = finalPosition, Label = user.firstName + " " + user.middleName + " " + user.lastName, Address = user.cityOfDeath + ", " + user.regionOfDeath + ", " + user.countryOfDeath, Url = String.Join(",", organIcons), genderIcon = genderIcon, userPhoto = profilePhoto, userId = user.id }; customMap.CustomPins.Add(pin.Position, pin); lock (customMap.Pins) { customMap.Pins.Add(pin); } } StartTimer(200); Console.WriteLine("Reached the end of OnAppearing"); break; case HttpStatusCode.ServiceUnavailable: await DisplayAlert("", "Server unavailable, check connection", "OK"); StartTimer(200); break; case HttpStatusCode.InternalServerError: await DisplayAlert("", "Server error retrieving organs, please try again (500)", "OK"); StartTimer(200); break; } }
private async void prepareList() { //getSupportActionBar.Show(); receiverTable = FindViewById <TableLayout>(Resource.Id.ReceiverTableLayout); var organText = FindViewById <TextView>(Resource.Id.Organ_Name); organTimerText = FindViewById <TextView>(Resource.Id.Time_Left); var organImage = FindViewById <ImageView>(Resource.Id.Organ_Picture); transferText = FindViewById <TextView>(Resource.Id.transferText); switch (organ.organType.ToLower()) { case "bone": organImage.SetImageResource(Resource.Drawable.bone_icon); organText.Text = "Bone Marrow"; break; case "ear": organImage.SetImageResource(Resource.Drawable.ear_icon); organText.Text = "Middle Ear"; break; case "cornea": organImage.SetImageResource(Resource.Drawable.cornea_icon); organText.Text = "Cornea"; break; case "heart": organImage.SetImageResource(Resource.Drawable.heart_icon); organText.Text = "Heart"; break; case "intestine": organImage.SetImageResource(Resource.Drawable.intestine_icon); organText.Text = "Intestines"; break; case "kidney": organImage.SetImageResource(Resource.Drawable.kidney_icon); organText.Text = "Kidney"; break; case "liver": organImage.SetImageResource(Resource.Drawable.liver_icon); organText.Text = "Liver"; break; case "lung": organImage.SetImageResource(Resource.Drawable.lung_icon); organText.Text = "Lungs"; break; case "pancreas": organImage.SetImageResource(Resource.Drawable.pancreas_icon); organText.Text = "Pancreas"; break; case "skin": organImage.SetImageResource(Resource.Drawable.skin_icon); organText.Text = "Skin"; break; case "tissue": organImage.SetImageResource(Resource.Drawable.tissue_icon); organText.Text = "Connective Tissue"; break; } //Set the user donor string Tuple <string, long> timeRemainingTuple = organ.getTimeRemaining(); organTimerText.Text = timeRemainingTuple.Item1; //Change colour based on severity long timeRemaining = timeRemainingTuple.Item2; if (timeRemaining <= 3600) { organTimerText.SetTextColor(Android.Graphics.Color.Rgb(191, 14, 0)); } else if (timeRemaining <= 10800) { organTimerText.SetTextColor(Android.Graphics.Color.Rgb(186, 68, 1)); } else if (timeRemaining <= 21600) { organTimerText.SetTextColor(Android.Graphics.Color.Rgb(181, 119, 2)); } else if (timeRemaining <= 43200) { organTimerText.SetTextColor(Android.Graphics.Color.Rgb(176, 167, 3)); } else if (timeRemaining <= 86400) { organTimerText.SetTextColor(Android.Graphics.Color.Rgb(131, 171, 4)); } else if (timeRemaining <= 172800) { organTimerText.SetTextColor(Android.Graphics.Color.Rgb(81, 166, 5)); } else { organTimerText.SetTextColor(Android.Graphics.Color.Rgb(34, 161, 6)); } //----------------------------------------------------------------------------------------------- //Bottom Card //------------------------------------------------------------------------------------ allRecipientRows = new List <TableRow>(); if (organ.expired) { organTimerText.Text = "EXPIRED"; transferText.Text = "This organ has expired."; } else if (organ.inTransfer == 1) { organTimerText.Text = "IN TRANSIT"; transferText.Text = "This organ is in transit."; } else if (organ.inTransfer == 2) { organTimerText.Text = "SUCCESSFULLY TRANSFERRED"; transferText.Text = "This has been successfully transferred."; } else if (organ.topReceivers.IsEmpty()) { transferText.Text = "No valid receivers found."; } else { transferText.Text = "Loading Valid Receivers..."; foreach (User recipient in organ.topReceivers) { TableRow recipientRow = new TableRow(this); TextView recipientName = new TextView(this); TextView recipientAddress = new TextView(this); ImageView recipientImage = new ImageView(this); //TODO Get the users profile picture and set the imageView UserAPI userAPI = new UserAPI(); Tuple <System.Net.HttpStatusCode, String> tuple = await userAPI.GetUserPhotoForMapObjects(recipient.id); if (tuple.Item1 == System.Net.HttpStatusCode.OK) { if (tuple.Item2.Length == 0) { recipientImage.SetImageResource(Resource.Drawable.donationIcon); } else { var imageBytes = Convert.FromBase64String(tuple.Item2); var imageData = Android.Graphics.BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length); recipientImage.SetImageBitmap(imageData); } } else { recipientImage.SetImageResource(Resource.Drawable.donationIcon); } recipientName.Text = recipient.FullName; recipientName.SetTextAppearance(this, Android.Resource.Style.TextAppearanceMedium); recipientName.SetPadding(0, 0, 40, 15); recipientImage.SetAdjustViewBounds(true); recipientImage.SetMaxHeight(80); recipientImage.SetMaxWidth(80); recipientImage.SetPadding(0, 0, 15, 15); recipientAddress.Text = recipient?.currentAddress + ", " + recipient?.region; recipientRow.AddView(recipientImage); recipientRow.AddView(recipientName); recipientRow.AddView(recipientAddress); recipientRow.SetOnClickListener(this); receiverTable.AddView(recipientRow); allRecipientRows.Add(recipientRow); } transferText.Text = "Tap on a receiver to begin transfer."; StartTickingTimer(1000); } }
async void prepareRecipientsOnMap(Position position) { string detailString = timeRemainingLabel.Text; if (detailString.Equals("EXPIRED")) { return; } else if (detailString.Equals("IN TRANSIT")) { return; } else if (detailString.Equals("SUCCESSFULLY TRANSFERRED")) { return; } else { string timeLeftString = detailString.Substring(16); string timeString = timeLeftString.Remove(timeLeftString.Length - 5); TimeSpan timeLeft = TimeSpan.Parse(timeString); organTimeLeft = timeLeft.TotalSeconds; double distanceTime = organTimeLeft * 70; double mapRadius; if (distanceTime > 500000) { mapRadius = 500000; } else { mapRadius = distanceTime; } map.Circle = new CustomCircle { Position = position, Radius = mapRadius }; var circleOverlay = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(map.Circle.Position.Latitude, map.Circle.Position.Longitude), map.Circle.Radius); nativeMap.AddOverlay(circleOverlay); Position mapCenter = new Position(position.Latitude, position.Longitude); map.MoveToRegion(MapSpan.FromCenterAndRadius( mapCenter, Distance.FromMeters(map.Circle.Radius))); //Add all other user objects around the user Random rnd = new Random(); int i = 0; foreach (User item in currentOrgan.topReceivers) { //SET GENDER ICON //Randomize man or woman photo //If other then set to a pin //If none then also set to a pin string recipientIcon = "recipientIcon" + i + ".png"; i++; //Find the position of the Pin Geocoder geocoder = new Geocoder(); IEnumerable <Position> usersPosition = await geocoder.GetPositionsForAddressAsync(item?.currentAddress + ", " + item?.region + ", " + item?.country); Position receiverPosition = new Position(); using (var sequenceEnum = usersPosition.GetEnumerator()) { while (sequenceEnum.MoveNext()) { receiverPosition = sequenceEnum.Current; } } //double randomNumberLongitude = rnd.NextDouble() / 50.00; //double randomNumberLatitude = rnd.NextDouble() / 50.00; //Position finalPosition = new Position(organPosition.Latitude + randomNumberLatitude, organPosition.Longitude + randomNumberLongitude); Position finalPosition = new Position(receiverPosition.Latitude, receiverPosition.Longitude); //SET PROFILE PHOTO //Get profile photo from users uploaded photo (if there is one) UserAPI userAPI = new UserAPI(); string profilePhoto = ""; Tuple <HttpStatusCode, string> photoResponse = await userAPI.GetUserPhotoForMapObjects(item.id); if (photoResponse.Item1 != HttpStatusCode.OK) { Console.WriteLine("Failed to retrieve profile photo or no profile photo found."); Byte[] bytes = File.ReadAllBytes("donationIcon.png"); profilePhoto = Convert.ToBase64String(bytes); } else { profilePhoto = photoResponse.Item2; } var pin = new CustomPin { CustomType = ODMSPinType.RECEIVER, Position = finalPosition, Label = item.FullName, Address = item?.currentAddress + ", " + item?.region, Url = "ReceiverURL," + item.id.ToString(), genderIcon = recipientIcon, userPhoto = profilePhoto, userId = item.id }; map.CustomPins.Add(pin.Position, pin); map.Pins.Add(pin); } } }