diff --git a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/SendKeystrokesToHostActivity.java b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/SendKeystrokesToHostActivity.java index 1b512d72..de1d2f04 100644 --- a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/SendKeystrokesToHostActivity.java +++ b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/SendKeystrokesToHostActivity.java @@ -166,7 +166,7 @@ public class SendKeystrokesToHostActivity extends BaseActivity val deviceId = pairedDevices[position].deviceId diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java index 599bcf8c..12037e2d 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java @@ -111,9 +111,9 @@ public class ShareActivity extends BaseActivity { if (d.isPaired() && (intentHasUrl || d.isReachable())) { devicesList.add(d); if (!d.isReachable()) { - items.add(new UnreachableDeviceItem(d, null)); + items.add(new UnreachableDeviceItem(d)); } else { - items.add(new DeviceItem(d, null)); + items.add(new DeviceItem(d)); } section.isEmpty = false; } diff --git a/src/org/kde/kdeconnect/UserInterface/List/DeviceItem.java b/src/org/kde/kdeconnect/UserInterface/List/DeviceItem.java deleted file mode 100644 index f04010b4..00000000 --- a/src/org/kde/kdeconnect/UserInterface/List/DeviceItem.java +++ /dev/null @@ -1,52 +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.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/DeviceItem.kt b/src/org/kde/kdeconnect/UserInterface/List/DeviceItem.kt new file mode 100644 index 00000000..3e53c289 --- /dev/null +++ b/src/org/kde/kdeconnect/UserInterface/List/DeviceItem.kt @@ -0,0 +1,36 @@ +/* + * SPDX-FileCopyrightText: 2025 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 org.kde.kdeconnect.Device +import org.kde.kdeconnect_tp.databinding.ListItemDeviceEntryBinding + +open class DeviceItem( + val device: Device, + private val callback: ((d: Device) -> Unit)? +) : ListAdapter.Item +{ + constructor(device: Device) : this(device, null) + + protected lateinit var binding: ListItemDeviceEntryBinding + + override fun inflateView(layoutInflater: LayoutInflater): View { + binding = ListItemDeviceEntryBinding.inflate(layoutInflater) + + binding.listItemEntryIcon.setImageDrawable(device.icon) + binding.listItemEntryTitle.text = device.name + + if (callback != null) { + binding.getRoot().setOnClickListener(View.OnClickListener { v1: View? -> + callback(device) + }) + } + + return binding.getRoot() + } +} diff --git a/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.java b/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.java deleted file mode 100644 index 1f6193dd..00000000 --- a/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.java +++ /dev/null @@ -1,36 +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.view.LayoutInflater; -import android.view.View; - -import androidx.annotation.NonNull; - -import org.kde.kdeconnect.Device; -import org.kde.kdeconnect_tp.R; - -public class PairingDeviceItem extends DeviceItem { - - public PairingDeviceItem(Device device, Callback callback) { - super(device, callback); - } - - @NonNull - @Override - public View inflateView(@NonNull LayoutInflater layoutInflater) { - 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); - } - return ret; - } - -} diff --git a/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.kt b/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.kt new file mode 100644 index 00000000..b42613cc --- /dev/null +++ b/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.kt @@ -0,0 +1,25 @@ +/* + * SPDX-FileCopyrightText: 2025 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 org.kde.kdeconnect.Device +import org.kde.kdeconnect_tp.R + +class PairingDeviceItem( + device: Device, + callback: ((d: Device) -> Unit)? +) : DeviceItem(device, callback) { + override fun inflateView(layoutInflater: LayoutInflater): View { + return super.inflateView(layoutInflater).also { + if (device.compareProtocolVersion() > 0) { + binding.listItemEntrySummary.setText(R.string.protocol_version_newer) + binding.listItemEntrySummary.visibility = View.VISIBLE + } + } + } +} diff --git a/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.java b/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.java deleted file mode 100644 index 7f8e630a..00000000 --- a/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.java +++ /dev/null @@ -1,34 +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.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; - } - -} diff --git a/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.kt b/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.kt new file mode 100644 index 00000000..db9f4ffd --- /dev/null +++ b/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.kt @@ -0,0 +1,20 @@ +/* + * SPDX-FileCopyrightText: 2025 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 org.kde.kdeconnect.Device +import org.kde.kdeconnect_tp.R + +class UnreachableDeviceItem(device: Device) : DeviceItem(device) { + override fun inflateView(layoutInflater: LayoutInflater): View { + return super.inflateView(layoutInflater).also { + binding.listItemEntrySummary.setText(R.string.runcommand_notreachable) + binding.listItemEntrySummary.visibility = View.VISIBLE + } + } +} diff --git a/src/org/kde/kdeconnect/UserInterface/PairingFragment.kt b/src/org/kde/kdeconnect/UserInterface/PairingFragment.kt index c29101d2..0f49aa7c 100644 --- a/src/org/kde/kdeconnect/UserInterface/PairingFragment.kt +++ b/src/org/kde/kdeconnect/UserInterface/PairingFragment.kt @@ -45,7 +45,7 @@ import org.kde.kdeconnect_tp.databinding.PairingExplanationTextNoWifiBinding /** * The view that the user will see when there are no devices paired, or when you choose "add a new device" from the sidebar. */ -class PairingFragment : BaseFragment(), PairingDeviceItem.Callback { +class PairingFragment : BaseFragment() { private var _textBinding: PairingExplanationTextBinding? = null private var _duplicateNamesBinding: PairingExplanationDuplicateNamesBinding? = null @@ -212,7 +212,7 @@ class PairingFragment : BaseFragment(), PairingDeviceItem.Ca val devices: Collection = KdeConnect.getInstance().devices.values for (device in devices) { if (device.isReachable && device.isPaired) { - items.add(PairingDeviceItem(device, this@PairingFragment)) + items.add(PairingDeviceItem(device, ::deviceClicked)) connectedSection.isEmpty = false } } @@ -224,7 +224,7 @@ class PairingFragment : BaseFragment(), PairingDeviceItem.Ca items.add(availableSection) for (device in devices) { if (device.isReachable && !device.isPaired) { - items.add(PairingDeviceItem(device, this@PairingFragment)) + items.add(PairingDeviceItem(device, ::deviceClicked)) availableSection.isEmpty = false } } @@ -236,7 +236,7 @@ class PairingFragment : BaseFragment(), PairingDeviceItem.Ca items.add(rememberedSection) for (device in devices) { if (!device.isReachable && device.isPaired) { - items.add(PairingDeviceItem(device, this@PairingFragment)) + items.add(PairingDeviceItem(device, ::deviceClicked)) rememberedSection.isEmpty = false } } @@ -310,7 +310,7 @@ class PairingFragment : BaseFragment(), PairingDeviceItem.Ca super.onStop() } - override fun pairingClicked(device: Device) { + fun deviceClicked(device: Device) { mainActivity.onDeviceSelected(device.deviceId, !device.isPaired || !device.isReachable) }