From 29758798fdc3111c6aeb7f34892fc6d8c421394f Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 16 Aug 2017 18:08:16 +0200 Subject: [PATCH] Displays accounts that have replied --- .../activities/ShowConversationActivity.java | 5 ++ .../asynctasks/RetrieveContextAsyncTask.java | 13 +++- .../mastodon/client/Entities/Status.java | 11 ++++ .../mastodon/drawers/StatusListAdapter.java | 60 ++++++++++++++++++- .../OnRetrieveContextInterface.java | 1 + app/src/main/res/layout/drawer_status.xml | 10 ++-- app/src/main/res/values-fr/strings.xml | 4 +- app/src/main/res/values/strings.xml | 4 +- 8 files changed, 98 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java index 6527d170a..3f5e72059 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java @@ -272,4 +272,9 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet } } + + @Override + public void onRetrievedReplies(Context context, Error error, int position) { + + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java index 13fd13c86..988ea48f1 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java @@ -33,13 +33,21 @@ public class RetrieveContextAsyncTask extends AsyncTask { 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 { @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); } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java index abd4f8569..73a76b435 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java @@ -48,6 +48,7 @@ public class Status implements Parcelable { private boolean attachmentShown = false; private boolean spoilerShown = false; private ArrayList media_attachments; + private List replies; private List mentions; private List 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 getReplies() { + return replies; + } + + public void setReplies(List replies) { + this.replies = replies; + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index f2e109ac1..160287d43 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -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 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()); + }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; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveContextInterface.java b/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveContextInterface.java index 909211fca..9f53a6f54 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveContextInterface.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveContextInterface.java @@ -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); } diff --git a/app/src/main/res/layout/drawer_status.xml b/app/src/main/res/layout/drawer_status.xml index f204158c0..c7ba3061b 100644 --- a/app/src/main/res/layout/drawer_status.xml +++ b/app/src/main/res/layout/drawer_status.xml @@ -398,16 +398,18 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> + - \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 8c493fb7b..c66b3ee0f 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -124,8 +124,8 @@ - et %d autre réponse - et %d autres réponses + %d réponse + %d réponses diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a6969c0e1..0a3cfefb1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -126,8 +126,8 @@ - and one another reply - and %d other replies + %d reply + %d replies