private async void EndActivity(object sender, System.EventArgs e) { timer.Dispose(); timer = null; var request = new GeolocationRequest(GeolocationAccuracy.Medium); var finalLocation = await Geolocation.GetLocationAsync(request); double km = Location.CalculateDistance(startLocation, finalLocation, DistanceUnits.Kilometers); this.FindByName <Label>("distance").Text = km.ToString("#.000") + "km"; startLocation = null; string finaltime = this.FindByName <Label>("txtTimer").Text; string setColor = "Orange"; int points = 0; DateTime totalTime = DateTime.ParseExact(finaltime, "H:m:s", CultureInfo.CurrentCulture); if (this.FindByName <Label>("labelAct").Text.ToLower().Equals("run")) { setColor = "#E02F2C"; points += 10; } if (this.FindByName <Label>("labelAct").Text.ToLower().Equals("walk")) { setColor = "#2C68E0"; points += 10; } if (this.FindByName <Label>("labelAct").Text.ToLower().Equals("cycle")) { setColor = "#2CE056"; points += 10; } Act1 act = new Act1() { Name = this.FindByName <Label>("labelAct").Text, Duration = totalTime.ToString("HH:mm:ss"), Image = this.FindByName <Label>("labelAct").Text.ToLower() + ".png", Color = setColor, DateUtc = DateTime.UtcNow }; var fetchedUser = await Data.ReadAsync <User>(Preferences.Get("UserID", null), DefaultPartitions.UserDocuments); var result = JsonConvert.DeserializeObject <User>(fetchedUser.JsonValue.ToString()); result.Points += points; result.Acts.Add(act); Preferences.Set("AddedActivity", true); await Data.ReplaceAsync(Preferences.Get("UserID", null), result, DefaultPartitions.UserDocuments); this.FindByName <StackLayout>("ProgressBox").IsVisible = false; this.FindByName <Label>("txtTimer").Text = "0:0:0"; hour = 0; min = 0; sec = 0; }
async void SignInAndroid() { try { if (Preferences.Get("UserID", null) == null) { User user = new User { Points = 100 }; Act1 act = new Act1 { Name = "Test Activity", Color = "Blue", Image = "Walk.png", Duration = "00:00:00", DateUtc = DateTime.UtcNow }; Food1 food = new Food1 { Name = "Broc", Calories = 100, Points = 10, FID = "1", Color = "Green", Image = "test.png" }; Achievements ach = new Achievements { Name = "Test", AID = 1, Description = "Test", Image = "Test.png", Points = 100 }; Shop1 item = new Shop1 { Name = "Test", Description = "test", Color = "Red", Coupon = "2002", Image = "test.png", Points = 100, SId = 1 }; user.Items.Add(item); user.Foods.Add(food); user.Achs.Add(ach); user.Acts.Add(act); Preferences.Set("UserID", user.Id.ToString()); Console.WriteLine("~Android~ : Successfully added user to firebase!"); } await this.Navigation.PushAsync(new MainPage()); } catch (Exception e) { Console.WriteLine("Debug 1: Unable to sign in"); // Do something with sign-in failure. } }
async void ActivityButton_Clicked(object sender, System.EventArgs e) { var setColor = ""; int points = 0; if (classID.Equals("run")) { setColor = "#E02F2C"; points = 10; } if (classID.Equals("walk")) { setColor = "#2C68E0"; points = 10; } if (classID.Equals("cycle")) { setColor = "#2CE056"; points = 10; } if (classID.Equals("basketball")) { setColor = "#E09E2C"; points = 10; } if (classID.Equals("soccer")) { setColor = "#12160F"; points = 10; } if (classID.Equals("swim")) { setColor = "#2CCBE0"; points = 10; } if (classID.Equals("tennis")) { setColor = "#E02C83"; points = 10; } time = durationEntry.Time.ToString(); Analytics.TrackEvent("[Tracker] Activity : " + char.ToUpper(classID[0]) + classID.Substring(1)); Act1 act = new Act1 { Name = char.ToUpper(classID[0]) + classID.Substring(1), Duration = time, Image = classID + ".png", Color = setColor, DateUtc = DateTime.UtcNow }; var fetchedUser = await Data.ReadAsync <User>(Preferences.Get("UserID", null), DefaultPartitions.UserDocuments); var result = JsonConvert.DeserializeObject <User>(fetchedUser.JsonValue.ToString()); result.Points += points; result.Acts.Add(act); Preferences.Set("AddedActivity", true); await Data.ReplaceAsync(Preferences.Get("UserID", null), result, DefaultPartitions.UserDocuments); //Act1 user = new Act1() //{ // Name = char.ToUpper(classID[0]) + classID.Substring(1), // Duration = time, // Image = classID + ".png", // Color = setColor, // DateUtc = DateTime.UtcNow //}; //using (SQLiteConnection conn = new SQLiteConnection(App.FilePath)) //{ // //Act1 - database name // //conn.Execute("DELETE FROM user"); // conn.CreateTable<Act1>(); // int rowsAdded = conn.Insert(user); //} await Navigation.PopAsync(); }
public ComplexAction(Act1 action1, Act2 action2) { this.action1 = action1; this.action2 = action2; }
async void SignInIOS() { try { // Authenticate UserInformation userInfo = await Auth.SignInAsync(); string accountId = userInfo.AccountId; // Testing //Act1 act = new Act1 { Name = "Run", Color = "Blue", Duration = "10:10:10" }; //user.Acts.Add(act); //Preferences.Clear(); //Check if new user if (Preferences.Get("UserID", null) == null) { User user = new User { Points = 100 }; Act1 act = new Act1 { Name = "Test Activity", Color = "Blue", Image = "Walk.png", Duration = "00:00:00", DateUtc = DateTime.UtcNow }; user.Acts.Add(act); Preferences.Set("UserID", user.Id.ToString()); // Create new user await Data.CreateAsync(user.Id.ToString(), user, DefaultPartitions.UserDocuments); } // For achievements var fetchedUser = await Data.ReadAsync <User>(Preferences.Get("UserID", null), DefaultPartitions.UserDocuments); var fetched = await Data.ReadAsync <AchievementRetriever>("public-achievements", DefaultPartitions.AppDocuments); var result = JsonConvert.DeserializeObject <AchievementRetriever>(fetched.JsonValue.ToString()); var resultUser = JsonConvert.DeserializeObject <User>(fetchedUser.JsonValue.ToString()); foreach (Achievements i in result.Achs) { //resultUser.Achs.Add(i); Console.WriteLine(i.AID + "/" + i.Name + "/" + i.Description + "/" + i.Points); } //await Data.ReplaceAsync(resultUser.Id.ToString(), resultUser, DefaultPartitions.UserDocuments); await this.Navigation.PushAsync(new MainPage()); Console.WriteLine("Debug 1: " + accountId); } catch (Exception e) { Console.WriteLine("Debug 1: Unable to sign in"); // Do something with sign-in failure. } }