From 42bcb6688464674ea068c4661fc4fcf64210a89c Mon Sep 17 00:00:00 2001 From: Sean Hoyt Date: Wed, 28 Feb 2024 23:05:37 -0600 Subject: [PATCH] Add a upload mode selector Used in the scanner to upload data to the correct locations in the sheet. --- .../androidscouting/fragment/Scanner.java | 41 ++++++++++++- .../util/SheetsUpdateTaskNew.java | 61 +++++++++++++++---- app/src/main/res/layout/fragment_scanner.xml | 54 ++++++++++++++++ 3 files changed, 142 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/databits/androidscouting/fragment/Scanner.java b/app/src/main/java/com/databits/androidscouting/fragment/Scanner.java index dd1d917..3c32cc3 100644 --- a/app/src/main/java/com/databits/androidscouting/fragment/Scanner.java +++ b/app/src/main/java/com/databits/androidscouting/fragment/Scanner.java @@ -151,6 +151,21 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { //} }); + binding.buttonGroupUploadMode.setOnPositionChangedListener(position -> { + switch (position) { + case 0: + configPreference.setString("uploadMode", "Crowd"); + break; + case 1: + configPreference.setString("uploadMode","Speciality"); + break; + case 2: + configPreference.setString("uploadMode","Pit"); + break; + + } + }); + binding.testButton.setOnClickListener(view1 -> PowerPreference.showDebugScreen(true)); @@ -337,8 +352,26 @@ private void saveData(String bar_string) { // Add non-split data to the list raw_data.add(new String[] {bar_string}); + String uploadData = null; + String uploadLines = null; + + switch (configPreference.getString("uploadMode")) { + case "Crowd": + uploadData = "upload_data"; + uploadLines = "seen_lines"; + break; + case "Speciality": + uploadData = "special_upload_data"; + uploadLines = "special_seen_lines"; + break; + case "Pit": + uploadData = "pit_upload_data"; + uploadLines = "pit_seen_lines"; + break; + } + // Create a HashSet to keep track of the lines we've already seen - Set seenLines = listPreference.getObject("seen_lines", Set.class, + Set seenLines = listPreference.getObject(uploadLines, Set.class, new HashSet<>()); // Check for duplicate and don't upload role qr data @@ -348,10 +381,10 @@ private void saveData(String bar_string) { seenLines.add(bar_string); // Save the HashSet to the shared preferences - listPreference.setObject("seen_lines", seenLines); + listPreference.setObject(uploadLines, seenLines); // Save the data to the shared preferences - matchPreference.setObject("upload_data", raw_data); + matchPreference.setObject(uploadData, raw_data); } } @@ -468,6 +501,7 @@ private void refreshUI() { binding.buttonBack.setText(R.string.back); binding.matchSelectorText.setVisibility(View.GONE); binding.buttonUpload.setVisibility(View.GONE); + binding.buttonGroupUploadMode.setVisibility(View.GONE); } else { binding.teamListDisplay.getRoot().setVisibility(View.VISIBLE); binding.uiInsideNumberPicker.setVisibility(View.VISIBLE); @@ -475,6 +509,7 @@ private void refreshUI() { binding.buttonBack.setText(R.string.back); binding.matchSelectorText.setVisibility(View.VISIBLE); binding.buttonUpload.setVisibility(View.VISIBLE); + binding.buttonGroupUploadMode.setVisibility(View.VISIBLE); } } diff --git a/app/src/main/java/com/databits/androidscouting/util/SheetsUpdateTaskNew.java b/app/src/main/java/com/databits/androidscouting/util/SheetsUpdateTaskNew.java index dd042e7..51bd47d 100644 --- a/app/src/main/java/com/databits/androidscouting/util/SheetsUpdateTaskNew.java +++ b/app/src/main/java/com/databits/androidscouting/util/SheetsUpdateTaskNew.java @@ -35,7 +35,7 @@ public class SheetsUpdateTaskNew extends AsyncTask> columnData = new ArrayList<>(matchPreference.getObject("upload_data", - ArrayList.class, new ArrayList<>())); + List> columnData = null; + switch (configPreference.getString("uploadMode")) { + case "Crowd": + columnData = new ArrayList<>(matchPreference.getObject("upload_data", + ArrayList.class, new ArrayList<>())); + break; + case "Pit": + columnData = new ArrayList<>(matchPreference.getObject("pit_upload_data", + ArrayList.class, new ArrayList<>())); + break; + case "Speciality": + columnData = new ArrayList<>(matchPreference.getObject("special_upload_data", + ArrayList.class, new ArrayList<>())); + break; + } + + try { // Sheet name and range to upload data to - String range; - - if (configPreference.getBoolean("altMode", false)) { - // Royal Twrecks - range = "Raw Data!A2:BL700"; - } else { - // Databits - range = "SuperRawDatabase!A2:BL700"; + String range = null; + + boolean altMode = configPreference.getBoolean("altMode", false); + + switch (configPreference.getString("uploadMode")) { + case "Crowd": + if (altMode) { + // Royal Twrecks + range = "Raw Data!A2:BL700"; + } else { + // Databits + range = "SuperRawDatabase!A2:BL700"; + } + break; + case "Pit": + if (altMode) { + // Royal Twrecks + range = "Raw Data!A2:BL700"; + } else { + // Databits + range = "PitData!A2:Z700"; + } + break; + case "Speciality": + if (altMode) { + // Royal Twrecks + range = "Raw Data!A2:BL700"; + } else { + // Databits + range = "SuperSpecializedRawData!A2:X700"; + } + break; } // Configure a new value range to store the data diff --git a/app/src/main/res/layout/fragment_scanner.xml b/app/src/main/res/layout/fragment_scanner.xml index 96040f4..d7ef4e1 100644 --- a/app/src/main/res/layout/fragment_scanner.xml +++ b/app/src/main/res/layout/fragment_scanner.xml @@ -104,4 +104,58 @@ android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_percent=".17" /> + + + + + + + + + \ No newline at end of file