Add rescout option

This commit is contained in:
Michael Mikovsky
2025-03-26 10:56:05 -06:00
parent d2c075da9c
commit 967dc3c967
10 changed files with 189 additions and 25 deletions
@@ -104,10 +104,31 @@ public class TeamSelectorFragment extends Fragment {
if(pits_mode) {
if (fileEditor.fileExist(evcode + "-" + team.teamNumber + ".pitscoutdata")) {
teamRow.setColor(0x3000FF00);
String filename = evcode + "-" + team.teamNumber + ".pitscoutdata";
if (fileEditor.fileExist(filename)) {
final boolean[] rescout = {DataManager.rescout_list.contains(filename)};
teamRow.setColor(DataManager.rescout_list.contains(filename) ? 0x300000FF : 0x3000FF00);
teamRow.setOnLongClickListener(v -> {
rescout[0] = !rescout[0];
if(rescout[0]){
DataManager.rescout_list.add(filename);
teamRow.setColor(0x300000FF);
DataManager.save_rescout_list();
}else{
DataManager.rescout_list.remove(filename);
teamRow.setColor(0x3000FF00);
DataManager.save_rescout_list();
}
return true;
});
} else {
teamRow.setColor(0x30FF0000);
teamRow.setOnLongClickListener(v -> true);
}
}
@@ -61,6 +61,7 @@ public class EventFragment extends Fragment {
}
public static int color_found = 0x7f00ff00;
public static int color_rescout = 0x7f0000ff;
public static int color_not_found = 0x7f7f0000;
private void addTableText(TableRow tr, String textStr){
@@ -104,8 +105,25 @@ public class EventFragment extends Fragment {
text.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
text.setText(String.valueOf(num));
if(fileEditor.fileExist(event.eventCode + "-" + num + ".pitscoutdata")){
text.setBackgroundColor(color_found);
final String filename = event.eventCode + "-" + num + ".pitscoutdata";
if(fileEditor.fileExist(filename)){
final boolean[] rescout = {DataManager.rescout_list.contains(filename)};
text.setBackgroundColor(rescout[0] ? color_rescout : color_found);
text.setOnLongClickListener(view -> {
rescout[0] = !rescout[0];
if(rescout[0]) {
text.setBackgroundColor(color_rescout);
DataManager.rescout_list.add(filename);
DataManager.save_rescout_list();
}else{
text.setBackgroundColor(color_found);
DataManager.rescout_list.remove(filename);
DataManager.save_rescout_list();
}
return true;
});
}else{
text.setBackgroundColor(color_not_found);
}
@@ -158,8 +176,26 @@ public class EventFragment extends Fragment {
}
text.setText(String.valueOf(team_num));
if(fileEditor.fileExist(event.eventCode + "-" + match.matchIndex + "-" + alliance_position + "-" + team_num + ".matchscoutdata")){
text.setBackgroundColor(color_found);
final String filename = event.eventCode + "-" + match.matchIndex + "-" + alliance_position + "-" + team_num + ".matchscoutdata";
if(fileEditor.fileExist(filename)){
final boolean[] rescout = {DataManager.rescout_list.contains(filename)};
text.setBackgroundColor(rescout[0] ? color_rescout : color_found);
text.setOnLongClickListener(view -> {
rescout[0] = !rescout[0];
if(rescout[0]) {
text.setBackgroundColor(color_rescout);
DataManager.rescout_list.add(filename);
DataManager.save_rescout_list();
}else{
text.setBackgroundColor(color_found);
DataManager.rescout_list.remove(filename);
DataManager.save_rescout_list();
}
return true;
});
}else{
text.setBackgroundColor(color_not_found);
}
@@ -130,12 +130,14 @@ public class MatchScoutingFragment extends Fragment {
private static final int unsaved_color = 0x60ff0000;
private static final int saved_color = 0x6000ff00;
private static final int rescout_color = 0x600000ff;
String alliance_position;
int cur_match_num;
String username;
String filename;
boolean edited = false;
boolean rescout = false;
ToggleTitleView[] titles;
AutoSaveManager asm = new AutoSaveManager(this::save);
@@ -144,7 +146,7 @@ public class MatchScoutingFragment extends Fragment {
public void save(){
System.out.println("Saved!");
edited = false;
set_indicator_color(saved_color);
enableRescoutButton();
AlertManager.toast("Saved " + filename);
save_fields();
}
@@ -157,6 +159,7 @@ public class MatchScoutingFragment extends Fragment {
// v.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN);
edited = true;
set_indicator_color(unsaved_color);
disableRescoutButton();
asm.update();
}
@@ -275,6 +278,8 @@ public class MatchScoutingFragment extends Fragment {
filename = evcode + "-" + (cur_match_num+1) + "-" + alliance_position + "-" + team_num + ".matchscoutdata";
rescout = DataManager.rescout_list.contains(filename);
return team;
}
@@ -304,14 +309,16 @@ public class MatchScoutingFragment extends Fragment {
if(new_file){
default_fields();
set_indicator_color(unsaved_color);
disableRescoutButton();
}else{
try {
get_fields();
set_indicator_color(saved_color);
enableRescoutButton();
} catch (Exception e){
AlertManager.error(e);
default_fields();
set_indicator_color(unsaved_color);
disableRescoutButton();
}
}
@@ -367,4 +374,26 @@ public class MatchScoutingFragment extends Fragment {
else
System.out.println("Error saving");
}
private void enableRescoutButton(){
set_indicator_color(rescout ? rescout_color : saved_color);
binding.fileIndicator.setOnLongClickListener(v -> {
rescout = !rescout;
if(rescout){
set_indicator_color(rescout_color);
DataManager.rescout_list.add(filename);
DataManager.save_rescout_list();
}else{
set_indicator_color(saved_color);
DataManager.rescout_list.remove(filename);
DataManager.save_rescout_list();
}
return true;
});
}
private void disableRescoutButton(){
binding.fileIndicator.setOnLongClickListener(null);
}
}
@@ -17,6 +17,7 @@ import androidx.fragment.app.Fragment;
import com.google.android.material.divider.MaterialDivider;
import com.ridgebotics.ridgescout.ui.ToggleTitleView;
import com.ridgebotics.ridgescout.ui.settings.settingsFragment;
import com.ridgebotics.ridgescout.utility.AlertManager;
import com.ridgebotics.ridgescout.utility.settingsManager;
import com.ridgebotics.ridgescout.databinding.FragmentScoutingPitBinding;
@@ -55,8 +56,11 @@ public class PitScoutingFragment extends Fragment {
}
private static final int unsaved_color = 0x60ff0000;
private static final int saved_color = 0x6000ff00;
private static final int rescout_color = 0x600000ff;
boolean edited = false;
boolean rescout = false;
String filename;
String username;
@@ -69,7 +73,7 @@ public class PitScoutingFragment extends Fragment {
public void save(){
edited = false;
set_indicator_color(saved_color);
enableRescoutButton();
dataType[] types = new dataType[pit_latest_values.length];
@@ -92,6 +96,7 @@ public class PitScoutingFragment extends Fragment {
// v.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN);
edited = true;
set_indicator_color(unsaved_color);
disableRescoutButton();
asm.update();
}
@@ -102,11 +107,11 @@ public class PitScoutingFragment extends Fragment {
binding.pitFileIndicator.setVisibility(View.VISIBLE);
binding.pitsTeamCard.setVisibility(View.VISIBLE);
binding.pitBarTeamNum.setText(String.valueOf(team.teamNumber));
binding.pitUsername.setText(settingsManager.getUsername());
binding.pitsTeamCard.fromTeam(team);
filename = evcode + "-" + team.teamNumber + ".pitscoutdata";
boolean new_file = !fileEditor.fileExist(filename);
rescout = DataManager.rescout_list.contains(filename);
if(asm.isRunning){
asm.stop();
@@ -114,13 +119,16 @@ public class PitScoutingFragment extends Fragment {
create_fields();
if(new_file){
if(!fileEditor.fileExist(filename)){
default_fields();
set_indicator_color(unsaved_color);
disableRescoutButton();
}else{
try {
get_fields();
set_indicator_color(saved_color);
enableRescoutButton();
} catch (Exception e){
AlertManager.error(e);
default_fields();
@@ -128,10 +136,34 @@ public class PitScoutingFragment extends Fragment {
}
}
binding.pitFileIndicator.bringToFront();
asm.start();
}
private void enableRescoutButton(){
set_indicator_color(rescout ? rescout_color : saved_color);
binding.pitFileIndicator.setOnLongClickListener(v -> {
rescout = !rescout;
if(rescout){
set_indicator_color(rescout_color);
DataManager.rescout_list.add(filename);
DataManager.save_rescout_list();
}else{
set_indicator_color(saved_color);
DataManager.rescout_list.remove(filename);
DataManager.save_rescout_list();
}
return true;
});
}
private void disableRescoutButton(){
binding.pitFileIndicator.setOnLongClickListener(null);
}
private void create_fields() {
if(asm.isRunning){
@@ -58,6 +58,7 @@ public class FileBundle {
MainActivity.setResultRelay(new MainActivity.activityResultRelay() {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(data == null) return;
Uri uri = data.getData();
if(uri == null) return;
@@ -100,8 +101,8 @@ public class FileBundle {
AlertManager.alert("Saved",
String.join("\n", filenames));
}catch (BuiltByteParser.byteParsingExeption e){
AlertManager.error(e);
}catch (Exception e){
AlertManager.error("Failed saving files!", e);
}
}
}
@@ -128,7 +128,7 @@ public class BuiltByteParser {
intArrayObject ia = new intArrayObject();
ia.arr = intArr;
System.out.println(Arrays.toString(intArr));
// System.out.println(Arrays.toString(intArr));
objects.add(ia);
break;
case 4:
@@ -5,6 +5,11 @@ import com.ridgebotics.ridgescout.scoutingData.transfer.transferType;
import com.ridgebotics.ridgescout.types.frcEvent;
import com.ridgebotics.ridgescout.types.input.inputType;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class DataManager {
public static String evcode;
public static frcEvent event;
@@ -19,6 +24,8 @@ public class DataManager {
AlertManager.addSimpleError("Failed to load event!");
settingsManager.setEVCode("unset");
evcode = "unset";
}else{
reload_rescout_list();
}
}
@@ -35,7 +42,7 @@ public class DataManager {
match_latest_values = match_values[match_values.length - 1];
match_transferValues = transferType.get_transfer_values(match_values);
} catch (Exception e){
AlertManager.error(e);
AlertManager.error("Error reading match fields", e);
}
}
@@ -48,7 +55,38 @@ public class DataManager {
pit_latest_values = pit_values[pit_values.length-1];
pit_transferValues = transferType.get_transfer_values(pit_values);
} catch (Exception e){
AlertManager.error(e);
AlertManager.error("Error reading pit fields", e);
}
}
public static List<String> rescout_list = new ArrayList<>();
public static void reload_rescout_list(){
if(!fileEditor.fileExist(evcode + ".rescout")) {rescout_list = new ArrayList<>(); return;}
byte[] file = fileEditor.readFile(evcode + ".rescout");
if(file == null) {rescout_list = new ArrayList<>(); return;}
try {
BuiltByteParser bbp = new BuiltByteParser(file);
rescout_list = new ArrayList<>(Arrays.asList((String[]) (bbp.parse().get(0).get())));
} catch (Exception e){
AlertManager.error("Error loading scout fields", e);
rescout_list = new ArrayList<>();
}
}
public static void save_rescout_list() {
try {
if(rescout_list.size() == 0){
fileEditor.deleteFile(evcode + ".rescout");
return;
}
ByteBuilder bb = new ByteBuilder();
bb.addStringArray(rescout_list.toArray(new String[0]));
fileEditor.writeFile(evcode + ".rescout", bb.build());
} catch (Exception e){
AlertManager.error("Error saving scout fields", e);
}
}
}
@@ -264,6 +264,14 @@ public final class fileEditor {
}
}
public static boolean deleteFile(String filepath){
if(fileExist(filepath)){
return true;
}
File file = new File(baseDir + filepath);
return file.delete();
}
public static boolean fileExist(String path){
File f = new File(baseDir + path);
return f.exists() && !f.isDirectory();