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:
committed by
Albert Vaca Cintora
parent
45da75f331
commit
ec952b49d9
@@ -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);
|
||||
}
|
||||
|
||||
}
|
@@ -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
|
||||
}
|
||||
}
|
@@ -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; }
|
||||
}
|
@@ -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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user