Displays accounts that have replied
This commit is contained in:
parent
21b567f285
commit
29758798fd
|
@ -272,4 +272,9 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievedReplies(Context context, Error error, int position) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,13 +33,21 @@ public class RetrieveContextAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
private fr.gouv.etalab.mastodon.client.Entities.Context statusContext;
|
||||
private OnRetrieveContextInterface listener;
|
||||
private API api;
|
||||
private int position;
|
||||
|
||||
public RetrieveContextAsyncTask(Context context, String statusId, OnRetrieveContextInterface onRetrieveContextInterface){
|
||||
this.context = context;
|
||||
this.statusId = statusId;
|
||||
this.listener = onRetrieveContextInterface;
|
||||
this.position = -1;
|
||||
}
|
||||
|
||||
public RetrieveContextAsyncTask(Context context, String statusId, int position, OnRetrieveContextInterface onRetrieveContextInterface){
|
||||
this.context = context;
|
||||
this.statusId = statusId;
|
||||
this.listener = onRetrieveContextInterface;
|
||||
this.position = position;
|
||||
}
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
api = new API(context);
|
||||
|
@ -49,7 +57,10 @@ public class RetrieveContextAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveFeeds(statusContext, api.getError());
|
||||
if( position == - 1)
|
||||
listener.onRetrieveFeeds(statusContext, api.getError());
|
||||
else
|
||||
listener.onRetrievedReplies(statusContext, api.getError(), position);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ public class Status implements Parcelable {
|
|||
private boolean attachmentShown = false;
|
||||
private boolean spoilerShown = false;
|
||||
private ArrayList<Attachment> media_attachments;
|
||||
private List<Status> replies;
|
||||
private List<Mention> mentions;
|
||||
private List<Tag> tags;
|
||||
private Application application;
|
||||
|
@ -63,6 +64,7 @@ public class Status implements Parcelable {
|
|||
in_reply_to_account_id = in.readString();
|
||||
reblog = in.readParcelable(Status.class.getClassLoader());
|
||||
account = in.readParcelable(Account.class.getClassLoader());
|
||||
replies = in.readArrayList(Status.class.getClassLoader());
|
||||
mentions = in.readArrayList(Mention.class.getClassLoader());
|
||||
content = in.readString();
|
||||
content_translated = in.readString();
|
||||
|
@ -277,6 +279,7 @@ public class Status implements Parcelable {
|
|||
dest.writeString(in_reply_to_id);
|
||||
dest.writeString(in_reply_to_account_id);
|
||||
dest.writeParcelable(reblog, flags);
|
||||
dest.writeList(replies);
|
||||
dest.writeParcelable(account, flags);
|
||||
dest.writeList(mentions);
|
||||
dest.writeString(content);
|
||||
|
@ -334,4 +337,12 @@ public class Status implements Parcelable {
|
|||
public void setContent_translated(String content_translated) {
|
||||
this.content_translated = content_translated;
|
||||
}
|
||||
|
||||
public List<Status> getReplies() {
|
||||
return replies;
|
||||
}
|
||||
|
||||
public void setReplies(List<Status> replies) {
|
||||
this.replies = replies;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import android.support.v7.widget.CardView;
|
|||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -69,6 +70,7 @@ import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
|
|||
import fr.gouv.etalab.mastodon.activities.ShowConversationActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.TootActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveContextAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
||||
|
@ -77,6 +79,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Status;
|
|||
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveContextInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnTranslatedInterface;
|
||||
import fr.gouv.etalab.mastodon.translation.YandexQuery;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
@ -89,7 +92,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
|||
* Created by Thomas on 24/04/2017.
|
||||
* Adapter for Status
|
||||
*/
|
||||
public class StatusListAdapter extends BaseAdapter implements OnPostActionInterface, OnTranslatedInterface {
|
||||
public class StatusListAdapter extends BaseAdapter implements OnPostActionInterface, OnTranslatedInterface, OnRetrieveContextInterface {
|
||||
|
||||
private Context context;
|
||||
private List<Status> statuses;
|
||||
|
@ -193,12 +196,48 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
holder.status_spoiler = (TextView) convertView.findViewById(R.id.status_spoiler);
|
||||
holder.status_spoiler_button = (Button) convertView.findViewById(R.id.status_spoiler_button);
|
||||
holder.yandex_translate = (TextView) convertView.findViewById(R.id.yandex_translate);
|
||||
holder.status_replies = (LinearLayout) convertView.findViewById(R.id.status_replies);
|
||||
holder.status_replies_profile_pictures = (LinearLayout) convertView.findViewById(R.id.status_replies_profile_pictures);
|
||||
holder.status_replies_text = (TextView) convertView.findViewById(R.id.status_replies_text);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
||||
//Display a preview for accounts that have replied *if enabled and only for home timeline*
|
||||
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
|
||||
boolean showPreview = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, true);
|
||||
if (showPreview) {
|
||||
if (status.getReplies() == null) {
|
||||
new RetrieveContextAsyncTask(context, (status.getReblog() != null) ? status.getReblog().getId() : status.getId(), position, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else { // replies have already been retrieved
|
||||
if ( status.getReplies().size() == 0){
|
||||
holder.status_replies.setVisibility(View.GONE);
|
||||
}else if(status.getReplies().size() > 0 ){
|
||||
holder.status_replies_profile_pictures.removeAllViews();
|
||||
int i = 0;
|
||||
for(Status replies: status.getReplies()){
|
||||
if( i > 5 )
|
||||
break;
|
||||
final ImageView imageView = new ImageView(context);
|
||||
imageLoader.displayImage(replies.getAccount().getAvatar(), imageView, options);
|
||||
LinearLayout.LayoutParams imParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
imParams.setMargins(10, 5, 10, 5);
|
||||
imParams.height = (int) Helper.convertDpToPixel(50, context);
|
||||
holder.status_replies_profile_pictures.addView(imageView, imParams);
|
||||
i++;
|
||||
}
|
||||
holder.status_replies_text.setText(context.getResources().getQuantityString(R.plurals.preview_replies, status.getReplies().size(), status.getReplies().size()));
|
||||
holder.status_replies.setVisibility(View.VISIBLE);
|
||||
holder.status_replies_text.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
holder.status_replies.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 100);
|
||||
int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 100);
|
||||
|
||||
|
@ -859,6 +898,21 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
return aJsonString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(fr.gouv.etalab.mastodon.client.Entities.Context context, Error error) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievedReplies(fr.gouv.etalab.mastodon.client.Entities.Context context, Error error, int position) {
|
||||
if( error != null || context.getDescendants() == null || context.getDescendants().size() < 1) {
|
||||
statuses.get(position).setReplies(new ArrayList<Status>());
|
||||
}else{
|
||||
statuses.get(position).setReplies(context.getDescendants());
|
||||
}
|
||||
statusListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private class ViewHolder {
|
||||
LinearLayout status_content_container;
|
||||
LinearLayout status_spoiler_container;
|
||||
|
@ -897,6 +951,10 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
LinearLayout status_container3;
|
||||
LinearLayout main_container;
|
||||
TextView yandex_translate;
|
||||
|
||||
LinearLayout status_replies;
|
||||
LinearLayout status_replies_profile_pictures;
|
||||
TextView status_replies_text;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,4 +24,5 @@ import fr.gouv.etalab.mastodon.client.Entities.Error;
|
|||
*/
|
||||
public interface OnRetrieveContextInterface {
|
||||
void onRetrieveFeeds(Context context, Error error);
|
||||
void onRetrievedReplies(Context context, Error error, int position);
|
||||
}
|
||||
|
|
|
@ -398,16 +398,18 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:id="@+id/status_replies_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/status_replies_profile_pictures"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"/>
|
||||
<TextView
|
||||
android:id="@+id/status_replies_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
|
@ -124,8 +124,8 @@
|
|||
</string-array>
|
||||
|
||||
<plurals name="preview_replies">
|
||||
<item quantity="one">et %d autre réponse</item>
|
||||
<item quantity="other">et %d autres réponses</item>
|
||||
<item quantity="one">%d réponse</item>
|
||||
<item quantity="other">%d réponses</item>
|
||||
</plurals>
|
||||
<!-- Date -->
|
||||
<plurals name="date_seconds">
|
||||
|
|
|
@ -126,8 +126,8 @@
|
|||
</string-array>
|
||||
|
||||
<plurals name="preview_replies">
|
||||
<item quantity="one">and one another reply</item>
|
||||
<item quantity="other">and %d other replies</item>
|
||||
<item quantity="one">%d reply</item>
|
||||
<item quantity="other">%d replies</item>
|
||||
</plurals>
|
||||
<!-- Date -->
|
||||
<plurals name="date_seconds">
|
||||
|
|
Loading…
Reference in New Issue