need to pull
This commit is contained in:
commit
0e35c000a5
@ -36,10 +36,11 @@ public class AutoActivity extends AppCompatActivity {
|
||||
private Button l1Button;
|
||||
private Button processorButton;
|
||||
private Button netButton;
|
||||
private String eventString, matchString, TeamString;
|
||||
private String eventString, matchString, TeamString, startingPostionString;
|
||||
public static final String Event_Key = "EVENTCONFIRM";
|
||||
public static final String Match_key = "MATCHCONFIRM";
|
||||
public static final String Team_key = "TEAMCONFIRM";
|
||||
public static final String Postion_key = "POSTIONKEY";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -55,6 +56,7 @@ public class AutoActivity extends AppCompatActivity {
|
||||
eventString = intentinput.getStringExtra(MainActivity.Event_Key);
|
||||
matchString = intentinput.getStringExtra(MainActivity.Match_key);
|
||||
TeamString = intentinput.getStringExtra(MainActivity.Team_key);
|
||||
startingPostionString = intentinput.getStringExtra(MainActivity.Postion_key);
|
||||
|
||||
|
||||
l4Button = (Button) findViewById(R.id.button_L4);
|
||||
@ -144,6 +146,7 @@ public class AutoActivity extends AppCompatActivity {
|
||||
intent.putExtra(Event_Key, eventString);
|
||||
intent.putExtra(Match_key, matchString);
|
||||
intent.putExtra(Team_key, TeamString);
|
||||
intent.putExtra(Postion_key, startingPostionString);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
|
@ -7,7 +7,9 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.annotation.NonNull;
|
||||
@ -36,6 +38,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
private String Match_numberString;
|
||||
private String EventString;
|
||||
private String TeamString;
|
||||
private String startingPostionString;
|
||||
public static final String Postion_key = "POSTIONKEY";
|
||||
public static final String Event_Key = "EVENTCONFIRM";
|
||||
public static final String Match_key = "MATCHCONFIRM";
|
||||
public static final String Team_key = "TEAMCONFIRM";
|
||||
@ -61,13 +65,18 @@ public class MainActivity extends AppCompatActivity {
|
||||
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();
|
||||
if ((Match_numberString == null || Match_numberString.isEmpty()) ||
|
||||
(EventString == null || EventString.isEmpty()) ||
|
||||
(TeamString == null || TeamString.isEmpty()) ||
|
||||
(startingPostionString == null || startingPostionString.isEmpty())){
|
||||
Toast.makeText(getApplicationContext(), "Fill in EVERYTHING", Toast.LENGTH_SHORT).show();
|
||||
}else {
|
||||
makeIntent();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
Button submit = (Button) findViewById(R.id.Submit_button);
|
||||
@ -75,7 +84,43 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public void onClick(View view) {
|
||||
Submit submit = new Submit();
|
||||
submit.uploadSheets(MainActivity.this, "unuploaded.csv");
|
||||
submit.uploadSheets(MainActivity.this, EventString+Match_number+TeamString+".csv");
|
||||
}
|
||||
});
|
||||
|
||||
RadioButton Rbutton1 = findViewById(R.id.Rbutton1);
|
||||
Rbutton1.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startingPostionString = "1";
|
||||
}
|
||||
});
|
||||
RadioButton Rbutton2 = findViewById(R.id.Rbutton2);
|
||||
Rbutton2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startingPostionString = "2";
|
||||
}
|
||||
});
|
||||
RadioButton Rbutton3 = findViewById(R.id.Rbutton3);
|
||||
Rbutton3.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startingPostionString = "3";
|
||||
}
|
||||
});
|
||||
RadioButton Rbutton4 = findViewById(R.id.Rbutton4);
|
||||
Rbutton4.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startingPostionString = "4";
|
||||
}
|
||||
});
|
||||
RadioButton Rbutton5 = findViewById(R.id.Rbutton5);
|
||||
Rbutton5.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startingPostionString = "5";
|
||||
}
|
||||
});
|
||||
|
||||
@ -154,14 +199,18 @@ 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);
|
||||
intent.putExtra(Team_key, TeamString);
|
||||
intent.putExtra(Postion_key, startingPostionString);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
@ -2,7 +2,12 @@ package com.example.scoutingapp;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
@ -24,6 +29,13 @@ import java.util.List;
|
||||
public class Submit {
|
||||
|
||||
void uploadSheets(Context context, String csvFileString) {
|
||||
if (!isWifiConnected(context)) {
|
||||
Log.e("NetworkError", "No Wi-Fi connection. Cannot upload.");
|
||||
Toast.makeText(context, "upload failed, Upload later", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
//adds account info
|
||||
@ -58,10 +70,9 @@ public class Submit {
|
||||
.execute();
|
||||
|
||||
Log.d("GoogleSheets", "Data uploaded to Google Sheets successfully.");
|
||||
deleteCSVFile(context);
|
||||
deleteCSVFile(context, csvFileString);
|
||||
} catch (Exception e) {
|
||||
Log.d("GoogleSheets", "Error uploading data", e);
|
||||
renameFile(context, csvFileString);
|
||||
Log.e("GoogleSheetFailed", "Failed to upload");
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
@ -81,7 +92,7 @@ public class Submit {
|
||||
}
|
||||
|
||||
|
||||
public void deleteCSVFile(Context context) {
|
||||
public void deleteCSVFile(Context context, String csvFileString) {
|
||||
// Get the directory containing the files
|
||||
File directory = context.getFilesDir();
|
||||
|
||||
@ -89,20 +100,24 @@ public class Submit {
|
||||
File[] files = directory.listFiles();
|
||||
|
||||
if (files != null) {
|
||||
// Iterate through each file in the directory
|
||||
for (File file : files) {
|
||||
// Deletes the file
|
||||
// Check if the file name matches the given string
|
||||
if (file.getName().equals(csvFileString)) {
|
||||
if (file.delete()) {
|
||||
Log.d("CSVDelete", file.getName() + " deleted successfully.");
|
||||
} else {
|
||||
Log.d("CSVDelete", "Failed to delete " + file.getName());
|
||||
}
|
||||
return; // Exit after deleting the file
|
||||
}
|
||||
}
|
||||
Log.d("CSVDelete", "File " + csvFileString + " not found.");
|
||||
} else {
|
||||
Log.d("CSVDelete", "No files found in the directory.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void renameFile(Context context, String csvFileString) {
|
||||
File csvFile = new File(context.getFilesDir(), csvFileString);
|
||||
|
||||
@ -111,7 +126,7 @@ public class Submit {
|
||||
return;
|
||||
}
|
||||
|
||||
File renamedFile = new File(context.getFilesDir(), "unuploaded.csv");
|
||||
File renamedFile = new File(context.getFilesDir(), csvFileString);
|
||||
|
||||
if (csvFile.renameTo(renamedFile)) {
|
||||
Log.d("CSVRename", "File renamed successfully to: " + renamedFile.getAbsolutePath());
|
||||
@ -136,4 +151,16 @@ public class Submit {
|
||||
Log.d("CSVRenameFail", "File renaming failed. Possible reasons: file is in use, permission issue, or incorrect file path.");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWifiConnected(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
if (cm != null) {
|
||||
android.net.Network network = cm.getActiveNetwork();
|
||||
if (network == null) return false;
|
||||
NetworkCapabilities capabilities = cm.getNetworkCapabilities(network);
|
||||
return capabilities != null && capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -36,10 +36,11 @@ public class TeleActivity extends AppCompatActivity {
|
||||
private Button l1Button;
|
||||
private Button processorButton;
|
||||
private Button netButton;
|
||||
private String eventString, matchString, TeamString;
|
||||
private String eventString, matchString, TeamString, startingPostionString;
|
||||
public static final String Event_Key = "EVENTCONFIRM";
|
||||
public static final String Match_key = "MATCHCONFIRM";
|
||||
public static final String Team_key = "TEAMCONFIRM";
|
||||
public static final String Postion_key = "POSTIONKEY";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -55,6 +56,8 @@ public class TeleActivity extends AppCompatActivity {
|
||||
eventString = intentinput.getStringExtra(AutoActivity.Event_Key);
|
||||
matchString = intentinput.getStringExtra(AutoActivity.Match_key);
|
||||
TeamString = intentinput.getStringExtra(AutoActivity.Team_key);
|
||||
startingPostionString = intentinput.getStringExtra(AutoActivity.Postion_key);
|
||||
|
||||
|
||||
l4Button = (Button) findViewById(R.id.button_L4);
|
||||
l3Button = (Button) findViewById(R.id.button_L3);
|
||||
@ -184,7 +187,7 @@ public class TeleActivity extends AppCompatActivity {
|
||||
public void csvMake() {
|
||||
//adds the strings
|
||||
String CSVLine = String.format(
|
||||
"Tele,%s,%s,%s,%s,%s,%s,%s,%s,%s",
|
||||
"Tele,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
|
||||
l4Scored,
|
||||
l3Scored,
|
||||
l2Scored,
|
||||
@ -193,7 +196,8 @@ public class TeleActivity extends AppCompatActivity {
|
||||
netScored,
|
||||
reefPickup,
|
||||
canLeave,
|
||||
coralPickup
|
||||
coralPickup,
|
||||
startingPostionString
|
||||
);
|
||||
|
||||
//makes the file
|
||||
|
@ -89,17 +89,65 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Team number"
|
||||
app:layout_constraintBottom_toTopOf="@+id/textInputLayout2"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textInputLayout3"
|
||||
tools:layout_editor_absoluteX="-16dp" />
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/textInputLayout" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/Submit_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Submit"
|
||||
android:text="Submit Unuploaded data"
|
||||
app:layout_constraintBottom_toTopOf="@+id/nextButton"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textInputLayout2" />
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="100dp"
|
||||
android:layout_marginEnd="100dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/nextButton" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/nextButton">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/Rbutton1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Starting Postion 1" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/Rbutton2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Starting Postion 2" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/Rbutton3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Starting Postion 3" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/Rbutton4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Starting Postion 4" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/Rbutton5"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Starting Postion 5" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/Explain"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="98dp"
|
||||
android:text="To upload old data enter the Info at the top, and it is case sentitive" />
|
||||
</RadioGroup>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue
Block a user