mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 08:38:03 -06:00
Stuff
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
package com.ridgebotics.ridgescout.types;
|
||||
|
||||
public class ColabArray {
|
||||
}
|
||||
@@ -9,14 +9,13 @@ import com.ridgebotics.ridgescout.utility.ByteBuilder;
|
||||
import com.ridgebotics.ridgescout.utility.SettingsManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
// Class to contain data for an entire event.
|
||||
// Easily encoded and decoded to binary format.
|
||||
public class frcEvent {
|
||||
|
||||
public static final int typecode = 254;
|
||||
public String eventCode;
|
||||
public String name;
|
||||
public ArrayList<frcMatch> matches;
|
||||
@@ -134,29 +133,29 @@ public class frcEvent {
|
||||
return null;
|
||||
}
|
||||
|
||||
// public
|
||||
|
||||
// Returns the soonest match that there will be all the possible upcoming data on other teams
|
||||
public void getReportMatches(int ourTeamNum){
|
||||
frcMatch[] teamMatches = event.getTeamMatches(ourTeamNum);
|
||||
public int getMostInformedBy(int ourTeamNum, int curMatch){
|
||||
frcMatch teamMatch = getNextTeamMatch(ourTeamNum, curMatch);
|
||||
|
||||
for(int i = 0; i < teamMatches.length; i++){
|
||||
int maxMatch = -1;
|
||||
for(int a = 0; a < 6; a++){
|
||||
int teamNum;
|
||||
if(a < 3)
|
||||
teamNum = teamMatches[i].redAlliance[a];
|
||||
else
|
||||
teamNum = teamMatches[i].blueAlliance[a-3];
|
||||
int maxMatch = Integer.MIN_VALUE;
|
||||
|
||||
if(teamNum == ourTeamNum)
|
||||
continue;
|
||||
for(int a = 0; a < 6; a++){
|
||||
int teamNum;
|
||||
if(a < 3)
|
||||
teamNum = teamMatch.redAlliance[a];
|
||||
else
|
||||
teamNum = teamMatch.blueAlliance[a-3];
|
||||
|
||||
int matchNum = event.getMostRecentTeamMatch(teamNum, teamMatches[i].matchIndex);
|
||||
if(maxMatch < matchNum)
|
||||
maxMatch = matchNum;
|
||||
}
|
||||
if(teamNum == ourTeamNum)
|
||||
continue;
|
||||
|
||||
int matchNum = event.getMostRecentTeamMatch(teamNum, teamMatch.matchIndex);
|
||||
if(maxMatch < matchNum)
|
||||
maxMatch = matchNum;
|
||||
}
|
||||
|
||||
return maxMatch;
|
||||
}
|
||||
|
||||
public frcTeam getTeamByNum(int teamNum){
|
||||
@@ -168,6 +167,26 @@ public class frcEvent {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<frcTeam> getTeamsSorted() {
|
||||
int[] teamNums = new int[teams.size()];
|
||||
|
||||
for(int i = 0 ; i < teams.size(); i++){
|
||||
teamNums[i] = teams.get(i).teamNumber;
|
||||
}
|
||||
|
||||
Arrays.sort(teamNums);
|
||||
|
||||
List<frcTeam> list = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < teams.size(); i++){
|
||||
frcTeam team = getTeamByNum(teamNums[i]);
|
||||
assert team != null;
|
||||
list.add(team);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public boolean getIsBlueAlliance(int teamNum, int matchNum){
|
||||
return getIsBlueAlliance(teamNum, matches.get(matchNum));
|
||||
|
||||
@@ -15,6 +15,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -89,7 +90,7 @@ public class ScoutingFragment extends Fragment {
|
||||
|
||||
binding.textMatchAlliance.setVisibility(View.GONE);
|
||||
binding.textName.setVisibility(View.GONE);
|
||||
binding.textNextMatch.setVisibility(View.GONE);
|
||||
binding.infoBox.setVisibility(View.GONE);
|
||||
binding.textRescoutIndicator.setVisibility(View.GONE);
|
||||
|
||||
binding.matchScoutingButton.setEnabled(false);
|
||||
@@ -123,21 +124,7 @@ public class ScoutingFragment extends Fragment {
|
||||
findNavController(this).navigate(R.id.action_navigation_scouting_to_navigation_scouting_event);
|
||||
});
|
||||
|
||||
|
||||
binding.textName.setText("Welcome, " + SettingsManager.getUsername() + "!");
|
||||
|
||||
int matchNum = SettingsManager.getMatchNum();
|
||||
int nextMatch = -1;
|
||||
int teamNum = SettingsManager.getTeamNum();
|
||||
try {
|
||||
nextMatch = event.getNextTeamMatch(teamNum, matchNum).matchIndex;
|
||||
} catch (Exception e){
|
||||
AlertManager.error("Sorry, in event ("+evcode+"), your team number ("+teamNum+") wasn't found!", e);
|
||||
}
|
||||
|
||||
binding.textNextMatch.setText("Our next match: Match " + nextMatch);
|
||||
binding.textMatchAlliance.setText("Match: " + (matchNum+1) + ", " + SettingsManager.getAllyPos());
|
||||
binding.textRescoutIndicator.setText("Things to rescout: " + DataManager.rescout_list.size());
|
||||
updateDashboard();
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
@@ -166,4 +153,32 @@ public class ScoutingFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
private void updateDashboard() {
|
||||
binding.textName.setText("Welcome, " + SettingsManager.getUsername() + "!");
|
||||
|
||||
int curMatchNum = SettingsManager.getMatchNum();
|
||||
int nextMatch;
|
||||
int teamNum = SettingsManager.getTeamNum();
|
||||
try {
|
||||
nextMatch = event.getNextTeamMatch(teamNum, curMatchNum).matchIndex;
|
||||
} catch (Exception e){
|
||||
AlertManager.error("Sorry, in event ("+evcode+"), your team number ("+teamNum+") wasn't found!", e);
|
||||
return;
|
||||
}
|
||||
|
||||
binding.textMatchAlliance.setText("Match: " + (curMatchNum+1) + ", " + SettingsManager.getAllyPos());
|
||||
binding.textRescoutIndicator.setText("Things to rescout: " + DataManager.rescout_list.size());
|
||||
|
||||
TextView nextMatchText = new TextView(getContext());
|
||||
nextMatchText.setText("Our next match: Match " + nextMatch);
|
||||
nextMatchText.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Body1);
|
||||
binding.infoBox.addView(nextMatchText);
|
||||
|
||||
int informedBy = event.getMostInformedBy(teamNum, curMatchNum);
|
||||
|
||||
TextView mostInformedText = new TextView(getContext());
|
||||
mostInformedText.setText("Most informed by: Match " + informedBy);
|
||||
mostInformedText.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Body1);
|
||||
binding.infoBox.addView(mostInformedText);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.ridgebotics.ridgescout.ui.transfer.codes;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Handler;
|
||||
@@ -21,25 +19,12 @@ import androidx.fragment.app.Fragment;
|
||||
import com.ridgebotics.ridgescout.databinding.FragmentTransferCodeSenderBinding;
|
||||
import com.ridgebotics.ridgescout.utility.AlertManager;
|
||||
import com.ridgebotics.ridgescout.utility.FileEditor;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.MultiFormatWriter;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.ridgebotics.ridgescout.utility.TaskRunner;
|
||||
|
||||
import java.lang.reflect.Executable;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
// Class to show the code transfer thing.
|
||||
public class CodeGeneratorView extends Fragment {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class CustomSpinnerView extends LinearLayout {
|
||||
this.index = defaultOption;
|
||||
|
||||
if(defaultOption != -1)
|
||||
this.item.setText(options.get(defaultOption));
|
||||
this.item.setText("▼ " + options.get(defaultOption));
|
||||
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
@@ -110,7 +110,7 @@ public class CustomSpinnerView extends LinearLayout {
|
||||
}
|
||||
|
||||
public void setOption(int index) {
|
||||
item.setText(options.get(index));
|
||||
item.setText("▼ " + options.get(index));
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.ridgebotics.ridgescout.ui.views;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RecyclerAdapter<T> extends RecyclerView.Adapter<RecyclerHolder<T>> {
|
||||
private List<T> items;
|
||||
private final int layoutResId;
|
||||
private final RecyclerHolderFactory<T> viewHolderFactory;
|
||||
private RecyclerClickListener<T> onItemClickListener;
|
||||
|
||||
public RecyclerAdapter(int layoutResId, RecyclerHolderFactory<T> viewHolderFactory) {
|
||||
this.items = new ArrayList<>();
|
||||
this.layoutResId = layoutResId;
|
||||
this.viewHolderFactory = viewHolderFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerHolder<T> onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(layoutResId, parent, false);
|
||||
return viewHolderFactory.createViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerHolder<T> holder, int position) {
|
||||
T item = items.get(position);
|
||||
holder.bind(item, position);
|
||||
holder.setOnItemClickListener(item, onItemClickListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
// List management methods
|
||||
public void setItems(List<T> newItems) {
|
||||
this.items.clear();
|
||||
if (newItems != null) {
|
||||
this.items.addAll(newItems);
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void addItem(T item) {
|
||||
items.add(item);
|
||||
notifyItemInserted(items.size() - 1);
|
||||
}
|
||||
|
||||
public void addItem(int position, T item) {
|
||||
items.add(position, item);
|
||||
notifyItemInserted(position);
|
||||
}
|
||||
|
||||
public void removeItem(int position) {
|
||||
if (position >= 0 && position < items.size()) {
|
||||
items.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeItem(T item) {
|
||||
int position = items.indexOf(item);
|
||||
if (position != -1) {
|
||||
removeItem(position);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateItem(int position, T item) {
|
||||
if (position >= 0 && position < items.size()) {
|
||||
items.set(position, item);
|
||||
notifyItemChanged(position);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
int size = items.size();
|
||||
items.clear();
|
||||
notifyItemRangeRemoved(0, size);
|
||||
}
|
||||
|
||||
public T getItem(int position) {
|
||||
return items.get(position);
|
||||
}
|
||||
|
||||
public List<T> getItems() {
|
||||
return new ArrayList<>(items);
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(RecyclerClickListener<T> listener) {
|
||||
this.onItemClickListener = listener;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.ridgebotics.ridgescout.ui.views;
|
||||
|
||||
public interface RecyclerClickListener<T> {
|
||||
void onItemClick(T item, int position);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.ridgebotics.ridgescout.ui.views;
|
||||
|
||||
import android.view.View;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public abstract class RecyclerHolder<T> extends RecyclerView.ViewHolder {
|
||||
public RecyclerHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
|
||||
public abstract void bind(T item, int position);
|
||||
|
||||
// Optional method for handling item clicks
|
||||
public void setOnItemClickListener(T item, RecyclerClickListener<T> listener) {
|
||||
if (listener != null) {
|
||||
itemView.setOnClickListener(v -> listener.onItemClick(item, getAdapterPosition()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.ridgebotics.ridgescout.ui.views;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
public interface RecyclerHolderFactory<T> {
|
||||
RecyclerHolder<T> createViewHolder(View itemView);
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.ridgebotics.ridgescout.ui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import java.util.List;
|
||||
|
||||
public class RecyclerList<T> extends RecyclerView {
|
||||
private RecyclerAdapter<T> adapter;
|
||||
|
||||
public RecyclerList(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public RecyclerList(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public RecyclerList(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
// Set default layout manager
|
||||
setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
// Enable optimizations
|
||||
setHasFixedSize(true);
|
||||
setItemViewCacheSize(20);
|
||||
setDrawingCacheEnabled(true);
|
||||
setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
|
||||
}
|
||||
|
||||
// Setup method to configure the RecyclerView
|
||||
public RecyclerList<T> setup(int layoutResId, RecyclerHolderFactory<T> RecyclerHolderFactory) {
|
||||
adapter = new RecyclerAdapter<>(layoutResId, RecyclerHolderFactory);
|
||||
setAdapter(adapter);
|
||||
return this;
|
||||
}
|
||||
|
||||
// Layout manager convenience methods
|
||||
public RecyclerList<T> withLinearLayout() {
|
||||
setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecyclerList<T> withLinearLayout(int orientation) {
|
||||
setLayoutManager(new LinearLayoutManager(getContext(), orientation, false));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecyclerList<T> withGridLayout(int spanCount) {
|
||||
setLayoutManager(new GridLayoutManager(getContext(), spanCount));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecyclerList<T> withDivider() {
|
||||
DividerItemDecoration divider = new DividerItemDecoration(getContext(),
|
||||
DividerItemDecoration.VERTICAL);
|
||||
addItemDecoration(divider);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecyclerList<T> withItemClickListener(RecyclerClickListener<T> listener) {
|
||||
if (adapter != null) {
|
||||
adapter.setOnItemClickListener(listener);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// Data management methods
|
||||
public void setItems(List<T> items) {
|
||||
if (adapter != null) {
|
||||
adapter.setItems(items);
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(T item) {
|
||||
if (adapter != null) {
|
||||
adapter.addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(int position, T item) {
|
||||
if (adapter != null) {
|
||||
adapter.addItem(position, item);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeItem(int position) {
|
||||
if (adapter != null) {
|
||||
adapter.removeItem(position);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeItem(T item) {
|
||||
if (adapter != null) {
|
||||
adapter.removeItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateItem(int position, T item) {
|
||||
if (adapter != null) {
|
||||
adapter.updateItem(position, item);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
if (adapter != null) {
|
||||
adapter.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public T getItem(int position) {
|
||||
return adapter != null ? adapter.getItem(position) : null;
|
||||
}
|
||||
|
||||
public List<T> getItems() {
|
||||
return adapter != null ? adapter.getItems() : null;
|
||||
}
|
||||
|
||||
public RecyclerAdapter<T> getGenericAdapter() {
|
||||
return adapter;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user