2024-09-20 15:59:35 -06:00
|
|
|
package com.ridgebotics.ridgescout.utility;
|
|
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
public class settingsManager {
|
|
|
|
|
public static SharedPreferences prefs;
|
|
|
|
|
public static SharedPreferences.Editor editor;
|
|
|
|
|
|
|
|
|
|
public static final String UnameKey = "username";
|
|
|
|
|
public static final String SelEVCodeKey = "selected_event_code";
|
2025-02-16 23:31:27 -07:00
|
|
|
public static final String YearNumKey = "year_num";
|
2024-09-20 15:59:35 -06:00
|
|
|
public static final String WifiModeKey = "wifi_mode";
|
|
|
|
|
public static final String MatchNumKey = "match_num";
|
|
|
|
|
public static final String AllyPosKey = "alliance_pos";
|
|
|
|
|
public static final String DataModeKey = "data_view_mode";
|
|
|
|
|
public static final String BtUUIDKey = "bt_uuid";
|
2024-10-05 18:47:36 -06:00
|
|
|
public static final String FTPEnabled = "ftp_enabled";
|
|
|
|
|
public static final String FTPServer = "ftp_server";
|
2025-01-23 11:58:45 -07:00
|
|
|
public static final String FTPSendMetaFiles = "ftp_send_meta_files";
|
2025-02-18 08:34:27 -07:00
|
|
|
public static final String CustomEventsKey = "enable_custom_event";
|
2024-09-20 15:59:35 -06:00
|
|
|
|
|
|
|
|
public static Map defaults = getDefaults();
|
|
|
|
|
private static Map getDefaults(){
|
|
|
|
|
Map<String, Object> hm = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
hm.put(UnameKey, "Username");
|
|
|
|
|
hm.put(SelEVCodeKey, "unset");
|
|
|
|
|
hm.put(WifiModeKey, false);
|
2025-02-16 23:31:27 -07:00
|
|
|
hm.put(YearNumKey, 2025);
|
2024-09-20 15:59:35 -06:00
|
|
|
hm.put(MatchNumKey, 0);
|
|
|
|
|
hm.put(AllyPosKey, "red-1");
|
|
|
|
|
hm.put(DataModeKey, 0);
|
|
|
|
|
hm.put(BtUUIDKey, UUID.randomUUID().toString());
|
2024-10-05 18:47:36 -06:00
|
|
|
hm.put(FTPEnabled, false);
|
|
|
|
|
hm.put(FTPServer, "0.0.0.0");
|
2025-01-23 11:58:45 -07:00
|
|
|
hm.put(FTPSendMetaFiles, false);
|
2025-02-18 08:34:27 -07:00
|
|
|
hm.put(CustomEventsKey, false);
|
2024-09-20 15:59:35 -06:00
|
|
|
|
|
|
|
|
return hm;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-05 18:47:36 -06:00
|
|
|
public static SharedPreferences.Editor getEditor(){
|
2024-09-20 15:59:35 -06:00
|
|
|
if(editor == null) editor = prefs.edit();
|
|
|
|
|
return editor;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-01 07:32:00 -06:00
|
|
|
public static void resetSettings(){
|
|
|
|
|
getEditor() .putString(UnameKey, (String) defaults.get( UnameKey )).apply();
|
|
|
|
|
getEditor() .putString(SelEVCodeKey,(String) defaults.get( SelEVCodeKey)).apply();
|
|
|
|
|
getEditor().putBoolean(WifiModeKey, (boolean) defaults.get( WifiModeKey )).apply();
|
2024-10-05 18:47:36 -06:00
|
|
|
|
2025-02-16 23:31:27 -07:00
|
|
|
getEditor() .putInt(YearNumKey, (int) defaults.get( YearNumKey )).apply();
|
2024-10-01 07:32:00 -06:00
|
|
|
getEditor() .putInt(MatchNumKey, (int) defaults.get( MatchNumKey )).apply();
|
|
|
|
|
getEditor() .putString(AllyPosKey, (String) defaults.get( AllyPosKey )).apply();
|
|
|
|
|
getEditor() .putInt(DataModeKey, (int) defaults.get( DataModeKey )).apply();
|
2024-10-05 18:47:36 -06:00
|
|
|
|
2024-10-01 07:32:00 -06:00
|
|
|
getEditor() .putString(BtUUIDKey, (String) defaults.get( BtUUIDKey )).apply();
|
2024-10-05 18:47:36 -06:00
|
|
|
|
2025-01-23 11:58:45 -07:00
|
|
|
getEditor().putBoolean(FTPEnabled, (boolean) defaults.get( FTPEnabled )).apply();
|
|
|
|
|
getEditor() .putString(FTPServer, (String) defaults.get( FTPServer )).apply();
|
|
|
|
|
getEditor().putBoolean(FTPSendMetaFiles, (boolean) defaults.get( FTPSendMetaFiles )).apply();
|
2025-02-18 08:34:27 -07:00
|
|
|
|
|
|
|
|
getEditor().putBoolean(CustomEventsKey, (boolean) defaults.get( CustomEventsKey )).apply();
|
2024-10-01 07:32:00 -06:00
|
|
|
}
|
|
|
|
|
|
2024-09-20 15:59:35 -06:00
|
|
|
// IDK why I decided to format these functions like this. It looks cool though.
|
|
|
|
|
public static String getUsername(){return prefs.getString( UnameKey, (String) defaults.get(UnameKey));}
|
|
|
|
|
public static void setUsername(String str){ getEditor().putString( UnameKey,str).apply();}
|
|
|
|
|
|
|
|
|
|
public static String getEVCode(){return prefs.getString( SelEVCodeKey, (String) defaults.get(SelEVCodeKey));}
|
|
|
|
|
public static void setEVCode(String str){ getEditor().putString( SelEVCodeKey,str).apply();}
|
|
|
|
|
|
|
|
|
|
public static boolean getWifiMode(){return prefs.getBoolean( WifiModeKey, (boolean) defaults.get(WifiModeKey));}
|
|
|
|
|
public static void setWifiMode(boolean bool){getEditor().putBoolean( WifiModeKey,bool).apply();}
|
|
|
|
|
|
2025-02-16 23:31:27 -07:00
|
|
|
public static int getYearNum(){return prefs.getInt( YearNumKey, (int) defaults.get(YearNumKey));}
|
|
|
|
|
public static void setYearNum(int num){ getEditor().putInt( YearNumKey,num).apply();}
|
2024-09-20 15:59:35 -06:00
|
|
|
|
|
|
|
|
public static int getMatchNum(){return prefs.getInt( MatchNumKey, (int) defaults.get(MatchNumKey));}
|
|
|
|
|
public static void setMatchNum(int num){ getEditor().putInt( MatchNumKey,num).apply();}
|
|
|
|
|
|
|
|
|
|
public static String getAllyPos(){return prefs.getString( AllyPosKey, (String) defaults.get(AllyPosKey));}
|
|
|
|
|
public static void setAllyPos(String str){ getEditor().putString( AllyPosKey,str).apply();}
|
|
|
|
|
|
|
|
|
|
public static int getDataMode(){return prefs.getInt( DataModeKey, (int) defaults.get(DataModeKey));}
|
|
|
|
|
public static void setDataMode(int num){ getEditor().putInt( DataModeKey,num).apply();}
|
|
|
|
|
|
|
|
|
|
public static String getBtUUID(){return prefs.getString( BtUUIDKey, (String) defaults.get(BtUUIDKey));}
|
|
|
|
|
public static void setBtUUID(String str){ getEditor().putString( BtUUIDKey,str).apply();}
|
|
|
|
|
|
2024-10-05 18:47:36 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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();}
|
|
|
|
|
|
2025-01-23 12:29:45 -07:00
|
|
|
public static boolean getFTPSendMetaFiles(){return prefs.getBoolean(FTPSendMetaFiles, (boolean) defaults.get(FTPSendMetaFiles));}
|
2025-02-18 08:34:27 -07:00
|
|
|
public static void setFTPSendMetaFiles(boolean bool){getEditor().putBoolean(FTPSendMetaFiles,bool).apply();}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean getCustomEvents(){return prefs.getBoolean(CustomEventsKey, (boolean) defaults.get(FTPSendMetaFiles));}
|
|
|
|
|
public static void setCustomEvents(boolean bool){getEditor().putBoolean(CustomEventsKey,bool).apply();}
|
|
|
|
|
|
2025-01-23 11:58:45 -07:00
|
|
|
|
2024-10-05 18:47:36 -06:00
|
|
|
|
|
|
|
|
|
2024-09-20 15:59:35 -06:00
|
|
|
}
|