Made a Fail safe so you can upload later
This commit is contained in:
parent
cebee81e39
commit
fae1eb8c8b
@ -26,7 +26,7 @@ import java.io.File;
|
||||
|
||||
|
||||
public class EndActivity extends AppCompatActivity {
|
||||
private String eventString, matchString;
|
||||
private String eventString, matchString, TeamString;
|
||||
public static final String Event_Key = "EVENTCONFIRM";
|
||||
public static final String Match_key = "MATCHCONFIRM";
|
||||
|
||||
@ -41,21 +41,23 @@ public class EndActivity extends AppCompatActivity {
|
||||
return insets;
|
||||
});
|
||||
Intent intentinput = getIntent();
|
||||
eventString = intentinput.getStringExtra(AutoActivity.Event_Key);
|
||||
matchString = intentinput.getStringExtra(AutoActivity.Match_key);
|
||||
eventString = intentinput.getStringExtra(TeleActivity.Event_Key);
|
||||
matchString = intentinput.getStringExtra(TeleActivity.Match_key);
|
||||
TeamString = intentinput.getStringExtra(TeleActivity.Team_key);
|
||||
|
||||
Button submit = (Button) findViewById(R.id.Submit_button);
|
||||
submit.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
public void onClick(View view) {
|
||||
String csvFileString = eventString+".csv";
|
||||
String csvFileString = eventString+matchString+TeamString+".csv";
|
||||
Submit submit = new Submit();
|
||||
//Writes data to file to make google sheet read it as a list
|
||||
File csvFilefile = new File(getFilesDir(), "csvFileString");
|
||||
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, csvFileString);
|
||||
submit.renameFile(EndActivity.this, eventString);
|
||||
//submit.renameFile(EndActivity.this, csvFileString);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.example.scoutingapp;
|
||||
|
||||
import android.content.Intent;
|
||||
import static java.sql.DriverManager.println;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
@ -21,21 +19,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 EditText Team;
|
||||
private String Match_numberString;
|
||||
private String EventString;
|
||||
private String TeamString;
|
||||
public static final String Event_Key = "EVENTCONFIRM";
|
||||
public static final String Match_key = "MATCHCONFIRM";
|
||||
public static final String Team_key = "TEAMCONFIRM";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -50,16 +48,28 @@ public class MainActivity extends AppCompatActivity {
|
||||
});
|
||||
Match_number = (EditText) findViewById(R.id.Match);
|
||||
Event = (EditText) findViewById(R.id.Event);
|
||||
Team = (EditText) findViewById(R.id.TeamNumber);
|
||||
Button nextButton = (Button) findViewById(R.id.nextButton);
|
||||
nextButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Submit submit = new Submit();
|
||||
submit.renameFileagain(MainActivity.this, "unuploaded.csv");
|
||||
Match_numberString = Match_number.getText().toString();
|
||||
EventString = Event.getText().toString();
|
||||
TeamString = Team.getText().toString();
|
||||
makeIntent();
|
||||
}
|
||||
|
||||
});
|
||||
Button submit = (Button) findViewById(R.id.Submit_button);
|
||||
submit.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
public void onClick(View view) {
|
||||
Submit submit = new Submit();
|
||||
submit.uploadSheets(MainActivity.this, "unuploaded.csv");
|
||||
}
|
||||
});
|
||||
|
||||
TextView TBAView = (TextView)findViewById(R.id.TBATest);
|
||||
}
|
||||
@ -106,6 +116,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
Intent intent = new Intent(this, AutoActivity.class);
|
||||
intent.putExtra(Event_Key, EventString);
|
||||
intent.putExtra(Match_key, Match_numberString);
|
||||
intent.putExtra(Team_key, TeamString);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
@ -47,7 +47,7 @@ public class Submit {
|
||||
//data for the sheet API
|
||||
ValueRange body = new ValueRange().setValues(data);
|
||||
//the ID for the google sheet
|
||||
String spreadsheetId = "1WqULxMRuXV97sUy01hdy8hiDIud1M4j5oNpWWHDsvcI";
|
||||
String spreadsheetId = "1ky5LBTpnEeBEEaaF7z6UWdh-E7YmOSeij4dYdR2PU4A";
|
||||
//starting point
|
||||
String range = "Sheet1!a2:O2";
|
||||
//inserts data to the sheet
|
||||
@ -60,16 +60,26 @@ public class Submit {
|
||||
Log.d("GoogleSheets", "Data uploaded to Google Sheets successfully.");
|
||||
} catch (Exception e) {
|
||||
Log.d("GoogleSheets", "Error uploading data", e);
|
||||
renameFile(context, csvFileString);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
List<List<Object>> parseCSVToList(File csvFile) {
|
||||
//makes A array
|
||||
List<List<Object>> data = Lists.newArrayList();
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] values = line.split(","); // Assuming CSV is comma-separated
|
||||
data.add(Arrays.asList((Object[]) values));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.d("CSVError", "Error reading CSV file", e);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
public void deleteCSVFile(Context context) {
|
||||
// Get the directory containing the files
|
||||
File directory = context.getFilesDir();
|
||||
@ -91,27 +101,38 @@ public class Submit {
|
||||
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");
|
||||
public void renameFile(Context context, String csvFileString) {
|
||||
File csvFile = new File(context.getFilesDir(), csvFileString);
|
||||
|
||||
if (csvFile.renameTo(newFile)) {
|
||||
Log.d("CSVRename", "File renamed successfully to: " + newFile.getAbsolutePath());
|
||||
} else {
|
||||
Log.d("CSVRenameFail", "File renaming failed.");
|
||||
if (!csvFile.exists()) {
|
||||
Log.d("CSVRenameFail", "File does not exist: " + csvFile.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
|
||||
// Define the new file name
|
||||
File renamedFile = new File(context.getFilesDir(), "old"+csvFileString+".csv");
|
||||
File renamedFile = new File(context.getFilesDir(), "unuploaded.csv");
|
||||
|
||||
// Rename the original file
|
||||
if (csvFile.renameTo(newFile)) {
|
||||
if (csvFile.renameTo(renamedFile)) {
|
||||
Log.d("CSVRename", "File renamed successfully to: " + renamedFile.getAbsolutePath());
|
||||
} else {
|
||||
Log.d("CSVRenameFail", "File renaming failed.");
|
||||
Log.d("CSVRenameFail", "File renaming failed. Possible reasons: file is in use, permission issue, or incorrect file path.");
|
||||
}
|
||||
}
|
||||
|
||||
public void renameFileagain(Context context, String csvFileString) {
|
||||
File csvFile = new File(context.getFilesDir(), csvFileString);
|
||||
|
||||
if (!csvFile.exists()) {
|
||||
Log.d("CSVRenameFail", "File does not exist: " + csvFile.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
|
||||
File renamedFile = new File(context.getFilesDir(), "uploaded.csv");
|
||||
|
||||
if (csvFile.renameTo(renamedFile)) {
|
||||
Log.d("CSVRename", "File renamed successfully to: " + renamedFile.getAbsolutePath());
|
||||
} else {
|
||||
Log.d("CSVRenameFail", "File renaming failed. Possible reasons: file is in use, permission issue, or incorrect file path.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user