more work
This commit is contained in:
parent
8f5cfed775
commit
c9652e7de5
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,172 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/general_settings_title"
|
||||
android:textColor="#000000"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="15dp"
|
||||
android:background="#000000" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleProfileName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/profile_name_title"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editProfileName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/profile_name_hint"
|
||||
android:inputType="text"
|
||||
android:textSize="12sp"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10dp"
|
||||
android:background="#000000" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleApiUrl"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/api_url_title"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editApiUrl"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/api_url_hint"
|
||||
android:inputType="textUri"
|
||||
android:textSize="12sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleApiKey"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/api_key_title"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editApiKey"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/api_key_hint"
|
||||
android:inputType="text"
|
||||
android:textSize="12sp"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10dp"
|
||||
android:background="#000000" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/useTelegram"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/use_telegram" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleBotToken"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/bot_token_title"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editBotToken"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/bot_token_hint"
|
||||
android:inputType="text"
|
||||
android:textSize="12sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleChatId"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/chat_id_title"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editChatId"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/chat_id_hint"
|
||||
android:inputType="text"
|
||||
android:textSize="12sp"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10dp"
|
||||
android:background="#000000" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleTimeBetweenQueries"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/time_between_queries_title"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTimeBetweenQueries"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:autofillHints="10"
|
||||
android:hint="@string/time_between_queries_hint"
|
||||
android:inputType="numberDecimal"
|
||||
android:textSize="12sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleAmountOfLogLines"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/log_lines_to_display_title"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editAmountOfLogLines"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:autofillHints="5"
|
||||
android:hint="@string/amount_of_log_lines_hint"
|
||||
android:inputType="number"
|
||||
android:textSize="12sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleAmountOfLastTrades"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/last_trades_to_display_title"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editAmountOfLastTrades"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:autofillHints="9"
|
||||
android:hint="@string/amount_of_last_trades_hint"
|
||||
android:inputType="number"
|
||||
android:textSize="12sp"/>
|
||||
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonSaveSettings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/save_settings" />
|
||||
</LinearLayout>
|
||||
|
|
@ -34,4 +34,11 @@
|
|||
android:name="com.example.dcav2gui.ui.exchanges.OkxFragment"
|
||||
android:label="@string/menu_okx"
|
||||
tools:layout="@layout/fragment_okx" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/nav_settings"
|
||||
android:name="com.example.dcav2gui.ui.settings.SettingsFragment"
|
||||
android:label="Settings"
|
||||
tools:layout="@layout/fragment_settings" />
|
||||
|
||||
</navigation>
|
||||
|
|
@ -12,4 +12,25 @@
|
|||
<string name="menu_gateio">Gate.io</string>
|
||||
<string name="menu_kucoin">KuCoin</string>
|
||||
<string name="menu_okx">OKX</string>
|
||||
|
||||
<string name="profile_name_hint">Enter the profile name</string>
|
||||
<string name="api_url_hint">Enter the API URL</string>
|
||||
<string name="api_key_hint">Enter the API Key</string>
|
||||
<string name="use_telegram">Use Telegram</string>
|
||||
<string name="bot_token_hint">Enter the bot token</string>
|
||||
<string name="chat_id_hint">Enter the chat ID</string>
|
||||
<string name="time_between_queries_hint">Enter the desired time between queries (in seconds)</string>
|
||||
<string name="amount_of_log_lines_hint">Enter the desired amount of log lines</string>
|
||||
<string name="amount_of_last_trades_hint">Enter the desired amount of last trades</string>
|
||||
|
||||
<string name="save_settings">Save settings</string>
|
||||
<string name="time_between_queries_title">Time between queries</string>
|
||||
<string name="log_lines_to_display_title">Log lines to display</string>
|
||||
<string name="last_trades_to_display_title">Last trades to display</string>
|
||||
<string name="api_url_title">API URL</string>
|
||||
<string name="api_key_title">API key</string>
|
||||
<string name="bot_token_title">Bot token</string>
|
||||
<string name="chat_id_title">Chat ID</string>
|
||||
<string name="profile_name_title">Profile name</string>
|
||||
<string name="general_settings_title">General settings</string>
|
||||
</resources>
|
||||
|
|
@ -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" }
|
||||
|
|
|
|||
Loading…
Reference in New Issue