Reverts
This commit is contained in:
parent
a98d9d9453
commit
ab105e9ee5
|
@ -66,6 +66,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
private RecyclerView lv_notifications;
|
private RecyclerView lv_notifications;
|
||||||
private String lastReadNotifications;
|
private String lastReadNotifications;
|
||||||
private String userId;
|
private String userId;
|
||||||
|
private SharedPreferences sharedpreferences;
|
||||||
LinearLayoutManager mLayoutManager;
|
LinearLayoutManager mLayoutManager;
|
||||||
|
|
||||||
public DisplayNotificationsFragment(){
|
public DisplayNotificationsFragment(){
|
||||||
|
@ -81,9 +82,10 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
notifications = new ArrayList<>();
|
notifications = new ArrayList<>();
|
||||||
swiped = false;
|
swiped = false;
|
||||||
|
|
||||||
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
|
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
|
||||||
|
|
||||||
lv_notifications = rootView.findViewById(R.id.lv_notifications);
|
lv_notifications = rootView.findViewById(R.id.lv_notifications);
|
||||||
lv_notifications.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
|
lv_notifications.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
|
||||||
mainLoader = rootView.findViewById(R.id.loader);
|
mainLoader = rootView.findViewById(R.id.loader);
|
||||||
|
@ -171,7 +173,6 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRetrieveNotifications(APIResponse apiResponse, String acct, String userId, boolean refreshData) {
|
public void onRetrieveNotifications(APIResponse apiResponse, String acct, String userId, boolean refreshData) {
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
mainLoader.setVisibility(View.GONE);
|
mainLoader.setVisibility(View.GONE);
|
||||||
nextElementLoader.setVisibility(View.GONE);
|
nextElementLoader.setVisibility(View.GONE);
|
||||||
if( apiResponse.getError() != null){
|
if( apiResponse.getError() != null){
|
||||||
|
@ -211,11 +212,14 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
}
|
}
|
||||||
if( firstLoad) {
|
if( firstLoad) {
|
||||||
//Update the id of the last notification retrieved
|
//Update the id of the last notification retrieved
|
||||||
MainActivity.lastNotificationId = notifications.get(0).getId();
|
if( MainActivity.lastNotificationId == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(MainActivity.lastNotificationId))
|
||||||
if (notifications.size() > 0)
|
MainActivity.lastNotificationId = notifications.get(0).getId();
|
||||||
updateNotificationLastId(sharedpreferences, this.userId, notifications.get(0).getId());
|
updateNotificationLastId(notifications.get(0).getId());
|
||||||
}
|
}
|
||||||
notificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size());
|
notificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size());
|
||||||
|
}else {
|
||||||
|
if( firstLoad)
|
||||||
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
if( firstLoad )
|
if( firstLoad )
|
||||||
((MainActivity)context).updateNotifCounter();
|
((MainActivity)context).updateNotifCounter();
|
||||||
|
@ -239,9 +243,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
if( context == null)
|
if( context == null)
|
||||||
return;
|
return;
|
||||||
//Store last notification id to avoid to notify for those that have been already seen
|
//Store last notification id to avoid to notify for those that have been already seen
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
if (visible && notifications != null && notifications.size() > 0) {
|
if (visible && notifications != null && notifications.size() > 0) {
|
||||||
updateNotificationLastId(sharedpreferences, this.userId, notifications.get(0).getId());
|
updateNotificationLastId(notifications.get(0).getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,10 +252,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
if( lv_notifications != null)
|
if( lv_notifications != null)
|
||||||
lv_notifications.setAdapter(notificationsListAdapter);
|
lv_notifications.setAdapter(notificationsListAdapter);
|
||||||
//Store last toot id for home timeline to avoid to notify for those that have been already seen
|
//Store last toot id for home timeline to avoid to notify for those that have been already seen
|
||||||
//Store last notification id to avoid to notify for those that have been already seen
|
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
if (this.notifications != null && this.notifications.size() > 0) {
|
if (this.notifications != null && this.notifications.size() > 0) {
|
||||||
updateNotificationLastId(sharedpreferences, this.userId, this.notifications.get(0).getId());
|
updateNotificationLastId(this.notifications.get(0).getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,17 +314,15 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records the id of the notification only if its greater than the previous one.
|
* Records the id of the notification only if its greater than the previous one.
|
||||||
* @param sharedPreferences SharedPreferences
|
|
||||||
* @param userId String current logged user
|
|
||||||
* @param notificationId String current notification id to check
|
* @param notificationId String current notification id to check
|
||||||
*/
|
*/
|
||||||
private void updateNotificationLastId(SharedPreferences sharedPreferences, String userId, String notificationId){
|
private void updateNotificationLastId(String notificationId){
|
||||||
|
|
||||||
|
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId, null);
|
||||||
String lastNotif = sharedPreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId, null);
|
|
||||||
if( lastNotif == null || Long.parseLong(notificationId) > Long.parseLong(lastNotif)){
|
if( lastNotif == null || Long.parseLong(notificationId) > Long.parseLong(lastNotif)){
|
||||||
this.lastReadNotifications = notificationId;
|
this.lastReadNotifications = notificationId;
|
||||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
MainActivity.countNewNotifications = 0;
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notificationId);
|
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notificationId);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
private Intent streamingFederatedIntent, streamingLocalIntent;
|
private Intent streamingFederatedIntent, streamingLocalIntent;
|
||||||
LinearLayoutManager mLayoutManager;
|
LinearLayoutManager mLayoutManager;
|
||||||
boolean firstTootsLoaded;
|
boolean firstTootsLoaded;
|
||||||
|
private String lastReadStatus;
|
||||||
|
private String userId;
|
||||||
|
private SharedPreferences sharedpreferences;
|
||||||
|
|
||||||
public DisplayStatusFragment(){
|
public DisplayStatusFragment(){
|
||||||
}
|
}
|
||||||
|
@ -99,7 +102,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
firstLoad = true;
|
firstLoad = true;
|
||||||
swiped = false;
|
swiped = false;
|
||||||
assert context != null;
|
assert context != null;
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||||
int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
|
int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
|
||||||
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
|
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
|
||||||
|
@ -114,7 +117,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
lv_status.setAdapter(statusListAdapter);
|
lv_status.setAdapter(statusListAdapter);
|
||||||
mLayoutManager = new LinearLayoutManager(context);
|
mLayoutManager = new LinearLayoutManager(context);
|
||||||
lv_status.setLayoutManager(mLayoutManager);
|
lv_status.setLayoutManager(mLayoutManager);
|
||||||
|
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
lastReadStatus = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId, null);
|
||||||
|
|
||||||
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
|
||||||
|
@ -142,7 +146,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
if(statuses != null && statuses.size() > firstVisibleItem )
|
if(statuses != null && statuses.size() > firstVisibleItem )
|
||||||
if( context instanceof BaseMainActivity){
|
if( context instanceof BaseMainActivity){
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
Long bookmarkL = Long.parseLong(statuses.get(firstVisibleItem).getId()) + 1;
|
Long bookmarkL = Long.parseLong(statuses.get(firstVisibleItem).getId()) + 1;
|
||||||
editor.putString(Helper.BOOKMARK_ID + userId, String.valueOf(bookmarkL));
|
editor.putString(Helper.BOOKMARK_ID + userId, String.valueOf(bookmarkL));
|
||||||
editor.apply();
|
editor.apply();
|
||||||
|
@ -249,7 +252,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
mainLoader.setVisibility(View.GONE);
|
mainLoader.setVisibility(View.GONE);
|
||||||
nextElementLoader.setVisibility(View.GONE);
|
nextElementLoader.setVisibility(View.GONE);
|
||||||
//Discards 404 - error which can often happen due to toots which have been deleted
|
//Discards 404 - error which can often happen due to toots which have been deleted
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
if( apiResponse.getError() != null ){
|
if( apiResponse.getError() != null ){
|
||||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||||
if( show_error_messages && !apiResponse.getError().getError().startsWith("404 -"))
|
if( show_error_messages && !apiResponse.getError().getError().startsWith("404 -"))
|
||||||
|
@ -298,7 +300,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
this.statuses.addAll(statuses);
|
this.statuses.addAll(statuses);
|
||||||
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
||||||
}else { //Toots are younger than the bookmark
|
}else { //Toots are younger than the bookmark
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
String currentMaxId = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
|
String currentMaxId = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
|
||||||
int position = 0;
|
int position = 0;
|
||||||
while (position < this.statuses.size() && Long.parseLong(statuses.get(0).getId()) < Long.parseLong(this.statuses.get(position).getId())) {
|
while (position < this.statuses.size() && Long.parseLong(statuses.get(0).getId()) < Long.parseLong(this.statuses.get(position).getId())) {
|
||||||
|
@ -334,10 +335,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
this.statuses.addAll(statuses);
|
this.statuses.addAll(statuses);
|
||||||
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
||||||
}
|
}
|
||||||
if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME && statuses.size() > 0) {
|
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
|
||||||
//Update the id of the last toot retrieved
|
//Update the id of the last toot retrieved
|
||||||
MainActivity.lastHomeId = statuses.get(0).getId();
|
if( MainActivity.lastHomeId == null || Long.parseLong(statuses.get(0).getId()) > Long.parseLong(MainActivity.lastHomeId))
|
||||||
updateMaxId(statuses.get(0).getId());
|
MainActivity.lastHomeId = statuses.get(0).getId();
|
||||||
|
if( firstLoad )
|
||||||
|
updateNotificationLastId(statuses.get(0).getId());
|
||||||
}
|
}
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.HOME)
|
if( type == RetrieveFeedsAsyncTask.Type.HOME)
|
||||||
//Display new value in counter
|
//Display new value in counter
|
||||||
|
@ -363,17 +366,18 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
&& Long.parseLong(status.getId()) > Long.parseLong(statuses.get(0).getId())) {
|
&& Long.parseLong(status.getId()) > Long.parseLong(statuses.get(0).getId())) {
|
||||||
if (type == RetrieveFeedsAsyncTask.Type.HOME) {
|
if (type == RetrieveFeedsAsyncTask.Type.HOME) {
|
||||||
|
|
||||||
//Update the id of the last toot retrieved
|
//Makes sure the status is not already displayed
|
||||||
MainActivity.lastHomeId = status.getId();
|
if( lastReadStatus == null || Long.parseLong(status.getId()) > Long.parseLong(lastReadStatus)) {
|
||||||
status.setReplies(new ArrayList<Status>());
|
//Update the id of the last toot retrieved
|
||||||
statuses.add(0, status);
|
MainActivity.lastHomeId = status.getId();
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
status.setReplies(new ArrayList<Status>());
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
statuses.add(0, status);
|
||||||
if (!status.getAccount().getId().equals(userId))
|
if (!status.getAccount().getId().equals(userId))
|
||||||
MainActivity.countNewStatus++;
|
MainActivity.countNewStatus++;
|
||||||
statusListAdapter.notifyItemInserted(0);
|
statusListAdapter.notifyItemInserted(0);
|
||||||
if (textviewNoAction.getVisibility() == View.VISIBLE)
|
if (textviewNoAction.getVisibility() == View.VISIBLE)
|
||||||
textviewNoAction.setVisibility(View.GONE);
|
textviewNoAction.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (type == RetrieveFeedsAsyncTask.Type.PUBLIC || type == RetrieveFeedsAsyncTask.Type.LOCAL) {
|
} else if (type == RetrieveFeedsAsyncTask.Type.PUBLIC || type == RetrieveFeedsAsyncTask.Type.LOCAL) {
|
||||||
|
|
||||||
|
@ -405,9 +409,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.PUBLIC){
|
if( type == RetrieveFeedsAsyncTask.Type.PUBLIC){
|
||||||
|
|
||||||
if( getUserVisibleHint() ){
|
if( getUserVisibleHint() ){
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, true);
|
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, true);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
streamingFederatedIntent = new Intent(context, StreamingFederatedTimelineService.class);
|
streamingFederatedIntent = new Intent(context, StreamingFederatedTimelineService.class);
|
||||||
|
@ -418,9 +420,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
}else if (type == RetrieveFeedsAsyncTask.Type.LOCAL){
|
}else if (type == RetrieveFeedsAsyncTask.Type.LOCAL){
|
||||||
|
|
||||||
if( getUserVisibleHint() ){
|
if( getUserVisibleHint() ){
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, true);
|
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, true);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
streamingLocalIntent = new Intent(context, StreamingLocalTimelineService.class);
|
streamingLocalIntent = new Intent(context, StreamingLocalTimelineService.class);
|
||||||
|
@ -450,12 +450,10 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
return;
|
return;
|
||||||
//Store last toot id for home timeline to avoid to notify for those that have been already seen
|
//Store last toot id for home timeline to avoid to notify for those that have been already seen
|
||||||
if (type == RetrieveFeedsAsyncTask.Type.HOME && visible && statuses != null && statuses.size() > 0) {
|
if (type == RetrieveFeedsAsyncTask.Type.HOME && visible && statuses != null && statuses.size() > 0) {
|
||||||
updateMaxId(statuses.get(0).getId());
|
updateNotificationLastId(statuses.get(0).getId());
|
||||||
} else if( type == RetrieveFeedsAsyncTask.Type.PUBLIC ){
|
} else if( type == RetrieveFeedsAsyncTask.Type.PUBLIC ){
|
||||||
if (visible) {
|
if (visible) {
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, true);
|
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, true);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
streamingFederatedIntent = new Intent(context, StreamingFederatedTimelineService.class);
|
streamingFederatedIntent = new Intent(context, StreamingFederatedTimelineService.class);
|
||||||
|
@ -464,9 +462,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
retrieveMissingToots(statuses.get(0).getId());
|
retrieveMissingToots(statuses.get(0).getId());
|
||||||
}else {
|
}else {
|
||||||
if( streamingFederatedIntent != null ){
|
if( streamingFederatedIntent != null ){
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
|
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
context.stopService(streamingFederatedIntent);
|
context.stopService(streamingFederatedIntent);
|
||||||
|
@ -474,9 +470,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
}
|
}
|
||||||
}else if (type == RetrieveFeedsAsyncTask.Type.LOCAL){
|
}else if (type == RetrieveFeedsAsyncTask.Type.LOCAL){
|
||||||
if (visible) {
|
if (visible) {
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, true);
|
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, true);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
streamingLocalIntent = new Intent(context, StreamingLocalTimelineService.class);
|
streamingLocalIntent = new Intent(context, StreamingLocalTimelineService.class);
|
||||||
|
@ -485,9 +479,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
retrieveMissingToots(statuses.get(0).getId());
|
retrieveMissingToots(statuses.get(0).getId());
|
||||||
}else {
|
}else {
|
||||||
if( streamingLocalIntent != null ){
|
if( streamingLocalIntent != null ){
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, false);
|
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, false);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
context.stopService(streamingLocalIntent);
|
context.stopService(streamingLocalIntent);
|
||||||
|
@ -500,16 +492,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
public void onStop(){
|
public void onStop(){
|
||||||
super.onStop();
|
super.onStop();
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.PUBLIC && streamingFederatedIntent != null){
|
if( type == RetrieveFeedsAsyncTask.Type.PUBLIC && streamingFederatedIntent != null){
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
|
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
context.stopService(streamingFederatedIntent);
|
context.stopService(streamingFederatedIntent);
|
||||||
}else if(type == RetrieveFeedsAsyncTask.Type.LOCAL && streamingLocalIntent != null){
|
}else if(type == RetrieveFeedsAsyncTask.Type.LOCAL && streamingLocalIntent != null){
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, false);
|
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, false);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
context.stopService(streamingLocalIntent);
|
context.stopService(streamingLocalIntent);
|
||||||
|
@ -521,7 +509,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
lv_status.setAdapter(statusListAdapter);
|
lv_status.setAdapter(statusListAdapter);
|
||||||
//Store last toot id for home timeline to avoid to notify for those that have been already seen
|
//Store last toot id for home timeline to avoid to notify for those that have been already seen
|
||||||
if (type == RetrieveFeedsAsyncTask.Type.HOME && statuses != null && statuses.size() > 0) {
|
if (type == RetrieveFeedsAsyncTask.Type.HOME && statuses != null && statuses.size() > 0) {
|
||||||
updateMaxId(statuses.get(0).getId());
|
updateNotificationLastId(statuses.get(0).getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -538,8 +526,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
inserted++;
|
inserted++;
|
||||||
statuses.get(i).setReplies(new ArrayList<Status>());
|
statuses.get(i).setReplies(new ArrayList<Status>());
|
||||||
this.statuses.add(0, statuses.get(i));
|
this.statuses.add(0, statuses.get(i));
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
if (type == RetrieveFeedsAsyncTask.Type.HOME && !statuses.get(i).getAccount().getId().equals(userId))
|
if (type == RetrieveFeedsAsyncTask.Type.HOME && !statuses.get(i).getAccount().getId().equals(userId))
|
||||||
MainActivity.countNewStatus++;
|
MainActivity.countNewStatus++;
|
||||||
}
|
}
|
||||||
|
@ -558,15 +544,19 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMaxId(String max_id){
|
|
||||||
if( max_id == null)
|
/**
|
||||||
return;
|
* Records the id of the status only if its greater than the previous one.
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
* @param statusId String current status id to check
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
*/
|
||||||
String currentMaxId = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
|
private void updateNotificationLastId(String statusId){
|
||||||
if( currentMaxId == null || Long.parseLong(max_id) > Long.parseLong(currentMaxId)) {
|
|
||||||
|
String lastNotif = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
|
||||||
|
if( lastNotif == null || Long.parseLong(statusId) > Long.parseLong(lastNotif)){
|
||||||
|
this.lastReadStatus = statusId;
|
||||||
|
MainActivity.countNewStatus = 0;
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, max_id);
|
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statusId);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue