mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 08:38:03 -06:00
Update icon, and FINALLY invent the version stack
This commit is contained in:
@@ -12,6 +12,8 @@ import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
import com.astatin3.scoutingapp2025.databinding.ActivityMainBinding;
|
||||
|
||||
import com.astatin3.scoutingapp2025.SettingsVersionStack.latestSettings;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
@@ -33,6 +35,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
|
||||
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
|
||||
NavigationUI.setupWithNavController(binding.navView, navController);
|
||||
|
||||
latestSettings settings = new latestSettings();
|
||||
}
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.astatin3.scoutingapp2025.SettingsVersionStack;
|
||||
|
||||
public class latestSettings {
|
||||
public static v2 settings = new v2();
|
||||
public latestSettings(){
|
||||
settings.init_settings();
|
||||
settings.update();
|
||||
}
|
||||
}
|
||||
+85
-32
@@ -5,47 +5,100 @@ import com.astatin3.scoutingapp2025.fileEditor;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public abstract class settingsVersion {
|
||||
private static String settingsFilename = "settings.txt";
|
||||
private static final String settingsFilename = "settings.txt";
|
||||
public abstract void defaultSettings();
|
||||
public abstract int getVersion();
|
||||
public abstract void update();
|
||||
|
||||
public static String readLine(int line){
|
||||
if(!fileEditor.fileExist("settings.txt")){return null;}
|
||||
|
||||
String[] fileContent = new String(fileEditor.readFile("settings.txt"), StandardCharsets.UTF_8).split("\n");
|
||||
|
||||
if(fileContent.length <= line){return null;}
|
||||
|
||||
return fileContent[line];
|
||||
public static String get_settings_file_content(){
|
||||
byte[] data = fileEditor.readFile(settingsFilename);
|
||||
if(data == null){return "";}
|
||||
return new String(data, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static String w riteLine(int line, String data){
|
||||
String[] fileContent;
|
||||
public int get_file_version(){
|
||||
String[] fileContent = get_settings_file_content().split("\n");
|
||||
try{
|
||||
return Integer.parseInt(fileContent[0]);
|
||||
}catch(Exception e){
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void set_file_version(int version){
|
||||
String[] fileContent = get_settings_file_content().split("\n");
|
||||
String output = String.valueOf(version);
|
||||
for(int i = 0; i < fileContent.length; i++){
|
||||
output += ("\n" + fileContent[i]);
|
||||
}
|
||||
fileEditor.writeFile(settingsFilename, output.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public String readTag(String search_tag){
|
||||
String[] fileContent = get_settings_file_content().split("\n");
|
||||
|
||||
try{
|
||||
for(String line : fileContent){
|
||||
if(line.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
String[] split = line.split("=");
|
||||
if(split[0].equals(search_tag)){
|
||||
return split[1];
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void init_settings(){
|
||||
if(!fileEditor.fileExist(settingsFilename)){
|
||||
fileContent = new String[]{};
|
||||
fileEditor.createFile(settingsFilename);
|
||||
|
||||
defaultSettings();
|
||||
|
||||
set_file_version(getVersion());
|
||||
}
|
||||
}
|
||||
|
||||
public String forceWriteTag(String tag_name, String data){
|
||||
String fileContent = get_settings_file_content();
|
||||
String output = fileContent + "\n" + tag_name + "=" + data;
|
||||
fileEditor.writeFile(settingsFilename, output.getBytes(StandardCharsets.UTF_8));
|
||||
return output;
|
||||
}
|
||||
|
||||
public String writeTag(String tag_name, String data){
|
||||
final boolean already_exists = readTag(tag_name) != null;
|
||||
|
||||
if(!already_exists){
|
||||
String fileContent = get_settings_file_content();
|
||||
String output = fileContent + "\n" + tag_name + "=" + data;
|
||||
fileEditor.writeFile(settingsFilename, output.getBytes(StandardCharsets.UTF_8));
|
||||
return output;
|
||||
}else{
|
||||
fileContent = new String(fileEditor.readFile(settingsFilename), StandardCharsets.UTF_8).split("\n");
|
||||
}
|
||||
|
||||
String newFile = "";
|
||||
|
||||
for(int i = 0; i < Math.max(fileContent.length-1, line); i++){
|
||||
|
||||
if(i == line) {
|
||||
newFile += data + "\n";
|
||||
|
||||
}else if(i > fileContent.length-1){
|
||||
newFile += fileContent[i];
|
||||
|
||||
}
|
||||
|
||||
if(i < Math.max(fileContent.length - 1, line) - 1){
|
||||
newFile += "\n";
|
||||
String[] fileContent = get_settings_file_content().split("\n");
|
||||
try{
|
||||
for(int i = 0; i < fileContent.length; i++){
|
||||
if(fileContent[i].isEmpty()){
|
||||
continue;
|
||||
}
|
||||
String[] split = fileContent[i].split("=");
|
||||
if(split[0].equals(tag_name)){
|
||||
fileContent[i] = tag_name + "=" + data;
|
||||
String output = String.join("\n", fileContent);
|
||||
fileEditor.writeFile(settingsFilename, output.getBytes(StandardCharsets.UTF_8));
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return newFile;
|
||||
|
||||
// fileEditor.writeFile(settingsFilename, newFile.getBytes(StandardCharsets.UTF_8));
|
||||
return "No idea how this happened";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.astatin3.scoutingapp2025.SettingsVersionStack;
|
||||
|
||||
public class v0 extends settingsVersion {
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
set_file_version(getVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultSettings() {
|
||||
forceWriteTag("test1", "value1");
|
||||
forceWriteTag("test2", "value2");
|
||||
forceWriteTag("test3", "value3");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.astatin3.scoutingapp2025.SettingsVersionStack;
|
||||
|
||||
public class v1 extends v0 {
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return 1;
|
||||
}
|
||||
@Override
|
||||
public void update(){
|
||||
if(get_file_version() < getVersion()){super.update();}
|
||||
set_file_version(getVersion());
|
||||
// writeTag("test1", "value_v1_1");
|
||||
writeTag("test2", "value_v1_2");
|
||||
writeTag("test3", "value_v1_3");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultSettings() {
|
||||
forceWriteTag("test1", "value1");
|
||||
forceWriteTag("test2", "value2");
|
||||
forceWriteTag("test3", "value3");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.astatin3.scoutingapp2025.SettingsVersionStack;
|
||||
|
||||
public class v2 extends v1 {
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return 2;
|
||||
}
|
||||
@Override
|
||||
public void update(){
|
||||
if(get_file_version() < getVersion()){super.update();}
|
||||
set_file_version(getVersion());
|
||||
// writeTag("test1", "value_v2_1");
|
||||
// writeTag("test2", "value_v2_2");
|
||||
writeTag("test3", "value_v2 _3");
|
||||
}
|
||||
@Override
|
||||
public void defaultSettings() {
|
||||
forceWriteTag("test1", "value1");
|
||||
forceWriteTag("test2", "value2");
|
||||
forceWriteTag("test3", "value3");
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,7 @@ public final class fileEditor {
|
||||
|
||||
public static boolean writeFile(String filepath, byte[] data) {
|
||||
try {
|
||||
FileOutputStream output = new FileOutputStream(filepath);
|
||||
FileOutputStream output = new FileOutputStream(baseDir + filepath);
|
||||
output.write(data);
|
||||
output.close();
|
||||
return true;
|
||||
@@ -136,6 +136,20 @@ public final class fileEditor {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean createFile(String filepath){
|
||||
if(fileExist(filepath)){
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
File file = new File(baseDir + filepath);
|
||||
return file.createNewFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean fileExist(String path){
|
||||
File f = new File(baseDir + path);
|
||||
return f.exists() && !f.isDirectory();
|
||||
|
||||
+3
-6
@@ -1,4 +1,4 @@
|
||||
package com.astatin3.scoutingapp2025.ui.Settings;
|
||||
package com.astatin3.scoutingapp2025.ui.settings;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.os.Bundle;
|
||||
@@ -13,7 +13,7 @@ import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.astatin3.scoutingapp2025.databinding.FragmentSettingsBinding;
|
||||
import com.astatin3.scoutingapp2025.fileEditor;
|
||||
import com.astatin3.scoutingapp2025.SettingsVersionStack.v0;
|
||||
import com.astatin3.scoutingapp2025.SettingsVersionStack.latestSettings;
|
||||
|
||||
import com.skydoves.powerspinner.IconSpinnerAdapter;
|
||||
import com.skydoves.powerspinner.IconSpinnerItem;
|
||||
@@ -65,10 +65,7 @@ public class settingsFragment extends Fragment {
|
||||
spinnerView.selectItemByIndex(0);
|
||||
}
|
||||
|
||||
alert("test", v0.writeLine(1, "oeseo"));
|
||||
|
||||
|
||||
alert("test", v0.readLine(0));
|
||||
alert("test", latestSettings.settings.readTag("test2"));
|
||||
|
||||
return root;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public class TBAView extends ScrollView {
|
||||
}else if(currentTime.after(startDate) && currentTime.before(endDate)){
|
||||
tr.setBackgroundColor(0x30FFFF00);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.astatin3.scoutingapp2025.ui.transfer;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
@@ -60,6 +61,16 @@ public class generatorView extends ConstraintLayout {
|
||||
super(context, attributeSet);
|
||||
}
|
||||
|
||||
private void alert(String title, String content) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
|
||||
alert.setMessage(content);
|
||||
alert.setTitle(title);
|
||||
alert.setPositiveButton("OK", null);
|
||||
alert.setCancelable(true);
|
||||
alert.create().show();
|
||||
}
|
||||
|
||||
|
||||
private Bitmap generateQrCode(String contents) throws WriterException {
|
||||
|
||||
final int size = 512;
|
||||
@@ -139,16 +150,25 @@ public class generatorView extends ConstraintLayout {
|
||||
|
||||
}
|
||||
|
||||
if(compiledData.isEmpty()){
|
||||
alert("Error!", "Empty data!");
|
||||
return;
|
||||
}
|
||||
|
||||
minQrSize = Math.round(compiledData.length()/maxQrCount)+1;
|
||||
|
||||
qrSizeSlider.setMax(maxQrSize-minQrSize);
|
||||
qrSpeedSlider.setMax((minQrSpeed-maxQrSpeed)*2);
|
||||
|
||||
qrSizeSlider.setProgress(minQrSize+qrSize);
|
||||
qrSpeedSlider.setProgress(defaultQrDelay+5);
|
||||
|
||||
sendData(compiledData);
|
||||
}
|
||||
|
||||
private void sendData(String data){
|
||||
|
||||
// minQrSize = 0;
|
||||
minQrSize = Math.round(data.length()/maxQrCount)+1;
|
||||
|
||||
qrSizeSlider.setMax(maxQrSize-minQrSize);
|
||||
qrSpeedSlider.setMax((minQrSpeed-maxQrSpeed)*2);
|
||||
|
||||
qrCount = (data.length()/qrSize)+1;
|
||||
qrIndexD.setText(String.valueOf(qrCount));
|
||||
@@ -181,7 +201,7 @@ public class generatorView extends ConstraintLayout {
|
||||
}
|
||||
});
|
||||
|
||||
qrSpeedSlider.setProgress(defaultQrDelay+5);
|
||||
// qrSizeSlider.setProgress(qr);
|
||||
|
||||
qrBitmaps = new ArrayList<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user