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(pits_mode) {
if (fileEditor.fileExist(evcode + "-" + team.teamNumber + ".pitscoutdata")) { String filename = evcode + "-" + team.teamNumber + ".pitscoutdata";
teamRow.setColor(0x3000FF00);
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 { } else {
teamRow.setColor(0x30FF0000); 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_found = 0x7f00ff00;
public static int color_rescout = 0x7f0000ff;
public static int color_not_found = 0x7f7f0000; public static int color_not_found = 0x7f7f0000;
private void addTableText(TableRow tr, String textStr){ private void addTableText(TableRow tr, String textStr){
@@ -104,8 +105,25 @@ public class EventFragment extends Fragment {
text.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); text.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
text.setText(String.valueOf(num)); text.setText(String.valueOf(num));
if(fileEditor.fileExist(event.eventCode + "-" + num + ".pitscoutdata")){ final String filename = event.eventCode + "-" + num + ".pitscoutdata";
text.setBackgroundColor(color_found); 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{ }else{
text.setBackgroundColor(color_not_found); text.setBackgroundColor(color_not_found);
} }
@@ -158,8 +176,26 @@ public class EventFragment extends Fragment {
} }
text.setText(String.valueOf(team_num)); text.setText(String.valueOf(team_num));
if(fileEditor.fileExist(event.eventCode + "-" + match.matchIndex + "-" + alliance_position + "-" + team_num + ".matchscoutdata")){ final String filename = event.eventCode + "-" + match.matchIndex + "-" + alliance_position + "-" + team_num + ".matchscoutdata";
text.setBackgroundColor(color_found); 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{ }else{
text.setBackgroundColor(color_not_found); 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 unsaved_color = 0x60ff0000;
private static final int saved_color = 0x6000ff00; private static final int saved_color = 0x6000ff00;
private static final int rescout_color = 0x600000ff;
String alliance_position; String alliance_position;
int cur_match_num; int cur_match_num;
String username; String username;
String filename; String filename;
boolean edited = false; boolean edited = false;
boolean rescout = false;
ToggleTitleView[] titles; ToggleTitleView[] titles;
AutoSaveManager asm = new AutoSaveManager(this::save); AutoSaveManager asm = new AutoSaveManager(this::save);
@@ -144,7 +146,7 @@ public class MatchScoutingFragment extends Fragment {
public void save(){ public void save(){
System.out.println("Saved!"); System.out.println("Saved!");
edited = false; edited = false;
set_indicator_color(saved_color); enableRescoutButton();
AlertManager.toast("Saved " + filename); AlertManager.toast("Saved " + filename);
save_fields(); save_fields();
} }
@@ -157,6 +159,7 @@ public class MatchScoutingFragment extends Fragment {
// v.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN); // v.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN);
edited = true; edited = true;
set_indicator_color(unsaved_color); set_indicator_color(unsaved_color);
disableRescoutButton();
asm.update(); asm.update();
} }
@@ -275,6 +278,8 @@ public class MatchScoutingFragment extends Fragment {
filename = evcode + "-" + (cur_match_num+1) + "-" + alliance_position + "-" + team_num + ".matchscoutdata"; filename = evcode + "-" + (cur_match_num+1) + "-" + alliance_position + "-" + team_num + ".matchscoutdata";
rescout = DataManager.rescout_list.contains(filename);
return team; return team;
} }
@@ -304,14 +309,16 @@ public class MatchScoutingFragment extends Fragment {
if(new_file){ if(new_file){
default_fields(); default_fields();
set_indicator_color(unsaved_color); set_indicator_color(unsaved_color);
disableRescoutButton();
}else{ }else{
try { try {
get_fields(); get_fields();
set_indicator_color(saved_color); enableRescoutButton();
} catch (Exception e){ } catch (Exception e){
AlertManager.error(e); AlertManager.error(e);
default_fields(); default_fields();
set_indicator_color(unsaved_color); set_indicator_color(unsaved_color);
disableRescoutButton();
} }
} }
@@ -367,4 +374,26 @@ public class MatchScoutingFragment extends Fragment {
else else
System.out.println("Error saving"); 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.google.android.material.divider.MaterialDivider;
import com.ridgebotics.ridgescout.ui.ToggleTitleView; import com.ridgebotics.ridgescout.ui.ToggleTitleView;
import com.ridgebotics.ridgescout.ui.settings.settingsFragment;
import com.ridgebotics.ridgescout.utility.AlertManager; import com.ridgebotics.ridgescout.utility.AlertManager;
import com.ridgebotics.ridgescout.utility.settingsManager; import com.ridgebotics.ridgescout.utility.settingsManager;
import com.ridgebotics.ridgescout.databinding.FragmentScoutingPitBinding; 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 unsaved_color = 0x60ff0000;
private static final int saved_color = 0x6000ff00; private static final int saved_color = 0x6000ff00;
private static final int rescout_color = 0x600000ff;
boolean edited = false; boolean edited = false;
boolean rescout = false;
String filename; String filename;
String username; String username;
@@ -69,7 +73,7 @@ public class PitScoutingFragment extends Fragment {
public void save(){ public void save(){
edited = false; edited = false;
set_indicator_color(saved_color); enableRescoutButton();
dataType[] types = new dataType[pit_latest_values.length]; 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); // v.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN);
edited = true; edited = true;
set_indicator_color(unsaved_color); set_indicator_color(unsaved_color);
disableRescoutButton();
asm.update(); asm.update();
} }
@@ -102,11 +107,11 @@ public class PitScoutingFragment extends Fragment {
binding.pitFileIndicator.setVisibility(View.VISIBLE); binding.pitFileIndicator.setVisibility(View.VISIBLE);
binding.pitsTeamCard.setVisibility(View.VISIBLE); binding.pitsTeamCard.setVisibility(View.VISIBLE);
binding.pitBarTeamNum.setText(String.valueOf(team.teamNumber)); binding.pitBarTeamNum.setText(String.valueOf(team.teamNumber));
binding.pitUsername.setText(settingsManager.getUsername());
binding.pitsTeamCard.fromTeam(team); binding.pitsTeamCard.fromTeam(team);
filename = evcode + "-" + team.teamNumber + ".pitscoutdata"; filename = evcode + "-" + team.teamNumber + ".pitscoutdata";
rescout = DataManager.rescout_list.contains(filename);
boolean new_file = !fileEditor.fileExist(filename);
if(asm.isRunning){ if(asm.isRunning){
asm.stop(); asm.stop();
@@ -114,13 +119,16 @@ public class PitScoutingFragment extends Fragment {
create_fields(); create_fields();
if(new_file){ if(!fileEditor.fileExist(filename)){
default_fields(); default_fields();
set_indicator_color(unsaved_color); set_indicator_color(unsaved_color);
disableRescoutButton();
}else{ }else{
try { try {
get_fields(); get_fields();
set_indicator_color(saved_color);
enableRescoutButton();
} catch (Exception e){ } catch (Exception e){
AlertManager.error(e); AlertManager.error(e);
default_fields(); default_fields();
@@ -128,10 +136,34 @@ public class PitScoutingFragment extends Fragment {
} }
} }
binding.pitFileIndicator.bringToFront();
asm.start(); 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() { private void create_fields() {
if(asm.isRunning){ if(asm.isRunning){
@@ -58,6 +58,7 @@ public class FileBundle {
MainActivity.setResultRelay(new MainActivity.activityResultRelay() { MainActivity.setResultRelay(new MainActivity.activityResultRelay() {
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(data == null) return;
Uri uri = data.getData(); Uri uri = data.getData();
if(uri == null) return; if(uri == null) return;
@@ -100,8 +101,8 @@ public class FileBundle {
AlertManager.alert("Saved", AlertManager.alert("Saved",
String.join("\n", filenames)); String.join("\n", filenames));
}catch (BuiltByteParser.byteParsingExeption e){ }catch (Exception e){
AlertManager.error(e); AlertManager.error("Failed saving files!", e);
} }
} }
} }
@@ -128,7 +128,7 @@ public class BuiltByteParser {
intArrayObject ia = new intArrayObject(); intArrayObject ia = new intArrayObject();
ia.arr = intArr; ia.arr = intArr;
System.out.println(Arrays.toString(intArr)); // System.out.println(Arrays.toString(intArr));
objects.add(ia); objects.add(ia);
break; break;
case 4: case 4:
@@ -5,6 +5,11 @@ import com.ridgebotics.ridgescout.scoutingData.transfer.transferType;
import com.ridgebotics.ridgescout.types.frcEvent; import com.ridgebotics.ridgescout.types.frcEvent;
import com.ridgebotics.ridgescout.types.input.inputType; 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 class DataManager {
public static String evcode; public static String evcode;
public static frcEvent event; public static frcEvent event;
@@ -19,6 +24,8 @@ public class DataManager {
AlertManager.addSimpleError("Failed to load event!"); AlertManager.addSimpleError("Failed to load event!");
settingsManager.setEVCode("unset"); settingsManager.setEVCode("unset");
evcode = "unset"; evcode = "unset";
}else{
reload_rescout_list();
} }
} }
@@ -35,7 +42,7 @@ public class DataManager {
match_latest_values = match_values[match_values.length - 1]; match_latest_values = match_values[match_values.length - 1];
match_transferValues = transferType.get_transfer_values(match_values); match_transferValues = transferType.get_transfer_values(match_values);
} catch (Exception e){ } 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_latest_values = pit_values[pit_values.length-1];
pit_transferValues = transferType.get_transfer_values(pit_values); pit_transferValues = transferType.get_transfer_values(pit_values);
} catch (Exception e){ } 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){ public static boolean fileExist(String path){
File f = new File(baseDir + path); File f = new File(baseDir + path);
return f.exists() && !f.isDirectory(); return f.exists() && !f.isDirectory();
+1 -2
View File
@@ -35,8 +35,7 @@
android:textSize="34sp" android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintTop_toBottomOf="@id/fieldsButton" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
@@ -17,7 +17,7 @@
android:id="@+id/pit_bar_team_num" android:id="@+id/pit_bar_team_num"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="" android:text="4388"
android:textAlignment="center" android:textAlignment="center"
android:textSize="24sp" android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
@@ -26,13 +26,13 @@
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/textView" android:id="@+id/pitUsername"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="" android:text="Username"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@+id/pit_bar_team_num" app:layout_constraintEnd_toStartOf="@+id/pit_bar_team_num"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>