Differential D12229 Diff 33881 src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java
Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java
Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | 61 | public class NotificationsPlugin extends Plugin implements NotificationReceiver.NotificationListener { | |||
---|---|---|---|---|---|
103 | public boolean onCreate() { | 103 | public boolean onCreate() { | ||
104 | 104 | | |||
105 | if (!hasPermission()) return false; | 105 | if (!hasPermission()) return false; | ||
106 | 106 | | |||
107 | pendingIntents = new HashMap<>(); | 107 | pendingIntents = new HashMap<>(); | ||
108 | 108 | | |||
109 | appDatabase = new AppDatabase(context, true); | 109 | appDatabase = new AppDatabase(context, true); | ||
110 | 110 | | |||
111 | NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() { | 111 | NotificationReceiver.RunCommand(context, service -> { | ||
112 | @Override | | |||
113 | public void onServiceStart(NotificationReceiver service) { | | |||
114 | 112 | | |||
115 | service.addListener(NotificationsPlugin.this); | 113 | service.addListener(NotificationsPlugin.this); | ||
116 | 114 | | |||
117 | serviceReady = service.isConnected(); | 115 | serviceReady = service.isConnected(); | ||
118 | 116 | | |||
119 | if (serviceReady) { | 117 | if (serviceReady) { | ||
120 | sendCurrentNotifications(service); | 118 | sendCurrentNotifications(service); | ||
121 | } | 119 | } | ||
122 | } | | |||
123 | }); | 120 | }); | ||
124 | 121 | | |||
125 | return true; | 122 | return true; | ||
126 | } | 123 | } | ||
127 | 124 | | |||
128 | @Override | 125 | @Override | ||
129 | public void onDestroy() { | 126 | public void onDestroy() { | ||
130 | 127 | | |||
131 | NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() { | 128 | NotificationReceiver.RunCommand(context, service -> service.removeListener(NotificationsPlugin.this)); | ||
132 | @Override | | |||
133 | public void onServiceStart(NotificationReceiver service) { | | |||
134 | service.removeListener(NotificationsPlugin.this); | | |||
135 | } | | |||
136 | }); | | |||
137 | } | 129 | } | ||
138 | 130 | | |||
139 | @Override | 131 | @Override | ||
140 | public void onListenerConnected(NotificationReceiver service) { | 132 | public void onListenerConnected(NotificationReceiver service) { | ||
141 | serviceReady = true; | 133 | serviceReady = true; | ||
142 | sendCurrentNotifications(service); | 134 | sendCurrentNotifications(service); | ||
143 | } | 135 | } | ||
144 | 136 | | |||
▲ Show 20 Lines • Show All 311 Lines • ▼ Show 20 Line(s) | |||||
456 | } | 448 | } | ||
457 | 449 | | |||
458 | @Override | 450 | @Override | ||
459 | public boolean onPacketReceived(final NetworkPacket np) { | 451 | public boolean onPacketReceived(final NetworkPacket np) { | ||
460 | 452 | | |||
461 | if (np.getBoolean("request")) { | 453 | if (np.getBoolean("request")) { | ||
462 | 454 | | |||
463 | if (serviceReady) { | 455 | if (serviceReady) { | ||
464 | NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() { | 456 | NotificationReceiver.RunCommand(context, this::sendCurrentNotifications); | ||
465 | @Override | | |||
466 | public void onServiceStart(NotificationReceiver service) { | | |||
467 | sendCurrentNotifications(service); | | |||
468 | } | | |||
469 | }); | | |||
470 | } | 457 | } | ||
471 | 458 | | |||
472 | } else if (np.has("cancel")) { | 459 | } else if (np.has("cancel")) { | ||
473 | 460 | | |||
474 | NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() { | 461 | NotificationReceiver.RunCommand(context, service -> { | ||
475 | @Override | | |||
476 | public void onServiceStart(NotificationReceiver service) { | | |||
477 | String dismissedId = np.getString("cancel"); | 462 | String dismissedId = np.getString("cancel"); | ||
478 | cancelNotificationCompat(service, dismissedId); | 463 | cancelNotificationCompat(service, dismissedId); | ||
479 | } | | |||
480 | }); | 464 | }); | ||
481 | 465 | | |||
482 | } else if (np.has("requestReplyId") && np.has("message")) { | 466 | } else if (np.has("requestReplyId") && np.has("message")) { | ||
483 | 467 | | |||
484 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { | 468 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { | ||
485 | replyToNotification(np.getString("requestReplyId"), np.getString("message")); | 469 | replyToNotification(np.getString("requestReplyId"), np.getString("message")); | ||
486 | } | 470 | } | ||
487 | 471 | | |||
488 | } | 472 | } | ||
489 | 473 | | |||
490 | return true; | 474 | return true; | ||
491 | } | 475 | } | ||
492 | 476 | | |||
493 | 477 | | |||
494 | @Override | 478 | @Override | ||
495 | public AlertDialog getErrorDialog(final Activity deviceActivity) { | 479 | public AlertDialog getErrorDialog(final Activity deviceActivity) { | ||
496 | 480 | | |||
497 | return new AlertDialog.Builder(deviceActivity) | 481 | return new AlertDialog.Builder(deviceActivity) | ||
498 | .setTitle(R.string.pref_plugin_notifications) | 482 | .setTitle(R.string.pref_plugin_notifications) | ||
499 | .setMessage(R.string.no_permissions) | 483 | .setMessage(R.string.no_permissions) | ||
500 | .setPositiveButton(R.string.open_settings, new DialogInterface.OnClickListener() { | 484 | .setPositiveButton(R.string.open_settings, (dialogInterface, i) -> { | ||
501 | @Override | | |||
502 | public void onClick(DialogInterface dialogInterface, int i) { | | |||
503 | Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); | 485 | Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); | ||
504 | deviceActivity.startActivityForResult(intent, MainActivity.RESULT_NEEDS_RELOAD); | 486 | deviceActivity.startActivityForResult(intent, MainActivity.RESULT_NEEDS_RELOAD); | ||
505 | } | | |||
506 | }) | 487 | }) | ||
507 | .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { | 488 | .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { | ||
508 | @Override | | |||
509 | public void onClick(DialogInterface dialogInterface, int i) { | | |||
510 | //Do nothing | 489 | //Do nothing | ||
511 | } | | |||
512 | }) | 490 | }) | ||
513 | .create(); | 491 | .create(); | ||
514 | 492 | | |||
515 | } | 493 | } | ||
516 | 494 | | |||
517 | @Override | 495 | @Override | ||
518 | public String[] getSupportedPacketTypes() { | 496 | public String[] getSupportedPacketTypes() { | ||
519 | return new String[]{PACKET_TYPE_NOTIFICATION_REQUEST, PACKET_TYPE_NOTIFICATION_REPLY}; | 497 | return new String[]{PACKET_TYPE_NOTIFICATION_REQUEST, PACKET_TYPE_NOTIFICATION_REPLY}; | ||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |