diff --git a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/SendKeystrokesToHostActivity.java b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/SendKeystrokesToHostActivity.java index de1d2f04..ff245caf 100644 --- a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/SendKeystrokesToHostActivity.java +++ b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/SendKeystrokesToHostActivity.java @@ -36,6 +36,7 @@ import java.util.stream.Collectors; import kotlin.Lazy; import kotlin.LazyKt; +import kotlin.Unit; public class SendKeystrokesToHostActivity extends BaseActivity { @@ -166,17 +167,16 @@ public class SendKeystrokesToHostActivity extends BaseActivity { - 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 - val deviceId = pairedDevices[position].deviceId - saveWidgetDeviceIdPref(this, appWidgetId, deviceId) - - val appWidgetManager = AppWidgetManager.getInstance(this) - updateAppWidget(this, appWidgetManager, appWidgetId) - - val resultValue = Intent() - resultValue.putExtra(EXTRA_APPWIDGET_ID, appWidgetId) - setResult(RESULT_OK, resultValue) - finish() - } binding.runCommandsDeviceList.emptyView = binding.noDevices } + + fun deviceClicked(device: Device) { + val deviceId = device.deviceId + saveWidgetDeviceIdPref(this, appWidgetId, deviceId) + + val appWidgetManager = AppWidgetManager.getInstance(this) + updateAppWidget(this, appWidgetManager, appWidgetId) + + val resultValue = Intent() + resultValue.putExtra(EXTRA_APPWIDGET_ID, appWidgetId) + setResult(RESULT_OK, resultValue) + finish() + } } private const val PREFS_NAME = "org.kde.kdeconnect_tp.WidgetProvider" diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java index 12037e2d..ef5ef9fe 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java @@ -39,6 +39,7 @@ import java.util.Set; import kotlin.Lazy; import kotlin.LazyKt; +import kotlin.Unit; public class ShareActivity extends BaseActivity { private static final String KEY_UNREACHABLE_URL_LIST = "key_unreachable_url_list"; @@ -111,26 +112,31 @@ public class ShareActivity extends BaseActivity { 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! - SharePlugin plugin = KdeConnect.getInstance().getDevicePlugin(device.getDeviceId(), SharePlugin.class); - if (intentHasUrl && !device.isReachable()) { - // Store the URL to be delivered once device becomes online - storeUrlForFutureDelivery(device, intent.getStringExtra(Intent.EXTRA_TEXT)); - } else if (plugin != null) { - plugin.share(intent); - } - finish(); - }); + + // 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 + storeUrlForFutureDelivery(device, intent.getStringExtra(Intent.EXTRA_TEXT)); + } else if (plugin != null) { + plugin.share(intent); + } + finish(); + return Unit.INSTANCE; } private boolean doesIntentContainUrl(Intent intent) { diff --git a/src/org/kde/kdeconnect/UserInterface/List/DeviceItem.kt b/src/org/kde/kdeconnect/UserInterface/List/DeviceItem.kt index 3e53c289..5f48e667 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/DeviceItem.kt +++ b/src/org/kde/kdeconnect/UserInterface/List/DeviceItem.kt @@ -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) - }) - } + binding.getRoot().setOnClickListener(View.OnClickListener { v1: View? -> + callback(device) + }) return binding.getRoot() } diff --git a/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.kt b/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.kt index b42613cc..a5dc9a9d 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.kt +++ b/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.kt @@ -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 { diff --git a/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.kt b/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.kt index db9f4ffd..2ada2c14 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.kt +++ b/src/org/kde/kdeconnect/UserInterface/List/UnreachableDeviceItem.kt @@ -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)