From 385d1fce729add781ae91d4f916e31af4c8b3d64 Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 20 Sep 2017 15:00:47 +0200 Subject: [PATCH] Adds a control on the id which sends broadcast to activity --- .../activities/MainActivity.java | 51 ++++++++++--------- .../mastodon/services/StreamingService.java | 5 +- .../activities/MainActivity.java | 51 ++++++++++--------- 3 files changed, 59 insertions(+), 48 deletions(-) diff --git a/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java b/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java index 43a286b88..b68464142 100644 --- a/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java +++ b/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java @@ -142,6 +142,7 @@ public class MainActivity extends AppCompatActivity private boolean display_local, display_global; public static int countNewStatus = 0; public static int countNewNotifications = 0; + private String userIdService; public MainActivity() { } @@ -157,34 +158,38 @@ public class MainActivity extends AppCompatActivity public void onReceive(Context context, Intent intent) { Bundle b = intent.getExtras(); StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming"); - if( eventStreaming == StreamingService.EventStreaming.NOTIFICATION){ - Notification notification = b.getParcelable("data"); - if(notificationsFragment != null){ - notificationsFragment.refresh(notification); - countNewNotifications++; - }else { - tempNotifications.add(notification); - } - }else if(eventStreaming == StreamingService.EventStreaming.UPDATE){ - Status status = b.getParcelable("data"); - if( homeFragment != null){ - homeFragment.refresh(status); - countNewStatus++; - }else { - tempStatuses.add(status); - } - }else if(eventStreaming == StreamingService.EventStreaming.DELETE){ - String id = b.getString("id"); - if(notificationsFragment != null) { - if (notificationsFragment.getUserVisibleHint()) { - + userIdService = b.getString("userIdService", null); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + if( userIdService != null && userIdService.equals(userId)) { + if (eventStreaming == StreamingService.EventStreaming.NOTIFICATION) { + Notification notification = b.getParcelable("data"); + if (notificationsFragment != null) { + notificationsFragment.refresh(notification); + countNewNotifications++; } else { + tempNotifications.add(notification); + } + } else if (eventStreaming == StreamingService.EventStreaming.UPDATE) { + Status status = b.getParcelable("data"); + if (homeFragment != null) { + homeFragment.refresh(status); + countNewStatus++; + } else { + tempStatuses.add(status); + } + } else if (eventStreaming == StreamingService.EventStreaming.DELETE) { + String id = b.getString("id"); + if (notificationsFragment != null) { + if (notificationsFragment.getUserVisibleHint()) { + } else { + + } } } + updateNotifCounter(); + updateHomeCounter(); } - updateNotifCounter(); - updateHomeCounter(); } }; Intent intentService = new Intent(this, StreamingService.class); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingService.java b/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingService.java index 82bd7f9cf..6ce069cbc 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingService.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingService.java @@ -176,7 +176,7 @@ public class StreamingService extends Service { lastEvent = EventStreaming.NONE; try { JSONObject eventJson = new JSONObject(event); - onRetrieveStreaming(eventStreaming, eventJson); + onRetrieveStreaming(eventStreaming, account, eventJson); } catch (JSONException e) { e.printStackTrace(); } @@ -208,7 +208,7 @@ public class StreamingService extends Service { } - public void onRetrieveStreaming(EventStreaming event, JSONObject response) { + public void onRetrieveStreaming(EventStreaming event, Account account, JSONObject response) { if( response == null ) return; //No previous notifications in cache, so no notification will be sent @@ -232,6 +232,7 @@ public class StreamingService extends Service { e.printStackTrace(); } } + b.putString("userIdService", account.getId()); Intent intentBC = new Intent(Helper.RECEIVE_DATA); intentBC.putExtra("eventStreaming", event); intentBC.putExtras(b); diff --git a/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java b/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java index 1c9a77b40..7384d4e57 100644 --- a/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java +++ b/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java @@ -145,6 +145,7 @@ public class MainActivity extends AppCompatActivity private boolean display_local, display_global; public static int countNewStatus = 0; public static int countNewNotifications = 0; + private String userIdService; public MainActivity() { } @@ -160,34 +161,38 @@ public class MainActivity extends AppCompatActivity public void onReceive(Context context, Intent intent) { Bundle b = intent.getExtras(); StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming"); - if( eventStreaming == StreamingService.EventStreaming.NOTIFICATION){ - Notification notification = b.getParcelable("data"); - if(notificationsFragment != null){ - notificationsFragment.refresh(notification); - countNewNotifications++; - }else { - tempNotifications.add(notification); - } - }else if(eventStreaming == StreamingService.EventStreaming.UPDATE){ - Status status = b.getParcelable("data"); - if( homeFragment != null){ - homeFragment.refresh(status); - countNewStatus++; - }else { - tempStatuses.add(status); - } - }else if(eventStreaming == StreamingService.EventStreaming.DELETE){ - String id = b.getString("id"); - if(notificationsFragment != null) { - if (notificationsFragment.getUserVisibleHint()) { - + userIdService = b.getString("userIdService", null); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + if( userIdService != null && userIdService.equals(userId)) { + if (eventStreaming == StreamingService.EventStreaming.NOTIFICATION) { + Notification notification = b.getParcelable("data"); + if (notificationsFragment != null) { + notificationsFragment.refresh(notification); + countNewNotifications++; } else { + tempNotifications.add(notification); + } + } else if (eventStreaming == StreamingService.EventStreaming.UPDATE) { + Status status = b.getParcelable("data"); + if (homeFragment != null) { + homeFragment.refresh(status); + countNewStatus++; + } else { + tempStatuses.add(status); + } + } else if (eventStreaming == StreamingService.EventStreaming.DELETE) { + String id = b.getString("id"); + if (notificationsFragment != null) { + if (notificationsFragment.getUserVisibleHint()) { + } else { + + } } } + updateNotifCounter(); + updateHomeCounter(); } - updateNotifCounter(); - updateHomeCounter(); } }; Intent intentService = new Intent(this, StreamingService.class);