Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java
Show First 20 Lines • Show All 213 Lines • ▼ Show 20 Line(s) | 213 | } catch (FileNotFoundException e) { | |||
---|---|---|---|---|---|
214 | e.printStackTrace(); | 214 | e.printStackTrace(); | ||
215 | return; | 215 | return; | ||
216 | } | 216 | } | ||
217 | final Uri destinationUri = destinationDocument.getUri(); | 217 | final Uri destinationUri = destinationDocument.getUri(); | ||
218 | 218 | | |||
219 | final ShareNotification notification = new ShareNotification(device, filename); | 219 | final ShareNotification notification = new ShareNotification(device, filename); | ||
220 | notification.show(); | 220 | notification.show(); | ||
221 | 221 | | |||
222 | new Thread(new Runnable() { | 222 | new Thread(() -> { | ||
223 | @Override | | |||
224 | public void run() { | | |||
225 | try { | 223 | try { | ||
226 | byte data[] = new byte[4096]; | 224 | byte data[] = new byte[4096]; | ||
227 | long progress = 0, prevProgressPercentage = -1; | 225 | long progress = 0, prevProgressPercentage = -1; | ||
228 | int count; | 226 | int count; | ||
229 | long lastUpdate = 0; | 227 | long lastUpdate = 0; | ||
230 | while ((count = input.read(data)) >= 0) { | 228 | while ((count = input.read(data)) >= 0) { | ||
231 | progress += count; | 229 | progress += count; | ||
232 | destinationOutput.write(data, 0, count); | 230 | destinationOutput.write(data, 0, count); | ||
Show All 40 Lines | 270 | try { | |||
273 | destinationOutput.close(); | 271 | destinationOutput.close(); | ||
274 | } catch (Exception e) { | 272 | } catch (Exception e) { | ||
275 | } | 273 | } | ||
276 | try { | 274 | try { | ||
277 | input.close(); | 275 | input.close(); | ||
278 | } catch (Exception e) { | 276 | } catch (Exception e) { | ||
279 | } | 277 | } | ||
280 | } | 278 | } | ||
281 | } | | |||
282 | }).start(); | 279 | }).start(); | ||
283 | } | 280 | } | ||
284 | 281 | | |||
285 | @Override | 282 | @Override | ||
286 | public void startPreferencesActivity(SettingsActivity parentActivity) { | 283 | public void startPreferencesActivity(SettingsActivity parentActivity) { | ||
287 | Intent intent = new Intent(parentActivity, ShareSettingsActivity.class); | 284 | Intent intent = new Intent(parentActivity, ShareSettingsActivity.class); | ||
288 | intent.putExtra("plugin_display_name", getDisplayName()); | 285 | intent.putExtra("plugin_display_name", getDisplayName()); | ||
289 | intent.putExtra("plugin_key", getPluginKey()); | 286 | intent.putExtra("plugin_key", getPluginKey()); | ||
290 | parentActivity.startActivity(intent); | 287 | parentActivity.startActivity(intent); | ||
291 | } | 288 | } | ||
292 | 289 | | |||
293 | static void queuedSendUriList(Context context, final Device device, final ArrayList<Uri> uriList) { | 290 | static void queuedSendUriList(Context context, final Device device, final ArrayList<Uri> uriList) { | ||
294 | 291 | | |||
295 | //Read all the data early, as we only have permissions to do it while the activity is alive | 292 | //Read all the data early, as we only have permissions to do it while the activity is alive | ||
296 | final ArrayList<NetworkPacket> toSend = new ArrayList<>(); | 293 | final ArrayList<NetworkPacket> toSend = new ArrayList<>(); | ||
297 | for (Uri uri : uriList) { | 294 | for (Uri uri : uriList) { | ||
298 | toSend.add(uriToNetworkPacket(context, uri)); | 295 | toSend.add(uriToNetworkPacket(context, uri)); | ||
299 | } | 296 | } | ||
300 | 297 | | |||
301 | //Callback that shows a progress notification | 298 | //Callback that shows a progress notification | ||
302 | final NotificationUpdateCallback notificationUpdateCallback = new NotificationUpdateCallback(context, device, toSend); | 299 | final NotificationUpdateCallback notificationUpdateCallback = new NotificationUpdateCallback(context, device, toSend); | ||
303 | 300 | | |||
304 | //Do the sending in background | 301 | //Do the sending in background | ||
305 | new Thread(new Runnable() { | 302 | new Thread(() -> { | ||
306 | @Override | | |||
307 | public void run() { | | |||
308 | //Actually send the files | 303 | //Actually send the files | ||
309 | try { | 304 | try { | ||
310 | for (NetworkPacket np : toSend) { | 305 | for (NetworkPacket np : toSend) { | ||
311 | boolean success = device.sendPacketBlocking(np, notificationUpdateCallback); | 306 | boolean success = device.sendPacketBlocking(np, notificationUpdateCallback); | ||
312 | if (!success) { | 307 | if (!success) { | ||
313 | Log.e("SharePlugin", "Error sending files"); | 308 | Log.e("SharePlugin", "Error sending files"); | ||
314 | return; | 309 | return; | ||
315 | } | 310 | } | ||
316 | } | 311 | } | ||
317 | } catch (Exception e) { | 312 | } catch (Exception e) { | ||
318 | e.printStackTrace(); | 313 | e.printStackTrace(); | ||
319 | } | 314 | } | ||
320 | } | | |||
321 | }).start(); | 315 | }).start(); | ||
322 | 316 | | |||
323 | } | 317 | } | ||
324 | 318 | | |||
325 | //Create the network package from the URI | 319 | //Create the network package from the URI | ||
326 | private static NetworkPacket uriToNetworkPacket(final Context context, final Uri uri) { | 320 | private static NetworkPacket uriToNetworkPacket(final Context context, final Uri uri) { | ||
327 | 321 | | |||
328 | try { | 322 | try { | ||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |