Adds a control on the id which sends broadcast to activity

This commit is contained in:
tom79 2017-09-20 15:00:47 +02:00
parent 153dc8f15f
commit 385d1fce72
3 changed files with 59 additions and 48 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);