mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 08:38:03 -06:00
Work on converting everything to fragments
This commit is contained in:
@@ -55,6 +55,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
|
||||
R.id.navigation_scouting, R.id.navigation_transfer, R.id.navigation_settings)
|
||||
.build();
|
||||
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
|
||||
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
|
||||
NavigationUI.setupWithNavController(binding.navView, navController);
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.astatin3.scoutingapp2025.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.astatin3.scoutingapp2025.SettingsVersionStack.latestSettings;
|
||||
import com.astatin3.scoutingapp2025.databinding.FragmentMatchScoutDataEnterBinding;
|
||||
import com.astatin3.scoutingapp2025.databinding.FragmentTeamSelectorBinding;
|
||||
import com.astatin3.scoutingapp2025.types.frcEvent;
|
||||
import com.astatin3.scoutingapp2025.types.frcTeam;
|
||||
import com.astatin3.scoutingapp2025.utility.AlertManager;
|
||||
import com.astatin3.scoutingapp2025.utility.fileEditor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TeamSelectorFragment extends Fragment {
|
||||
private FragmentTeamSelectorBinding binding;
|
||||
|
||||
private String evcode;
|
||||
private frcEvent event;
|
||||
private static onTeamSelected onSelect = new onTeamSelected() {@Override public void onSelect(TeamSelectorFragment self, frcTeam team) {}};
|
||||
|
||||
public interface onTeamSelected {
|
||||
void onSelect(TeamSelectorFragment self, frcTeam team);
|
||||
}
|
||||
public static void setOnSelect(onTeamSelected tmponSelect){
|
||||
onSelect = tmponSelect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
binding = FragmentTeamSelectorBinding.inflate(inflater, container, false);
|
||||
|
||||
// event = fileEditor.g
|
||||
evcode = latestSettings.settings.get_evcode();
|
||||
|
||||
if(evcode == null || evcode.equals("unset")){
|
||||
AlertManager.error("You somehow have not loaded an event!");
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
load_teams();
|
||||
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
public void load_teams(){
|
||||
// binding.pitFileIndicator.setVisibility(View.GONE);
|
||||
// binding.pitTeamName.setVisibility(View.GONE);
|
||||
// binding.pitTeamDescription.setVisibility(View.GONE);
|
||||
//
|
||||
// clear_fields();
|
||||
|
||||
|
||||
int[] teamNums = new int[event.teams.size()];
|
||||
|
||||
for(int i = 0 ; i < event.teams.size(); i++){
|
||||
teamNums[i] = event.teams.get(i).teamNumber;
|
||||
}
|
||||
|
||||
Arrays.sort(teamNums);
|
||||
|
||||
TableLayout table = new TableLayout(getContext());
|
||||
table.setStretchAllColumns(true);
|
||||
binding.teams.addView(table);
|
||||
|
||||
|
||||
for(int i = 0; i < event.teams.size(); i++){
|
||||
frcTeam team = null;
|
||||
for(int a = 0 ; a < event.teams.size(); a++){
|
||||
if(event.teams.get(a).teamNumber == teamNums[i]){
|
||||
team = event.teams.get(a);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TableRow tr = new TableRow(getContext());
|
||||
TableLayout.LayoutParams rowParams = new TableLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
rowParams.setMargins(20,20,20,20);
|
||||
tr.setLayoutParams(rowParams);
|
||||
tr.setPadding(20,20,20,20);
|
||||
table.addView(tr);
|
||||
|
||||
if(fileEditor.fileExist(evcode + "-" + team.teamNumber + ".pitscoutdata")){
|
||||
tr.setBackgroundColor(0x3000FF00);
|
||||
}else{
|
||||
tr.setBackgroundColor(0x30FF0000);
|
||||
}
|
||||
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setText(String.valueOf(team.teamNumber));
|
||||
tv.setTextSize(20);
|
||||
tr.addView(tv);
|
||||
|
||||
tv = new TextView(getContext());
|
||||
tv.setText(team.teamName);
|
||||
tv.setTextSize(16);
|
||||
tr.addView(tv);
|
||||
|
||||
frcTeam finalTeam = team;
|
||||
tr.setOnClickListener(v -> {
|
||||
onSelect.onSelect(this, finalTeam);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.astatin3.scoutingapp2025.ui.data;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
@@ -10,13 +10,11 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.astatin3.scoutingapp2025.databinding.FragmentDataBinding;
|
||||
import com.astatin3.scoutingapp2025.scoutingData.fields;
|
||||
import com.astatin3.scoutingapp2025.types.input.inputType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class fieldsView extends ConstraintLayout {
|
||||
@@ -78,10 +76,9 @@ public class fieldsView extends ConstraintLayout {
|
||||
rowParams.setMargins(20,20,20,20);
|
||||
tr.setLayoutParams(rowParams);
|
||||
tr.setPadding(20,20,20,20);
|
||||
tr.setBackgroundColor(background_color);
|
||||
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setText("v" + i + "\n eee");
|
||||
tv.setText("v" + i);
|
||||
tv.setTextSize(20);
|
||||
tr.addView(tv);
|
||||
|
||||
@@ -92,10 +89,15 @@ public class fieldsView extends ConstraintLayout {
|
||||
|
||||
binding.fieldsArea.addView(tr);
|
||||
|
||||
int fi = i;
|
||||
tr.setOnClickListener(v -> {
|
||||
display_fields(values[fi]);
|
||||
});
|
||||
if(i == values.length-1) {
|
||||
tr.setBackgroundColor(background_color);
|
||||
int fi = i;
|
||||
tr.setOnClickListener(v -> {
|
||||
display_fields(values[fi]);
|
||||
});
|
||||
}else{
|
||||
tr.setBackgroundColor(unfocused_background_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,21 +131,32 @@ public class fieldsView extends ConstraintLayout {
|
||||
tv.setText(version_values[i].name);
|
||||
tv.setTextSize(20);
|
||||
tr.addView(tv);
|
||||
binding.fieldsArea.addView(tr);
|
||||
tr.setOnClickListener(v -> {
|
||||
|
||||
trHighlight(tr);
|
||||
binding.fieldsArea.addView(tr);
|
||||
|
||||
tr.setOnClickListener(v -> {
|
||||
trOnClick(version_values, tr);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void trHighlight(TableRow self){
|
||||
for(int i = 0; i < binding.teamsArea.getChildCount(); i++){
|
||||
TableRow child = (TableRow) binding.teamsArea.getChildAt(i);
|
||||
child.setBackgroundColor(unfocused_background_color);
|
||||
private void trOnClick(inputType[] version_values, TableRow tr){
|
||||
int index = -1;
|
||||
for(int i = 0; i < binding.fieldsArea.getChildCount(); i++){
|
||||
View v = binding.fieldsArea.getChildAt(i);
|
||||
|
||||
if(v.equals(tr)) {
|
||||
tr.setBackgroundColor(background_color);
|
||||
index = i;
|
||||
} else
|
||||
binding.fieldsArea.getChildAt(i).setBackgroundColor(unfocused_background_color);
|
||||
}
|
||||
|
||||
self.setBackgroundColor(background_color);
|
||||
onFieldSelect(version_values[binding.fieldsArea.getReorderedIndexes().get(index)]);
|
||||
}
|
||||
|
||||
private void onFieldSelect(inputType field){
|
||||
System.out.println(field.name);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+341
@@ -0,0 +1,341 @@
|
||||
package com.astatin3.scoutingapp2025.ui.scouting;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.astatin3.scoutingapp2025.SettingsVersionStack.latestSettings;
|
||||
import com.astatin3.scoutingapp2025.databinding.FragmentMatchScoutDataEnterBinding;
|
||||
import com.astatin3.scoutingapp2025.scoutingData.ScoutingDataWriter;
|
||||
import com.astatin3.scoutingapp2025.scoutingData.fields;
|
||||
import com.astatin3.scoutingapp2025.scoutingData.transfer.transferType;
|
||||
import com.astatin3.scoutingapp2025.types.data.dataType;
|
||||
import com.astatin3.scoutingapp2025.types.frcEvent;
|
||||
import com.astatin3.scoutingapp2025.types.frcMatch;
|
||||
import com.astatin3.scoutingapp2025.types.frcTeam;
|
||||
import com.astatin3.scoutingapp2025.types.input.inputType;
|
||||
import com.astatin3.scoutingapp2025.utility.AutoSaveManager;
|
||||
import com.astatin3.scoutingapp2025.utility.fileEditor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class matchScoutDataEnterFragment extends Fragment {
|
||||
|
||||
private FragmentMatchScoutDataEnterBinding binding;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
binding = FragmentMatchScoutDataEnterBinding.inflate(inflater, container, false);
|
||||
|
||||
alliance_position = latestSettings.settings.get_alliance_pos();
|
||||
evcode = event.eventCode;
|
||||
username = latestSettings.settings.get_username();
|
||||
|
||||
binding.eventcode.setText(evcode);
|
||||
binding.alliancePosText.setText(alliance_position);
|
||||
|
||||
binding.teamDescription.setVisibility(View.GONE);
|
||||
binding.teamName.setVisibility(View.GONE);
|
||||
clear_fields();
|
||||
binding.teamDescription.setVisibility(View.VISIBLE);
|
||||
binding.teamName.setVisibility(View.VISIBLE);
|
||||
|
||||
if(values == null || values.length == 0){
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setText("Failed to load fields.\nTry to either download or create match scouting fields.");
|
||||
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
binding.MatchScoutArea.addView(tv);
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
values = fields.load(fields.matchFieldsFilename);
|
||||
if(values == null){
|
||||
return binding.getRoot();
|
||||
}
|
||||
latest_values = values[values.length-1];
|
||||
transferValues = transferType.get_transfer_values(values);
|
||||
|
||||
|
||||
cur_match_num = latestSettings.settings.get_match_num();
|
||||
update_match_num();
|
||||
|
||||
binding.nextButton.setOnClickListener(v -> {
|
||||
if(edited) save();
|
||||
latestSettings.settings.set_match_num(cur_match_num+1);
|
||||
cur_match_num += 1;
|
||||
update_match_num();
|
||||
update_scouting_data();
|
||||
});
|
||||
|
||||
binding.backButton.setOnClickListener(v -> {
|
||||
if(edited) save();
|
||||
latestSettings.settings.set_match_num(cur_match_num-1);
|
||||
cur_match_num -= 1;
|
||||
update_match_num();
|
||||
update_scouting_data();
|
||||
});
|
||||
|
||||
// binding.middleButton.setOnClickListener(v -> {
|
||||
// if(edited) save();
|
||||
// });
|
||||
|
||||
create_fields();
|
||||
update_scouting_data();
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
|
||||
private static final int unsaved_color = 0x60ff0000;
|
||||
private static final int saved_color = 0x6000ff00;
|
||||
|
||||
String alliance_position;
|
||||
String evcode;
|
||||
int cur_match_num;
|
||||
frcEvent event;
|
||||
String username;
|
||||
String filename;
|
||||
|
||||
boolean edited = false;
|
||||
|
||||
TextView[] titles;
|
||||
inputType[][] values;
|
||||
inputType[] latest_values;
|
||||
transferType[][] transferValues;
|
||||
|
||||
AutoSaveManager asm = new AutoSaveManager(this::save);
|
||||
|
||||
ArrayList<dataType> dataTypes;
|
||||
|
||||
|
||||
|
||||
public void save(){
|
||||
System.out.println("Saved!");
|
||||
edited = false;
|
||||
set_indicator_color(saved_color);
|
||||
// fileEditor.createFile(filename);
|
||||
save_fields();
|
||||
}
|
||||
|
||||
public void set_indicator_color(int color){
|
||||
binding.fileIndicator.setBackgroundColor(color);
|
||||
}
|
||||
|
||||
public void update_asm(){
|
||||
// v.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN);
|
||||
edited = true;
|
||||
set_indicator_color(unsaved_color);
|
||||
asm.update();
|
||||
}
|
||||
|
||||
|
||||
public void clear_fields(){
|
||||
int childCount = binding.MatchScoutArea.getChildCount();
|
||||
View[] views = new View[childCount];
|
||||
|
||||
for(int i = 0; i < childCount; i++){
|
||||
views[i] = binding.MatchScoutArea.getChildAt(i);
|
||||
}
|
||||
|
||||
for(int i = 0; i < childCount; i++){
|
||||
if(!views[i].isShown()) continue;
|
||||
binding.MatchScoutArea.removeView(views[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private int default_text_color = 0;
|
||||
|
||||
private void create_fields(){
|
||||
if(asm.isRunning){
|
||||
asm.stop();
|
||||
}
|
||||
|
||||
titles = new TextView[latest_values.length];
|
||||
|
||||
for(int i = 0 ; i < latest_values.length; i++) {
|
||||
final TextView tv = new TextView(getContext());
|
||||
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
tv.setText(latest_values[i].name);
|
||||
tv.setPadding(8,8,8,8);
|
||||
tv.setTextSize(24);
|
||||
titles[i] = tv;
|
||||
|
||||
default_text_color = tv.getCurrentTextColor();
|
||||
|
||||
final View v = latest_values[i].createView(getContext(), new Function<dataType, Integer>() {
|
||||
@Override
|
||||
public Integer apply(dataType dataType) {
|
||||
// edited = true;
|
||||
if(asm.isRunning)
|
||||
update_asm();
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
binding.MatchScoutArea.addView(tv);
|
||||
int fi = i;
|
||||
tv.setOnClickListener(p -> {
|
||||
// boolean blank = !latest_values[fi].getViewValue().isNull();
|
||||
|
||||
// System.out.println(blank);
|
||||
|
||||
asm.update();
|
||||
|
||||
if(!latest_values[fi].isBlank){
|
||||
tv.setBackgroundColor(0xffff0000);
|
||||
tv.setTextColor(0xff000000);
|
||||
latest_values[fi].nullify();
|
||||
}else{
|
||||
tv.setBackgroundColor(0x00000000);
|
||||
tv.setTextColor(default_text_color);
|
||||
latest_values[fi].setViewValue(latest_values[fi].default_value);
|
||||
}
|
||||
});
|
||||
|
||||
binding.MatchScoutArea.addView(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void update_match_num(){
|
||||
// cur_match_num = latestSettings.settings.get_match_num();
|
||||
|
||||
edited = false;
|
||||
|
||||
binding.matchnum.setText(String.valueOf(cur_match_num+1));
|
||||
|
||||
if(cur_match_num <= 0){
|
||||
binding.backButton.setVisibility(View.GONE);
|
||||
}else{
|
||||
binding.backButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if(cur_match_num >= event.matches.size()-1){
|
||||
binding.nextButton.setVisibility(View.GONE);
|
||||
}else{
|
||||
binding.nextButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private frcTeam get_team(frcMatch match){
|
||||
|
||||
// Get team number
|
||||
String[] split = alliance_position.split("-");
|
||||
Integer team_num = null;
|
||||
|
||||
switch (split[0]){
|
||||
case "red":
|
||||
team_num = match.redAlliance[Integer.parseInt(split[1])-1];
|
||||
break;
|
||||
case "blue":
|
||||
team_num = match.blueAlliance[Integer.parseInt(split[1])-1];
|
||||
break;
|
||||
}
|
||||
|
||||
binding.barTeamNum.setText(String.valueOf(team_num));
|
||||
|
||||
frcTeam team = null;
|
||||
for(int i=0; i < event.teams.size(); i++){
|
||||
frcTeam tmpteam = event.teams.get(i);
|
||||
if(tmpteam.teamNumber == team_num){
|
||||
team = tmpteam;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
filename = evcode + "-" + (cur_match_num+1) + "-" + alliance_position + "-" + team_num + ".matchscoutdata";
|
||||
|
||||
return team;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void update_scouting_data(){
|
||||
|
||||
frcMatch match = event.matches.get(cur_match_num);
|
||||
frcTeam team = get_team(match);
|
||||
|
||||
binding.teamName.setText(team.teamName);
|
||||
binding.teamDescription.setText(team.getDescription());
|
||||
|
||||
boolean new_file = !fileEditor.fileExist(filename);
|
||||
|
||||
if(asm.isRunning){
|
||||
asm.stop();
|
||||
}
|
||||
|
||||
if(new_file){
|
||||
default_fields();
|
||||
set_indicator_color(unsaved_color);
|
||||
}else{
|
||||
get_fields();
|
||||
set_indicator_color(saved_color);
|
||||
}
|
||||
|
||||
asm.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void default_fields(){
|
||||
for(int i = 0; i < latest_values.length; i++){
|
||||
inputType input = latest_values[i];
|
||||
input.setViewValue(input.default_value);
|
||||
|
||||
titles[i].setBackgroundColor(0x00000000);
|
||||
titles[i].setTextColor(default_text_color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void get_fields(){
|
||||
|
||||
ScoutingDataWriter.ParsedScoutingDataResult psdr = ScoutingDataWriter.load(filename, values, transferValues);
|
||||
dataType[] types = psdr.data.array;
|
||||
|
||||
for(int i = 0; i < latest_values.length; i++){
|
||||
// types[i] = latest_values[i].getViewValue();
|
||||
latest_values[i].setViewValue(types[i]);
|
||||
|
||||
if(latest_values[i].isBlank){
|
||||
titles[i].setBackgroundColor(0xffff0000);
|
||||
titles[i].setTextColor(0xff000000);
|
||||
}else{
|
||||
titles[i].setBackgroundColor(0x00000000);
|
||||
titles[i].setTextColor(default_text_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void save_fields(){
|
||||
|
||||
dataType[] types = new dataType[latest_values.length];
|
||||
|
||||
for(int i = 0; i < latest_values.length; i++){
|
||||
types[i] = latest_values[i].getViewValue();
|
||||
}
|
||||
|
||||
if(ScoutingDataWriter.save(values.length-1, username, filename, types))
|
||||
System.out.println("Saved!");
|
||||
else
|
||||
System.out.println("Error saving");
|
||||
}
|
||||
}
|
||||
+312
-310
@@ -26,316 +26,318 @@ import com.astatin3.scoutingapp2025.utility.AutoSaveManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class matchScoutingView extends ConstraintLayout {
|
||||
public matchScoutingView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
public matchScoutingView(Context context, AttributeSet attributeSet){
|
||||
super(context, attributeSet);
|
||||
}
|
||||
public class matchScoutingView {}
|
||||
|
||||
private static final int unsaved_color = 0x60ff0000;
|
||||
private static final int saved_color = 0x6000ff00;
|
||||
|
||||
FragmentScoutingBinding binding;
|
||||
String alliance_position;
|
||||
String evcode;
|
||||
int cur_match_num;
|
||||
frcEvent event;
|
||||
String filename;
|
||||
String username;
|
||||
|
||||
boolean edited = false;
|
||||
|
||||
TextView[] titles;
|
||||
inputType[][] values;
|
||||
inputType[] latest_values;
|
||||
transferType[][] transferValues;
|
||||
|
||||
AutoSaveManager asm = new AutoSaveManager(this::save);
|
||||
|
||||
ArrayList<dataType> dataTypes;
|
||||
|
||||
|
||||
|
||||
public void save(){
|
||||
System.out.println("Saved!");
|
||||
edited = false;
|
||||
set_indicator_color(saved_color);
|
||||
// fileEditor.createFile(filename);
|
||||
save_fields();
|
||||
}
|
||||
|
||||
public void set_indicator_color(int color){
|
||||
binding.fileIndicator.setBackgroundColor(color);
|
||||
}
|
||||
|
||||
public void update_asm(){
|
||||
// v.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN);
|
||||
edited = true;
|
||||
set_indicator_color(unsaved_color);
|
||||
asm.update();
|
||||
}
|
||||
|
||||
|
||||
public void clear_fields(){
|
||||
int childCount = binding.MatchScoutArea.getChildCount();
|
||||
View[] views = new View[childCount];
|
||||
|
||||
for(int i = 0; i < childCount; i++){
|
||||
views[i] = binding.MatchScoutArea.getChildAt(i);
|
||||
}
|
||||
|
||||
for(int i = 0; i < childCount; i++){
|
||||
if(!views[i].isShown()) continue;
|
||||
binding.MatchScoutArea.removeView(views[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void init(FragmentScoutingBinding tmp_binding, frcEvent event){
|
||||
binding = tmp_binding;
|
||||
|
||||
alliance_position = latestSettings.settings.get_alliance_pos();
|
||||
evcode = event.eventCode;
|
||||
this.event = event;
|
||||
username = latestSettings.settings.get_username();
|
||||
|
||||
binding.eventcode.setText(evcode);
|
||||
binding.alliancePosText.setText(alliance_position);
|
||||
|
||||
binding.teamDescription.setVisibility(View.GONE);
|
||||
binding.teamName.setVisibility(View.GONE);
|
||||
clear_fields();
|
||||
binding.teamDescription.setVisibility(View.VISIBLE);
|
||||
binding.teamName.setVisibility(View.VISIBLE);
|
||||
|
||||
|
||||
values = fields.load(fields.matchFieldsFilename);
|
||||
|
||||
if(values == null || values.length == 0){
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setText("Failed to load fields.\nTry to either download or create match scouting fields.");
|
||||
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
binding.MatchScoutArea.addView(tv);
|
||||
return;
|
||||
}
|
||||
|
||||
cur_match_num = latestSettings.settings.get_match_num();
|
||||
update_match_num();
|
||||
|
||||
binding.nextButton.setOnClickListener(v -> {
|
||||
if(edited) save();
|
||||
latestSettings.settings.set_match_num(cur_match_num+1);
|
||||
cur_match_num += 1;
|
||||
update_match_num();
|
||||
update_scouting_data();
|
||||
});
|
||||
|
||||
binding.backButton.setOnClickListener(v -> {
|
||||
if(edited) save();
|
||||
latestSettings.settings.set_match_num(cur_match_num-1);
|
||||
cur_match_num -= 1;
|
||||
update_match_num();
|
||||
update_scouting_data();
|
||||
});
|
||||
|
||||
// binding.middleButton.setOnClickListener(v -> {
|
||||
// if(edited) save();
|
||||
// });
|
||||
|
||||
latest_values = values[values.length-1];
|
||||
transferValues = transferType.get_transfer_values(values);
|
||||
|
||||
create_fields();
|
||||
update_scouting_data();
|
||||
}
|
||||
|
||||
private int default_text_color = 0;
|
||||
|
||||
private void create_fields(){
|
||||
if(asm.isRunning){
|
||||
asm.stop();
|
||||
}
|
||||
|
||||
titles = new TextView[latest_values.length];
|
||||
|
||||
for(int i = 0 ; i < latest_values.length; i++) {
|
||||
final TextView tv = new TextView(getContext());
|
||||
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
tv.setText(latest_values[i].name);
|
||||
tv.setPadding(8,8,8,8);
|
||||
tv.setTextSize(24);
|
||||
titles[i] = tv;
|
||||
|
||||
default_text_color = tv.getCurrentTextColor();
|
||||
|
||||
final View v = latest_values[i].createView(getContext(), new Function<dataType, Integer>() {
|
||||
@Override
|
||||
public Integer apply(dataType dataType) {
|
||||
// edited = true;
|
||||
if(asm.isRunning)
|
||||
update_asm();
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
binding.MatchScoutArea.addView(tv);
|
||||
int fi = i;
|
||||
tv.setOnClickListener(p -> {
|
||||
// boolean blank = !latest_values[fi].getViewValue().isNull();
|
||||
|
||||
// System.out.println(blank);
|
||||
|
||||
asm.update();
|
||||
|
||||
if(!latest_values[fi].isBlank){
|
||||
tv.setBackgroundColor(0xffff0000);
|
||||
tv.setTextColor(0xff000000);
|
||||
latest_values[fi].nullify();
|
||||
}else{
|
||||
tv.setBackgroundColor(0x00000000);
|
||||
tv.setTextColor(default_text_color);
|
||||
latest_values[fi].setViewValue(latest_values[fi].default_value);
|
||||
}
|
||||
});
|
||||
|
||||
binding.MatchScoutArea.addView(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void update_match_num(){
|
||||
//public class matchScoutingView extends ConstraintLayout {
|
||||
// public matchScoutingView(Context context) {
|
||||
// super(context);
|
||||
// }
|
||||
// public matchScoutingView(Context context, AttributeSet attributeSet){
|
||||
// super(context, attributeSet);
|
||||
// }
|
||||
//
|
||||
// private static final int unsaved_color = 0x60ff0000;
|
||||
// private static final int saved_color = 0x6000ff00;
|
||||
//
|
||||
// FragmentScoutingBinding binding;
|
||||
// String alliance_position;
|
||||
// String evcode;
|
||||
// int cur_match_num;
|
||||
// frcEvent event;
|
||||
// String filename;
|
||||
// String username;
|
||||
//
|
||||
// boolean edited = false;
|
||||
//
|
||||
// TextView[] titles;
|
||||
// inputType[][] values;
|
||||
// inputType[] latest_values;
|
||||
// transferType[][] transferValues;
|
||||
//
|
||||
// AutoSaveManager asm = new AutoSaveManager(this::save);
|
||||
//
|
||||
// ArrayList<dataType> dataTypes;
|
||||
//
|
||||
//
|
||||
//
|
||||
// public void save(){
|
||||
// System.out.println("Saved!");
|
||||
// edited = false;
|
||||
// set_indicator_color(saved_color);
|
||||
//// fileEditor.createFile(filename);
|
||||
// save_fields();
|
||||
// }
|
||||
//
|
||||
// public void set_indicator_color(int color){
|
||||
// binding.fileIndicator.setBackgroundColor(color);
|
||||
// }
|
||||
//
|
||||
// public void update_asm(){
|
||||
//// v.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN);
|
||||
// edited = true;
|
||||
// set_indicator_color(unsaved_color);
|
||||
// asm.update();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void clear_fields(){
|
||||
// int childCount = binding.MatchScoutArea.getChildCount();
|
||||
// View[] views = new View[childCount];
|
||||
//
|
||||
// for(int i = 0; i < childCount; i++){
|
||||
// views[i] = binding.MatchScoutArea.getChildAt(i);
|
||||
// }
|
||||
//
|
||||
// for(int i = 0; i < childCount; i++){
|
||||
// if(!views[i].isShown()) continue;
|
||||
// binding.MatchScoutArea.removeView(views[i]);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void init(FragmentScoutingBinding tmp_binding, frcEvent event){
|
||||
// binding = tmp_binding;
|
||||
//
|
||||
// alliance_position = latestSettings.settings.get_alliance_pos();
|
||||
// evcode = event.eventCode;
|
||||
// this.event = event;
|
||||
// username = latestSettings.settings.get_username();
|
||||
//
|
||||
// binding.eventcode.setText(evcode);
|
||||
// binding.alliancePosText.setText(alliance_position);
|
||||
//
|
||||
// binding.teamDescription.setVisibility(View.GONE);
|
||||
// binding.teamName.setVisibility(View.GONE);
|
||||
// clear_fields();
|
||||
// binding.teamDescription.setVisibility(View.VISIBLE);
|
||||
// binding.teamName.setVisibility(View.VISIBLE);
|
||||
//
|
||||
//
|
||||
// values = fields.load(fields.matchFieldsFilename);
|
||||
//
|
||||
// if(values == null || values.length == 0){
|
||||
// TextView tv = new TextView(getContext());
|
||||
// tv.setText("Failed to load fields.\nTry to either download or create match scouting fields.");
|
||||
// tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
// binding.MatchScoutArea.addView(tv);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// cur_match_num = latestSettings.settings.get_match_num();
|
||||
|
||||
edited = false;
|
||||
|
||||
binding.matchnum.setText(String.valueOf(cur_match_num+1));
|
||||
|
||||
if(cur_match_num <= 0){
|
||||
binding.backButton.setVisibility(View.GONE);
|
||||
}else{
|
||||
binding.backButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if(cur_match_num >= event.matches.size()-1){
|
||||
binding.nextButton.setVisibility(View.GONE);
|
||||
}else{
|
||||
binding.nextButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private frcTeam get_team(frcMatch match){
|
||||
|
||||
// Get team number
|
||||
String[] split = alliance_position.split("-");
|
||||
Integer team_num = null;
|
||||
|
||||
switch (split[0]){
|
||||
case "red":
|
||||
team_num = match.redAlliance[Integer.parseInt(split[1])-1];
|
||||
break;
|
||||
case "blue":
|
||||
team_num = match.blueAlliance[Integer.parseInt(split[1])-1];
|
||||
break;
|
||||
}
|
||||
|
||||
binding.barTeamNum.setText(String.valueOf(team_num));
|
||||
|
||||
frcTeam team = null;
|
||||
for(int i=0; i < event.teams.size(); i++){
|
||||
frcTeam tmpteam = event.teams.get(i);
|
||||
if(tmpteam.teamNumber == team_num){
|
||||
team = tmpteam;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
filename = evcode + "-" + (cur_match_num+1) + "-" + alliance_position + "-" + team_num + ".matchscoutdata";
|
||||
|
||||
return team;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void update_scouting_data(){
|
||||
|
||||
frcMatch match = event.matches.get(cur_match_num);
|
||||
frcTeam team = get_team(match);
|
||||
|
||||
binding.teamName.setText(team.teamName);
|
||||
binding.teamDescription.setText(team.getDescription());
|
||||
|
||||
boolean new_file = !fileEditor.fileExist(filename);
|
||||
|
||||
if(asm.isRunning){
|
||||
asm.stop();
|
||||
}
|
||||
|
||||
if(new_file){
|
||||
default_fields();
|
||||
set_indicator_color(unsaved_color);
|
||||
}else{
|
||||
get_fields();
|
||||
set_indicator_color(saved_color);
|
||||
}
|
||||
|
||||
asm.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void default_fields(){
|
||||
for(int i = 0; i < latest_values.length; i++){
|
||||
inputType input = latest_values[i];
|
||||
input.setViewValue(input.default_value);
|
||||
|
||||
titles[i].setBackgroundColor(0x00000000);
|
||||
titles[i].setTextColor(default_text_color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void get_fields(){
|
||||
|
||||
ScoutingDataWriter.ParsedScoutingDataResult psdr = ScoutingDataWriter.load(filename, values, transferValues);
|
||||
dataType[] types = psdr.data.array;
|
||||
|
||||
for(int i = 0; i < latest_values.length; i++){
|
||||
// update_match_num();
|
||||
//
|
||||
// binding.nextButton.setOnClickListener(v -> {
|
||||
// if(edited) save();
|
||||
// latestSettings.settings.set_match_num(cur_match_num+1);
|
||||
// cur_match_num += 1;
|
||||
// update_match_num();
|
||||
// update_scouting_data();
|
||||
// });
|
||||
//
|
||||
// binding.backButton.setOnClickListener(v -> {
|
||||
// if(edited) save();
|
||||
// latestSettings.settings.set_match_num(cur_match_num-1);
|
||||
// cur_match_num -= 1;
|
||||
// update_match_num();
|
||||
// update_scouting_data();
|
||||
// });
|
||||
//
|
||||
//// binding.middleButton.setOnClickListener(v -> {
|
||||
//// if(edited) save();
|
||||
//// });
|
||||
//
|
||||
// latest_values = values[values.length-1];
|
||||
// transferValues = transferType.get_transfer_values(values);
|
||||
//
|
||||
// create_fields();
|
||||
// update_scouting_data();
|
||||
// }
|
||||
//
|
||||
// private int default_text_color = 0;
|
||||
//
|
||||
// private void create_fields(){
|
||||
// if(asm.isRunning){
|
||||
// asm.stop();
|
||||
// }
|
||||
//
|
||||
// titles = new TextView[latest_values.length];
|
||||
//
|
||||
// for(int i = 0 ; i < latest_values.length; i++) {
|
||||
// final TextView tv = new TextView(getContext());
|
||||
// tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
// tv.setText(latest_values[i].name);
|
||||
// tv.setPadding(8,8,8,8);
|
||||
// tv.setTextSize(24);
|
||||
// titles[i] = tv;
|
||||
//
|
||||
// default_text_color = tv.getCurrentTextColor();
|
||||
//
|
||||
// final View v = latest_values[i].createView(getContext(), new Function<dataType, Integer>() {
|
||||
// @Override
|
||||
// public Integer apply(dataType dataType) {
|
||||
//// edited = true;
|
||||
// if(asm.isRunning)
|
||||
// update_asm();
|
||||
// return 0;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// binding.MatchScoutArea.addView(tv);
|
||||
// int fi = i;
|
||||
// tv.setOnClickListener(p -> {
|
||||
//// boolean blank = !latest_values[fi].getViewValue().isNull();
|
||||
//
|
||||
//// System.out.println(blank);
|
||||
//
|
||||
// asm.update();
|
||||
//
|
||||
// if(!latest_values[fi].isBlank){
|
||||
// tv.setBackgroundColor(0xffff0000);
|
||||
// tv.setTextColor(0xff000000);
|
||||
// latest_values[fi].nullify();
|
||||
// }else{
|
||||
// tv.setBackgroundColor(0x00000000);
|
||||
// tv.setTextColor(default_text_color);
|
||||
// latest_values[fi].setViewValue(latest_values[fi].default_value);
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// binding.MatchScoutArea.addView(v);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// private void update_match_num(){
|
||||
//// cur_match_num = latestSettings.settings.get_match_num();
|
||||
//
|
||||
// edited = false;
|
||||
//
|
||||
// binding.matchnum.setText(String.valueOf(cur_match_num+1));
|
||||
//
|
||||
// if(cur_match_num <= 0){
|
||||
// binding.backButton.setVisibility(View.GONE);
|
||||
// }else{
|
||||
// binding.backButton.setVisibility(View.VISIBLE);
|
||||
// }
|
||||
//
|
||||
// if(cur_match_num >= event.matches.size()-1){
|
||||
// binding.nextButton.setVisibility(View.GONE);
|
||||
// }else{
|
||||
// binding.nextButton.setVisibility(View.VISIBLE);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// private frcTeam get_team(frcMatch match){
|
||||
//
|
||||
// // Get team number
|
||||
// String[] split = alliance_position.split("-");
|
||||
// Integer team_num = null;
|
||||
//
|
||||
// switch (split[0]){
|
||||
// case "red":
|
||||
// team_num = match.redAlliance[Integer.parseInt(split[1])-1];
|
||||
// break;
|
||||
// case "blue":
|
||||
// team_num = match.blueAlliance[Integer.parseInt(split[1])-1];
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// binding.barTeamNum.setText(String.valueOf(team_num));
|
||||
//
|
||||
// frcTeam team = null;
|
||||
// for(int i=0; i < event.teams.size(); i++){
|
||||
// frcTeam tmpteam = event.teams.get(i);
|
||||
// if(tmpteam.teamNumber == team_num){
|
||||
// team = tmpteam;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// filename = evcode + "-" + (cur_match_num+1) + "-" + alliance_position + "-" + team_num + ".matchscoutdata";
|
||||
//
|
||||
// return team;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// public void update_scouting_data(){
|
||||
//
|
||||
// frcMatch match = event.matches.get(cur_match_num);
|
||||
// frcTeam team = get_team(match);
|
||||
//
|
||||
// binding.teamName.setText(team.teamName);
|
||||
// binding.teamDescription.setText(team.getDescription());
|
||||
//
|
||||
// boolean new_file = !fileEditor.fileExist(filename);
|
||||
//
|
||||
// if(asm.isRunning){
|
||||
// asm.stop();
|
||||
// }
|
||||
//
|
||||
// if(new_file){
|
||||
// default_fields();
|
||||
// set_indicator_color(unsaved_color);
|
||||
// }else{
|
||||
// get_fields();
|
||||
// set_indicator_color(saved_color);
|
||||
// }
|
||||
//
|
||||
// asm.start();
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public void default_fields(){
|
||||
// for(int i = 0; i < latest_values.length; i++){
|
||||
// inputType input = latest_values[i];
|
||||
// input.setViewValue(input.default_value);
|
||||
//
|
||||
// titles[i].setBackgroundColor(0x00000000);
|
||||
// titles[i].setTextColor(default_text_color);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public void get_fields(){
|
||||
//
|
||||
// ScoutingDataWriter.ParsedScoutingDataResult psdr = ScoutingDataWriter.load(filename, values, transferValues);
|
||||
// dataType[] types = psdr.data.array;
|
||||
//
|
||||
// for(int i = 0; i < latest_values.length; i++){
|
||||
//// types[i] = latest_values[i].getViewValue();
|
||||
// latest_values[i].setViewValue(types[i]);
|
||||
//
|
||||
// if(latest_values[i].isBlank){
|
||||
// titles[i].setBackgroundColor(0xffff0000);
|
||||
// titles[i].setTextColor(0xff000000);
|
||||
// }else{
|
||||
// titles[i].setBackgroundColor(0x00000000);
|
||||
// titles[i].setTextColor(default_text_color);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public void save_fields(){
|
||||
//
|
||||
// dataType[] types = new dataType[latest_values.length];
|
||||
//
|
||||
// for(int i = 0; i < latest_values.length; i++){
|
||||
// types[i] = latest_values[i].getViewValue();
|
||||
latest_values[i].setViewValue(types[i]);
|
||||
|
||||
if(latest_values[i].isBlank){
|
||||
titles[i].setBackgroundColor(0xffff0000);
|
||||
titles[i].setTextColor(0xff000000);
|
||||
}else{
|
||||
titles[i].setBackgroundColor(0x00000000);
|
||||
titles[i].setTextColor(default_text_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void save_fields(){
|
||||
|
||||
dataType[] types = new dataType[latest_values.length];
|
||||
|
||||
for(int i = 0; i < latest_values.length; i++){
|
||||
types[i] = latest_values[i].getViewValue();
|
||||
}
|
||||
|
||||
if(ScoutingDataWriter.save(values.length-1, username, filename, types))
|
||||
System.out.println("Saved!");
|
||||
else
|
||||
System.out.println("Error saving");
|
||||
}
|
||||
}
|
||||
// }
|
||||
//
|
||||
// if(ScoutingDataWriter.save(values.length-1, username, filename, types))
|
||||
// System.out.println("Saved!");
|
||||
// else
|
||||
// System.out.println("Error saving");
|
||||
// }
|
||||
//}
|
||||
|
||||
+71
-130
@@ -1,17 +1,22 @@
|
||||
package com.astatin3.scoutingapp2025.ui.scouting;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.astatin3.scoutingapp2025.SettingsVersionStack.latestSettings;
|
||||
import com.astatin3.scoutingapp2025.databinding.FragmentPitScoutingBinding;
|
||||
import com.astatin3.scoutingapp2025.databinding.FragmentScoutingBinding;
|
||||
import com.astatin3.scoutingapp2025.databinding.FragmentTeamSelectorBinding;
|
||||
import com.astatin3.scoutingapp2025.scoutingData.ScoutingDataWriter;
|
||||
import com.astatin3.scoutingapp2025.scoutingData.fields;
|
||||
import com.astatin3.scoutingapp2025.scoutingData.transfer.transferType;
|
||||
@@ -23,27 +28,33 @@ import com.astatin3.scoutingapp2025.utility.AutoSaveManager;
|
||||
import com.astatin3.scoutingapp2025.utility.fileEditor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class pitScoutingView extends ConstraintLayout {
|
||||
public pitScoutingView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
public pitScoutingView(Context context, AttributeSet attributeSet){
|
||||
super(context, attributeSet);
|
||||
public class pitScoutingFragment extends Fragment {
|
||||
|
||||
FragmentPitScoutingBinding binding;
|
||||
|
||||
private static frcTeam team;
|
||||
public static void setTeam(frcTeam tmpteam){
|
||||
team = tmpteam;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
binding = FragmentPitScoutingBinding.inflate(inflater, container, false);
|
||||
|
||||
loadTeam();
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
private static final int unsaved_color = 0x60ff0000;
|
||||
private static final int saved_color = 0x6000ff00;
|
||||
|
||||
boolean edited = false;
|
||||
|
||||
FragmentScoutingBinding binding;
|
||||
String alliance_position;
|
||||
String evcode;
|
||||
frcEvent event;
|
||||
String filename;
|
||||
String username;
|
||||
|
||||
@@ -84,122 +95,52 @@ public class pitScoutingView extends ConstraintLayout {
|
||||
}
|
||||
|
||||
|
||||
public void init(FragmentScoutingBinding tmp_binding, frcEvent event){
|
||||
binding = tmp_binding;
|
||||
// public void init(frcEvent event){
|
||||
//
|
||||
// evcode = event.eventCode;
|
||||
// this.event = event;
|
||||
// username = latestSettings.settings.get_username();
|
||||
//
|
||||
//// binding.eventcode.setText(evcode);
|
||||
//
|
||||
// binding.pitBackButton.setOnClickListener(view -> {
|
||||
// if(edited) save();
|
||||
// binding.pitTeamName.setVisibility(View.GONE);
|
||||
// binding.pitTeamDescription.setVisibility(View.GONE);
|
||||
// clear_fields();
|
||||
// load_teams();
|
||||
// });
|
||||
//
|
||||
// values = fields.load(fields.pitsFieldsFilename);
|
||||
//
|
||||
// if(values == null || values.length == 0){
|
||||
// TextView tv = new TextView(getContext());
|
||||
// tv.setText("Failed to load fields.\nTry to either download or create pit scouting fields.");
|
||||
// tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
// binding.pitScoutArea.addView(tv);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// latest_values = values[values.length-1];
|
||||
// transferValues = transferType.get_transfer_values(values);
|
||||
// }
|
||||
//
|
||||
// public void clear_fields(){
|
||||
// int childCount = binding.pitScoutArea.getChildCount();
|
||||
// View[] views = new View[childCount];
|
||||
//
|
||||
// for(int i = 0; i < childCount; i++){
|
||||
// views[i] = binding.pitScoutArea.getChildAt(i);
|
||||
// }
|
||||
//
|
||||
// for(int i = 0; i < childCount; i++){
|
||||
// if(!views[i].isShown()) continue;
|
||||
// binding.pitScoutArea.removeView(views[i]);
|
||||
// }
|
||||
// }
|
||||
|
||||
evcode = event.eventCode;
|
||||
this.event = event;
|
||||
username = latestSettings.settings.get_username();
|
||||
|
||||
binding.eventcode.setText(evcode);
|
||||
|
||||
binding.pitBackButton.setOnClickListener(view -> {
|
||||
if(edited) save();
|
||||
binding.pitTeamName.setVisibility(View.GONE);
|
||||
binding.pitTeamDescription.setVisibility(View.GONE);
|
||||
clear_fields();
|
||||
load_teams();
|
||||
});
|
||||
|
||||
values = fields.load(fields.pitsFieldsFilename);
|
||||
|
||||
if(values == null || values.length == 0){
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setText("Failed to load fields.\nTry to either download or create pit scouting fields.");
|
||||
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
binding.pitScoutArea.addView(tv);
|
||||
return;
|
||||
}
|
||||
|
||||
latest_values = values[values.length-1];
|
||||
transferValues = transferType.get_transfer_values(values);
|
||||
|
||||
// create_fields();
|
||||
// update_scouting_data();
|
||||
|
||||
load_teams();
|
||||
}
|
||||
|
||||
public void clear_fields(){
|
||||
int childCount = binding.pitScoutArea.getChildCount();
|
||||
View[] views = new View[childCount];
|
||||
|
||||
for(int i = 0; i < childCount; i++){
|
||||
views[i] = binding.pitScoutArea.getChildAt(i);
|
||||
}
|
||||
|
||||
for(int i = 0; i < childCount; i++){
|
||||
if(!views[i].isShown()) continue;
|
||||
binding.pitScoutArea.removeView(views[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void load_teams(){
|
||||
binding.pitFileIndicator.setVisibility(View.GONE);
|
||||
binding.pitTeamName.setVisibility(View.GONE);
|
||||
binding.pitTeamDescription.setVisibility(View.GONE);
|
||||
|
||||
clear_fields();
|
||||
|
||||
|
||||
int[] teamNums = new int[event.teams.size()];
|
||||
|
||||
for(int i = 0 ; i < event.teams.size(); i++){
|
||||
teamNums[i] = event.teams.get(i).teamNumber;
|
||||
}
|
||||
|
||||
Arrays.sort(teamNums);
|
||||
|
||||
TableLayout table = new TableLayout(getContext());
|
||||
table.setStretchAllColumns(true);
|
||||
binding.pitScoutArea.addView(table);
|
||||
|
||||
|
||||
for(int i = 0; i < event.teams.size(); i++){
|
||||
frcTeam team = null;
|
||||
for(int a = 0 ; a < event.teams.size(); a++){
|
||||
if(event.teams.get(a).teamNumber == teamNums[i]){
|
||||
team = event.teams.get(a);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TableRow tr = new TableRow(getContext());
|
||||
TableLayout.LayoutParams rowParams = new TableLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
rowParams.setMargins(20,20,20,20);
|
||||
tr.setLayoutParams(rowParams);
|
||||
tr.setPadding(20,20,20,20);
|
||||
table.addView(tr);
|
||||
|
||||
if(fileEditor.fileExist(evcode + "-" + team.teamNumber + ".pitscoutdata")){
|
||||
tr.setBackgroundColor(0x3000FF00);
|
||||
}else{
|
||||
tr.setBackgroundColor(0x30FF0000);
|
||||
}
|
||||
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setText(String.valueOf(team.teamNumber));
|
||||
tv.setTextSize(20);
|
||||
tr.addView(tv);
|
||||
|
||||
tv = new TextView(getContext());
|
||||
tv.setText(team.teamName);
|
||||
tv.setTextSize(16);
|
||||
tr.addView(tv);
|
||||
|
||||
frcTeam finalTeam = team;
|
||||
tr.setOnClickListener(v -> {
|
||||
// binding.pitScoutArea.removeView(table);
|
||||
loadTeam(finalTeam);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void loadTeam(frcTeam team){
|
||||
clear_fields();
|
||||
public void loadTeam(){
|
||||
// clear_fields();
|
||||
|
||||
binding.pitFileIndicator.setVisibility(View.VISIBLE);
|
||||
binding.pitTeamName.setVisibility(View.VISIBLE);
|
||||
@@ -209,8 +150,8 @@ public class pitScoutingView extends ConstraintLayout {
|
||||
binding.pitTeamDescription.setText(team.getDescription());
|
||||
binding.pitBarTeamNum.setText(String.valueOf(team.teamNumber));
|
||||
|
||||
binding.teamName.setText(team.teamName);
|
||||
binding.teamDescription.setText(team.getDescription());
|
||||
// binding.teamName.setText(team.teamName);
|
||||
// binding.teamDescription.setText(team.getDescription());
|
||||
|
||||
filename = evcode + "-" + team.teamNumber + ".pitscoutdata";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.astatin3.scoutingapp2025.ui.scouting;
|
||||
|
||||
import static androidx.navigation.fragment.FragmentKt.findNavController;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -11,9 +13,12 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.astatin3.scoutingapp2025.R;
|
||||
import com.astatin3.scoutingapp2025.SettingsVersionStack.latestSettings;
|
||||
import com.astatin3.scoutingapp2025.databinding.FragmentScoutingBinding;
|
||||
import com.astatin3.scoutingapp2025.types.frcEvent;
|
||||
import com.astatin3.scoutingapp2025.types.frcTeam;
|
||||
import com.astatin3.scoutingapp2025.ui.TeamSelectorFragment;
|
||||
import com.astatin3.scoutingapp2025.ui.data.sentimentAnalysis;
|
||||
import com.astatin3.scoutingapp2025.utility.fileEditor;
|
||||
|
||||
@@ -26,11 +31,8 @@ public class scoutingFragment extends Fragment {
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
binding = FragmentScoutingBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
|
||||
binding.buttons.setVisibility(View.VISIBLE);
|
||||
binding.matchScoutingView.setVisibility(View.GONE);
|
||||
binding.pitScoutingView.setVisibility(View.GONE);
|
||||
|
||||
String evcode = latestSettings.settings.get_evcode();
|
||||
|
||||
@@ -38,7 +40,7 @@ public class scoutingFragment extends Fragment {
|
||||
binding.noEventError.setVisibility(View.VISIBLE);
|
||||
binding.buttons.setVisibility(View.GONE);
|
||||
is_main_page = false;
|
||||
return root;
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
frcEvent event = frcEvent.decode(fileEditor.readFile(evcode + ".eventdata"));
|
||||
@@ -47,21 +49,30 @@ public class scoutingFragment extends Fragment {
|
||||
binding.matchScoutingButton.setVisibility(View.GONE);
|
||||
|
||||
binding.matchScoutingButton.setOnClickListener(v -> {
|
||||
binding.buttons.setVisibility(View.GONE);
|
||||
binding.matchScoutingView.setVisibility(View.VISIBLE);
|
||||
binding.matchScoutingView.init(binding, event);
|
||||
// binding.buttons.setVisibility(View.GONE);
|
||||
findNavController(this).navigate(R.id.action_navigation_scouting_to_navigation_match_scouting);
|
||||
// binding.init(binding, event);
|
||||
is_main_page = false;
|
||||
});
|
||||
|
||||
binding.pitScoutingButton.setOnClickListener(v -> {
|
||||
binding.pitScoutingView.setVisibility(View.VISIBLE);
|
||||
binding.buttons.setVisibility(View.GONE);
|
||||
// binding.pitScoutingView.setVisibility(View.VISIBLE);
|
||||
// binding.buttons.setVisibility(View.GONE);
|
||||
// binding.pitScoutArea.setVisibility(View.VISIBLE);
|
||||
binding.pitScoutingView.init(binding, event);
|
||||
// binding.pitScoutingView.init(binding, event);
|
||||
|
||||
TeamSelectorFragment.setOnSelect(new TeamSelectorFragment.onTeamSelected() {
|
||||
@Override
|
||||
public void onSelect(TeamSelectorFragment self, frcTeam team) {
|
||||
findNavController(self).navigate(R.id.action_navigation_scouting_to_navigation_team_selector);
|
||||
}
|
||||
});
|
||||
findNavController(this).navigate(R.id.action_navigation_scouting_to_navigation_team_selector);
|
||||
|
||||
is_main_page = false;
|
||||
});
|
||||
|
||||
return root;
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,9 +93,9 @@ public class scoutingFragment extends Fragment {
|
||||
&& keyCode == KeyEvent.KEYCODE_BACK
|
||||
&& !is_main_page){
|
||||
|
||||
binding.buttons.setVisibility(View.VISIBLE);
|
||||
binding.matchScoutingView.setVisibility(View.GONE);
|
||||
binding.pitScoutingView.setVisibility(View.GONE);
|
||||
// binding.buttons.setVisibility(View.VISIBLE);
|
||||
// binding.matchScoutingView.setVisibility(View.GONE);
|
||||
// binding.pitScoutingView.setVisibility(View.GONE);
|
||||
is_main_page = true;
|
||||
|
||||
return true;
|
||||
|
||||
+31
-33
@@ -1,39 +1,22 @@
|
||||
package com.astatin3.scoutingapp2025.utility;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ReorderableTableLayout extends TableLayout {
|
||||
private boolean reorderingEnabled = false;
|
||||
private int draggedRowIndex = -1;
|
||||
private float lastY;
|
||||
private List<View> originalRows;
|
||||
private List<View> rows;
|
||||
private List<Integer> reorderedIndices;
|
||||
private int rowHeight;
|
||||
|
||||
public ReorderableTableLayout(Context context) {
|
||||
@@ -47,7 +30,8 @@ public class ReorderableTableLayout extends TableLayout {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
originalRows = new ArrayList<>();
|
||||
rows = new ArrayList<>();
|
||||
reorderedIndices = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,16 +55,32 @@ public class ReorderableTableLayout extends TableLayout {
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addView(View child) {
|
||||
super.addView(child);
|
||||
reorderedIndices.add(reorderedIndices.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllViews() {
|
||||
super.removeAllViews();
|
||||
reorderedIndices.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (!reorderingEnabled || draggedRowIndex == -1) {
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
float currentY = event.getY();
|
||||
int targetIndex = getRowIndexAtY(currentY);
|
||||
View child = getChildAt(targetIndex);
|
||||
if(child != null)
|
||||
getChildAt(targetIndex).callOnClick();
|
||||
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
float currentY = event.getY();
|
||||
int targetIndex = getRowIndexAtY(currentY);
|
||||
if (targetIndex != -1 && targetIndex != draggedRowIndex) {
|
||||
updateRowOrder(draggedRowIndex, targetIndex);
|
||||
draggedRowIndex = targetIndex;
|
||||
@@ -106,25 +106,27 @@ public class ReorderableTableLayout extends TableLayout {
|
||||
}
|
||||
|
||||
private void saveOriginalOrder() {
|
||||
originalRows.clear();
|
||||
rows.clear();
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
originalRows.add(getChildAt(i));
|
||||
rows.add(getChildAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRowOrder(int fromIndex, int toIndex) {
|
||||
if (fromIndex < toIndex) {
|
||||
for (int i = fromIndex; i < toIndex; i++) {
|
||||
Collections.swap(originalRows, i, i + 1);
|
||||
Collections.swap(rows, i, i + 1);
|
||||
Collections.swap(reorderedIndices, i, i + 1);
|
||||
}
|
||||
} else {
|
||||
for (int i = fromIndex; i > toIndex; i--) {
|
||||
Collections.swap(originalRows, i, i - 1);
|
||||
Collections.swap(rows, i, i - 1);
|
||||
Collections.swap(reorderedIndices, i, i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
removeAllViewsInLayout();
|
||||
for (View view : originalRows) {
|
||||
for (View view : rows) {
|
||||
addViewInLayout(view, -1, view.getLayoutParams(), true);
|
||||
}
|
||||
requestLayout();
|
||||
@@ -136,10 +138,6 @@ public class ReorderableTableLayout extends TableLayout {
|
||||
}
|
||||
|
||||
public List<Integer> getReorderedIndexes() {
|
||||
List<Integer> reorderedIndexes = new ArrayList<>();
|
||||
for (View view : originalRows) {
|
||||
reorderedIndexes.add(indexOfChild(view));
|
||||
}
|
||||
return reorderedIndexes;
|
||||
return reorderedIndices;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user