Fix conversation min id
This commit is contained in:
parent
d1a23b6642
commit
ed2a6d6a7c
|
@ -20,10 +20,12 @@ import android.os.AsyncTask;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||||
import fr.gouv.etalab.mastodon.client.API;
|
import fr.gouv.etalab.mastodon.client.API;
|
||||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||||
|
import fr.gouv.etalab.mastodon.client.Entities.Conversation;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingFeedsInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingFeedsInterface;
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,7 +64,7 @@ public class RetrieveMissingFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
if( this.contextReference.get() == null)
|
if( this.contextReference.get() == null)
|
||||||
return null;
|
return null;
|
||||||
API api = new API(this.contextReference.get());
|
API api = new API(this.contextReference.get());
|
||||||
List<fr.gouv.etalab.mastodon.client.Entities.Status> tempStatus;
|
List<fr.gouv.etalab.mastodon.client.Entities.Status> tempStatus = null;
|
||||||
APIResponse apiResponse = null;
|
APIResponse apiResponse = null;
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.HOME)
|
if( type == RetrieveFeedsAsyncTask.Type.HOME)
|
||||||
apiResponse = api.getHomeTimeline(since_id);
|
apiResponse = api.getHomeTimeline(since_id);
|
||||||
|
@ -77,7 +79,24 @@ public class RetrieveMissingFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
else if (type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE)
|
else if (type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE)
|
||||||
apiResponse = api.getInstanceTimelineSinceId(remoteInstance, since_id);
|
apiResponse = api.getInstanceTimelineSinceId(remoteInstance, since_id);
|
||||||
if (apiResponse != null) {
|
if (apiResponse != null) {
|
||||||
tempStatus = apiResponse.getStatuses();
|
if( type != RetrieveFeedsAsyncTask.Type.CONVERSATION)
|
||||||
|
tempStatus = apiResponse.getStatuses();
|
||||||
|
else{
|
||||||
|
List<Conversation> conversations = apiResponse.getConversations();
|
||||||
|
tempStatus = new ArrayList<>();
|
||||||
|
if( conversations != null && conversations.size() > 0){
|
||||||
|
for(Conversation conversation: conversations){
|
||||||
|
fr.gouv.etalab.mastodon.client.Entities.Status status = conversation.getLast_status();
|
||||||
|
List<String> ppConversation = new ArrayList<>();
|
||||||
|
for (Account account : conversation.getAccounts())
|
||||||
|
ppConversation.add(account.getAvatar());
|
||||||
|
status.setConversationProfilePicture(ppConversation);
|
||||||
|
status.setConversationId(conversation.getId());
|
||||||
|
tempStatus.add(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( tempStatus != null)
|
if( tempStatus != null)
|
||||||
statuses.addAll(0, tempStatus);
|
statuses.addAll(0, tempStatus);
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,7 @@ public class Status implements Parcelable{
|
||||||
private SpannableString contentSpan, displayNameSpan, contentSpanCW, contentSpanTranslated;
|
private SpannableString contentSpan, displayNameSpan, contentSpanCW, contentSpanTranslated;
|
||||||
private RetrieveFeedsAsyncTask.Type type;
|
private RetrieveFeedsAsyncTask.Type type;
|
||||||
private int itemViewType;
|
private int itemViewType;
|
||||||
|
private String conversationId;
|
||||||
|
|
||||||
public Status(){}
|
public Status(){}
|
||||||
private List<String> conversationProfilePicture;
|
private List<String> conversationProfilePicture;
|
||||||
|
@ -128,6 +129,7 @@ public class Status implements Parcelable{
|
||||||
uri = in.readString();
|
uri = in.readString();
|
||||||
url = in.readString();
|
url = in.readString();
|
||||||
in_reply_to_id = in.readString();
|
in_reply_to_id = in.readString();
|
||||||
|
conversationId = in.readString();
|
||||||
in_reply_to_account_id = in.readString();
|
in_reply_to_account_id = in.readString();
|
||||||
reblog = in.readParcelable(Status.class.getClassLoader());
|
reblog = in.readParcelable(Status.class.getClassLoader());
|
||||||
card = in.readParcelable(Card.class.getClassLoader());
|
card = in.readParcelable(Card.class.getClassLoader());
|
||||||
|
@ -165,6 +167,7 @@ public class Status implements Parcelable{
|
||||||
dest.writeString(uri);
|
dest.writeString(uri);
|
||||||
dest.writeString(url);
|
dest.writeString(url);
|
||||||
dest.writeString(in_reply_to_id);
|
dest.writeString(in_reply_to_id);
|
||||||
|
dest.writeString(conversationId);
|
||||||
dest.writeString(in_reply_to_account_id);
|
dest.writeString(in_reply_to_account_id);
|
||||||
dest.writeParcelable(reblog, flags);
|
dest.writeParcelable(reblog, flags);
|
||||||
dest.writeParcelable(card, flags);
|
dest.writeParcelable(card, flags);
|
||||||
|
@ -1138,4 +1141,12 @@ public class Status implements Parcelable{
|
||||||
public void setItemViewType(int itemViewType) {
|
public void setItemViewType(int itemViewType) {
|
||||||
this.itemViewType = itemViewType;
|
this.itemViewType = itemViewType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getConversationId() {
|
||||||
|
return conversationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConversationId(String conversationId) {
|
||||||
|
this.conversationId = conversationId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ import android.widget.RelativeLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.gouv.etalab.mastodon.R;
|
import fr.gouv.etalab.mastodon.R;
|
||||||
|
@ -230,7 +231,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.HOME)
|
if( type == RetrieveFeedsAsyncTask.Type.HOME)
|
||||||
MainActivity.countNewStatus = 0;
|
MainActivity.countNewStatus = 0;
|
||||||
isSwipped = true;
|
isSwipped = true;
|
||||||
retrieveMissingToots(null);
|
retrieveMissingToots(statuses.get(0).getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -394,15 +395,15 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.CONVERSATION ){
|
if( type == RetrieveFeedsAsyncTask.Type.CONVERSATION ){
|
||||||
List<Conversation> conversations = apiResponse.getConversations();
|
List<Conversation> conversations = apiResponse.getConversations();
|
||||||
List<Status> statusesConversations = new ArrayList<>();
|
List<Status> statusesConversations = new ArrayList<>();
|
||||||
|
if( conversations != null)
|
||||||
for( Conversation conversation: conversations) {
|
for( Conversation conversation: conversations) {
|
||||||
Status status = conversation.getLast_status();
|
Status status = conversation.getLast_status();
|
||||||
if( status != null) {
|
status.setConversationId(conversation.getId());
|
||||||
List<String> ppConversation = new ArrayList<>();
|
List<String> ppConversation = new ArrayList<>();
|
||||||
for (Account account : conversation.getAccounts())
|
for (Account account : conversation.getAccounts())
|
||||||
ppConversation.add(account.getAvatar());
|
ppConversation.add(account.getAvatar());
|
||||||
status.setConversationProfilePicture(ppConversation);
|
status.setConversationProfilePicture(ppConversation);
|
||||||
statusesConversations.add(status);
|
statusesConversations.add(status);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
apiResponse.setStatuses(statusesConversations);
|
apiResponse.setStatuses(statusesConversations);
|
||||||
}
|
}
|
||||||
|
@ -586,6 +587,11 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
statusListAdapter.updateMuted(mutedAccount);
|
statusListAdapter.updateMuted(mutedAccount);
|
||||||
if( statuses != null && statuses.size() > 0)
|
if( statuses != null && statuses.size() > 0)
|
||||||
retrieveMissingToots(statuses.get(0).getId());
|
retrieveMissingToots(statuses.get(0).getId());
|
||||||
|
}else if (type == RetrieveFeedsAsyncTask.Type.TAG){
|
||||||
|
if( getUserVisibleHint() ){
|
||||||
|
if( statuses != null && statuses.size() > 0)
|
||||||
|
retrieveMissingToots(statuses.get(0).getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -707,6 +713,21 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
isSwipped = false;
|
isSwipped = false;
|
||||||
if( statuses != null && statuses.size() > 0) {
|
if( statuses != null && statuses.size() > 0) {
|
||||||
int inserted = 0;
|
int inserted = 0;
|
||||||
|
if(type == RetrieveFeedsAsyncTask.Type.CONVERSATION){ //Remove conversation already displayed if new messages
|
||||||
|
int position = 0;
|
||||||
|
if( this.statuses != null) {
|
||||||
|
for (Iterator<Status> it = this.statuses.iterator(); it.hasNext(); ) {
|
||||||
|
Status status = it.next();
|
||||||
|
for (Status status1 : statuses) {
|
||||||
|
if (status.getConversationId() != null && status.getConversationId().equals(status1.getConversationId())) {
|
||||||
|
statusListAdapter.notifyItemRemoved(position);
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
position++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for (int i = statuses.size() - 1; i >= 0; i--) {
|
for (int i = statuses.size() - 1; i >= 0; i--) {
|
||||||
if( this.statuses != null) {
|
if( this.statuses != null) {
|
||||||
if (this.statuses.size() == 0 ||
|
if (this.statuses.size() == 0 ||
|
||||||
|
|
Loading…
Reference in New Issue