Telegram checkbox now enables or disabled editing of bot_token and chat_id fields.

This commit is contained in:
Nicolás Sánchez 2024-12-09 16:03:03 -03:00
parent bb47d11cf9
commit cbb0f04ab0
2 changed files with 56 additions and 19 deletions

View File

@ -40,6 +40,18 @@ public class SettingsFragment extends Fragment {
Button buttonSaveSettings = root.findViewById(R.id.buttonSaveSettings);
// Add listener to the checkbox so we can enable or disable the editTexts if the checkbox
// is checked or unchecked respectively
checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
editBotToken.setEnabled(isChecked);
editBotToken.setFocusable(isChecked);
editBotToken.setFocusableInTouchMode(isChecked);
editChatId.setEnabled(isChecked);
editChatId.setFocusable(isChecked);
editChatId.setFocusableInTouchMode(isChecked);
});
buttonSaveSettings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -49,9 +61,26 @@ public class SettingsFragment extends Fragment {
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());
float timeBetweenQueries = 0;
int amountOfLogLines = 0;
int amountOfLastTrades = 0;
//Check if the user entered valid strings
if (profileName.isEmpty() || apiUrl.isEmpty() || apiKey.isEmpty() || botToken.isEmpty() || chatId.isEmpty()) {
Toast.makeText(getContext(), "Invalid input, please enter valid strings", Toast.LENGTH_SHORT).show();
return;
}
//Check if the user entered valid numbers
try {
timeBetweenQueries = Float.parseFloat(editTimeBetweenQueries.getText().toString());
amountOfLogLines = Integer.parseInt(editAmountOfLogLines.getText().toString());
amountOfLastTrades = Integer.parseInt(editAmountofLastTrades.getText().toString());
} catch (NumberFormatException e) {
Toast.makeText(getContext(), "Invalid input, please enter valid numbers", Toast.LENGTH_SHORT).show();
return;
}
settingsViewModel.saveSettings(
getContext(),
profileName,

View File

@ -23,15 +23,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/profile_name_title"
android:textSize="18sp"/>
android:textSize="14sp"/>
<EditText
android:id="@+id/editProfileName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/profile_name_hint"
android:textStyle="italic"
android:inputType="text"
android:textSize="12sp"/>
android:textSize="16sp"/>
<Space
android:layout_width="match_parent"
@ -43,30 +44,32 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/api_url_title"
android:textSize="18sp"/>
android:textSize="14sp"/>
<EditText
android:id="@+id/editApiUrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/api_url_hint"
android:textStyle="italic"
android:inputType="textUri"
android:textSize="12sp"/>
android:textSize="16sp"/>
<TextView
android:id="@+id/titleApiKey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/api_key_title"
android:textSize="18sp"/>
android:textSize="14sp"/>
<EditText
android:id="@+id/editApiKey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/api_key_hint"
android:textStyle="italic"
android:inputType="text"
android:textSize="12sp"/>
android:textSize="16sp"/>
<Space
android:layout_width="match_parent"
@ -84,30 +87,32 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/bot_token_title"
android:textSize="18sp"/>
android:textSize="14sp"/>
<EditText
android:id="@+id/editBotToken"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/bot_token_hint"
android:textStyle="italic"
android:inputType="text"
android:textSize="12sp"/>
android:textSize="16sp"/>
<TextView
android:id="@+id/titleChatId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/chat_id_title"
android:textSize="18sp"/>
android:textSize="14sp"/>
<EditText
android:id="@+id/editChatId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/chat_id_hint"
android:textStyle="italic"
android:inputType="text"
android:textSize="12sp"/>
android:textSize="16sp"/>
<Space
android:layout_width="match_parent"
@ -119,7 +124,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/time_between_queries_title"
android:textSize="18sp"/>
android:textSize="14sp"/>
<EditText
android:id="@+id/editTimeBetweenQueries"
@ -127,15 +132,16 @@
android:layout_height="wrap_content"
android:autofillHints="10"
android:hint="@string/time_between_queries_hint"
android:textStyle="italic"
android:inputType="numberDecimal"
android:textSize="12sp"/>
android:textSize="16sp"/>
<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"/>
android:textSize="14sp"/>
<EditText
android:id="@+id/editAmountOfLogLines"
@ -143,15 +149,16 @@
android:layout_height="wrap_content"
android:autofillHints="5"
android:hint="@string/amount_of_log_lines_hint"
android:textStyle="italic"
android:inputType="number"
android:textSize="12sp"/>
android:textSize="16sp"/>
<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"/>
android:textSize="14sp"/>
<EditText
android:id="@+id/editAmountOfLastTrades"
@ -159,8 +166,9 @@
android:layout_height="wrap_content"
android:autofillHints="9"
android:hint="@string/amount_of_last_trades_hint"
android:textStyle="italic"
android:inputType="number"
android:textSize="12sp"/>
android:textSize="16sp"/>