Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Network
KDE Connect Android
Commits
874e100e
Commit
874e100e
authored
Jan 26, 2019
by
Erik Duisters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add packet type "kdeconnect.share.request.update" to allow android to update the share notification
parent
205745af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
5 deletions
+35
-5
src/org/kde/kdeconnect/Plugins/SharePlugin/CompositeReceiveFileRunnable.java
...ect/Plugins/SharePlugin/CompositeReceiveFileRunnable.java
+23
-4
src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java
src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java
+12
-1
No files found.
src/org/kde/kdeconnect/Plugins/SharePlugin/CompositeReceiveFileRunnable.java
View file @
874e100e
...
...
@@ -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
(
25
0
);
Thread
.
sleep
(
100
0
);
}
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
);
...
...
src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java
View file @
874e100e
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment