2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-22 09:58:08 +00:00

Fix devices not being clickable in share activity

This commit is contained in:
Albert Vaca Cintora 2025-07-02 08:30:50 +02:00
parent a733433551
commit c0c5ba1024
No known key found for this signature in database
6 changed files with 57 additions and 51 deletions

View File

@ -36,6 +36,7 @@ import java.util.stream.Collectors;
import kotlin.Lazy;
import kotlin.LazyKt;
import kotlin.Unit;
public class SendKeystrokesToHostActivity extends BaseActivity<ActivitySendkeystrokesBinding> {
@ -166,17 +167,16 @@ public class SendKeystrokesToHostActivity extends BaseActivity<ActivitySendkeyst
for (Device d : devices) {
if (d.isReachable() && d.isPaired()) {
devicesList.add(d);
items.add(new DeviceItem(d));
items.add(new DeviceItem(d, this::deviceClicked));
section.isEmpty = false;
}
}
getBinding().devicesList.setAdapter(new ListAdapter(SendKeystrokesToHostActivity.this, items));
getBinding().devicesList.setOnItemClickListener((adapterView, view, i, l) -> {
Device device = devicesList.get(i - 1); // NOTE: -1 because of the title!
sendKeys(device);
this.finish(); // close the activity
});
// Configure focus order for Accessibility, for touchpads, and for TV remotes
// (allow focus of items in the device list)
getBinding().devicesList.setItemsCanFocus(true);
// only one device is connected and we trust the text to send -> send it and close the activity.
// Usually we already check it in `onStart` - but if the BackgroundService was not started/connected to the host
@ -185,8 +185,15 @@ public class SendKeystrokesToHostActivity extends BaseActivity<ActivitySendkeyst
if (devicesList.size() == 1 && contentIsOkay) {
Device device = devicesList.get(0);
sendKeys(device);
this.finish(); // close the activity
}
finish(); // close the activity
}
}
private Unit deviceClicked(Device device) {
sendKeys(device);
finish(); // close the activity
return Unit.INSTANCE;
}
}

View File

@ -11,21 +11,14 @@ import android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.edit
import org.kde.kdeconnect.Device
import org.kde.kdeconnect.KdeConnect
import org.kde.kdeconnect.UserInterface.List.DeviceItem
import org.kde.kdeconnect.UserInterface.List.ListAdapter
import org.kde.kdeconnect_tp.R
import org.kde.kdeconnect_tp.databinding.WidgetRemoteCommandPluginDialogBinding
import java.util.stream.Collectors
class RunCommandWidgetConfigActivity : AppCompatActivity() {
@ -47,12 +40,15 @@ class RunCommandWidgetConfigActivity : AppCompatActivity() {
val binding = WidgetRemoteCommandPluginDialogBinding.inflate(layoutInflater)
setContentView(binding.root)
val pairedDevices = KdeConnect.getInstance().devices.values.stream().filter(Device::isPaired).collect(Collectors.toList())
val pairedDevices = KdeConnect.getInstance().devices.values.asSequence().filter(Device::isPaired).toList()
val list = ListAdapter(this, pairedDevices.map { DeviceItem(it) })
val list = ListAdapter(this, pairedDevices.map { DeviceItem(it, ::deviceClicked) })
binding.runCommandsDeviceList.adapter = list
binding.runCommandsDeviceList.setOnItemClickListener { _, _, position, _ ->
val deviceId = pairedDevices[position].deviceId
binding.runCommandsDeviceList.emptyView = binding.noDevices
}
fun deviceClicked(device: Device) {
val deviceId = device.deviceId
saveWidgetDeviceIdPref(this, appWidgetId, deviceId)
val appWidgetManager = AppWidgetManager.getInstance(this)
@ -63,8 +59,6 @@ class RunCommandWidgetConfigActivity : AppCompatActivity() {
setResult(RESULT_OK, resultValue)
finish()
}
binding.runCommandsDeviceList.emptyView = binding.noDevices
}
}
private const val PREFS_NAME = "org.kde.kdeconnect_tp.WidgetProvider"

View File

@ -39,6 +39,7 @@ import java.util.Set;
import kotlin.Lazy;
import kotlin.LazyKt;
import kotlin.Unit;
public class ShareActivity extends BaseActivity<ActivityShareBinding> {
private static final String KEY_UNREACHABLE_URL_LIST = "key_unreachable_url_list";
@ -111,17 +112,22 @@ public class ShareActivity extends BaseActivity<ActivityShareBinding> {
if (d.isPaired() && (intentHasUrl || d.isReachable())) {
devicesList.add(d);
if (!d.isReachable()) {
items.add(new UnreachableDeviceItem(d));
items.add(new UnreachableDeviceItem(d, device -> deviceClicked(device, intentHasUrl, intent)));
} else {
items.add(new DeviceItem(d));
items.add(new DeviceItem(d, device -> deviceClicked(device, intentHasUrl, intent)));
}
section.isEmpty = false;
}
}
getBinding().devicesListLayout.devicesList.setAdapter(new ListAdapter(ShareActivity.this, items));
getBinding().devicesListLayout.devicesList.setOnItemClickListener((adapterView, view, i, l) -> {
Device device = devicesList.get(i - 1); //NOTE: -1 because of the title!
// Configure focus order for Accessibility, for touchpads, and for TV remotes
// (allow focus of items in the device list)
getBinding().devicesListLayout.devicesList.setItemsCanFocus(true);
}
private Unit deviceClicked(Device device, boolean intentHasUrl, Intent intent) {
SharePlugin plugin = KdeConnect.getInstance().getDevicePlugin(device.getDeviceId(), SharePlugin.class);
if (intentHasUrl && !device.isReachable()) {
// Store the URL to be delivered once device becomes online
@ -130,7 +136,7 @@ public class ShareActivity extends BaseActivity<ActivityShareBinding> {
plugin.share(intent);
}
finish();
});
return Unit.INSTANCE;
}
private boolean doesIntentContainUrl(Intent intent) {

View File

@ -12,11 +12,9 @@ import org.kde.kdeconnect_tp.databinding.ListItemDeviceEntryBinding
open class DeviceItem(
val device: Device,
private val callback: ((d: Device) -> Unit)?
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 {
@ -25,11 +23,9 @@ open class DeviceItem(
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()
}

View File

@ -12,7 +12,7 @@ import org.kde.kdeconnect_tp.R
class PairingDeviceItem(
device: Device,
callback: ((d: Device) -> Unit)?
callback: ((d: Device) -> Unit)
) : DeviceItem(device, callback) {
override fun inflateView(layoutInflater: LayoutInflater): View {
return super.inflateView(layoutInflater).also {

View File

@ -10,7 +10,10 @@ import android.view.View
import org.kde.kdeconnect.Device
import org.kde.kdeconnect_tp.R
class UnreachableDeviceItem(device: Device) : DeviceItem(device) {
class UnreachableDeviceItem(
device: Device,
callback: ((d: Device) -> Unit),
) : DeviceItem(device, callback) {
override fun inflateView(layoutInflater: LayoutInflater): View {
return super.inflateView(layoutInflater).also {
binding.listItemEntrySummary.setText(R.string.runcommand_notreachable)