Make settings better, work on ftp transfer

This commit is contained in:
Astatin3
2024-10-05 18:47:36 -06:00
parent 2b753fcdb4
commit 03a1507ce2
15 changed files with 467 additions and 393 deletions
@@ -55,10 +55,8 @@ public class FieldsFragment extends Fragment {
@Nullable Bundle savedInstanceState) {
binding = FragmentDataFieldsBinding.inflate(inflater, container, false);
binding.revertVersionButton.setVisibility(View.VISIBLE);
binding.valueEditScrollview.setOnTouchListener((v, event) -> true);
binding.saveButton.setVisibility(View.GONE);
binding.cancelEditButton.setVisibility(View.GONE);
binding.editButton.setVisibility(View.GONE);
@@ -124,6 +122,25 @@ public class FieldsFragment extends Fragment {
tr.setBackgroundColor(unfocused_background_color);
}
}
if(values.length > 1) {
binding.revertVersionButton.setVisibility(View.VISIBLE);
binding.revertVersionButton.setOnClickListener(v -> {
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
alert.setTitle("Warning!");
alert.setMessage("If there is any data set this version, it will be deleted!");
alert.setPositiveButton("OK", (dialog, which) -> {
inputType[][] newArr = new inputType[values.length - 1][];
System.arraycopy(values, 0, newArr, 0, values.length - 1);
if(fields.save(filename, newArr))
AlertManager.toast("Saved");
load_field_menu();
});
alert.setNegativeButton("Cancel", null);
alert.setCancelable(true);
alert.create().show();
});
}
}
private void display_fields(inputType[] version_values) {
@@ -182,10 +199,7 @@ public class FieldsFragment extends Fragment {
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
alert.setTitle("Warning!");
alert.setMessage("Changing or removing some values will result in lost data!\nBut this will create a new field version, and you can revert at any time.");
alert.setPositiveButton("OK", null);
alert.setNegativeButton("Cancel", null);
alert.setCancelable(true);
alert.setOnDismissListener(b -> {
alert.setPositiveButton("OK", (dialog, which) -> {
inputType[][] currentValues = fields.load(filename);
assert currentValues != null;
inputType[][] newValues = new inputType[currentValues.length+1][];
@@ -198,11 +212,13 @@ public class FieldsFragment extends Fragment {
}
// newValues[newValues.length-1] = values[values.length-1];
boolean saved = fields.save(filename, newValues);
AlertManager.alert("Saved", String.valueOf(saved));
if(fields.save(filename, newValues))
AlertManager.toast("Saved");
Navigation.findNavController((Activity) getContext(), R.id.nav_host_fragment_activity_main).navigate(R.id.action_navigation_data_fields_to_navigation_data_fields_chooser);
});
alert.setNegativeButton("Cancel", null);
alert.setCancelable(true);
alert.create().show();
}
@@ -503,7 +519,7 @@ public class FieldsFragment extends Fragment {
newValues[newValues.length-1] = field;
values[values.length-1] = newValues;
AlertManager.alert("Test", String.valueOf(binding.fieldsArea.getReorderedIndexes()));
// AlertManager.alert("Test", String.valueOf(binding.fieldsArea.getReorderedIndexes()));
//TableRow tr = getTableRow(field);
//binding.fieldsArea.addView(tr);
@@ -310,8 +310,14 @@ public class MatchScoutingFragment extends Fragment {
default_fields();
set_indicator_color(unsaved_color);
}else{
get_fields();
set_indicator_color(saved_color);
try {
get_fields();
set_indicator_color(saved_color);
} catch (Exception e){
AlertManager.error(e);
default_fields();
set_indicator_color(unsaved_color);
}
}
asm.start();
@@ -119,8 +119,14 @@ public class PitScoutingFragment extends Fragment {
default_fields();
set_indicator_color(unsaved_color);
}else{
get_fields();
set_indicator_color(saved_color);
try {
get_fields();
set_indicator_color(saved_color);
} catch (Exception e){
AlertManager.error(e);
default_fields();
set_indicator_color(unsaved_color);
}
}
asm.start();
@@ -1,9 +1,22 @@
package com.ridgebotics.ridgescout.ui.settings;
import static android.text.InputType.TYPE_CLASS_NUMBER;
import static com.ridgebotics.ridgescout.utility.settingsManager.AllyPosKey;
import static com.ridgebotics.ridgescout.utility.settingsManager.FTPEnabled;
import static com.ridgebotics.ridgescout.utility.settingsManager.FTPServer;
import static com.ridgebotics.ridgescout.utility.settingsManager.SelEVCodeKey;
import static com.ridgebotics.ridgescout.utility.settingsManager.TeamNumKey;
import static com.ridgebotics.ridgescout.utility.settingsManager.UnameKey;
import static com.ridgebotics.ridgescout.utility.settingsManager.WifiModeKey;
import static com.ridgebotics.ridgescout.utility.settingsManager.defaults;
import static com.ridgebotics.ridgescout.utility.settingsManager.getEditor;
import static com.ridgebotics.ridgescout.utility.settingsManager.prefs;
import android.app.AlertDialog;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -13,11 +26,14 @@ import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TableRow;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.google.android.material.divider.MaterialDivider;
import com.ridgebotics.ridgescout.databinding.FragmentSettingsBinding;
import com.ridgebotics.ridgescout.types.data.intType;
import com.ridgebotics.ridgescout.utility.fileEditor;
@@ -27,9 +43,14 @@ import com.skydoves.powerspinner.IconSpinnerAdapter;
import com.skydoves.powerspinner.IconSpinnerItem;
import com.skydoves.powerspinner.OnSpinnerItemSelectedListener;
import com.skydoves.powerspinner.PowerSpinnerView;
import com.skydoves.powerspinner.SpinnerGravity;
import org.checkerframework.checker.units.qual.C;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class settingsFragment extends Fragment {
@@ -37,9 +58,21 @@ public class settingsFragment extends Fragment {
private android.widget.ScrollView ScrollArea;
private android.widget.TableLayout Table;
private void setDropdownItems(Spinner dropdown, String[] items){
ArrayAdapter<String> adapter = new ArrayAdapter<>(requireActivity(), android.R.layout.simple_spinner_item, items);
dropdown.setAdapter(adapter);
// private void setDropdownItems(Spinner dropdown, String[] items){
// ArrayAdapter<String> adapter = new ArrayAdapter<>(requireActivity(), android.R.layout.simple_spinner_item, items);
// dropdown.setAdapter(adapter);
// }
private View[] concatArrays(View[] a, View[] b){
return Stream.of(a, b).flatMap(Stream::of).toArray(View[]::new);
}
private View[] addViews(View[] a){
for(int i = 0; i < a.length; i++){
binding.SettingsTable.addView(a[i]);
}
return a;
}
private int safeToInt(String num){
@@ -52,6 +85,144 @@ public class settingsFragment extends Fragment {
}
}
private View[] createHeading(String name){
TextView tv = new TextView(getContext());
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
TableRow.LayoutParams params = new TableRow.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
params.topMargin = 100;
tv.setLayoutParams(params);
tv.setTextSize(20);
tv.setText(name);
View divider = new MaterialDivider(getContext());
return new View[]{tv, divider};
}
private View[] addStringEdit(String name, String key){
View[] heading = createHeading(name);
EditText et = new EditText(getContext());
et.setText(prefs.getString(key, (String) defaults.get(key)));
et.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
getEditor().putString(key, s.toString()).apply();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
return concatArrays(heading, new View[]{et});
}
private View[] addNumberEdit(String name, String key){
View[] heading = createHeading(name);
EditText et = new EditText(getContext());
et.setText(String.valueOf(prefs.getInt(key, (Integer) defaults.get(key))));
et.setInputType(TYPE_CLASS_NUMBER);
et.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
getEditor().putInt(key, safeToInt(s.toString())).apply();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
return concatArrays(heading, new View[]{et});
}
private PowerSpinnerView addDropdownEdit(String name, String[] options, String key){
PowerSpinnerView dropdown = new PowerSpinnerView(getContext());
List<IconSpinnerItem> iconSpinnerItems = new ArrayList<>();
for(int i = 0; i < options.length; i++){
iconSpinnerItems.add(new IconSpinnerItem(options[i]));
}
IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(dropdown);
dropdown.setGravity(Gravity.CENTER);
dropdown.setSpinnerAdapter(iconSpinnerAdapter);
dropdown.setItems(iconSpinnerItems);
dropdown.setHint("Unselected");
dropdown.setPadding(10,20,10,20);
dropdown.setBackgroundColor(0xf0000000);
dropdown.setTextColor(0xff00ff00);
dropdown.setTextSize(14.5f);
dropdown.setArrowGravity(SpinnerGravity.END);
dropdown.setArrowPadding(8);
dropdown.setSpinnerPopupElevation(14);
return dropdown;
}
private View[] addDropdownByString(String name, String[] options, String key){
View[] heading = createHeading(name);
PowerSpinnerView dropdown = addDropdownEdit(name, options, key);
int index = Arrays.asList(options).indexOf(prefs.getString(key, (String) defaults.get(key)));
System.out.println(index);
if(options.length != 0 && index != -1){
dropdown.selectItemByIndex(index);
}
dropdown.setOnSpinnerItemSelectedListener(
(OnSpinnerItemSelectedListener<IconSpinnerItem>)
(oldIndex, oldItem, newIndex, newItem) -> getEditor().putString(key, newItem.getText().toString()).apply()
);
return concatArrays(heading, new View[]{dropdown});
}
private View[] addDropdownByIndex(String name, String[] options, String key){
View[] heading = createHeading(name);
PowerSpinnerView dropdown = addDropdownEdit(name, options, key);
int index = prefs.getInt(key, (Integer) defaults.get(key));
if(dropdown.length() != 0 && index != -1){
dropdown.selectItemByIndex(index);
}
dropdown.setOnSpinnerItemSelectedListener(
(OnSpinnerItemSelectedListener<IconSpinnerItem>)
(oldIndex, oldItem, newIndex, newItem) -> getEditor().putInt(key, newIndex).apply()
);
return concatArrays(heading, new View[]{dropdown});
}
private View[] addCheckbox(String name, String key, View[] dependency){
CheckBox cb = new CheckBox(getContext());
cb.setText(name);
cb.setTextSize(22);
boolean checked = prefs.getBoolean(key, (Boolean) defaults.get(key));
cb.setChecked(checked);
if(dependency != null && !checked){
for(int i = 0; i < dependency.length; i++){
dependency[i].setVisibility(View.GONE);
}
}
cb.setOnCheckedChangeListener((buttonView, isChecked) -> {
getEditor().putBoolean(key, isChecked).apply();
if(dependency != null){
for(int i = 0; i < dependency.length; i++){
dependency[i].setVisibility(isChecked ? View.VISIBLE : View.GONE);
System.out.println(dependency[i]);
}
}
});
return new View[]{new MaterialDivider(getContext()), cb};
}
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
@@ -59,172 +230,19 @@ public class settingsFragment extends Fragment {
binding = FragmentSettingsBinding.inflate(inflater, container, false);
View root = binding.getRoot();
EditText username = binding.username;
username.setText(settingsManager.getUsername());
username.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
settingsManager.setUsername(username.getText().toString());
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
PowerSpinnerView spinnerView = binding.eventDropdown;
List<IconSpinnerItem> iconSpinnerItems = new ArrayList<>();
String target_event_name = settingsManager.getEVCode();
int target_index = -1;
ArrayList<String> evlist = fileEditor.getEventList();
for(int i = 0; i < evlist.size(); i++){
if(evlist.get(i).equals(target_event_name)){
target_index = i;
}
iconSpinnerItems.add(new IconSpinnerItem(evlist.get(i)));
}
IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(spinnerView);
spinnerView.setSpinnerAdapter(iconSpinnerAdapter);
spinnerView.setItems(iconSpinnerItems);
// spinnerView.setLifecycleOwner(this);
if(!iconSpinnerItems.isEmpty() && target_index != -1){
spinnerView.selectItemByIndex(target_index);
}
spinnerView.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener<IconSpinnerItem>() {
@Override
public void onItemSelected(int oldIndex, @Nullable IconSpinnerItem oldItem, int newIndex,
IconSpinnerItem newItem) {
settingsManager.setEVCode(newItem.getText().toString());
}
});
PowerSpinnerView alliance_pos_spinnerView = binding.alliancePosDropdown;
List<IconSpinnerItem> alliance_pos_iconSpinnerItems = new ArrayList<>();
String target_alliance_pos = settingsManager.getAllyPos();
int alliance_pos_target_index = -1;
String[] alliance_pos_list = new String[]{"red-1", "red-2", "red-3",
"blue-1", "blue-2", "blue-3"};
for(int i = 0; i < alliance_pos_list.length; i++){
if(alliance_pos_list[i].equals(target_alliance_pos)){
alliance_pos_target_index = i;
}
alliance_pos_iconSpinnerItems.add(new IconSpinnerItem(alliance_pos_list[i]));
}
addViews(addStringEdit("Username", UnameKey));
addViews(addDropdownByString("Event Code", fileEditor.getEventList().toArray(new String[0]), SelEVCodeKey));
addViews(addDropdownByString("Alliance Position", alliance_pos_list, AllyPosKey));
addViews(addNumberEdit("Team Number", TeamNumKey));
IconSpinnerAdapter alliance_pos_iconSpinnerAdapter = new IconSpinnerAdapter(alliance_pos_spinnerView);
alliance_pos_spinnerView.setSpinnerAdapter(alliance_pos_iconSpinnerAdapter);
alliance_pos_spinnerView.setItems(alliance_pos_iconSpinnerItems);
alliance_pos_spinnerView.setLifecycleOwner(this);
if(alliance_pos_target_index != -1){
alliance_pos_spinnerView.selectItemByIndex(alliance_pos_target_index);
}
alliance_pos_spinnerView.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener<IconSpinnerItem>() {
@Override
public void onItemSelected(int oldIndex, @Nullable IconSpinnerItem oldItem, int newIndex,
IconSpinnerItem newItem) {
settingsManager.setAllyPos(newItem.getText().toString());
}
});
//
// CheckBox practice_mode = binding.practiceMode;
// practice_mode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
// @Override
// public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
// latestSettings.settings.set_practice_mode(isChecked);
// }
//
// });
//
// practice_mode.setChecked(latestSettings.settings.get_practice_mode());
EditText team_num = binding.teamNumber;
team_num.setText(String.valueOf(settingsManager.getTeamNum()));
team_num.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
settingsManager.setTeamNum(safeToInt(team_num.getText().toString()));
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
CheckBox wifi_mode = binding.wifiMode;
wifi_mode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
settingsManager.setWifiMode(isChecked);
}
});
wifi_mode.setChecked(settingsManager.getWifiMode());
Button reset_button = binding.resetButton;
reset_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
alert.setTitle("Warning");
alert.setMessage("Do you really want to reset settings?");
alert.setCancelable(true);
alert.setPositiveButton("Ok", (dialog, which) -> {
settingsManager.resetSettings();
username.setText(settingsManager.getUsername());
spinnerView.clearSelectedItem();
// practice_mode.setChecked(latestSettings.settings.get_practice_mode());
wifi_mode.setChecked(settingsManager.getWifiMode());
alliance_pos_spinnerView.selectItemByIndex(0);
team_num.setText(String.valueOf(settingsManager.getTeamNum()));
});
alert.setNegativeButton("Cancel", null);
alert.create().show();
}
});
View[] FTPDependency = addStringEdit("FTP Server", FTPServer);
View[] WifiDependency = addCheckbox("FTP Enabled", FTPEnabled, FTPDependency);
addViews(addCheckbox("Wifi Mode", WifiModeKey, concatArrays(FTPDependency, WifiDependency)));
addViews(WifiDependency);
addViews(FTPDependency);
return root;
}
@@ -0,0 +1,166 @@
package com.ridgebotics.ridgescout.ui.transfer;
import static com.ridgebotics.ridgescout.utility.DataManager.evcode;
import static com.ridgebotics.ridgescout.utility.fileEditor.baseDir;
import android.content.Context;
import android.net.Uri;
import com.ridgebotics.ridgescout.utility.AlertManager;
import com.ridgebotics.ridgescout.utility.DataManager;
import com.ridgebotics.ridgescout.utility.fileEditor;
import com.ridgebotics.ridgescout.utility.settingsManager;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.checkerframework.checker.units.qual.C;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.InetAddress;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
public class FTPSync extends Thread {
private static final String remoteBasePath = "/RidgeScout/";
public interface onResult {
void onResult(boolean error);
}
public onResult onResult;
public static void sync(onResult onResult){
DataManager.reload_event();
FTPSync ftpSync = new FTPSync();
ftpSync.onResult = onResult;
ftpSync.start();
}
private class FileDate {
public String filename;
public Calendar lastModified;
}
public boolean sendFile(FTPClient ftpClient, String filename) throws Exception{
FileInputStream fin = new FileInputStream(baseDir + filename);
boolean worked = ftpClient.storeFile(remoteBasePath + filename, fin);
fin.close();
return worked;
}
public void run() {
try {
FTPClient ftpClient = new FTPClient();
InetAddress address = InetAddress.getByName(settingsManager.getFTPServer());
ftpClient.connect(address);
ftpClient.login("anonymous", null);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
// ftpClient.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE)
FTPFile[] remoteFilestmp = ftpClient.listFiles(remoteBasePath);
String[] localFilestmp = fileEditor.getEventFiles(evcode);
FileDate[] remoteFiles = new FileDate[remoteFilestmp.length];
for(int i = 0; i < remoteFilestmp.length; i++){
// System.out.println(remoteFilestmp[i].getName());
remoteFiles[i] = new FileDate();
remoteFiles[i].filename = remoteFilestmp[i].getName();
System.out.println(remoteFiles[i].filename);
remoteFiles[i].lastModified = remoteFilestmp[i].getTimestamp();
}
FileDate[] localFiles = new FileDate[localFilestmp.length];
for(int i = 0; i < localFilestmp.length; i++){
// sendFile(localFilestmp[i]);
String filename = "matches.fields";
File f = new File(baseDir + filename);
// File f = new File(baseDir + localFilestmp[i]);
// System.out.println(f.exists());
// FileInputStream fin = new FileInputStream(f);
// System.out.println(f.getName() + ", " + f.exists() + ", " + sendFile(ftpClient, f));
// fin.close();
// System.out.println(ftpClient.getStatus());
localFiles[i] = new FileDate();
localFiles[i].filename = localFilestmp[i];
localFiles[i].lastModified = fileEditor.getLastModified(localFilestmp[i]);
}
FileAction[] localActions = compareDates(localFiles, fd2map(remoteFiles), false);
System.out.println(localActions.length);
for(int i = 0 ; i < localActions.length; i++){
System.out.println(localActions[i].filename + ", " + localActions[i].action);
switch (localActions[i].action){
case SEND:
sendFile(ftpClient, localActions[i].filename);
fileEditor.setLastModified(localActions[i].filename, localActions[i].otherTimestamp);
break;
case RECIEVE:
break;
}
}
} catch (Exception e) {
AlertManager.error(e);
onResult.onResult(true);
AlertManager.toast("Error Syncing!");
}
// } finally {
// AlertManager.toast("Synced!");
// onResult.onResult(false);
// }
}
private Map<String, Calendar> fd2map(FileDate[] fdarr){
Map<String, Calendar> map = new HashMap<>();
for(int i = 0; i < fdarr.length; i++)
map.put(fdarr[i].filename, fdarr[i].lastModified);
return map;
}
private enum SyncAction {
SEND,
RECIEVE,
NONE
}
private class FileAction {
String filename;
SyncAction action;
Calendar otherTimestamp;
public FileAction(String filename, SyncAction action, Calendar otherTimestamp){
this.filename = filename;
this.action = action;
this.otherTimestamp = otherTimestamp;
}
}
private FileAction[] compareDates(FileDate[] files, Map<String, Calendar> refrence, boolean reverse){
FileAction[] actions = new FileAction[files.length];
for(int i = 0; i < files.length; i++){
Calendar ref = refrence.get(files[i].filename);
System.out.println(ref);
if(ref == null || files[i].lastModified.after(ref)) {
actions[i] = new FileAction(files[i].filename, !reverse ? SyncAction.SEND : SyncAction.RECIEVE, ref);
}else if(files[i].lastModified.before(ref)){
actions[i] = new FileAction(files[i].filename, !reverse ? SyncAction.RECIEVE : SyncAction.SEND, ref);
}else {
actions[i] = new FileAction(files[i].filename, SyncAction.NONE, ref);
}
}
return actions;
}
}
@@ -71,6 +71,7 @@ public class TransferFragment extends Fragment {
binding.uploadButton.setEnabled(false);
binding.CSVButton.setEnabled(false);
binding.downloadButton.setEnabled(true);
binding.SyncButton.setEnabled(false);
return binding.getRoot();
}
@@ -106,8 +107,19 @@ public class TransferFragment extends Fragment {
builder.show();
});
if(!settingsManager.getWifiMode())
if(!settingsManager.getWifiMode()) {
binding.TBAButton.setEnabled(false);
binding.SyncButton.setEnabled(false);
}
if(!settingsManager.getFTPEnabled()) {
binding.SyncButton.setEnabled(false);
}
binding.SyncButton.setOnClickListener(v -> {
binding.SyncButton.setEnabled(false);
FTPSync.sync(error -> getActivity().runOnUiThread(() -> binding.SyncButton.setEnabled(true)));
});
return binding.getRoot();
}
@@ -17,15 +17,17 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
public final class fileEditor {
private final static String baseDir = "/data/data/com.ridgebotics.ridgescout/";
public final static String baseDir = "/data/data/com.ridgebotics.ridgescout/";
public static final byte internalDataVersion = 0x01;
public static final int maxCompressedBlockSize = 4096;
@@ -43,7 +45,6 @@ public final class fileEditor {
}
public static char byteToChar(int num){
return new String(toBytes(num, 1), StandardCharsets.ISO_8859_1).charAt(0);
}
@@ -189,7 +190,22 @@ public final class fileEditor {
public static Calendar getLastModified(String filepath){
File f = new File(baseDir + filepath);
if(f.exists()){
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(f.lastModified());
return calendar;
}
return null;
}
public static void setLastModified(String filepath, Calendar calendar){
File f = new File(baseDir + filepath);
if(f.exists()){
f.setLastModified(calendar.getTimeInMillis());
}
}
@@ -19,6 +19,8 @@ public class settingsManager {
public static final String AllyPosKey = "alliance_pos";
public static final String DataModeKey = "data_view_mode";
public static final String BtUUIDKey = "bt_uuid";
public static final String FTPEnabled = "ftp_enabled";
public static final String FTPServer = "ftp_server";
public static Map defaults = getDefaults();
private static Map getDefaults(){
@@ -32,11 +34,13 @@ public class settingsManager {
hm.put(AllyPosKey, "red-1");
hm.put(DataModeKey, 0);
hm.put(BtUUIDKey, UUID.randomUUID().toString());
hm.put(FTPEnabled, false);
hm.put(FTPServer, "0.0.0.0");
return hm;
}
private static SharedPreferences.Editor getEditor(){
public static SharedPreferences.Editor getEditor(){
if(editor == null) editor = prefs.edit();
return editor;
}
@@ -45,11 +49,16 @@ public class settingsManager {
getEditor() .putString(UnameKey, (String) defaults.get( UnameKey )).apply();
getEditor() .putString(SelEVCodeKey,(String) defaults.get( SelEVCodeKey)).apply();
getEditor().putBoolean(WifiModeKey, (boolean) defaults.get( WifiModeKey )).apply();
getEditor() .putInt(TeamNumKey, (int) defaults.get( TeamNumKey )).apply();
getEditor() .putInt(MatchNumKey, (int) defaults.get( MatchNumKey )).apply();
getEditor() .putString(AllyPosKey, (String) defaults.get( AllyPosKey )).apply();
getEditor() .putInt(DataModeKey, (int) defaults.get( DataModeKey )).apply();
getEditor() .putString(BtUUIDKey, (String) defaults.get( BtUUIDKey )).apply();
getEditor().putBoolean(FTPEnabled, (boolean) defaults.get(FTPEnabled )).apply();
getEditor() .putString(FTPServer, (String) defaults.get( BtUUIDKey )).apply();
}
// IDK why I decided to format these functions like this. It looks cool though.
@@ -77,4 +86,14 @@ public class settingsManager {
public static String getBtUUID(){return prefs.getString( BtUUIDKey, (String) defaults.get(BtUUIDKey));}
public static void setBtUUID(String str){ getEditor().putString( BtUUIDKey,str).apply();}
public static boolean getFTPEnabled(){return prefs.getBoolean( FTPEnabled, (boolean) defaults.get(FTPEnabled));}
public static void setFTPEnabled(boolean bool){getEditor().putBoolean( FTPEnabled,bool).apply();}
public static String getFTPServer(){return prefs.getString( FTPServer, (String) defaults.get(FTPServer));}
public static void setFTPServer(String str){ getEditor().putString( FTPServer,str).apply();}
}
+4 -169
View File
@@ -7,7 +7,6 @@
tools:context=".ui.settings.settingsFragment">
<ScrollView
android:id="@+id/ScrollArea"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="60dp"
@@ -18,177 +17,13 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
<TableLayout
android:id="@+id/SettingsTable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_height="wrap_content">
</TableLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- <CheckBox-->
<!-- android:id="@+id/practice_mode"-->
<!-- android:layout_width="412dp"-->
<!-- android:layout_height="79dp"-->
<!-- android:layout_marginTop="20dp"-->
<!-- android:text="Practice Mode"-->
<!-- android:textSize="24sp"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintHorizontal_bias="0.0"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toBottomOf="@+id/eventDropdown" />-->
<TextView
android:id="@+id/textView2"
android:layout_width="66dp"
android:layout_height="24dp"
android:layout_marginTop="16dp"
android:text="Name"
android:textAlignment="center"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/username"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="Username"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<TextView
android:id="@+id/textView1"
android:layout_width="107dp"
android:layout_height="24dp"
android:layout_marginStart="152dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="152dp"
android:text="Event Code"
android:textAlignment="center"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/username" />
<com.skydoves.powerspinner.PowerSpinnerView
android:id="@+id/eventDropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black_2"
android:gravity="center"
android:hint="No events selected"
android:padding="10dp"
android:textColor="@color/main_500"
android:textColorHint="@color/teal_700"
android:textSize="14.5sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView1"
app:spinner_arrow_gravity="end"
app:spinner_arrow_padding="8dp"
app:spinner_divider_color="@color/teal_200"
app:spinner_divider_show="true"
app:spinner_divider_size="0.4dp"
app:spinner_popup_background="@color/black_2"
app:spinner_popup_elevation="14dp" />
<TextView
android:id="@+id/alliance_pos_text"
android:layout_width="107dp"
android:layout_height="24dp"
android:layout_marginStart="152dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="152dp"
android:text="Alliance Position"
android:textAlignment="center"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/eventDropdown" />
<com.skydoves.powerspinner.PowerSpinnerView
android:id="@+id/alliance_pos_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black_2"
android:gravity="center"
android:hint="No events selected"
android:padding="10dp"
android:textColor="@color/main_500"
android:textColorHint="@color/teal_700"
android:textSize="14.5sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/alliance_pos_text"
app:spinner_arrow_gravity="end"
app:spinner_arrow_padding="8dp"
app:spinner_divider_color="@color/teal_200"
app:spinner_divider_show="true"
app:spinner_divider_size="0.4dp"
app:spinner_popup_background="@color/black_2"
app:spinner_popup_elevation="14dp" />
<TextView
android:id="@+id/team_num_settings_label"
android:layout_width="107dp"
android:layout_height="24dp"
android:layout_marginStart="152dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="152dp"
android:text="Team number"
android:textAlignment="center"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/alliance_pos_dropdown" />
<EditText
android:id="@+id/team_number"
android:layout_width="193dp"
android:layout_height="65dp"
android:ems="10"
android:gravity="center"
android:inputType="number"
android:padding="10dp"
android:text="4388"
android:textColor="@color/main_500"
android:textColorHint="@color/teal_700"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/team_num_settings_label" />
<CheckBox
android:id="@+id/wifi_mode"
android:layout_width="412dp"
android:layout_height="79dp"
android:layout_marginTop="24dp"
android:text="Wifi Mode"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/team_number" />
<Button
android:id="@+id/reset_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset Settings"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
+18 -5
View File
@@ -33,7 +33,7 @@
android:layout_height="wrap_content"
android:text="Upload"
android:textSize="34sp"
app:layout_constraintBottom_toTopOf="@+id/CSVButton"
app:layout_constraintBottom_toTopOf="@+id/SyncButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@@ -44,21 +44,34 @@
android:layout_height="wrap_content"
android:text="Download"
android:textSize="34sp"
app:layout_constraintBottom_toTopOf="@+id/CSVButton"
app:layout_constraintBottom_toTopOf="@+id/SyncButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/uploadButton" />
<Button
android:id="@+id/SyncButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SYNC"
android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/CSVButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CSV"
android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="@+id/TBAButton"
app:layout_constraintBottom_toTopOf="@+id/TBAButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/uploadButton" />
app:layout_constraintTop_toBottomOf="@+id/SyncButton" />
<Button
android:id="@+id/TBAButton"
@@ -69,7 +82,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/CSVButton" />
app:layout_constraintTop_toBottomOf="@+id/SyncButton" />
</androidx.constraintlayout.widget.ConstraintLayout>