mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-21 17:37:39 +00:00
Compare commits
2 Commits
a733433551
...
04f5863f6a
Author | SHA1 | Date | |
---|---|---|---|
|
04f5863f6a | ||
|
c0c5ba1024 |
@ -298,6 +298,7 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="org.kde.kdeconnect.Plugins.MousePadPlugin.MousePadActivity" />
|
||||
</activity>
|
||||
<!-- TODO: Remove? This is only used by https://github.com/andOTP/andOTP, which is unmaintained since 2021. Do people use forks or can we remove this? -->
|
||||
<activity
|
||||
android:name="org.kde.kdeconnect.Plugins.MousePadPlugin.SendKeystrokesToHostActivity"
|
||||
android:label="@string/pref_plugin_mousepad_send_keystrokes"
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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,24 +40,25 @@ 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
|
||||
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"
|
||||
|
@ -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,26 +112,31 @@ 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!
|
||||
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) {
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user