Add PoC action support for Add Device button.
This commit is contained in:
parent
d87b748b64
commit
3cd90abdc9
6 changed files with 39 additions and 71 deletions
|
@ -1,5 +1,7 @@
|
|||
package dev.nuculabs.nucuhub.domain;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -55,4 +57,10 @@ public class Device {
|
|||
"Malformed URL provided for device: %s", url));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.target;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,9 +24,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
}
|
||||
|
||||
private void initializeDeviceListItems() {
|
||||
// TODO dummy code to update device list entries
|
||||
SharedPreferences sp = Objects.requireNonNull(getContext()).getSharedPreferences(SettingValues.NAME, Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor spe = sp.edit();
|
||||
DeviceListPreference devicesList = findPreference(DEVICE_LIST_PREFERENCE);
|
||||
Set<String> savedEntries = sp.getStringSet(SettingValues.CURRENT_DEVICE_LIST, null);
|
||||
if (savedEntries != null) {
|
||||
|
@ -38,6 +36,6 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
}
|
||||
devicesList.setEntries(items);
|
||||
}
|
||||
|
||||
// TODO: Set default device.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,19 +10,23 @@ import android.view.View;
|
|||
import android.view.WindowManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.preference.ListPreference;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import dev.nuculabs.nucuhub.R;
|
||||
import dev.nuculabs.nucuhub.domain.SettingValues;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DeviceManagementDialog extends Dialog {
|
||||
private SharedPreferences sharedPreferences;
|
||||
private ListPreference preference = null;
|
||||
private ArrayAdapter<String> adapter;
|
||||
private TextInputLayout deviceTextInputLayout;
|
||||
|
||||
public DeviceManagementDialog(@NonNull Context context) {
|
||||
super(context, R.style.ThemeOverlay_AppCompat_ActionBar);
|
||||
|
@ -36,24 +40,22 @@ public class DeviceManagementDialog extends Dialog {
|
|||
setupToolbar();
|
||||
|
||||
sharedPreferences = getContext().getSharedPreferences(SettingValues.NAME, Activity.MODE_PRIVATE);
|
||||
|
||||
final ListView deviceListView = findViewById(R.id.settings_device_dialog_list);
|
||||
final ListView deviceListView = requireViewById(R.id.settings_device_dialog_list);
|
||||
final Button addDeviceButton = requireViewById(R.id.settings_device_add_button);
|
||||
deviceTextInputLayout = requireViewById(R.id.settings_device_input_device);
|
||||
adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1);
|
||||
|
||||
deviceListView.setAdapter(adapter);
|
||||
|
||||
// todo: dummy code to add simple items.
|
||||
// Add the existing items in the list adapter so they will be displayed.
|
||||
final CharSequence [] preferenceCharSeq = preference.getEntries();
|
||||
for (CharSequence item : preferenceCharSeq) {
|
||||
adapter.add(item.toString());
|
||||
}
|
||||
|
||||
Button testConnectionButton = findViewById(R.id.settings_device_test_connection_button);
|
||||
testConnectionButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
adapter.add("new object.");
|
||||
}
|
||||
});
|
||||
// on-click handlers.
|
||||
addDeviceButton.setOnClickListener(new AddNewDeviceAction());
|
||||
// TODO add support for selecting device and deleting.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -84,7 +86,6 @@ public class DeviceManagementDialog extends Dialog {
|
|||
}
|
||||
|
||||
private void updatePreferenceEntryValues() {
|
||||
// todo dummy code to update the entries.
|
||||
int itemsLength = adapter.getCount();
|
||||
CharSequence[] entries = new CharSequence[itemsLength];
|
||||
HashSet<String> entriesSet = new HashSet<>();
|
||||
|
@ -109,4 +110,16 @@ public class DeviceManagementDialog extends Dialog {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class AddNewDeviceAction implements View.OnClickListener {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO: Test connection before adding. loading -> testing connection -> show dialog.
|
||||
EditText editText = Objects.requireNonNull(deviceTextInputLayout.getEditText());
|
||||
String target = editText.getText().toString();
|
||||
adapter.add(target);
|
||||
editText.setText(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:orientation="vertical"
|
||||
>
|
||||
|
||||
|
@ -38,22 +38,12 @@
|
|||
android:hint="@string/settings_device_add_new_device_input_hint"/>
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<TextView
|
||||
android:text="$$Connection status$$"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/text_connection_status" android:gravity="center"/>
|
||||
<Button
|
||||
android:text="@string/settings_device_test_connection_btn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/settings_device_test_connection_button"
|
||||
android:layout_height="wrap_content" android:id="@+id/settings_device_add_button"
|
||||
tools:text="Test Connection"/>
|
||||
|
||||
<Button
|
||||
android:text="@string/settings_device_add_device_btn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/settings_device_add_device_button"
|
||||
android:enabled="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View android:layout_height="1dp"
|
||||
|
|
|
@ -35,9 +35,8 @@
|
|||
<string name="device_selection_title">Your current device</string>
|
||||
<string name="device_management_title">Device Management</string>
|
||||
<string name="settings_connect_new_device">Connect new device</string>
|
||||
<string name="settings_device_test_connection_btn">Test Connection</string>
|
||||
<string name="settings_device_add_new_device_input_hint">http://hostname:port</string>
|
||||
<string name="settings_device_add_device_btn">Add Device</string>
|
||||
<string name="settings_device_test_connection_btn">Add Device</string>
|
||||
<string name="settings_device_add_new_device_input_hint">hostname:port</string>
|
||||
<string name="settings_device_saved_devices">Saved Devices</string>
|
||||
|
||||
|
||||
|
|
|
@ -1,43 +1,5 @@
|
|||
<PreferenceScreen
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<!-- <PreferenceCategory-->
|
||||
<!-- app:title="@string/messages_header">-->
|
||||
|
||||
<!-- <EditTextPreference-->
|
||||
<!-- app:key="signature"-->
|
||||
<!-- app:title="@string/signature_title"-->
|
||||
<!-- app:useSimpleSummaryProvider="true"/>-->
|
||||
|
||||
<!-- <ListPreference-->
|
||||
<!-- app:key="reply"-->
|
||||
<!-- app:title="@string/reply_title"-->
|
||||
<!-- app:entries="@array/reply_entries"-->
|
||||
<!-- app:entryValues="@array/reply_values"-->
|
||||
<!-- app:defaultValue="reply"-->
|
||||
<!-- app:useSimpleSummaryProvider="true"/>-->
|
||||
|
||||
<!-- </PreferenceCategory>-->
|
||||
|
||||
<!-- <PreferenceCategory-->
|
||||
<!-- app:title="@string/sync_header">-->
|
||||
|
||||
<!-- <SwitchPreferenceCompat-->
|
||||
<!-- app:key="sync"-->
|
||||
<!-- app:title="@string/sync_title"/>-->
|
||||
|
||||
<!-- <SwitchPreferenceCompat-->
|
||||
<!-- app:key="attachment"-->
|
||||
<!-- app:title="@string/attachment_title"-->
|
||||
<!-- app:summaryOn="@string/attachment_summary_on"-->
|
||||
<!-- app:summaryOff="@string/attachment_summary_off"-->
|
||||
<!-- app:dependency="sync"/>-->
|
||||
|
||||
<!-- </PreferenceCategory>-->
|
||||
|
||||
<PreferenceCategory
|
||||
app:title="@string/devices_header">
|
||||
|
||||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<PreferenceCategory app:title="@string/devices_header">
|
||||
<dev.nuculabs.nucuhub.ui.settings.device.DeviceListPreference
|
||||
app:key="device_list"
|
||||
app:title="@string/device_selection_title"
|
||||
|
@ -45,7 +7,5 @@
|
|||
app:entryValues="@array/reply_values"
|
||||
app:defaultValue="reply"
|
||||
app:useSimpleSummaryProvider="true"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in a new issue