Adds a control on the id which sends broadcast to activity
This commit is contained in:
parent
153dc8f15f
commit
385d1fce72
|
@ -142,6 +142,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
private boolean display_local, display_global;
|
private boolean display_local, display_global;
|
||||||
public static int countNewStatus = 0;
|
public static int countNewStatus = 0;
|
||||||
public static int countNewNotifications = 0;
|
public static int countNewNotifications = 0;
|
||||||
|
private String userIdService;
|
||||||
|
|
||||||
public MainActivity() {
|
public MainActivity() {
|
||||||
}
|
}
|
||||||
|
@ -157,34 +158,38 @@ public class MainActivity extends AppCompatActivity
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Bundle b = intent.getExtras();
|
Bundle b = intent.getExtras();
|
||||||
StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
||||||
if( eventStreaming == StreamingService.EventStreaming.NOTIFICATION){
|
userIdService = b.getString("userIdService", null);
|
||||||
Notification notification = b.getParcelable("data");
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
if(notificationsFragment != null){
|
if( userIdService != null && userIdService.equals(userId)) {
|
||||||
notificationsFragment.refresh(notification);
|
if (eventStreaming == StreamingService.EventStreaming.NOTIFICATION) {
|
||||||
countNewNotifications++;
|
Notification notification = b.getParcelable("data");
|
||||||
}else {
|
if (notificationsFragment != null) {
|
||||||
tempNotifications.add(notification);
|
notificationsFragment.refresh(notification);
|
||||||
}
|
countNewNotifications++;
|
||||||
}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 {
|
} 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);
|
Intent intentService = new Intent(this, StreamingService.class);
|
||||||
|
|
|
@ -176,7 +176,7 @@ public class StreamingService extends Service {
|
||||||
lastEvent = EventStreaming.NONE;
|
lastEvent = EventStreaming.NONE;
|
||||||
try {
|
try {
|
||||||
JSONObject eventJson = new JSONObject(event);
|
JSONObject eventJson = new JSONObject(event);
|
||||||
onRetrieveStreaming(eventStreaming, eventJson);
|
onRetrieveStreaming(eventStreaming, account, eventJson);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
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 )
|
if( response == null )
|
||||||
return;
|
return;
|
||||||
//No previous notifications in cache, so no notification will be sent
|
//No previous notifications in cache, so no notification will be sent
|
||||||
|
@ -232,6 +232,7 @@ public class StreamingService extends Service {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
b.putString("userIdService", account.getId());
|
||||||
Intent intentBC = new Intent(Helper.RECEIVE_DATA);
|
Intent intentBC = new Intent(Helper.RECEIVE_DATA);
|
||||||
intentBC.putExtra("eventStreaming", event);
|
intentBC.putExtra("eventStreaming", event);
|
||||||
intentBC.putExtras(b);
|
intentBC.putExtras(b);
|
||||||
|
|
|
@ -145,6 +145,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
private boolean display_local, display_global;
|
private boolean display_local, display_global;
|
||||||
public static int countNewStatus = 0;
|
public static int countNewStatus = 0;
|
||||||
public static int countNewNotifications = 0;
|
public static int countNewNotifications = 0;
|
||||||
|
private String userIdService;
|
||||||
|
|
||||||
public MainActivity() {
|
public MainActivity() {
|
||||||
}
|
}
|
||||||
|
@ -160,34 +161,38 @@ public class MainActivity extends AppCompatActivity
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Bundle b = intent.getExtras();
|
Bundle b = intent.getExtras();
|
||||||
StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
||||||
if( eventStreaming == StreamingService.EventStreaming.NOTIFICATION){
|
userIdService = b.getString("userIdService", null);
|
||||||
Notification notification = b.getParcelable("data");
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
if(notificationsFragment != null){
|
if( userIdService != null && userIdService.equals(userId)) {
|
||||||
notificationsFragment.refresh(notification);
|
if (eventStreaming == StreamingService.EventStreaming.NOTIFICATION) {
|
||||||
countNewNotifications++;
|
Notification notification = b.getParcelable("data");
|
||||||
}else {
|
if (notificationsFragment != null) {
|
||||||
tempNotifications.add(notification);
|
notificationsFragment.refresh(notification);
|
||||||
}
|
countNewNotifications++;
|
||||||
}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 {
|
} 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);
|
Intent intentService = new Intent(this, StreamingService.class);
|
||||||
|
|
Loading…
Reference in New Issue