mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 00:37:59 -06:00
Improve TBA event downloading
This commit is contained in:
@@ -9,6 +9,8 @@ import androidx.annotation.NonNull;
|
||||
import com.ridgebotics.ridgescout.utility.AlertManager;
|
||||
import com.ridgebotics.ridgescout.utility.BuiltByteParser;
|
||||
import com.ridgebotics.ridgescout.utility.ByteBuilder;
|
||||
import com.ridgebotics.ridgescout.utility.settingsManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
@@ -35,6 +37,10 @@ public class frcEvent {
|
||||
bb.addRaw(frcMatch.typecode, match.encode());
|
||||
}
|
||||
|
||||
if(settingsManager.getEVCode().equals("unset")){
|
||||
settingsManager.setEVCode(eventCode);
|
||||
}
|
||||
|
||||
return bb.build();
|
||||
} catch (ByteBuilder.buildingException e) {
|
||||
AlertManager.error(e);
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.ridgebotics.ridgescout.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.ridgebotics.ridgescout.R;
|
||||
import com.ridgebotics.ridgescout.types.frcTeam;
|
||||
|
||||
public class TBAEventOption extends LinearLayout {
|
||||
public TBAEventOption(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public TBAEventOption(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private TextView eventCode;
|
||||
private TextView eventName;
|
||||
private TextView eventType;
|
||||
|
||||
private ConstraintLayout box;
|
||||
private View coloredBackground;
|
||||
|
||||
public void init(Context context) {
|
||||
LayoutInflater.from(context).inflate(R.layout.view_tba_event, this, true);
|
||||
|
||||
eventCode = findViewById(R.id.tba_event_code);
|
||||
eventName = findViewById(R.id.tba_event_name);
|
||||
eventType = findViewById(R.id.tba_event_type);
|
||||
|
||||
|
||||
box = findViewById(R.id.tba_event_box);
|
||||
coloredBackground = findViewById(R.id.tba_event_background);
|
||||
}
|
||||
|
||||
public void setCode(String code){
|
||||
eventCode.setText(String.valueOf(code));
|
||||
}
|
||||
|
||||
public void setName(String name){
|
||||
eventName.setText(name);
|
||||
}
|
||||
public void setType(String name){
|
||||
eventType.setText(name);
|
||||
}
|
||||
|
||||
|
||||
// public void fromTeam(frcTeam team){
|
||||
// setTeamNumber(team.teamNumber);
|
||||
// setTeamName(team.teamName);
|
||||
//
|
||||
// if(team.bitmap != null) {
|
||||
// setTeamLogo(team.bitmap);
|
||||
// }else{
|
||||
// hideLogo();
|
||||
// }
|
||||
//
|
||||
// setColor(team.getTeamColor());
|
||||
// }
|
||||
|
||||
public void setColor(int color){
|
||||
Drawable drawable = box.getBackground();
|
||||
drawable.mutate();
|
||||
drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||
|
||||
float[] hsv = new float[3];
|
||||
Color.colorToHSV(color,hsv);
|
||||
|
||||
coloredBackground.setBackgroundColor(
|
||||
Color.HSVToColor(127, new float[]{
|
||||
hsv[0],
|
||||
Math.min(hsv[1], 0.75f),
|
||||
Math.min(hsv[2], 0.5f)
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -74,8 +74,7 @@ public class FieldDataFragment extends Fragment {
|
||||
if (psda.data.array[fieldIndex] != null && psda.data.array[fieldIndex].get() != null)
|
||||
data[teamIndex].add(psda.data.array[fieldIndex]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
AlertManager.addSimpleError("Failure to load file " + filenames.get(i));
|
||||
AlertManager.error("Failure to load file " + filenames.get(i), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,8 +270,7 @@ public class TeamsFragment extends Fragment {
|
||||
match_latest_values[i].add_individual_view(binding.matchArea, psda.data.array[i]);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
AlertManager.alert("Warning!", "Failure to load file " + files[matchIndex]);
|
||||
AlertManager.error("Failure to load file " + files[matchIndex], e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -291,8 +290,7 @@ public class TeamsFragment extends Fragment {
|
||||
data[a][i] = psda.data.array[a];
|
||||
}
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
AlertManager.alert("Warning!", "Failure to load file " + files[i]);
|
||||
AlertManager.error("Failure to load file " + files[i], e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,8 +325,7 @@ public class TeamsFragment extends Fragment {
|
||||
data[a][i] = psda.data.array[a];
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
AlertManager.alert("Warning!", "Failure to load file " + files[i]);
|
||||
AlertManager.error("Failure to load file " + files[i], e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,13 @@ public class FileSelectorFragment extends Fragment {
|
||||
boolean sel = !selected_arr[fi];
|
||||
selected_arr[fi] = sel;
|
||||
|
||||
tr.setBackgroundColor(sel ? background_color : unselected_background_color);
|
||||
((CheckBox) tr.getChildAt(0)).setChecked(sel);
|
||||
});
|
||||
checkBox.setOnClickListener(view -> {
|
||||
boolean sel = !selected_arr[fi];
|
||||
selected_arr[fi] = sel;
|
||||
|
||||
tr.setBackgroundColor(sel ? background_color : unselected_background_color);
|
||||
((CheckBox) tr.getChildAt(0)).setChecked(sel);
|
||||
});
|
||||
|
||||
+46
-146
@@ -1,7 +1,10 @@
|
||||
package com.ridgebotics.ridgescout.ui.transfer;
|
||||
|
||||
import static androidx.navigation.fragment.FragmentKt.findNavController;
|
||||
import static com.ridgebotics.ridgescout.utility.fileEditor.TBAAddress;
|
||||
import static com.ridgebotics.ridgescout.utility.fileEditor.TBAHeader;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -16,15 +19,17 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.ridgebotics.ridgescout.R;
|
||||
import com.ridgebotics.ridgescout.databinding.FragmentTransferTbaBinding;
|
||||
import com.ridgebotics.ridgescout.utility.AlertManager;
|
||||
import com.ridgebotics.ridgescout.utility.ImageRequestTask;
|
||||
import com.ridgebotics.ridgescout.utility.RequestTask;
|
||||
import com.ridgebotics.ridgescout.types.frcEvent;
|
||||
import com.ridgebotics.ridgescout.types.frcMatch;
|
||||
import com.ridgebotics.ridgescout.types.frcTeam;
|
||||
import com.ridgebotics.ridgescout.utility.fileEditor;
|
||||
import com.ridgebotics.ridgescout.ui.TBAEventOption;
|
||||
import com.ridgebotics.ridgescout.utility.AlertManager;
|
||||
import com.ridgebotics.ridgescout.utility.ImageRequestTask;
|
||||
import com.ridgebotics.ridgescout.utility.JSONUtil;
|
||||
import com.ridgebotics.ridgescout.utility.RequestTask;
|
||||
import com.ridgebotics.ridgescout.utility.fileEditor;
|
||||
import com.ridgebotics.ridgescout.utility.settingsManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
@@ -37,46 +42,64 @@ import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class TBAFragment extends Fragment {
|
||||
private static final String TBAAddress = "https://www.thebluealliance.com/api/v3/";
|
||||
private static final String TBAHeader = "X-TBA-Auth-Key: tjEKSZojAU2pgbs2mBt06SKyOakVhLutj3NwuxLTxPKQPLih11aCIwRIVFXKzY4e";
|
||||
public class TBAEventFragment extends Fragment {
|
||||
|
||||
private android.widget.TableLayout Table;
|
||||
private TableLayout Table;
|
||||
private FragmentTransferTbaBinding binding;
|
||||
|
||||
private final int year = settingsManager.getYearNum();
|
||||
|
||||
private ProgressDialog loadingDialog;
|
||||
|
||||
private static JSONObject eventData = null;
|
||||
public static void setEventData(JSONObject j){
|
||||
eventData = j;
|
||||
}
|
||||
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
binding = FragmentTransferTbaBinding.inflate(inflater, container, false);
|
||||
|
||||
final String matchKey;
|
||||
try {
|
||||
matchKey = eventData.getString("key");
|
||||
} catch (JSONException e) {
|
||||
AlertManager.error("Failed loading event key!", e);
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
Table = binding.matchTable;
|
||||
|
||||
Table.setStretchAllColumns(true);
|
||||
|
||||
TableRow tr = new TableRow(getContext());
|
||||
addTableText(tr, "Loading Events...");
|
||||
Table.addView(tr);
|
||||
startLoading("Loading Teams and Matches...");
|
||||
Table.removeAllViews();
|
||||
Table.setStretchAllColumns(true);
|
||||
Table.bringToFront();
|
||||
|
||||
startLoading("Loading Events...");
|
||||
TableRow tr1 = new TableRow(getContext());
|
||||
addTableText(tr1, "Downloading Teams...");
|
||||
Table.addView(tr1);
|
||||
|
||||
final RequestTask rq = new RequestTask();
|
||||
rq.onResult(s -> {
|
||||
if(s == null || s.isEmpty()) {
|
||||
AlertManager.addSimpleError("Could not fetch event!");
|
||||
AlertManager.updateErrors();
|
||||
rq.onResult(teamsStr -> {
|
||||
TableRow tr11 = new TableRow(getContext());
|
||||
addTableText(tr11, "Downloading Matches...");
|
||||
Table.addView(tr11);
|
||||
|
||||
final RequestTask rq1 = new RequestTask();
|
||||
rq1.onResult(matchesStr -> {
|
||||
matchTable(matchesStr, teamsStr, eventData);
|
||||
stopLoading();
|
||||
return null;
|
||||
}
|
||||
eventTable(s);
|
||||
});
|
||||
rq1.execute((TBAAddress + "event/" + matchKey + "/matches"), TBAHeader);
|
||||
return null;
|
||||
});
|
||||
rq.execute(TBAAddress + "events/"+year, TBAHeader);
|
||||
rq.execute((TBAAddress + "event/" + matchKey + "/teams"), TBAHeader);
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
@@ -89,129 +112,6 @@ public class TBAFragment extends Fragment {
|
||||
tr.addView(text);
|
||||
}
|
||||
|
||||
public void eventTable(String dataString){
|
||||
|
||||
Table.removeAllViews();
|
||||
Table.setStretchAllColumns(true);
|
||||
Table.bringToFront();
|
||||
|
||||
Date currentTime = Calendar.getInstance().getTime();
|
||||
|
||||
try {
|
||||
JSONArray data = new JSONArray(dataString);
|
||||
|
||||
Table.setStretchAllColumns(true);
|
||||
Table.bringToFront();
|
||||
|
||||
boolean toggle = false;
|
||||
|
||||
for(int i=0;i<data.length();i++){
|
||||
TableRow tr = new TableRow(getContext());
|
||||
TableLayout.LayoutParams rowParams = new TableLayout.LayoutParams(
|
||||
TableRow.LayoutParams.WRAP_CONTENT,
|
||||
TableRow.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
rowParams.setMargins(20,20,20,20);
|
||||
tr.setLayoutParams(rowParams);
|
||||
tr.setPadding(20,20,20,20);
|
||||
tr.setBackgroundColor(0x30000000);
|
||||
|
||||
|
||||
JSONObject j = data.getJSONObject(i);
|
||||
|
||||
String matchKey = j.getString("key");
|
||||
String name = j.getString("short_name");
|
||||
|
||||
// Sometimes, a short name is not present on TBA Events
|
||||
if(name.isEmpty()){
|
||||
name = j.getString("name");
|
||||
}
|
||||
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setGravity(Gravity.CENTER_VERTICAL);
|
||||
tv.setTextSize(12);
|
||||
tv.setText(j.getString("key"));
|
||||
tr.addView(tv);
|
||||
|
||||
tv = new TextView(getContext());
|
||||
tv.setTextSize(18);
|
||||
tv.setText(name);
|
||||
tr.addView(tv);
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
Date startDate = format.parse(j.getString("start_date"));
|
||||
Date endDate = format.parse(j.getString("end_date"));
|
||||
if(currentTime.after(endDate)){
|
||||
tr.setBackgroundColor(0x30FF0000);
|
||||
}else if(currentTime.before(startDate)){
|
||||
tr.setBackgroundColor(0x3000FF00);
|
||||
}else if(currentTime.after(startDate) && currentTime.before(endDate)){
|
||||
tr.setBackgroundColor(0x30FFFF00);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AlertManager.error("Failed finding start and end dates!", e);
|
||||
stopLoading();
|
||||
}
|
||||
|
||||
|
||||
tr.setOnClickListener(v -> {
|
||||
startLoading("Loading Teams and Matches...");
|
||||
Table.removeAllViews();
|
||||
Table.setStretchAllColumns(true);
|
||||
Table.bringToFront();
|
||||
|
||||
TableRow tr1 = new TableRow(getContext());
|
||||
addTableText(tr1, "Downloading Teams...");
|
||||
Table.addView(tr1);
|
||||
|
||||
final RequestTask rq = new RequestTask();
|
||||
rq.onResult(teamsStr -> {
|
||||
TableRow tr11 = new TableRow(getContext());
|
||||
addTableText(tr11, "Downloading Matches...");
|
||||
Table.addView(tr11);
|
||||
|
||||
final RequestTask rq1 = new RequestTask();
|
||||
rq1.onResult(matchesStr -> {
|
||||
matchTable(matchesStr, teamsStr, j);
|
||||
stopLoading();
|
||||
return null;
|
||||
});
|
||||
rq1.execute((TBAAddress + "event/" + matchKey + "/matches"), TBAHeader);
|
||||
return null;
|
||||
});
|
||||
rq.execute((TBAAddress + "event/" + matchKey + "/teams"), TBAHeader);
|
||||
});
|
||||
|
||||
// tr.addView(cl);
|
||||
Table.addView(tr, rowParams);
|
||||
|
||||
|
||||
toggle = !toggle;
|
||||
}
|
||||
|
||||
stopLoading();
|
||||
}catch (JSONException j){
|
||||
AlertManager.error("Failed Downloading", j);
|
||||
stopLoading();
|
||||
}
|
||||
}
|
||||
|
||||
static class matchComparator implements Comparator<JSONObject>
|
||||
{
|
||||
|
||||
public int compare(JSONObject a, JSONObject b)
|
||||
{
|
||||
try {
|
||||
return a.getInt("match_number") - b.getInt("match_number");
|
||||
}catch (JSONException j){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void matchTable(String matchesString, String teamsString, JSONObject eventData){
|
||||
Table.removeAllViews();
|
||||
Table.setStretchAllColumns(true);
|
||||
@@ -493,8 +393,6 @@ public class TBAFragment extends Fragment {
|
||||
matchName = eventData.getString("name");
|
||||
}
|
||||
|
||||
startLoading("Saving teams");
|
||||
|
||||
ArrayList<frcTeam> teams = new ArrayList<>();
|
||||
for (int i = 0; i < teamData.length(); i++) {
|
||||
frcTeam teamObj = new frcTeam();
|
||||
@@ -532,6 +430,8 @@ public class TBAFragment extends Fragment {
|
||||
|
||||
fileEditor.setEvent(event);
|
||||
AlertManager.toast("Saved!");
|
||||
|
||||
getActivity().runOnUiThread(() -> findNavController(this).navigate(R.id.action_navigation_tba_event_to_navigation_transfer));
|
||||
stopLoading();
|
||||
|
||||
}catch(Exception j) {
|
||||
@@ -0,0 +1,230 @@
|
||||
package com.ridgebotics.ridgescout.ui.transfer;
|
||||
|
||||
import static androidx.navigation.fragment.FragmentKt.findNavController;
|
||||
import static com.ridgebotics.ridgescout.utility.fileEditor.TBAAddress;
|
||||
import static com.ridgebotics.ridgescout.utility.fileEditor.TBAHeader;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.ridgebotics.ridgescout.R;
|
||||
import com.ridgebotics.ridgescout.databinding.FragmentTransferTbaBinding;
|
||||
import com.ridgebotics.ridgescout.ui.TBAEventOption;
|
||||
import com.ridgebotics.ridgescout.utility.AlertManager;
|
||||
import com.ridgebotics.ridgescout.utility.ImageRequestTask;
|
||||
import com.ridgebotics.ridgescout.utility.RequestTask;
|
||||
import com.ridgebotics.ridgescout.types.frcEvent;
|
||||
import com.ridgebotics.ridgescout.types.frcMatch;
|
||||
import com.ridgebotics.ridgescout.types.frcTeam;
|
||||
import com.ridgebotics.ridgescout.utility.fileEditor;
|
||||
import com.ridgebotics.ridgescout.utility.JSONUtil;
|
||||
import com.ridgebotics.ridgescout.utility.settingsManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class TBASelectorFragment extends Fragment {
|
||||
|
||||
private android.widget.TableLayout Table;
|
||||
private FragmentTransferTbaBinding binding;
|
||||
|
||||
private final int year = settingsManager.getYearNum();
|
||||
|
||||
private ProgressDialog loadingDialog;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
binding = FragmentTransferTbaBinding.inflate(inflater, container, false);
|
||||
|
||||
Table = binding.matchTable;
|
||||
|
||||
Table.setStretchAllColumns(true);
|
||||
|
||||
TableRow tr = new TableRow(getContext());
|
||||
addTableText(tr, "Loading Events...");
|
||||
Table.addView(tr);
|
||||
|
||||
startLoading("Loading Events...");
|
||||
|
||||
final RequestTask rq = new RequestTask();
|
||||
rq.onResult(s -> {
|
||||
if(s == null || s.isEmpty()) {
|
||||
AlertManager.error("Could not fetch event!");
|
||||
stopLoading();
|
||||
return null;
|
||||
}
|
||||
eventTable(s);
|
||||
return null;
|
||||
});
|
||||
rq.execute(TBAAddress + "events/"+year, TBAHeader);
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private void addTableText(TableRow tr, String textStr){
|
||||
TextView text = new TextView(getContext());
|
||||
text.setTextSize(18);
|
||||
text.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); // Text align center
|
||||
text.setText(textStr);
|
||||
tr.addView(text);
|
||||
}
|
||||
|
||||
public static int getEventTypeWeight(String type){
|
||||
switch(type){
|
||||
case "Preseason": return -3;
|
||||
case "District": return -2;
|
||||
case "Regional": return -1;
|
||||
case "District Championship Division": return 0;
|
||||
case "District Championship": return 1;
|
||||
case "Championship Divison": return 2;
|
||||
case "Championship Finals": return 3;
|
||||
case "Offseason": return 4;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void eventTable(String dataString){
|
||||
|
||||
Table.removeAllViews();
|
||||
Table.setStretchAllColumns(true);
|
||||
Table.bringToFront();
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date currentTime = Calendar.getInstance().getTime();
|
||||
|
||||
try {
|
||||
JSONArray events = new JSONArray(dataString);
|
||||
|
||||
List<JSONObject> data = new ArrayList<>();
|
||||
for(int i = 0; i < events.length(); i++){
|
||||
data.add(events.getJSONObject(i));
|
||||
}
|
||||
|
||||
// Sort events by date, and then type
|
||||
data.sort((a, b) -> {
|
||||
try {
|
||||
// return (int) (currentTime.getTime() - format.parse(a.getString("start_date")).getTime())
|
||||
// -
|
||||
// (int) (currentTime.getTime() - format.parse(b.getString("start_date")).getTime());
|
||||
|
||||
int diff = format.parse(a.getString("start_date")).compareTo(format.parse(b.getString("start_date"))) * 10;
|
||||
|
||||
if(diff == 0){
|
||||
diff = getEventTypeWeight(a.getString("event_type_string")) - getEventTypeWeight(b.getString("event_type_string"));
|
||||
}
|
||||
|
||||
return diff;
|
||||
} catch (ParseException | JSONException e) {
|
||||
AlertManager.error(e);
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
boolean toggle = false;
|
||||
|
||||
for(int i=0;i<data.size();i++){
|
||||
JSONObject j = data.get(i);
|
||||
|
||||
TBAEventOption row = new TBAEventOption(getContext());
|
||||
|
||||
|
||||
// TableRow tr = new TableRow(getContext());
|
||||
// TableLayout.LayoutParams rowParams = new TableLayout.LayoutParams(
|
||||
// TableRow.LayoutParams.WRAP_CONTENT,
|
||||
// TableRow.LayoutParams.WRAP_CONTENT
|
||||
// );
|
||||
// rowParams.setMargins(20,20,20,20);
|
||||
// tr.setLayoutParams(rowParams);
|
||||
// tr.setPadding(20,20,20,20);
|
||||
row.setBackgroundColor(0x30000000);
|
||||
|
||||
String name = j.getString("short_name");
|
||||
|
||||
// Sometimes, a short name is not present on TBA Events
|
||||
if(name.isEmpty()){
|
||||
name = j.getString("name");
|
||||
}
|
||||
|
||||
String eventType = j.getString("event_type_string");
|
||||
if(eventType.equals("District") || eventType.equals("Regional"))
|
||||
eventType = "Week " + (j.getInt("week")+1) + " " + eventType;
|
||||
|
||||
row.setName(name);
|
||||
row.setCode(j.getString("key"));
|
||||
row.setType(eventType);
|
||||
|
||||
try {
|
||||
Date startDate = format.parse(j.getString("start_date"));
|
||||
Date endDate = format.parse(j.getString("end_date"));
|
||||
if(currentTime.after(endDate)){
|
||||
row.setColor(0x30FF0000);
|
||||
}else if(currentTime.before(startDate)){
|
||||
row.setColor(0x3000FF00);
|
||||
}else if(currentTime.after(startDate) && currentTime.before(endDate)){
|
||||
row.setColor(0x30FFFF00);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AlertManager.error("Failed finding start and end dates!", e);
|
||||
stopLoading();
|
||||
}
|
||||
|
||||
|
||||
row.setOnClickListener(v -> {
|
||||
TBAEventFragment.setEventData(j);
|
||||
findNavController(this).navigate(R.id.action_navigation_tba_selector_to_navigation_tba_event);
|
||||
});
|
||||
|
||||
// tr.addView(cl);
|
||||
Table.addView(row);
|
||||
|
||||
|
||||
toggle = !toggle;
|
||||
}
|
||||
|
||||
stopLoading();
|
||||
}catch (JSONException j){
|
||||
AlertManager.error("Failed Downloading", j);
|
||||
stopLoading();
|
||||
}
|
||||
}
|
||||
private void startLoading(String title){
|
||||
getActivity().runOnUiThread(() -> {
|
||||
if(loadingDialog != null && loadingDialog.isShowing())
|
||||
loadingDialog.dismiss();
|
||||
loadingDialog = ProgressDialog.show(getActivity(), title, "Please wait...");
|
||||
});
|
||||
}
|
||||
|
||||
private void stopLoading(){
|
||||
getActivity().runOnUiThread(() -> {
|
||||
if (loadingDialog != null)
|
||||
loadingDialog.cancel();
|
||||
loadingDialog = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class TransferFragment extends Fragment {
|
||||
});
|
||||
|
||||
binding.TBAButton.setOnClickListener(v -> {
|
||||
findNavController(this).navigate(R.id.action_navigation_transfer_to_navigation_tba);
|
||||
findNavController(this).navigate(R.id.action_navigation_transfer_to_navigation_tba_selector);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public class DataManager {
|
||||
public static String evcode;
|
||||
public static frcEvent event;
|
||||
public static void reload_event(){
|
||||
if(event != null) return;
|
||||
// if(event != null) return;
|
||||
evcode = getevcode();
|
||||
|
||||
if(evcode.equals("unset")) return;
|
||||
|
||||
@@ -36,6 +36,11 @@ public final class fileEditor {
|
||||
public static final byte internalDataVersion = 0x01;
|
||||
public static final int maxCompressedBlockSize = 4096;
|
||||
public static final int lengthHeaderBytes = 3;
|
||||
|
||||
|
||||
public static final String TBAAddress = "https://www.thebluealliance.com/api/v3/";
|
||||
public static final String TBAHeader = "X-TBA-Auth-Key: tjEKSZojAU2pgbs2mBt06SKyOakVhLutj3NwuxLTxPKQPLih11aCIwRIVFXKzY4e";
|
||||
|
||||
// private TimeZone localTimeZone = TimeZone.getDefault();
|
||||
|
||||
|
||||
@@ -405,7 +410,7 @@ public final class fileEditor {
|
||||
}
|
||||
});
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
AlertManager.error(e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/tba_event_box"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_margin="5dp"
|
||||
android:background="@drawable/border"
|
||||
android:orientation="horizontal"
|
||||
tools:ignore="UselessParent">
|
||||
|
||||
<View
|
||||
android:id="@+id/tba_event_background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tba_event_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="15dp"
|
||||
android:overlapAnchor="false"
|
||||
android:text="Colorado"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
|
||||
app:autoSizeTextType="uniform"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tba_event_code"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:paddingLeft="3dp"
|
||||
android:paddingRight="3dp"
|
||||
android:text="2025code"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tba_event_type"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="3dp"
|
||||
android:paddingRight="5dp"
|
||||
android:text="Week 4 Regional"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -39,6 +39,33 @@
|
||||
tools:layout="@layout/fragment_scouting_match">
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/navigation_tba_selector"
|
||||
android:name="com.ridgebotics.ridgescout.ui.transfer.TBASelectorFragment"
|
||||
tools:layout="@layout/fragment_transfer_tba">
|
||||
<action
|
||||
android:id="@+id/action_navigation_tba_selector_to_navigation_tba_event"
|
||||
app:destination="@id/navigation_tba_event"
|
||||
app:enterAnim="@anim/enter_anim"
|
||||
app:exitAnim="@anim/exit_anim"
|
||||
app:popEnterAnim="@anim/pop_enter_anim"
|
||||
app:popExitAnim="@anim/pop_exit_anim" />
|
||||
</fragment>
|
||||
|
||||
|
||||
<fragment
|
||||
android:id="@+id/navigation_tba_event"
|
||||
android:name="com.ridgebotics.ridgescout.ui.transfer.TBAEventFragment"
|
||||
tools:layout="@layout/fragment_transfer_tba">
|
||||
<action
|
||||
android:id="@+id/action_navigation_tba_event_to_navigation_transfer"
|
||||
app:destination="@id/navigation_transfer"
|
||||
app:enterAnim="@anim/enter_anim"
|
||||
app:exitAnim="@anim/exit_anim"
|
||||
app:popEnterAnim="@anim/pop_enter_anim"
|
||||
app:popExitAnim="@anim/pop_exit_anim" />
|
||||
</fragment>
|
||||
|
||||
|
||||
<fragment
|
||||
android:id="@+id/navigation_scouting_pit_selector"
|
||||
@@ -77,7 +104,11 @@
|
||||
app:popExitAnim="@anim/pop_exit_anim"/>
|
||||
<action
|
||||
android:id="@+id/action_navigation_data_to_navigation_data_field_data"
|
||||
app:destination="@id/navigation_data_field_data" />
|
||||
app:destination="@id/navigation_data_field_data"
|
||||
app:enterAnim="@anim/enter_anim"
|
||||
app:exitAnim="@anim/exit_anim"
|
||||
app:popEnterAnim="@anim/pop_enter_anim"
|
||||
app:popExitAnim="@anim/pop_exit_anim" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
@@ -120,13 +151,6 @@
|
||||
android:name="com.ridgebotics.ridgescout.ui.transfer.TransferFragment"
|
||||
android:label="@string/title_transfer"
|
||||
tools:layout="@layout/fragment_transfer">
|
||||
<action
|
||||
android:id="@+id/action_navigation_transfer_to_navigation_tba"
|
||||
app:destination="@id/navigation_tba"
|
||||
app:enterAnim="@anim/enter_anim"
|
||||
app:exitAnim="@anim/exit_anim"
|
||||
app:popEnterAnim="@anim/pop_enter_anim"
|
||||
app:popExitAnim="@anim/pop_exit_anim" />
|
||||
<action
|
||||
android:id="@+id/action_navigation_transfer_to_navigation_file_selector"
|
||||
app:destination="@id/navigation_file_selector"
|
||||
@@ -141,6 +165,13 @@
|
||||
app:exitAnim="@anim/exit_anim"
|
||||
app:popEnterAnim="@anim/pop_enter_anim"
|
||||
app:popExitAnim="@anim/pop_exit_anim" />
|
||||
<action
|
||||
android:id="@+id/action_navigation_transfer_to_navigation_tba_selector"
|
||||
app:destination="@id/navigation_tba_selector"
|
||||
app:enterAnim="@anim/enter_anim"
|
||||
app:exitAnim="@anim/exit_anim"
|
||||
app:popEnterAnim="@anim/pop_enter_anim"
|
||||
app:popExitAnim="@anim/pop_exit_anim" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
@@ -214,12 +245,6 @@
|
||||
tools:layout="@layout/fragment_transfer_bluetooth_receiver">
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/navigation_tba"
|
||||
android:name="com.ridgebotics.ridgescout.ui.transfer.TBAFragment"
|
||||
tools:layout="@layout/fragment_transfer_tba">
|
||||
</fragment>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user