summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java')
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java99
1 files changed, 61 insertions, 38 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java
index 1c511e1ea..a0cd0414a 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java
@@ -40,6 +40,7 @@ import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
@@ -123,6 +124,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
private boolean ownVideos;
private BroadcastReceiver receive_action;
private BroadcastReceiver receive_data;
+ private Date lastReadTootDate, initialBookMarkDate, updatedBookMarkDate;
public DisplayStatusFragment(){
}
@@ -189,7 +191,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
//For Home timeline, fetch stored values for bookmark and last read toot
if( type == RetrieveFeedsAsyncTask.Type.HOME) {
initialBookMark = sharedpreferences.getString(Helper.BOOKMARK_ID + userId + instance, null);
+ initialBookMarkDate = Helper.stringToDate(context, sharedpreferences.getString(Helper.BOOKMARK_DATE + userId + instance, null));
lastReadToot = sharedpreferences.getString(Helper.LAST_READ_TOOT_ID + userId + instance, null);
+ lastReadTootDate = Helper.stringToDate(context, sharedpreferences.getString(Helper.LAST_READ_TOOT_DATE + userId + instance, null));
}
if( instanceType.equals("MASTODON") || instanceType.equals("MISSKEY") ){
if( type == RetrieveFeedsAsyncTask.Type.TAG && tag != null) {
@@ -217,6 +221,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
pixelfedListAdapter = new PixelfedListAdapter(context, type, this.statuses);
lv_status.setAdapter(pixelfedListAdapter);
}else if( instanceType.equals("ART")){
+ if ( type == RetrieveFeedsAsyncTask.Type.TAG) {
+ List<TagTimeline> tagTimelines = new SearchDAO(context, db).getTimelineInfo(tag);
+ if (tagTimelines != null && tagTimelines.size() > 0) {
+ tagTimeline = tagTimelines.get(0);
+ }
+ }
artListAdapter = new ArtListAdapter(context, this.statuses);
lv_status.setAdapter(artListAdapter);
}
@@ -225,7 +235,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
//Manage broadcast receiver for Mastodon timelines
- if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
+ if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA|| MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if( receive_action != null)
LocalBroadcastManager.getInstance(context).unregisterReceiver(receive_action);
receive_action = new BroadcastReceiver() {
@@ -296,10 +306,13 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
}
if(type == RetrieveFeedsAsyncTask.Type.HOME && statuses != null && statuses.size() > firstVisibleItem && firstVisibleItem >= 0) {
- Long bookmarkL = Long.parseLong(statuses.get(firstVisibleItem).getId()) + 1;
- updatedBookMark = String.valueOf(bookmarkL);
- if( lastReadToot == null || bookmarkL > Long.parseLong(lastReadToot)) //Last read toot, only incremented if the id of the toot is greater than the recorded one
- lastReadToot = String.valueOf(bookmarkL);
+ Date bookmarkL = statuses.get(firstVisibleItem).getCreated_at();
+ updatedBookMark = statuses.get(firstVisibleItem).getId();
+ updatedBookMarkDate = statuses.get(firstVisibleItem).getCreated_at();
+ if( lastReadTootDate == null || bookmarkL.after(lastReadTootDate)){
+ //Last read toot, only incremented if the id of the toot is greater than the recorded one
+ lastReadTootDate = bookmarkL;
+ }
}
}
});
@@ -314,8 +327,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
isSwipped = true;
if( type != RetrieveFeedsAsyncTask.Type.CONVERSATION)
retrieveMissingToots(null);
- else if( statuses.size() > 0)
- retrieveMissingToots(statuses.get(0).getId());
+ else{
+ if( statuses.size() > 0)
+ retrieveMissingToots(statuses.get(0).getId());
+ else
+ retrieveMissingToots(null);
+ }
}
});
@@ -380,10 +397,13 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
SharedPreferences.Editor editor = sharedpreferences.edit();
if(updatedBookMark != null)
editor.putString(Helper.BOOKMARK_ID + userId + instance, updatedBookMark);
+ if(updatedBookMarkDate != null)
+ editor.putString(Helper.BOOKMARK_DATE + userId + instance, Helper.dateToString(updatedBookMarkDate));
if( lastReadToot != null)
editor.putString(Helper.LAST_READ_TOOT_ID + userId + instance, lastReadToot);
- if( lastReadToot != null || updatedBookMark != null)
- editor.apply();
+ if( lastReadTootDate != null)
+ editor.putString(Helper.LAST_READ_TOOT_DATE + userId + instance, Helper.dateToString(lastReadTootDate));
+ editor.apply();
}
}
@@ -428,7 +448,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
flag_loading = false;
return;
}
-
//For remote Peertube remote instances
if(instanceType.equals("PEERTUBE")){
int previousPosition = this.peertubes.size();
@@ -547,7 +566,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if (context == null)
return;
if( status.getId() != null && statuses != null && statuses.size() > 0 && statuses.get(0)!= null
- && Long.parseLong(status.getId()) > Long.parseLong(statuses.get(0).getId())) {
+ && status.getCreated_at().after(statuses.get(0).getCreated_at()) ) {
List<Status> tempTootResult = new ArrayList();
tempTootResult.add(status);
if( tempTootResult.size() > 0)
@@ -605,8 +624,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
context.startService(streamingHomeIntent);
}catch (Exception ignored){}
}
- if( statuses != null && statuses.size() > 0)
+ if( statuses != null && statuses.size() > 0) {
retrieveMissingToots(statuses.get(0).getId());
+ }
}
} else if( type == RetrieveFeedsAsyncTask.Type.PUBLIC){
if( getUserVisibleHint() ){
@@ -685,8 +705,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
int batteryProfile = sharedpreferences.getInt(Helper.SET_BATTERY_PROFILE, Helper.BATTERY_PROFILE_NORMAL);
//Store last toot id for home timeline to avoid to notify for those that have been already seen
if (type == RetrieveFeedsAsyncTask.Type.HOME ) {
-
if (visible) {
+
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_HOME + userId + instance, true);
editor.apply();
@@ -696,8 +716,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
context.startService(streamingHomeIntent);
}catch (Exception ignored){}
}
- if( statuses != null && statuses.size() > 0)
+ if( statuses != null && statuses.size() > 0) {
retrieveMissingToots(statuses.get(0).getId());
+ }
}else {
if( streamingHomeIntent != null ){
SharedPreferences.Editor editor = sharedpreferences.edit();
@@ -780,6 +801,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
lv_status.setAdapter(pixelfedListAdapter);
else if( artListAdapter != null && instanceType.equals("ART"))
lv_status.setAdapter(artListAdapter);
+ else if( peertubeAdapater != null && instanceType.equals("PEERTUBE"))
+ lv_status.setAdapter(peertubeAdapater);
}
}
@@ -801,7 +824,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if(swipeRefreshLayout == null)
return;
swipeRefreshLayout.setRefreshing(false);
-
if( isSwipped && this.statuses != null && this.statuses.size() > 0) {
for (Status status : this.statuses) {
status.setNew(false);
@@ -814,7 +836,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
artListAdapter.notifyItemRangeChanged(0, this.statuses.size());
}
isSwipped = false;
+
if( statuses != null && statuses.size() > 0) {
+ if( textviewNoAction.getVisibility() == View.VISIBLE){
+ textviewNoAction.setVisibility(View.GONE);
+ lv_status.setVisibility(View.VISIBLE);
+ }
int inserted = 0;
int insertedConversation = 0;
if(type == RetrieveFeedsAsyncTask.Type.CONVERSATION){ //Remove conversation already displayed if new messages
@@ -841,28 +868,19 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
for (int i = statuses.size() - 1; i >= 0; i--) {
if( this.statuses != null) {
if( type != RetrieveFeedsAsyncTask.Type.HOME){
- if( tagTimeline == null || !tagTimeline.isART() || (tagTimeline.isART() && tagTimeline.isNSFW())) {
- if (this.statuses.size() == 0 || Long.parseLong(statuses.get(i).getId()) > Long.parseLong(this.statuses.get(0).getId())) {
- inserted++;
+ if( tagTimeline != null && instanceType.equals("ART") && !tagTimeline.isNSFW() ){
+ if( !statuses.get(i).isSensitive()) {
this.statuses.add(0, statuses.get(i));
-
+ inserted++;
}
- }else{
- ArrayList<Status> safeStatuses = new ArrayList<>();
- for(Status status: statuses){
- if( !status.isSensitive())
- safeStatuses.add(status);
+ }else {
+ if (this.statuses.size() == 0 || statuses.get(i).getCreated_at().after(this.statuses.get(0).getCreated_at())) {
+ inserted++;
+ this.statuses.add(0, statuses.get(i));
}
- this.statuses.addAll(safeStatuses);
- if( instanceType.equals("MASTODON") || instanceType.equals("MISSKEY"))
- statusListAdapter.notifyItemRangeInserted(0, safeStatuses.size());
- else if( instanceType.equals("PIXELFED"))
- pixelfedListAdapter.notifyItemRangeInserted(0, safeStatuses.size());
- else if( instanceType.equals("ART"))
- artListAdapter.notifyItemRangeInserted(0, safeStatuses.size());
}
}else {
- if( lastReadToot != null && Long.parseLong(statuses.get(i).getId()) > Long.parseLong(lastReadToot)) {
+ if( lastReadTootDate != null && statuses.get(i).getCreated_at().after(lastReadTootDate)) {
if( !this.statuses.contains(statuses.get(i)) ) {
statuses.get(i).setNew(true);
MainActivity.countNewStatus++;
@@ -873,11 +891,11 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
}
}
- if( instanceType.equals("MASTODON") || instanceType.equals("MISSKEY"))
+ if( statusListAdapter != null && (instanceType.equals("MASTODON") || instanceType.equals("MISSKEY")))
statusListAdapter.notifyItemRangeInserted(0, inserted);
- else if( instanceType.equals("PIXELFED"))
+ else if( pixelfedListAdapter != null && instanceType.equals("PIXELFED"))
pixelfedListAdapter.notifyItemRangeInserted(0, inserted);
- else if( instanceType.equals("ART"))
+ else if( artListAdapter != null && instanceType.equals("ART"))
artListAdapter.notifyItemRangeInserted(0, inserted);
try {
if( type == RetrieveFeedsAsyncTask.Type.HOME)
@@ -899,6 +917,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
@Override
public void onRetrieveFeedsAfterBookmark(APIResponse apiResponse) {
+ if( statusListAdapter == null)
+ return;
if( apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404) ){
if( apiResponse == null)
Toasty.error(context, context.getString(R.string.toast_error),Toast.LENGTH_LONG).show();
@@ -913,7 +933,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
return;
//Find the position of toots between those already present
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() && statuses.get(0).getCreated_at().before(this.statuses.get(position).getCreated_at())) {
position++;
}
ArrayList<Status> tmpStatuses = new ArrayList<>();
@@ -921,7 +941,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
//Put the toot at its place in the list (id desc)
if( !this.statuses.contains(tmpStatus) ) { //Element not already added
//Mark status at new ones when their id is greater than the last read toot id
- if (type == RetrieveFeedsAsyncTask.Type.HOME && lastReadToot != null && Long.parseLong(tmpStatus.getId()) > Long.parseLong(lastReadToot)) {
+ if (type == RetrieveFeedsAsyncTask.Type.HOME && lastReadTootDate != null && tmpStatus.getCreated_at().after(lastReadTootDate) ) {
tmpStatus.setNew(true);
MainActivity.countNewStatus++;
}
@@ -934,12 +954,15 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
int tootPerPage = sharedpreferences.getInt(Helper.SET_TOOTS_PER_PAGE, 40);
//Display the fetch more toot button
if( tmpStatuses.size() >= tootPerPage) {
- if (initialBookMark != null && !fetchMoreButtonDisplayed && tmpStatuses.size() > 0 && Long.parseLong(tmpStatuses.get(tmpStatuses.size() - 1).getId()) > Long.parseLong(initialBookMark)) {
+ if (initialBookMarkDate != null && !fetchMoreButtonDisplayed && tmpStatuses.size() > 0 && tmpStatuses.get(tmpStatuses.size() - 1).getCreated_at().after(initialBookMarkDate)) {
tmpStatuses.get(tmpStatuses.size() - 1).setFetchMore(true);
fetchMoreButtonDisplayed = true;
}
}
this.statuses.addAll(position, tmpStatuses);
+ boolean display_content_after_fetch_more = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CONTENT_AFTER_FM, true);
+ if( position > 0 && display_content_after_fetch_more)
+ lv_status.scrollToPosition(position + tmpStatuses.size());
statusListAdapter.notifyItemRangeInserted(position, tmpStatuses.size());
if( textviewNoAction.getVisibility() == View.VISIBLE && tmpStatuses.size() > 0){
textviewNoAction.setVisibility(View.GONE);