mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-01 06:35:09 +00:00
Add packet type "kdeconnect.share.request.update" to allow android to update the share notification
This commit is contained in:
@@ -68,6 +68,7 @@ public class CompositeReceiveFileRunnable implements Runnable {
|
|||||||
private final List<NetworkPacket> networkPacketList;
|
private final List<NetworkPacket> networkPacketList;
|
||||||
private int totalNumFiles;
|
private int totalNumFiles;
|
||||||
private long totalPayloadSize;
|
private long totalPayloadSize;
|
||||||
|
private boolean isRunning;
|
||||||
|
|
||||||
CompositeReceiveFileRunnable(Device device, CallBack callBack) {
|
CompositeReceiveFileRunnable(Device device, CallBack callBack) {
|
||||||
this.device = device;
|
this.device = device;
|
||||||
@@ -85,16 +86,28 @@ public class CompositeReceiveFileRunnable implements Runnable {
|
|||||||
handler = new Handler(Looper.getMainLooper());
|
handler = new Handler(Looper.getMainLooper());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isRunning() { return isRunning; }
|
||||||
|
|
||||||
|
void updateTotals(int numberOfFiles, long totalPayloadSize) {
|
||||||
|
synchronized (lock) {
|
||||||
|
this.totalNumFiles = numberOfFiles;
|
||||||
|
this.totalPayloadSize = totalPayloadSize;
|
||||||
|
|
||||||
|
shareNotification.setTitle(device.getContext().getResources()
|
||||||
|
.getQuantityString(R.plurals.incoming_file_title, totalNumFiles, totalNumFiles, device.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void addNetworkPacket(NetworkPacket networkPacket) {
|
void addNetworkPacket(NetworkPacket networkPacket) {
|
||||||
if (!networkPacketList.contains(networkPacket)) {
|
synchronized (lock) {
|
||||||
synchronized (lock) {
|
if (!networkPacketList.contains(networkPacket)) {
|
||||||
networkPacketList.add(networkPacket);
|
networkPacketList.add(networkPacket);
|
||||||
|
|
||||||
totalNumFiles = networkPacket.getInt(SharePlugin.KEY_NUMBER_OF_FILES, 1);
|
totalNumFiles = networkPacket.getInt(SharePlugin.KEY_NUMBER_OF_FILES, 1);
|
||||||
totalPayloadSize = networkPacket.getLong(SharePlugin.KEY_TOTAL_PAYLOAD_SIZE);
|
totalPayloadSize = networkPacket.getLong(SharePlugin.KEY_TOTAL_PAYLOAD_SIZE);
|
||||||
|
|
||||||
shareNotification.setTitle(device.getContext().getResources()
|
shareNotification.setTitle(device.getContext().getResources()
|
||||||
.getQuantityString(R.plurals.incoming_file_title, totalNumFiles, totalNumFiles, device.getName()));
|
.getQuantityString(R.plurals.incoming_file_title, totalNumFiles, totalNumFiles, device.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,6 +124,8 @@ public class CompositeReceiveFileRunnable implements Runnable {
|
|||||||
try {
|
try {
|
||||||
DocumentFile fileDocument = null;
|
DocumentFile fileDocument = null;
|
||||||
|
|
||||||
|
isRunning = true;
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
currentNetworkPacket = networkPacketList.get(0);
|
currentNetworkPacket = networkPacketList.get(0);
|
||||||
@@ -150,7 +165,7 @@ public class CompositeReceiveFileRunnable implements Runnable {
|
|||||||
|
|
||||||
if (listIsEmpty) {
|
if (listIsEmpty) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(250);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException ignored) {}
|
} catch (InterruptedException ignored) {}
|
||||||
|
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
@@ -165,6 +180,8 @@ public class CompositeReceiveFileRunnable implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isRunning = false;
|
||||||
|
|
||||||
int numFiles;
|
int numFiles;
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
numFiles = totalNumFiles;
|
numFiles = totalNumFiles;
|
||||||
@@ -185,6 +202,8 @@ public class CompositeReceiveFileRunnable implements Runnable {
|
|||||||
}
|
}
|
||||||
handler.post(() -> callBack.onSuccess(this));
|
handler.post(() -> callBack.onSuccess(this));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
isRunning = false;
|
||||||
|
|
||||||
int failedFiles;
|
int failedFiles;
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
failedFiles = (totalNumFiles - currentFileNum + 1);
|
failedFiles = (totalNumFiles - currentFileNum + 1);
|
||||||
|
@@ -59,6 +59,7 @@ import androidx.core.content.ContextCompat;
|
|||||||
|
|
||||||
public class SharePlugin extends Plugin {
|
public class SharePlugin extends Plugin {
|
||||||
private final static String PACKET_TYPE_SHARE_REQUEST = "kdeconnect.share.request";
|
private final static String PACKET_TYPE_SHARE_REQUEST = "kdeconnect.share.request";
|
||||||
|
final static String PACKET_TYPE_SHARE_REQUEST_UPDATE = "kdeconnect.share.request.update";
|
||||||
|
|
||||||
final static String KEY_NUMBER_OF_FILES = "numberOfFiles";
|
final static String KEY_NUMBER_OF_FILES = "numberOfFiles";
|
||||||
final static String KEY_TOTAL_PAYLOAD_SIZE = "totalPayloadSize";
|
final static String KEY_TOTAL_PAYLOAD_SIZE = "totalPayloadSize";
|
||||||
@@ -122,6 +123,16 @@ public class SharePlugin extends Plugin {
|
|||||||
@WorkerThread
|
@WorkerThread
|
||||||
public boolean onPacketReceived(NetworkPacket np) {
|
public boolean onPacketReceived(NetworkPacket np) {
|
||||||
try {
|
try {
|
||||||
|
if (np.getType().equals(PACKET_TYPE_SHARE_REQUEST_UPDATE)) {
|
||||||
|
if (receiveFileRunnable != null && receiveFileRunnable.isRunning()) {
|
||||||
|
receiveFileRunnable.updateTotals(np.getInt(KEY_NUMBER_OF_FILES), np.getLong(KEY_TOTAL_PAYLOAD_SIZE));
|
||||||
|
} else {
|
||||||
|
Log.d("SharePlugin", "Received update packet but CompositeUploadJob is null or not running");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (np.has("filename")) {
|
if (np.has("filename")) {
|
||||||
if (isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
if (isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
receiveFile(np);
|
receiveFile(np);
|
||||||
@@ -388,7 +399,7 @@ public class SharePlugin extends Plugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSupportedPacketTypes() {
|
public String[] getSupportedPacketTypes() {
|
||||||
return new String[]{PACKET_TYPE_SHARE_REQUEST};
|
return new String[]{PACKET_TYPE_SHARE_REQUEST, PACKET_TYPE_SHARE_REQUEST_UPDATE};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user