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 {
|
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 Event_Key = "EVENTCONFIRM";
|
||||||
public static final String Match_key = "MATCHCONFIRM";
|
public static final String Match_key = "MATCHCONFIRM";
|
||||||
|
|
||||||
@ -41,21 +41,23 @@ public class EndActivity extends AppCompatActivity {
|
|||||||
return insets;
|
return insets;
|
||||||
});
|
});
|
||||||
Intent intentinput = getIntent();
|
Intent intentinput = getIntent();
|
||||||
eventString = intentinput.getStringExtra(AutoActivity.Event_Key);
|
eventString = intentinput.getStringExtra(TeleActivity.Event_Key);
|
||||||
matchString = intentinput.getStringExtra(AutoActivity.Match_key);
|
matchString = intentinput.getStringExtra(TeleActivity.Match_key);
|
||||||
|
TeamString = intentinput.getStringExtra(TeleActivity.Team_key);
|
||||||
|
|
||||||
Button submit = (Button) findViewById(R.id.Submit_button);
|
Button submit = (Button) findViewById(R.id.Submit_button);
|
||||||
submit.setOnClickListener(new View.OnClickListener() {
|
submit.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
String csvFileString = eventString+".csv";
|
String csvFileString = eventString+matchString+TeamString+".csv";
|
||||||
Submit submit = new Submit();
|
Submit submit = new Submit();
|
||||||
//Writes data to file to make google sheet read it as a list
|
//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);
|
List<List<Object>> data = submit.parseCSVToList(csvFilefile);
|
||||||
submit.parseCSVToList(csvFilefile);
|
submit.parseCSVToList(csvFilefile);
|
||||||
//Uploads the Data to the Google sheet
|
//Uploads the Data to the Google sheet
|
||||||
submit.uploadSheets(EndActivity.this, csvFileString);
|
submit.uploadSheets(EndActivity.this, csvFileString);
|
||||||
submit.renameFile(EndActivity.this, eventString);
|
//submit.renameFile(EndActivity.this, csvFileString);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package com.example.scoutingapp;
|
package com.example.scoutingapp;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import static java.sql.DriverManager.println;
|
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@ -21,21 +19,21 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import okhttp3.Call;
|
|
||||||
import okhttp3.Callback;
|
|
||||||
import okhttp3.Headers;
|
import okhttp3.Headers;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
private EditText Match_number;
|
private EditText Match_number;
|
||||||
private EditText Event;
|
private EditText Event;
|
||||||
|
private EditText Team;
|
||||||
private String Match_numberString;
|
private String Match_numberString;
|
||||||
private String EventString;
|
private String EventString;
|
||||||
|
private String TeamString;
|
||||||
public static final String Event_Key = "EVENTCONFIRM";
|
public static final String Event_Key = "EVENTCONFIRM";
|
||||||
public static final String Match_key = "MATCHCONFIRM";
|
public static final String Match_key = "MATCHCONFIRM";
|
||||||
|
public static final String Team_key = "TEAMCONFIRM";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -50,16 +48,28 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
Match_number = (EditText) findViewById(R.id.Match);
|
Match_number = (EditText) findViewById(R.id.Match);
|
||||||
Event = (EditText) findViewById(R.id.Event);
|
Event = (EditText) findViewById(R.id.Event);
|
||||||
|
Team = (EditText) findViewById(R.id.TeamNumber);
|
||||||
Button nextButton = (Button) findViewById(R.id.nextButton);
|
Button nextButton = (Button) findViewById(R.id.nextButton);
|
||||||
nextButton.setOnClickListener(new View.OnClickListener() {
|
nextButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
Submit submit = new Submit();
|
||||||
|
submit.renameFileagain(MainActivity.this, "unuploaded.csv");
|
||||||
Match_numberString = Match_number.getText().toString();
|
Match_numberString = Match_number.getText().toString();
|
||||||
EventString = Event.getText().toString();
|
EventString = Event.getText().toString();
|
||||||
|
TeamString = Team.getText().toString();
|
||||||
makeIntent();
|
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);
|
TextView TBAView = (TextView)findViewById(R.id.TBATest);
|
||||||
}
|
}
|
||||||
@ -106,6 +116,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
Intent intent = new Intent(this, AutoActivity.class);
|
Intent intent = new Intent(this, AutoActivity.class);
|
||||||
intent.putExtra(Event_Key, EventString);
|
intent.putExtra(Event_Key, EventString);
|
||||||
intent.putExtra(Match_key, Match_numberString);
|
intent.putExtra(Match_key, Match_numberString);
|
||||||
|
intent.putExtra(Team_key, TeamString);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -47,7 +47,7 @@ public class Submit {
|
|||||||
//data for the sheet API
|
//data for the sheet API
|
||||||
ValueRange body = new ValueRange().setValues(data);
|
ValueRange body = new ValueRange().setValues(data);
|
||||||
//the ID for the google sheet
|
//the ID for the google sheet
|
||||||
String spreadsheetId = "1WqULxMRuXV97sUy01hdy8hiDIud1M4j5oNpWWHDsvcI";
|
String spreadsheetId = "1ky5LBTpnEeBEEaaF7z6UWdh-E7YmOSeij4dYdR2PU4A";
|
||||||
//starting point
|
//starting point
|
||||||
String range = "Sheet1!a2:O2";
|
String range = "Sheet1!a2:O2";
|
||||||
//inserts data to the sheet
|
//inserts data to the sheet
|
||||||
@ -60,16 +60,26 @@ public class Submit {
|
|||||||
Log.d("GoogleSheets", "Data uploaded to Google Sheets successfully.");
|
Log.d("GoogleSheets", "Data uploaded to Google Sheets successfully.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d("GoogleSheets", "Error uploading data", e);
|
Log.d("GoogleSheets", "Error uploading data", e);
|
||||||
|
renameFile(context, csvFileString);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<List<Object>> parseCSVToList(File csvFile) {
|
List<List<Object>> parseCSVToList(File csvFile) {
|
||||||
//makes A array
|
|
||||||
List<List<Object>> data = Lists.newArrayList();
|
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;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void deleteCSVFile(Context context) {
|
public void deleteCSVFile(Context context) {
|
||||||
// Get the directory containing the files
|
// Get the directory containing the files
|
||||||
File directory = context.getFilesDir();
|
File directory = context.getFilesDir();
|
||||||
@ -91,27 +101,38 @@ public class Submit {
|
|||||||
Log.d("CSVDelete", "No files found in the directory.");
|
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
|
public void renameFile(Context context, String csvFileString) {
|
||||||
File newFile = new File(context.getFilesDir(), csvFileString+".csv");
|
File csvFile = new File(context.getFilesDir(), csvFileString);
|
||||||
|
|
||||||
if (csvFile.renameTo(newFile)) {
|
if (!csvFile.exists()) {
|
||||||
Log.d("CSVRename", "File renamed successfully to: " + newFile.getAbsolutePath());
|
Log.d("CSVRenameFail", "File does not exist: " + csvFile.getAbsolutePath());
|
||||||
} else {
|
return;
|
||||||
Log.d("CSVRenameFail", "File renaming failed.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the new file name
|
File renamedFile = new File(context.getFilesDir(), "unuploaded.csv");
|
||||||
File renamedFile = new File(context.getFilesDir(), "old"+csvFileString+".csv");
|
|
||||||
|
|
||||||
// Rename the original file
|
if (csvFile.renameTo(renamedFile)) {
|
||||||
if (csvFile.renameTo(newFile)) {
|
|
||||||
Log.d("CSVRename", "File renamed successfully to: " + renamedFile.getAbsolutePath());
|
Log.d("CSVRename", "File renamed successfully to: " + renamedFile.getAbsolutePath());
|
||||||
} else {
|
} 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