From 5bc41367edc5d378103c9c9107182799d6efa890 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Mon, 26 May 2025 12:03:20 +0200 Subject: [PATCH] Homegenize devices look in device lists --- res/layout/devices_list.xml | 2 +- res/layout/list_card_entry.xml | 51 -------------- res/layout/list_item_device_entry.xml | 69 +++++++++++++++++++ res/layout/list_item_with_icon_entry.xml | 67 ------------------ .../widget_remote_command_plugin_dialog.xml | 12 +++- res/values/strings.xml | 1 - .../SendKeystrokesToHostActivity.java | 4 +- .../RunCommandWidgetConfigActivity.kt | 13 ++-- .../Plugins/SharePlugin/ShareActivity.java | 9 +-- .../UserInterface/List/DeviceItem.java | 52 ++++++++++++++ .../UserInterface/List/EntryItemWithIcon.kt | 30 -------- .../UserInterface/List/PairingDeviceItem.java | 44 ++---------- .../List/UnreachableDeviceItem.java | 34 +++++++++ 13 files changed, 184 insertions(+), 204 deletions(-) delete mode 100644 res/layout/list_card_entry.xml create mode 100644 res/layout/list_item_device_entry.xml delete mode 100644 res/layout/list_item_with_icon_entry.xml create mode 100644 src/org/kde/kdeconnect/UserInterface/List/DeviceItem.java delete mode 100644 src/org/kde/kdeconnect/UserInterface/List/EntryItemWithIcon.kt create mode 100644 src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.java diff --git a/res/layout/devices_list.xml b/res/layout/devices_list.xml index b590ccb6..295e3501 100644 --- a/res/layout/devices_list.xml +++ b/res/layout/devices_list.xml @@ -23,7 +23,7 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted android:dividerHeight="12dp" android:orientation="vertical" android:clipToPadding="false" - tools:listitem="@layout/list_card_entry" + tools:listitem="@layout/list_item_device_entry" tools:context=".MainActivity" /> diff --git a/res/layout/list_card_entry.xml b/res/layout/list_card_entry.xml deleted file mode 100644 index f08dfd4d..00000000 --- a/res/layout/list_card_entry.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - diff --git a/res/layout/list_item_device_entry.xml b/res/layout/list_item_device_entry.xml new file mode 100644 index 00000000..87d27728 --- /dev/null +++ b/res/layout/list_item_device_entry.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/list_item_with_icon_entry.xml b/res/layout/list_item_with_icon_entry.xml deleted file mode 100644 index 9f3fced7..00000000 --- a/res/layout/list_item_with_icon_entry.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/layout/widget_remote_command_plugin_dialog.xml b/res/layout/widget_remote_command_plugin_dialog.xml index 29f94fe7..ce8e3528 100644 --- a/res/layout/widget_remote_command_plugin_dialog.xml +++ b/res/layout/widget_remote_command_plugin_dialog.xml @@ -7,11 +7,20 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted --> + + + android:dividerHeight="12dp" /> Allow controlling your media players without opening KDE Connect mpris_notification_enabled Share to… - %s (Unreachable) %s (✕) URLs shared to an unreachable device will be delivered to it once it becomes reachable.\n\n Protocol version: diff --git a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/SendKeystrokesToHostActivity.java b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/SendKeystrokesToHostActivity.java index 7e10c031..1b512d72 100644 --- a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/SendKeystrokesToHostActivity.java +++ b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/SendKeystrokesToHostActivity.java @@ -21,7 +21,7 @@ import org.kde.kdeconnect.Helpers.SafeTextChecker; import org.kde.kdeconnect.Helpers.WindowHelper; import org.kde.kdeconnect.KdeConnect; import org.kde.kdeconnect.NetworkPacket; -import org.kde.kdeconnect.UserInterface.List.EntryItemWithIcon; +import org.kde.kdeconnect.UserInterface.List.DeviceItem; import org.kde.kdeconnect.UserInterface.List.ListAdapter; import org.kde.kdeconnect.UserInterface.List.SectionItem; import org.kde.kdeconnect.base.BaseActivity; @@ -166,7 +166,7 @@ public class SendKeystrokesToHostActivity extends BaseActivity(this, 0, pairedDevices) { - override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - val view : View = convertView ?: layoutInflater.inflate(R.layout.list_item_with_icon_entry, parent, false) - val device = pairedDevices[position] - view.findViewById(R.id.list_item_entry_title).text = device.name - view.findViewById(R.id.list_item_entry_icon).setImageDrawable(device.icon) - return view - } - } + val list = ListAdapter(this, pairedDevices.map { DeviceItem(it, null) }) + binding.runCommandsDeviceList.adapter = list binding.runCommandsDeviceList.setOnItemClickListener { _, _, position, _ -> val deviceId = pairedDevices[position].deviceId saveWidgetDeviceIdPref(this, appWidgetId, deviceId) diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java index 1ac77225..599bcf8c 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java @@ -23,9 +23,10 @@ import org.kde.kdeconnect.BackgroundService; import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Helpers.WindowHelper; import org.kde.kdeconnect.KdeConnect; -import org.kde.kdeconnect.UserInterface.List.EntryItemWithIcon; +import org.kde.kdeconnect.UserInterface.List.DeviceItem; import org.kde.kdeconnect.UserInterface.List.ListAdapter; import org.kde.kdeconnect.UserInterface.List.SectionItem; +import org.kde.kdeconnect.UserInterface.List.UnreachableDeviceItem; import org.kde.kdeconnect.base.BaseActivity; import org.kde.kdeconnect_tp.R; import org.kde.kdeconnect_tp.databinding.ActivityShareBinding; @@ -109,11 +110,11 @@ public class ShareActivity extends BaseActivity { // Show the paired devices only if they are unreachable and the shared intent has a URL if (d.isPaired() && (intentHasUrl || d.isReachable())) { devicesList.add(d); - String deviceName = d.getName(); if (!d.isReachable()) { - deviceName = getString(R.string.unreachable_device, deviceName); + items.add(new UnreachableDeviceItem(d, null)); + } else { + items.add(new DeviceItem(d, null)); } - items.add(new EntryItemWithIcon(deviceName, d.getIcon())); section.isEmpty = false; } } diff --git a/src/org/kde/kdeconnect/UserInterface/List/DeviceItem.java b/src/org/kde/kdeconnect/UserInterface/List/DeviceItem.java new file mode 100644 index 00000000..f04010b4 --- /dev/null +++ b/src/org/kde/kdeconnect/UserInterface/List/DeviceItem.java @@ -0,0 +1,52 @@ +/* + * SPDX-FileCopyrightText: 2014 Albert Vaca Cintora + * + * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +*/ + +package org.kde.kdeconnect.UserInterface.List; + +import android.view.LayoutInflater; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import org.kde.kdeconnect.Device; +import org.kde.kdeconnect_tp.databinding.ListItemDeviceEntryBinding; + +public class DeviceItem implements ListAdapter.Item { + + public interface Callback { + void pairingClicked(Device d); + } + + private final @Nullable Callback callback; + protected final @NonNull Device device; + protected ListItemDeviceEntryBinding binding; + + public DeviceItem(@NonNull Device device, @Nullable Callback callback) { + this.device = device; + this.callback = callback; + } + + public @NonNull Device getDevice() { + return this.device; + } + + @NonNull + @Override + public View inflateView(@NonNull LayoutInflater layoutInflater) { + binding = ListItemDeviceEntryBinding.inflate(layoutInflater); + + binding.listItemEntryIcon.setImageDrawable(device.getIcon()); + binding.listItemEntryTitle.setText(device.getName()); + + if (callback != null) { + binding.getRoot().setOnClickListener(v1 -> callback.pairingClicked(device)); + } + + return binding.getRoot(); + } + +} diff --git a/src/org/kde/kdeconnect/UserInterface/List/EntryItemWithIcon.kt b/src/org/kde/kdeconnect/UserInterface/List/EntryItemWithIcon.kt deleted file mode 100644 index a7aa6829..00000000 --- a/src/org/kde/kdeconnect/UserInterface/List/EntryItemWithIcon.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2014 Albert Vaca Cintora - * - * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL - */ -package org.kde.kdeconnect.UserInterface.List - -import android.graphics.drawable.Drawable -import android.view.LayoutInflater -import android.view.View -import org.kde.kdeconnect_tp.databinding.ListCardEntryBinding - -open class EntryItemWithIcon : ListAdapter.Item { - protected val title: String - protected val icon: Drawable - - constructor(title: String, icon: Drawable) { - this.title = title - this.icon = icon - } - - override fun inflateView(layoutInflater: LayoutInflater): View { - val binding = ListCardEntryBinding.inflate(layoutInflater) - - binding.listItemEntryTitle.text = title - binding.listItemEntryIcon.setImageDrawable(icon) - - return binding.root - } -} diff --git a/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.java b/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.java index a70c526d..1f6193dd 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.java +++ b/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.java @@ -13,54 +13,24 @@ import androidx.annotation.NonNull; import org.kde.kdeconnect.Device; import org.kde.kdeconnect_tp.R; -import org.kde.kdeconnect_tp.databinding.ListItemWithIconEntryBinding; -public class PairingDeviceItem implements ListAdapter.Item { - - public interface Callback { - void pairingClicked(Device d); - } - - private final Callback callback; - private final Device device; +public class PairingDeviceItem extends DeviceItem { public PairingDeviceItem(Device device, Callback callback) { - this.device = device; - this.callback = callback; - } - - public Device getDevice() { - return this.device; + super(device, callback); } @NonNull @Override public View inflateView(@NonNull LayoutInflater layoutInflater) { - final ListItemWithIconEntryBinding binding = ListItemWithIconEntryBinding.inflate(layoutInflater); - - binding.listItemEntryIcon.setImageDrawable(device.getIcon()); -// binding.listItemEntryTitle.setText(device.getName() + " " + device.getConnectivityType()); - binding.listItemEntryTitle.setText(device.getName()); - - if (device.compareProtocolVersion() != 0) { - if (device.compareProtocolVersion() > 0) { - binding.listItemEntrySummary.setText(R.string.protocol_version_newer); - binding.listItemEntrySummary.setVisibility(View.VISIBLE); - } else { - //FIXME: Uncoment when we decide old versions are old enough to notify the user. - binding.listItemEntrySummary.setVisibility(View.GONE); - /* - summaryView.setText(R.string.protocol_version_older); - summaryView.setVisibility(View.VISIBLE); - */ - } + View ret = super.inflateView(layoutInflater); + if (device.compareProtocolVersion() > 0) { + binding.listItemEntrySummary.setText(R.string.protocol_version_newer); + binding.listItemEntrySummary.setVisibility(View.VISIBLE); } else { binding.listItemEntrySummary.setVisibility(View.GONE); } - - binding.getRoot().setOnClickListener(v1 -> callback.pairingClicked(device)); - - return binding.getRoot(); + return ret; } } diff --git a/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.java b/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.java new file mode 100644 index 00000000..7f8e630a --- /dev/null +++ b/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.java @@ -0,0 +1,34 @@ +/* + * SPDX-FileCopyrightText: 2014 Albert Vaca Cintora + * + * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +*/ + +package org.kde.kdeconnect.UserInterface.List; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; + +import androidx.annotation.NonNull; + +import org.kde.kdeconnect.Device; +import org.kde.kdeconnect_tp.R; + +public class UnreachableDeviceItem extends DeviceItem { + + public UnreachableDeviceItem(Device device, Callback callback) { + super(device, callback); + } + + @NonNull + @Override + public View inflateView(@NonNull LayoutInflater layoutInflater) { + View ret = super.inflateView(layoutInflater); + binding.listItemEntryTitle.setText(device.getName()); + binding.listItemEntrySummary.setText(R.string.runcommand_notreachable); + binding.listItemEntrySummary.setVisibility(View.VISIBLE); + return ret; + } + +}