2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 06:05:12 +00:00

Migrate LoopbackBackend to Kotlin

This commit is contained in:
TPJ Schikhof
2024-09-10 21:22:59 +00:00
committed by Albert Vaca Cintora
parent 45da75f331
commit ec952b49d9
4 changed files with 66 additions and 96 deletions

View File

@@ -1,50 +0,0 @@
/*
* SPDX-FileCopyrightText: 2014 Albert Vaca Cintora <albertvaka@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
package org.kde.kdeconnect.Backends.LoopbackBackend;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.WorkerThread;
import org.kde.kdeconnect.Backends.BaseLink;
import org.kde.kdeconnect.Backends.BaseLinkProvider;
import org.kde.kdeconnect.Device;
import org.kde.kdeconnect.DeviceInfo;
import org.kde.kdeconnect.Helpers.DeviceHelper;
import org.kde.kdeconnect.NetworkPacket;
public class LoopbackLink extends BaseLink {
public LoopbackLink(Context context, BaseLinkProvider linkProvider) {
super(context, linkProvider);
}
@Override
public String getName() {
return "LoopbackLink";
}
@WorkerThread
@Override
public boolean sendPacket(@NonNull NetworkPacket in, @NonNull Device.SendPacketStatusCallback callback, boolean sendPayloadFromSameThread) {
packetReceived(in);
if (in.hasPayload()) {
callback.onPayloadProgressChanged(0);
in.setPayload(in.getPayload());
callback.onPayloadProgressChanged(100);
}
callback.onSuccess();
return true;
}
@Override
public DeviceInfo getDeviceInfo() {
return DeviceHelper.getDeviceInfo(context);
}
}

View File

@@ -0,0 +1,34 @@
/*
* SPDX-FileCopyrightText: 2014 Albert Vaca Cintora <albertvaka@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
package org.kde.kdeconnect.Backends.LoopbackBackend
import android.content.Context
import androidx.annotation.WorkerThread
import org.kde.kdeconnect.Backends.BaseLink
import org.kde.kdeconnect.Backends.BaseLinkProvider
import org.kde.kdeconnect.Device
import org.kde.kdeconnect.DeviceInfo
import org.kde.kdeconnect.Helpers.DeviceHelper.getDeviceInfo
import org.kde.kdeconnect.NetworkPacket
class LoopbackLink : BaseLink {
constructor(context: Context, linkProvider: BaseLinkProvider) : super(context, linkProvider)
override fun getName(): String = "LoopbackLink"
override fun getDeviceInfo(): DeviceInfo = getDeviceInfo(context)
@WorkerThread
override fun sendPacket(packet: NetworkPacket, callback: Device.SendPacketStatusCallback, sendPayloadFromSameThread: Boolean): Boolean {
packetReceived(packet)
if (packet.hasPayload()) {
callback.onPayloadProgressChanged(0)
packet.payload = packet.payload // this triggers logic in the setter
callback.onPayloadProgressChanged(100)
}
callback.onSuccess()
return true
}
}

View File

@@ -1,46 +0,0 @@
/*
* SPDX-FileCopyrightText: 2014 Albert Vaca Cintora <albertvaka@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
package org.kde.kdeconnect.Backends.LoopbackBackend;
import android.content.Context;
import android.net.Network;
import androidx.annotation.Nullable;
import org.kde.kdeconnect.Backends.BaseLinkProvider;
public class LoopbackLinkProvider extends BaseLinkProvider {
private final Context context;
public LoopbackLinkProvider(Context context) {
this.context = context;
}
@Override
public void onStart() {
onNetworkChange(null);
}
@Override
public void onStop() {
}
@Override
public void onNetworkChange(@Nullable Network network) {
LoopbackLink link = new LoopbackLink(context, this);
onConnectionReceived(link);
}
@Override
public String getName() {
return "LoopbackLinkProvider";
}
@Override
public int getPriority() { return 0; }
}

View File

@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: 2014 Albert Vaca Cintora <albertvaka@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
package org.kde.kdeconnect.Backends.LoopbackBackend
import android.content.Context
import android.net.Network
import org.kde.kdeconnect.Backends.BaseLinkProvider
class LoopbackLinkProvider : BaseLinkProvider {
private val context: Context
constructor(context: Context) : super() {
this.context = context
}
override fun getName(): String = "LoopbackLinkProvider"
override fun getPriority(): Int = 0
override fun onStart() {
onNetworkChange(null)
}
override fun onStop() { }
override fun onNetworkChange(network: Network?) {
val link = LoopbackLink(context, this)
onConnectionReceived(link)
}
}