diff --git a/app/build.gradle b/app/build.gradle
index 2777071..c4ca91a 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -40,6 +40,7 @@ dependencies {
implementation libs.lifecycle.viewmodel.ktx
implementation libs.navigation.fragment
implementation libs.navigation.ui
+ implementation libs.gson
testImplementation libs.junit
androidTestImplementation libs.ext.junit
androidTestImplementation libs.espresso.core
diff --git a/app/src/main/java/com/example/dcav2gui/MainActivity.java b/app/src/main/java/com/example/dcav2gui/MainActivity.java
index fea71d3..80c04fe 100644
--- a/app/src/main/java/com/example/dcav2gui/MainActivity.java
+++ b/app/src/main/java/com/example/dcav2gui/MainActivity.java
@@ -37,6 +37,7 @@ public class MainActivity extends AppCompatActivity {
.setAnchorView(R.id.fab).show();
}
});
+
DrawerLayout drawer = binding.drawerLayout;
NavigationView navigationView = binding.navView;
// Passing each menu ID as a set of Ids because each
@@ -68,4 +69,4 @@ public class MainActivity extends AppCompatActivity {
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|| super.onSupportNavigateUp();
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/com/example/dcav2gui/ui/settings/SettingsData.java b/app/src/main/java/com/example/dcav2gui/ui/settings/SettingsData.java
new file mode 100644
index 0000000..be275cd
--- /dev/null
+++ b/app/src/main/java/com/example/dcav2gui/ui/settings/SettingsData.java
@@ -0,0 +1,36 @@
+// com.example.dcav2gui.ui.settings.SettingsData.java
+package com.example.dcav2gui.ui.settings;
+
+public class SettingsData {
+ public String profileName;
+ public String apiUrl;
+ public String apiKey;
+ public boolean useTelegram;
+ public String botToken;
+ public String chatId;
+ public float timeBetweenQueries;
+ public int amountOfLogLines;
+ public int amountOfLastTrades;
+
+ public SettingsData(
+ String profileName,
+ String apiUrl,
+ String apiKey,
+ boolean useTelegram,
+ String botToken,
+ String chatId,
+ float timeBetweenQueries,
+ int amountOfLogLines,
+ int amountOfLastTrades
+ ) {
+ this.profileName = profileName;
+ this.apiUrl = apiUrl;
+ this.apiKey = apiKey;
+ this.useTelegram = useTelegram;
+ this.botToken = botToken;
+ this.chatId = chatId;
+ this.timeBetweenQueries = timeBetweenQueries;
+ this.amountOfLogLines = amountOfLogLines;
+ this.amountOfLastTrades = amountOfLastTrades;
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/dcav2gui/ui/settings/SettingsFragment.java b/app/src/main/java/com/example/dcav2gui/ui/settings/SettingsFragment.java
new file mode 100644
index 0000000..c54c463
--- /dev/null
+++ b/app/src/main/java/com/example/dcav2gui/ui/settings/SettingsFragment.java
@@ -0,0 +1,72 @@
+// com.example.dcav2gui.ui.settings.SettingsFragment.java
+package com.example.dcav2gui.ui.settings;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+import androidx.lifecycle.ViewModelProvider;
+
+import com.example.dcav2gui.R;
+
+import java.util.Objects;
+
+public class SettingsFragment extends Fragment {
+
+ private SettingsViewModel settingsViewModel;
+
+ public View onCreateView(@NonNull LayoutInflater inflater,
+ ViewGroup container, Bundle savedInstanceState) {
+ settingsViewModel = new ViewModelProvider(this).get(SettingsViewModel.class);
+
+ View root = inflater.inflate(R.layout.fragment_settings, container, false);
+
+ EditText editProfileName = root.findViewById(R.id.editProfileName);
+ EditText editApiUrl = root.findViewById(R.id.editApiUrl);
+ EditText editApiKey = root.findViewById(R.id.editApiKey);
+ CheckBox checkBox = root.findViewById(R.id.useTelegram);
+ EditText editBotToken = root.findViewById(R.id.editBotToken);
+ EditText editChatId = root.findViewById(R.id.editChatId);
+ EditText editTimeBetweenQueries = root.findViewById(R.id.editTimeBetweenQueries);
+ EditText editAmountOfLogLines = root.findViewById(R.id.editAmountOfLogLines);
+ EditText editAmountofLastTrades = root.findViewById(R.id.editAmountOfLastTrades);
+
+ Button buttonSaveSettings = root.findViewById(R.id.buttonSaveSettings);
+
+ buttonSaveSettings.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ String profileName = editProfileName.getText().toString();
+ String apiUrl = editApiUrl.getText().toString();
+ String apiKey = editApiKey.getText().toString();
+ boolean useTelegram = checkBox.isChecked();
+ String botToken = editBotToken.getText().toString();
+ String chatId = editChatId.getText().toString();
+ int timeBetweenQueries = Integer.parseInt(editTimeBetweenQueries.getText().toString());
+ int amountOfLogLines = Integer.parseInt(editAmountOfLogLines.getText().toString());
+ int amountOfLastTrades = Integer.parseInt(editAmountofLastTrades.getText().toString());
+ settingsViewModel.saveSettings(
+ getContext(),
+ profileName,
+ apiUrl,
+ apiKey,
+ useTelegram,
+ botToken,
+ chatId,
+ timeBetweenQueries,
+ amountOfLogLines,
+ amountOfLastTrades);
+ Toast.makeText(getContext(), "Settings saved", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ return root;
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/dcav2gui/ui/settings/SettingsViewModel.java b/app/src/main/java/com/example/dcav2gui/ui/settings/SettingsViewModel.java
new file mode 100644
index 0000000..c77efec
--- /dev/null
+++ b/app/src/main/java/com/example/dcav2gui/ui/settings/SettingsViewModel.java
@@ -0,0 +1,76 @@
+// com.example.dcav2gui.ui.settings.SettingsViewModel.java
+package com.example.dcav2gui.ui.settings;
+
+
+import android.content.Context;
+
+import androidx.lifecycle.ViewModel;
+
+import com.google.gson.Gson;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+public class SettingsViewModel extends ViewModel {
+ //private Context context;
+
+ public String profileName;
+ public String apiUrl;
+ public String apiKey;
+ public boolean useTelegram;
+ public String botToken;
+ public String chatId;
+ public float timeBetweenQueries;
+ public int amountOfLogLines;
+ public int amountOfLastTrades;
+
+ public void saveSettings(
+ Context context,
+ String profileName,
+ String apiUrl,
+ String apiKey,
+ boolean useTelegram,
+ String botToken,
+ String chatId,
+ float timeBetweenQueries,
+ int amountOfLogLines,
+ int amountOfLastTrades
+ ) {
+ Context appContext = context.getApplicationContext();
+
+ this.profileName = profileName;
+ this.apiUrl = apiUrl;
+ this.apiKey = apiKey;
+ this.useTelegram = useTelegram;
+ this.botToken = botToken;
+ this.chatId = chatId;
+ this.timeBetweenQueries = timeBetweenQueries;
+ this.amountOfLogLines = amountOfLogLines;
+ this.amountOfLastTrades = amountOfLastTrades;
+
+ // Logic to save settings to JSON file
+ Gson gson = new Gson();
+ SettingsData settingsData = new SettingsData(
+ profileName,
+ apiUrl,
+ apiKey,
+ useTelegram,
+ botToken,
+ chatId,
+ timeBetweenQueries,
+ amountOfLogLines,
+ amountOfLastTrades
+ );
+
+ try {
+ File file = new File(context.getFilesDir(), "settings.json");
+ FileWriter writer = new FileWriter(file);
+ gson.toJson(settingsData, writer);
+ writer.flush();
+ writer.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml
new file mode 100644
index 0000000..467da6b
--- /dev/null
+++ b/app/src/main/res/layout/fragment_settings.xml
@@ -0,0 +1,172 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml
index 67480dd..bffafe9 100644
--- a/app/src/main/res/navigation/mobile_navigation.xml
+++ b/app/src/main/res/navigation/mobile_navigation.xml
@@ -34,4 +34,11 @@
android:name="com.example.dcav2gui.ui.exchanges.OkxFragment"
android:label="@string/menu_okx"
tools:layout="@layout/fragment_okx" />
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a04911d..89fb340 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -12,4 +12,25 @@
Gate.io
KuCoin
OKX
+
+ Enter the profile name
+ Enter the API URL
+ Enter the API Key
+ Use Telegram
+ Enter the bot token
+ Enter the chat ID
+ Enter the desired time between queries (in seconds)
+ Enter the desired amount of log lines
+ Enter the desired amount of last trades
+
+ Save settings
+ Time between queries
+ Log lines to display
+ Last trades to display
+ API URL
+ API key
+ Bot token
+ Chat ID
+ Profile name
+ General settings
\ No newline at end of file
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 2ae81e6..58bcfe3 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -10,6 +10,7 @@ lifecycleLivedataKtx = "2.8.7"
lifecycleViewmodelKtx = "2.8.7"
navigationFragment = "2.8.4"
navigationUi = "2.8.4"
+gson = "2.11.0"
[libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" }
@@ -22,6 +23,7 @@ lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-lived
lifecycle-viewmodel-ktx = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "lifecycleViewmodelKtx" }
navigation-fragment = { group = "androidx.navigation", name = "navigation-fragment", version.ref = "navigationFragment" }
navigation-ui = { group = "androidx.navigation", name = "navigation-ui", version.ref = "navigationUi" }
+gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }