Last improvements for 1.4.9-beta-2
This commit is contained in:
parent
724c459740
commit
5aeb317eca
|
@ -100,6 +100,8 @@ import fr.gouv.etalab.mastodon.fragments.TabLayoutSettingsFragment;
|
|||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment.tempNotifications;
|
||||
import static fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment.tempStatuses;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_THEME_INTENT;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_USER_INTENT;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT;
|
||||
|
@ -155,16 +157,20 @@ public class MainActivity extends AppCompatActivity
|
|||
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){
|
||||
Notification notification = b.getParcelable("data");
|
||||
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");
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.util.List;
|
|||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.drawers.NotificationsListAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
@ -61,6 +62,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
private ListView lv_notifications;
|
||||
private String lastReadNotifications;
|
||||
private String userId;
|
||||
public static ArrayList<Notification> tempNotifications = new ArrayList<>();
|
||||
|
||||
public DisplayNotificationsFragment(){
|
||||
}
|
||||
|
@ -157,6 +159,19 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
for(Notification notification: tempNotifications){
|
||||
int index = lv_notifications.getFirstVisiblePosition() + 1;
|
||||
View v = lv_notifications.getChildAt(0);
|
||||
int top = (v == null) ? 0 : v.getTop();
|
||||
notifications.add(0,notification);
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
lv_notifications.setSelectionFromTop(index, top);
|
||||
if (textviewNoAction.getVisibility() == View.VISIBLE)
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
}
|
||||
((MainActivity)context).updateNotifCounter();
|
||||
tempNotifications.clear();
|
||||
tempNotifications = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -77,6 +77,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
private String instanceValue;
|
||||
private String lastReadStatus;
|
||||
private String userId;
|
||||
public static ArrayList<Status> tempStatuses = new ArrayList<>();
|
||||
|
||||
public DisplayStatusFragment(){
|
||||
}
|
||||
|
@ -229,6 +230,24 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if( type == RetrieveFeedsAsyncTask.Type.HOME && tempStatuses != null && tempStatuses.size() > 0 ){
|
||||
for(Status status: tempStatuses){
|
||||
int index = lv_status.getFirstVisiblePosition() + 1;
|
||||
View v = lv_status.getChildAt(0);
|
||||
int top = (v == null) ? 0 : v.getTop();
|
||||
status.setReplies(new ArrayList<Status>());
|
||||
statuses.add(0,status);
|
||||
statusListAdapter.notifyDataSetChanged();
|
||||
lv_status.setSelectionFromTop(index, top);
|
||||
if (textviewNoAction.getVisibility() == View.VISIBLE)
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
MainActivity.countNewStatus++;
|
||||
}
|
||||
if( getActivity() != null && getActivity().getClass().isInstance(MainActivity.class))
|
||||
((MainActivity)context).updateHomeCounter();
|
||||
tempStatuses.clear();
|
||||
tempStatuses = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -176,7 +176,7 @@ public class StreamingService extends Service {
|
|||
lastEvent = EventStreaming.NONE;
|
||||
try {
|
||||
JSONObject eventJson = new JSONObject(event);
|
||||
onRetrieveStreaming(eventStreaming, eventJson, account.getId());
|
||||
onRetrieveStreaming(eventStreaming, eventJson);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ public class StreamingService extends Service {
|
|||
}
|
||||
|
||||
|
||||
public void onRetrieveStreaming(EventStreaming event, JSONObject response, String userId) {
|
||||
public void onRetrieveStreaming(EventStreaming event, JSONObject response) {
|
||||
if( response == null )
|
||||
return;
|
||||
//No previous notifications in cache, so no notification will be sent
|
||||
|
|
|
@ -102,6 +102,8 @@ import fr.gouv.etalab.mastodon.fragments.TabLayoutSettingsFragment;
|
|||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment.tempNotifications;
|
||||
import static fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment.tempStatuses;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_THEME_INTENT;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_USER_INTENT;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT;
|
||||
|
@ -158,16 +160,20 @@ public class MainActivity extends AppCompatActivity
|
|||
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){
|
||||
Notification notification = b.getParcelable("data");
|
||||
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");
|
||||
|
|
Loading…
Reference in New Issue