mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 13:47:41 +00:00
Add packet type "kdeconnect.share.request.update" to allow android to update the share notification
This commit is contained in:
parent
e1b665bc06
commit
e098ebdaf4
@ -68,6 +68,7 @@ public class CompositeReceiveFileRunnable implements Runnable {
|
||||
private final List<NetworkPacket> networkPacketList;
|
||||
private int totalNumFiles;
|
||||
private long totalPayloadSize;
|
||||
private boolean isRunning;
|
||||
|
||||
CompositeReceiveFileRunnable(Device device, CallBack callBack) {
|
||||
this.device = device;
|
||||
@ -85,16 +86,28 @@ public class CompositeReceiveFileRunnable implements Runnable {
|
||||
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) {
|
||||
if (!networkPacketList.contains(networkPacket)) {
|
||||
synchronized (lock) {
|
||||
synchronized (lock) {
|
||||
if (!networkPacketList.contains(networkPacket)) {
|
||||
networkPacketList.add(networkPacket);
|
||||
|
||||
totalNumFiles = networkPacket.getInt(SharePlugin.KEY_NUMBER_OF_FILES, 1);
|
||||
totalPayloadSize = networkPacket.getLong(SharePlugin.KEY_TOTAL_PAYLOAD_SIZE);
|
||||
|
||||
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 {
|
||||
DocumentFile fileDocument = null;
|
||||
|
||||
isRunning = true;
|
||||
|
||||
while (!done) {
|
||||
synchronized (lock) {
|
||||
currentNetworkPacket = networkPacketList.get(0);
|
||||
@ -150,7 +165,7 @@ public class CompositeReceiveFileRunnable implements Runnable {
|
||||
|
||||
if (listIsEmpty) {
|
||||
try {
|
||||
Thread.sleep(250);
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ignored) {}
|
||||
|
||||
synchronized (lock) {
|
||||
@ -165,6 +180,8 @@ public class CompositeReceiveFileRunnable implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
isRunning = false;
|
||||
|
||||
int numFiles;
|
||||
synchronized (lock) {
|
||||
numFiles = totalNumFiles;
|
||||
@ -185,6 +202,8 @@ public class CompositeReceiveFileRunnable implements Runnable {
|
||||
}
|
||||
handler.post(() -> callBack.onSuccess(this));
|
||||
} catch (Exception e) {
|
||||
isRunning = false;
|
||||
|
||||
int failedFiles;
|
||||
synchronized (lock) {
|
||||
failedFiles = (totalNumFiles - currentFileNum + 1);
|
||||
|
@ -59,6 +59,7 @@ import androidx.core.content.ContextCompat;
|
||||
|
||||
public class SharePlugin extends Plugin {
|
||||
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_TOTAL_PAYLOAD_SIZE = "totalPayloadSize";
|
||||
@ -122,6 +123,16 @@ public class SharePlugin extends Plugin {
|
||||
@WorkerThread
|
||||
public boolean onPacketReceived(NetworkPacket np) {
|
||||
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 (isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
receiveFile(np);
|
||||
@ -388,7 +399,7 @@ public class SharePlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPacketTypes() {
|
||||
return new String[]{PACKET_TYPE_SHARE_REQUEST};
|
||||
return new String[]{PACKET_TYPE_SHARE_REQUEST, PACKET_TYPE_SHARE_REQUEST_UPDATE};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user