async void matchTapped(object sender, Xamarin.Forms.ItemTappedEventArgs e) { int jsonIndex = Matches.matchesList.IndexOf(e.Item as Matches.MatchesListFormat); await Task.Run(async() => { JObject val = JObject.Parse(MatchesDetailView.returnMatchJSONText(jsonIndex)); JObject parameters = new JObject(); foreach (var x in val) { if (!x.Key.Equals("numEvents")) { parameters.Add(x.Key, x.Value); } else { break; } } Preferences.Set("tempParams", JsonConvert.SerializeObject(parameters.ToObject <MatchFormat.EntryParams> ())); NewMatchStart.events = MatchFormat.JSONEventsToObject(val); NewMatchStart.saveEvents(); Preferences.Set("timerValue", Convert.ToInt32(val.Property("timerValue").Value)); Preferences.Set("teamStart", (int)val.Property("team")); Device.BeginInvokeOnMainThread(() => { Navigation.PushAsync(new MatchEntryEditTab() { Title = AdapterMethods.getTeamString((int)val.Property("team").Value) }); }); }); }
public string matchCalc(JObject match) { this.match = match; String total; try { total = this.match["team"] + "," + this.match["matchNum"] + "," + MatchFormat.matchSideFromEnum((int)this.match["side"]) + ","; //Side } catch { total = ",,,"; } total += pickCalc((int)MatchFormat.CHOOSE_RANK_TYPE.pick1) + "," + //Hatch numCalc((int)MatchFormat.CHOOSE_RANK_TYPE.pick1) + ","; total += climbCalc() + ","; total += dropCalc((int)MatchFormat.CHOOSE_RANK_TYPE.drop1) + "," + dropCalc((int)MatchFormat.CHOOSE_RANK_TYPE.drop2) + "," + dropCalc((int)MatchFormat.CHOOSE_RANK_TYPE.drop3); return(total); }
async void openClicked(object sender, System.EventArgs e) { await Task.Run(async() => { JObject val = JObject.Parse(returnMatchJSONText(jsonIndex)); JObject parameters = new JObject(); foreach (var x in val) { if (!x.Key.Equals("numEvents")) { parameters.Add(x.Key, x.Value); } else { break; } } Preferences.Set("tempParams", JsonConvert.SerializeObject(parameters.ToObject <MatchFormat.EntryParams> ())); NewMatchStart.events = MatchFormat.JSONEventsToObject(val); CubeDroppedDialog.saveEvents(); Preferences.Set("timerValue", Convert.ToInt32(val.Property("timerValue").Value)); Preferences.Set("teamStart", val.Property("team").Value.ToString()); Device.BeginInvokeOnMainThread(() => { Navigation.PushAsync(new MatchEntryEditTab() { Title = val.Property("team").Value.ToString() }); }); }); }
private async Task addMatchItemsChecker(JObject data, JObject importJSON) { JArray temp = (JArray)data["Matches"]; JArray importTemp = (JArray)importJSON["Matches"]; var tempList = temp.ToList(); foreach (var match in importTemp.ToList()) { if (tempList.Exists(x => x["matchNum"].Equals(match["matchNum"]) && x["side"].Equals(match["side"]))) { var item = tempList.Find(x => x["matchNum"].Equals(match["matchNum"]) && x["side"].Equals(match["side"])); if (!item["team"].Equals(match["team"])) { var add = await DisplayAlert("Warning!", "Match: " + item["matchNum"] + "\nTeam: " + item["team"] + "\nSide: " + MatchFormat.matchSideFromEnum(Convert.ToInt32(item["side"])) + "\nConflicts with Existing Match", "Overwite", "Ignore"); if (add) { temp.Remove(item); temp.Add(match); } } } else { temp.Add(match); } } }
//Sets the value of the time if app crashed or match was restored private void timerValueSetter() { if (!Preferences.ContainsKey("lastItemPicked")) { Preferences.Set("lastItemPicked", 0); Preferences.Set("lastItemDroppped", 0); Preferences.Set("tempEventString", ""); Preferences.Set("tempMatchEvents", ""); } //else if (Preferences.Get ("lastItemPicked", 0) == 0 || Preferences.Get ("lastItemDropped", 0) == 0) { } else if (Preferences.Get ("lastItemDroppped", 0) > Preferences.Get ("lastItemDropped", 0)) { // cubePicked.Text = ConstantVars.ITEM_DROPPED_TEXT_LIVE; //} if (!Preferences.ContainsKey("timerValue")) { Preferences.Set("timerValue", (int)timerValue); } else if (Preferences.ContainsKey("timerValue") && firstTimerStart == true) { timerValue = Preferences.Get("timerValue", 0); timeSlider.Value = timerValue; timerText.Text = timeToString((int)timerValue); firstTimerStart = false; } try { try { events = MatchFormat.JSONEventsToObject(JObject.Parse(Preferences.Get("tempMatchEvents", ""))); if (events != null && events.Count > 0) { lastEvent = events[events.Count - 1]; } } catch (JsonReaderException) { } if (Object.ReferenceEquals(events, null)) { events = new List <MatchFormat.Data>(); } } catch (InvalidCastException) { } setEventButtons(isTimerRunning); int balls = calculateCurrentBalls(); currentCellAmt.Text = balls.ToString(); //setCubeButton (); }
//Sets the value of the time if app crashed or match was restored private void timerValueSetter() { if (!Preferences.ContainsKey("lastItemPicked")) { Preferences.Set("lastItemPicked", 0); Preferences.Set("lastItemDroppped", 0); Preferences.Set("tempEventString", ""); Preferences.Set("tempMatchEvents", ""); Application.Current.SavePropertiesAsync(); } else if (Preferences.Get("lastItemPicked", 0) == 0 || Preferences.Get("lastItemDropped", 0) == 0) { } else if (Preferences.Get("lastItemDroppped", 0) > Preferences.Get("lastItemDropped", 0)) { cubePicked.Image = ConstantVars.ITEM_DROPPED_IMAGE_LIVE; cubePicked.Text = ConstantVars.ITEM_DROPPED_TEXT_LIVE; } if (!Preferences.ContainsKey("timerValue")) { Preferences.Set("timerValue", (int)timerValue); } else if (Preferences.ContainsKey("timerValue") && firstTimerStart == true) { timerValue = Preferences.Get("timerValue", 0); timeSlider.Value = timerValue; timerText.Text = timeToString((int)timerValue); firstTimerStart = false; } try { try { events = MatchFormat.JSONEventsToObject(JObject.Parse(Preferences.Get("tempMatchEvents", ""))); } catch (JsonReaderException) { } if (Object.ReferenceEquals(events, null)) { events = new List <MatchFormat.Data> (); } } catch (InvalidCastException) { } setEventButtons(isTimerRunning); setCubeButton(); }
void populateMatchesList() { JObject x; string currentEvent = Preferences.Get(ConstantVars.CURRENT_EVENT_NAME, ""); if (!String.IsNullOrWhiteSpace(Preferences.Get(ConstantVars.APP_DATA_STORAGE, ""))) { try { x = (JObject)JObject.Parse(Preferences.Get(ConstantVars.APP_DATA_STORAGE, "")); if (x.ContainsKey(currentEvent)) { x = (JObject)x[currentEvent]; } else { x = new JObject(); } } catch { Console.WriteLine("Caught NullRepEx for populateMatchesList"); x = new JObject(); } } else { x = new JObject(); } if (!x.HasValues) { matchesList = null; listView.ItemsSource = null; } else { JObject matchesJSON = (JObject)JObject.Parse(Preferences.Get(ConstantVars.APP_DATA_STORAGE, ""))[currentEvent]; JArray temp = (JArray)matchesJSON["Matches"]; //Will Contain all items for matches list matchesList = new List <MatchesListFormat> (); int count; try { count = temp.Count; } catch { count = -1; } for (int i = 0; i < count; i++) { JObject match = (JObject)temp[i]; string teamTemp = ""; try { teamTemp = match["team"].ToString(); } catch {} String teamIdentifier = teamTemp; //try //{ // teamIdentifier = teamTemp.Split("-", 2)[MatchFormat.teamNameOrNum].Trim(); //} //catch { // teamIdentifier = teamTemp; //} matchesList.Add(new MatchesListFormat { matchNum = "Match " + match["matchNum"], teamNameAndSide = teamIdentifier + " - " + MatchFormat.matchSideFromEnum((int)match["side"]) }); } listView.ItemsSource = matchesList; } try { matchesView.IsVisible = matchesList.Count > 0; sadNoMatch.IsVisible = !matchesView.IsVisible; } catch { matchesView.IsVisible = false; sadNoMatch.IsVisible = true; } }
public static void saveEvents() { Preferences.Set("tempMatchEvents", JsonConvert.SerializeObject(MatchFormat.eventsListToJSONEvents(NewMatchStart.events))); MatchEvents.update = true; }
private async Task addMatchItemsChecker(JObject data, JObject importJSON, string comp) { int tooMuch = 0; int mode = 0; // 1 for overwite all, 2 for ignore all JArray importTemp = (JArray)importJSON["Matches"]; List <JToken> tempList = new List <JToken>(); if (data.ContainsKey(comp) && (JArray)data[comp]["Matches"] != null) { tempList = ((JArray)data[comp]["Matches"]).ToList(); } else if (!data.ContainsKey(comp)) { data[comp] = new JObject(); data[comp]["Matches"] = new JArray(); } else { data[comp]["Matches"] = new JArray(); } JArray temp = (JArray)data[comp]["Matches"]; foreach (var match in importTemp.ToList()) { Debug.WriteLine("hi" + match); if (tempList.Exists(x => x["matchNum"].Equals(match["matchNum"]) && x["side"].Equals(match["side"]))) { var item = tempList.Find(x => x["matchNum"].Equals(match["matchNum"]) && x["side"].Equals(match["side"])); if (!item["team"].Equals(match["team"])) { if (mode == 1) { temp.Remove(item); temp.Add(match); } else if (mode == 0) { tooMuch++; if (tooMuch <= 1) { var add = await DisplayAlert("Warning!", "\nEvent: " + AdapterMethods.getEventName(comp) + "Match: " + item["matchNum"] + "\nTeam: " + item["team"] + "\nSide: " + MatchFormat.matchSideFromEnum(Convert.ToInt32(item["side"])) + "\nConflicts with Existing Match", "Overwite", "Ignore"); if (add) { temp.Remove(item); temp.Add(match); } } else { var add = await DisplayActionSheet("Warning!", "Event: " + AdapterMethods.getEventName(comp) + "\nMatch: " + item["matchNum"] + "\nTeam: " + item["team"] + "\nSide: " + MatchFormat.matchSideFromEnum(Convert.ToInt32(item["side"])) + "\nConflicts with Existing Match", null, null, "Overwite", "Ignore", "Overwite All", "Ignore All"); if (add.Equals("Overwite")) { temp.Remove(item); temp.Add(match); } else if (add.Equals("Overwite All")) { temp.Remove(item); temp.Add(match); mode = 1; } else if (add.Equals("Ignore All")) { mode = 2; } } } } } else { temp.Add(match); } } //return data; }
//Checks if all neccesary Items exist, clears match data, and goes to Matches Page async void saveClicked(object sender, System.EventArgs e) { Entry.team = teamName; onParamUpdate(); if (popErrorsToScreen()) { } else { await Task.Run(async() => { Device.BeginInvokeOnMainThread(() => { //Disables save button so app doesn't crash when user taps many times saveButton.IsEnabled = false; }); //Gets and combines all of the match's events to a JObject JObject events = MatchFormat.eventsListToJSONEvents(NewMatchStart.events); events.Add("timerValue", NewMatchStart.timerValue); JObject parameters = JObject.FromObject(Entry); parameters.Merge(events); //Adds or creates new JObject to start all data in app cache JObject dataMain = initializeEventsObject(); JObject data = (JObject)dataMain[Preferences.Get(ConstantVars.CURRENT_EVENT_NAME, "")]; if (data.Count <= 0 || !data.ContainsKey("Matches")) { data.Add(new JProperty("Matches", new JArray())); pushBackToHome(dataMain, data, new JArray(), parameters); } else { JArray temp = (JArray)data["Matches"]; if (temp.ToList().Exists(x => x["matchNum"].Equals(parameters["matchNum"]) && x["side"].Equals(parameters["side"]))) { var item = temp.ToList().Find(x => x["matchNum"].Equals(parameters["matchNum"]) && x["side"].Equals(parameters["side"])); if (!item["team"].Equals(parameters["team"])) { Device.BeginInvokeOnMainThread(async() => { bool remove = await DisplayAlert("Error", "Overwrite Old Match with New Data?", "No", "Yes"); if (!remove) { temp.Remove(item); pushBackToHome(dataMain, data, temp, parameters); } else { saveButton.IsEnabled = true; return; } }); } else { temp.Remove(item); pushBackToHome(dataMain, data, temp, parameters); } } else { pushBackToHome(dataMain, data, temp, parameters); } } }); } }
void populateMatchesList() { JObject x; if (!String.IsNullOrWhiteSpace(Preferences.Get("matchEventsString", ""))) { try { x = JObject.Parse(Preferences.Get("matchEventsString", "")); } catch (NullReferenceException) { Console.WriteLine("Caught NullRepEx for populateMatchesList"); x = new JObject(); } } else { x = new JObject(); } if (!x.HasValues) { matchesList = null; listView.ItemsSource = null; } else { JObject matchesJSON = JObject.Parse(Preferences.Get("matchEventsString", "")); JArray temp = (JArray)matchesJSON["Matches"]; //Will Contain all items for matches list matchesList = new List <MatchesListFormat> (); int count; try { count = temp.Count; } catch (System.NullReferenceException) { count = -1; } for (int i = 0; i < count; i++) { JObject match = (JObject)temp[i]; String teamIdentifier = match["team"].ToString().Split('-') [MatchFormat.teamNameOrNum]; if (MatchFormat.teamNameOrNum == 0) { teamIdentifier = teamIdentifier.Substring(0, teamIdentifier.Length - 1); } else { teamIdentifier = teamIdentifier.Substring(1); } matchesList.Add(new MatchesListFormat { matchNum = "Match " + match["matchNum"].ToString(), teamNameAndSide = teamIdentifier + " - " + MatchFormat.matchSideFromEnum((int)match["side"]) }); } listView.ItemsSource = matchesList; } try { matchesView.IsVisible = matchesList.Count > 0; sadNoMatch.IsVisible = !matchesView.IsVisible; } catch (NullReferenceException) { matchesView.IsVisible = false; sadNoMatch.IsVisible = true; } }
private async Task addMatchItemsChecker(JObject data, JObject importJSON) { int tooMuch = 0; int mode = 0; // 1 for overwite all, 2 for ignore all JArray temp = (JArray)data["Matches"]; JArray importTemp = (JArray)importJSON["Matches"]; var tempList = temp.ToList(); foreach (var match in importTemp.ToList()) { if (tempList.Exists(x => x["matchNum"].Equals(match["matchNum"]) && x["side"].Equals(match["side"]))) { var item = tempList.Find(x => x["matchNum"].Equals(match["matchNum"]) && x["side"].Equals(match["side"])); if (!item["team"].Equals(match["team"])) { if (mode == 1) { temp.Remove(item); temp.Add(match); } else if (mode == 0) { tooMuch++; if (tooMuch <= 1) { var add = await DisplayAlert("Warning!", "Match: " + item["matchNum"] + "\nTeam: " + item["team"] + "\nSide: " + MatchFormat.matchSideFromEnum(Convert.ToInt32(item["side"])) + "\nConflicts with Existing Match", "Overwite", "Ignore"); if (add) { temp.Remove(item); temp.Add(match); } } else { var add = await DisplayActionSheet("Warning!" + "\nMatch: " + item["matchNum"] + "\nTeam: " + item["team"] + "\nSide: " + MatchFormat.matchSideFromEnum(Convert.ToInt32(item["side"])) + "\nConflicts with Existing Match", null, null, "Overwite", "Ignore", "Overwite All", "Ignore All"); if (add.Equals("Overwite")) { temp.Remove(item); temp.Add(match); } else if (add.Equals("Overwite All")) { temp.Remove(item); temp.Add(match); mode = 1; } else if (add.Equals("Ignore All")) { mode = 2; } } } } } else { temp.Add(match); } } }