mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
parent
53f5439444
commit
a8328d4a96
@ -57,8 +57,13 @@ import nodomain.freeyourgadget.gadgetbridge.activities.ConfigureAlarms;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.activities.VibrationActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.VibrationActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsActivity;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.DeviceDao;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||||
@ -468,6 +473,47 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//set alias, hidden under details
|
||||||
|
holder.setAlias.setOnClickListener(new View.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
final EditText input = new EditText(context);
|
||||||
|
input.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||||
|
input.setText(device.getAlias());
|
||||||
|
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
|
||||||
|
|
||||||
|
new AlertDialog.Builder(context)
|
||||||
|
.setView(input)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setTitle(context.getString(R.string.controlcenter_set_alias))
|
||||||
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||||
|
DaoSession session = dbHandler.getDaoSession();
|
||||||
|
Device dbDevice = DBHelper.getDevice(device, session);
|
||||||
|
String alias = input.getText().toString();
|
||||||
|
dbDevice.setAlias(alias);
|
||||||
|
dbDevice.update();
|
||||||
|
device.setAlias(alias);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
GB.toast(context, "Error setting alias: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
|
||||||
|
} finally {
|
||||||
|
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
||||||
|
LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -504,6 +550,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
|||||||
ListView deviceInfoList;
|
ListView deviceInfoList;
|
||||||
ImageView findDevice;
|
ImageView findDevice;
|
||||||
ImageView removeDevice;
|
ImageView removeDevice;
|
||||||
|
ImageView setAlias;
|
||||||
LinearLayout fmFrequencyBox;
|
LinearLayout fmFrequencyBox;
|
||||||
TextView fmFrequencyLabel;
|
TextView fmFrequencyLabel;
|
||||||
ImageView ledColor;
|
ImageView ledColor;
|
||||||
@ -537,6 +584,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
|||||||
deviceInfoList = view.findViewById(R.id.device_item_infos);
|
deviceInfoList = view.findViewById(R.id.device_item_infos);
|
||||||
findDevice = view.findViewById(R.id.device_action_find);
|
findDevice = view.findViewById(R.id.device_action_find);
|
||||||
removeDevice = view.findViewById(R.id.device_action_remove);
|
removeDevice = view.findViewById(R.id.device_action_remove);
|
||||||
|
setAlias = view.findViewById(R.id.device_action_set_alias);
|
||||||
fmFrequencyBox = view.findViewById(R.id.device_fm_frequency_box);
|
fmFrequencyBox = view.findViewById(R.id.device_fm_frequency_box);
|
||||||
fmFrequencyLabel = view.findViewById(R.id.fm_frequency);
|
fmFrequencyLabel = view.findViewById(R.id.fm_frequency);
|
||||||
ledColor = view.findViewById(R.id.device_led_color);
|
ledColor = view.findViewById(R.id.device_led_color);
|
||||||
|
@ -429,6 +429,7 @@ public class DBHelper {
|
|||||||
if (!isDeviceUpToDate(device, gbDevice)) {
|
if (!isDeviceUpToDate(device, gbDevice)) {
|
||||||
device.setIdentifier(gbDevice.getAddress());
|
device.setIdentifier(gbDevice.getAddress());
|
||||||
device.setName(gbDevice.getName());
|
device.setName(gbDevice.getName());
|
||||||
|
device.setAlias(gbDevice.getAlias());
|
||||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
|
||||||
device.setManufacturer(coordinator.getManufacturer());
|
device.setManufacturer(coordinator.getManufacturer());
|
||||||
device.setType(gbDevice.getType().getKey());
|
device.setType(gbDevice.getType().getKey());
|
||||||
@ -449,6 +450,9 @@ public class DBHelper {
|
|||||||
if (!Objects.equals(device.getName(), gbDevice.getName())) {
|
if (!Objects.equals(device.getName(), gbDevice.getName())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!Objects.equals(device.getAlias(), gbDevice.getAlias())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
|
||||||
if (!Objects.equals(device.getManufacturer(), coordinator.getManufacturer())) {
|
if (!Objects.equals(device.getManufacturer(), coordinator.getManufacturer())) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -169,6 +169,10 @@ public class GBDevice implements Parcelable {
|
|||||||
mName = name;
|
mName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAlias(String alias) {
|
||||||
|
mAlias = alias;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
return mAddress;
|
return mAddress;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_horizontal">
|
android:gravity="center_horizontal">
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
<androidx.cardview.widget.CardView
|
||||||
android:id="@+id/card_view"
|
android:id="@+id/card_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -34,23 +35,38 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_toStartOf="@+id/device_action_remove"
|
android:layout_toStartOf="@+id/device_action_set_alias"
|
||||||
android:focusable="false"
|
android:focusable="false"
|
||||||
android:scrollbars="none" />
|
android:scrollbars="none">
|
||||||
|
</ListView>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/device_action_set_alias"
|
||||||
|
android:layout_width="36dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginEnd="36dp"
|
||||||
|
android:background="?android:attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:contentDescription="@string/controlcenter_set_alias"
|
||||||
|
android:focusable="true"
|
||||||
|
android:tint="?attr/textColorTertiary"
|
||||||
|
card_view:srcCompat="@drawable/ic_font_download" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/device_action_remove"
|
android:id="@+id/device_action_remove"
|
||||||
android:layout_width="36dp"
|
android:layout_width="36dp"
|
||||||
android:layout_height="36dp"
|
android:layout_height="36dp"
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:background="?android:attr/selectableItemBackground"
|
android:background="?android:attr/selectableItemBackground"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:contentDescription="@string/controlcenter_delete_device"
|
android:contentDescription="@string/controlcenter_delete_device"
|
||||||
|
android:focusable="true"
|
||||||
android:tint="?attr/textColorTertiary"
|
android:tint="?attr/textColorTertiary"
|
||||||
card_view:srcCompat="@drawable/ic_remove_device"
|
card_view:srcCompat="@drawable/ic_remove_device" />
|
||||||
android:focusable="true" />
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
<string name="controlcenter_delete_device">Delete Device</string>
|
<string name="controlcenter_delete_device">Delete Device</string>
|
||||||
<string name="controlcenter_delete_device_name">Delete %1$s</string>
|
<string name="controlcenter_delete_device_name">Delete %1$s</string>
|
||||||
<string name="controlcenter_delete_device_dialogmessage">This will delete the device and all associated data!</string>
|
<string name="controlcenter_delete_device_dialogmessage">This will delete the device and all associated data!</string>
|
||||||
|
<string name="controlcenter_set_alias">Set Alias</string>
|
||||||
<string name="controlcenter_navigation_drawer_open">Open navigation drawer</string>
|
<string name="controlcenter_navigation_drawer_open">Open navigation drawer</string>
|
||||||
<string name="controlcenter_navigation_drawer_close">Close navigation drawer</string>
|
<string name="controlcenter_navigation_drawer_close">Close navigation drawer</string>
|
||||||
<string name="controlcenter_snackbar_need_longpress">Long press the card to disconnect</string>
|
<string name="controlcenter_snackbar_need_longpress">Long press the card to disconnect</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user