Made it so the file name will be the event name
Also deleted code no longer used + apparently broken from Submit.java
This commit is contained in:
parent
a734027652
commit
4445aef630
@ -19,6 +19,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class AutoActivity extends AppCompatActivity {
|
||||
private String auto = "Auto";
|
||||
private int l4Scored = 0;
|
||||
private int l3Scored = 0;
|
||||
private int l2Scored = 0;
|
||||
@ -36,6 +37,9 @@ public class AutoActivity extends AppCompatActivity {
|
||||
private TextView l1TV;
|
||||
private TextView processorTV;
|
||||
private TextView netTV;
|
||||
private String eventString, matchString;
|
||||
public static final String Event_Key = "EVENTCONFIRM";
|
||||
public static final String Match_key = "MATCHCONFIRM";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -47,6 +51,10 @@ public class AutoActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
Intent intentinput = getIntent();
|
||||
eventString = intentinput.getStringExtra(MainActivity.Event_Key);
|
||||
matchString = intentinput.getStringExtra(MainActivity.Match_key);
|
||||
|
||||
|
||||
Button l4Button = (Button) findViewById(R.id.button_L4);
|
||||
Button l3Button = (Button) findViewById(R.id.button_L3);
|
||||
@ -137,7 +145,10 @@ public class AutoActivity extends AppCompatActivity {
|
||||
|
||||
nextButton.setOnLongClickListener((v) -> {
|
||||
//submit data
|
||||
CSVmake(AutoActivity.this);
|
||||
Intent intent = new Intent(this, TeleActivity.class);
|
||||
intent.putExtra(Event_Key, eventString);
|
||||
intent.putExtra(Match_key, matchString);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
@ -179,17 +190,21 @@ public class AutoActivity extends AppCompatActivity {
|
||||
public void CSVmake(Context context) {
|
||||
//adds the strings
|
||||
String CSVLine = String.format(
|
||||
"%s %s %s %s %s %s %s",
|
||||
"%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
|
||||
auto,
|
||||
l4Scored,
|
||||
l3Scored,
|
||||
l2Scored,
|
||||
l1Scored,
|
||||
processorScored,
|
||||
netScored,
|
||||
reefPickup,
|
||||
canLeave,
|
||||
coralPickup
|
||||
);
|
||||
//makes the file
|
||||
File csvFile = new File(context.getFilesDir(), "match_data.csv");
|
||||
File csvFile = new File(context.getFilesDir(), eventString+".csv");
|
||||
Log.d("CSVFile", "File created/written at: " + csvFile.getAbsolutePath());
|
||||
//writes to file
|
||||
try (FileWriter writer = new FileWriter(csvFile, true)) {
|
||||
writer.append(CSVLine).append("\n");
|
||||
|
@ -26,6 +26,9 @@ import java.io.File;
|
||||
|
||||
|
||||
public class EndActivity extends AppCompatActivity {
|
||||
private String eventString, matchString;
|
||||
public static final String Event_Key = "EVENTCONFIRM";
|
||||
public static final String Match_key = "MATCHCONFIRM";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -37,18 +40,22 @@ public class EndActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
Intent intentinput = getIntent();
|
||||
eventString = intentinput.getStringExtra(AutoActivity.Event_Key);
|
||||
matchString = intentinput.getStringExtra(AutoActivity.Match_key);
|
||||
Button submit = (Button) findViewById(R.id.Submit_button);
|
||||
submit.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
public void onClick(View view) {
|
||||
String csvFileString = eventString+".csv";
|
||||
Submit submit = new Submit();
|
||||
//Writes data to file to make google sheet read it as a list
|
||||
File csvFile = new File(getFilesDir(), "match_data.csv");
|
||||
List<List<Object>> data = submit.parseCSVToList(csvFile);
|
||||
submit.parseCSVToList(csvFile);
|
||||
File csvFilefile = new File(getFilesDir(), "csvFileString");
|
||||
List<List<Object>> data = submit.parseCSVToList(csvFilefile);
|
||||
submit.parseCSVToList(csvFilefile);
|
||||
//Uploads the Data to the Google sheet
|
||||
submit.uploadSheets(EndActivity.this);
|
||||
submit.uploadSheets(EndActivity.this, csvFileString);
|
||||
submit.renameFile(EndActivity.this, eventString);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -7,6 +7,7 @@ import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
@ -20,12 +21,21 @@ import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private EditText Match_number;
|
||||
private EditText Event;
|
||||
private String Match_numberString;
|
||||
private String EventString;
|
||||
public static final String Event_Key = "EVENTCONFIRM";
|
||||
public static final String Match_key = "MATCHCONFIRM";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -36,11 +46,16 @@ public class MainActivity extends AppCompatActivity {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
|
||||
});
|
||||
Match_number = (EditText) findViewById(R.id.Match);
|
||||
Event = (EditText) findViewById(R.id.Event);
|
||||
Button nextButton = (Button) findViewById(R.id.nextButton);
|
||||
nextButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Match_numberString = Match_number.getText().toString();
|
||||
EventString = Event.getText().toString();
|
||||
makeIntent();
|
||||
}
|
||||
|
||||
@ -48,7 +63,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
TextView TBAView = (TextView)findViewById(R.id.TBATest);
|
||||
}
|
||||
|
||||
public final class AsynchronousGet {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@ -90,6 +104,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
private void makeIntent()
|
||||
{
|
||||
Intent intent = new Intent(this, AutoActivity.class);
|
||||
intent.putExtra(Event_Key, EventString);
|
||||
intent.putExtra(Match_key, Match_numberString);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ import java.util.List;
|
||||
|
||||
public class Submit {
|
||||
|
||||
void uploadSheets(Context context) {
|
||||
void uploadSheets(Context context, String csvFileString) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
//adds account info
|
||||
@ -37,7 +37,7 @@ public class Submit {
|
||||
).setApplicationName("Scouting App").build();
|
||||
|
||||
//make sure the file is there
|
||||
File csvFile = new File(context.getFilesDir(), "match_data.csv");
|
||||
File csvFile = new File(context.getFilesDir(), csvFileString);
|
||||
if (!csvFile.exists()) {
|
||||
Log.d("CSVError", "CSV file does not exist.");
|
||||
return;
|
||||
@ -67,33 +67,51 @@ public class Submit {
|
||||
List<List<Object>> parseCSVToList(File csvFile) {
|
||||
//makes A array
|
||||
List<List<Object>> data = Lists.newArrayList();
|
||||
//Reads the info from the CSV file and makes it usedable to upload to the google sheet
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
List<Object> row = Arrays.asList(line.split(","));
|
||||
data.add(row);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.d("parseCSVToList", "Error with BufferredReader");
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public void deleteCSVFile(Context context) {
|
||||
//Finds the file
|
||||
File csvFile = new File(context.getFilesDir(), "match_data.csv");
|
||||
// Get the directory containing the files
|
||||
File directory = context.getFilesDir();
|
||||
|
||||
//Checks if the file exists
|
||||
if (csvFile.exists()) {
|
||||
//Tries to delete file
|
||||
if (csvFile.delete()) {
|
||||
Log.d("CSVDelete", "match_data.csv deleted successfully.");
|
||||
// Get all files in the directory
|
||||
File[] files = directory.listFiles();
|
||||
|
||||
if (files != null) {
|
||||
// Iterate through each file in the directory
|
||||
for (File file : files) {
|
||||
// Deletes the file
|
||||
if (file.delete()) {
|
||||
Log.d("CSVDelete", file.getName() + " deleted successfully.");
|
||||
} else {
|
||||
Log.d("CSVDelete", "Failed to delete match_data.csv.");
|
||||
Log.d("CSVDelete", "Failed to delete " + file.getName());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.d("CSVDelete", "match_data.csv does not exist.");
|
||||
Log.d("CSVDelete", "No files found in the directory.");
|
||||
}
|
||||
}
|
||||
public void renameFile(Context context, String csvFileString){
|
||||
File csvFile = new File(context.getFilesDir(), csvFileString + ".csv");
|
||||
|
||||
// Then perform renaming
|
||||
File newFile = new File(context.getFilesDir(), csvFileString+".csv");
|
||||
|
||||
if (csvFile.renameTo(newFile)) {
|
||||
Log.d("CSVRename", "File renamed successfully to: " + newFile.getAbsolutePath());
|
||||
} else {
|
||||
Log.d("CSVRenameFail", "File renaming failed.");
|
||||
}
|
||||
|
||||
// Define the new file name
|
||||
File renamedFile = new File(context.getFilesDir(), "old"+csvFileString+".csv");
|
||||
|
||||
// Rename the original file
|
||||
if (csvFile.renameTo(newFile)) {
|
||||
Log.d("CSVRename", "File renamed successfully to: " + renamedFile.getAbsolutePath());
|
||||
} else {
|
||||
Log.d("CSVRenameFail", "File renaming failed.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TeleActivity extends AppCompatActivity {
|
||||
private String tele = "Teleop";
|
||||
private int l4Scored = 0;
|
||||
private int l3Scored = 0;
|
||||
private int l2Scored = 0;
|
||||
@ -36,6 +37,9 @@ public class TeleActivity extends AppCompatActivity {
|
||||
private TextView l1TV;
|
||||
private TextView processorTV;
|
||||
private TextView netTV;
|
||||
private String eventString, matchString;
|
||||
public static final String Event_Key = "EVENTCONFIRM";
|
||||
public static final String Match_key = "MATCHCONFIRM";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -47,6 +51,9 @@ public class TeleActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
Intent intentinput = getIntent();
|
||||
eventString = intentinput.getStringExtra(AutoActivity.Event_Key);
|
||||
matchString = intentinput.getStringExtra(AutoActivity.Match_key);
|
||||
|
||||
Button l4Button = (Button) findViewById(R.id.button_L4);
|
||||
Button l3Button = (Button) findViewById(R.id.button_L3);
|
||||
@ -139,6 +146,8 @@ public class TeleActivity extends AppCompatActivity {
|
||||
//submit data
|
||||
csvMake();
|
||||
Intent intent = new Intent(this, EndActivity.class);
|
||||
intent.putExtra(Event_Key, eventString);
|
||||
intent.putExtra(Match_key, matchString);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
@ -180,7 +189,8 @@ public class TeleActivity extends AppCompatActivity {
|
||||
public void csvMake() {
|
||||
//adds the strings
|
||||
String CSVLine = String.format(
|
||||
"%s %s %s %s %s %s %s %s %s",
|
||||
"%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
|
||||
tele,
|
||||
l4Scored,
|
||||
l3Scored,
|
||||
l2Scored,
|
||||
@ -192,7 +202,8 @@ public class TeleActivity extends AppCompatActivity {
|
||||
coralPickup
|
||||
);
|
||||
//makes the file
|
||||
File csvFile = new File(this.getFilesDir(), "match_data.csv");
|
||||
File csvFile = new File(this.getFilesDir(), eventString+".csv");
|
||||
Log.d("CSVFile", "File created/written at: " + csvFile.getAbsolutePath());
|
||||
//writes to file
|
||||
try (FileWriter writer = new FileWriter(csvFile, true)) {
|
||||
writer.append(CSVLine).append("\n");
|
||||
|
Loading…
Reference in New Issue
Block a user