From 21b567f28542f863b768be03c56273ca0c4d932e Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 16 Aug 2017 17:16:57 +0200 Subject: [PATCH 1/4] prepares layout to display replies --- .../fr/gouv/etalab/mastodon/helper/Helper.java | 1 + app/src/main/res/layout/drawer_status.xml | 17 +++++++++++++++++ app/src/main/res/values-fr/strings.xml | 5 +++++ app/src/main/res/values/strings.xml | 5 +++++ 4 files changed, 28 insertions(+) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 6ebbbbb4e..e3d73c08f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -196,6 +196,7 @@ public class Helper { public static final String SET_MEDIA_URLS = "set_media_urls"; public static final String SET_TEXT_SIZE = "set_text_size"; public static final String SET_ICON_SIZE = "set_icon_size"; + public static final String SET_PREVIEW_REPLIES = "set_preview_replies"; public static final int ATTACHMENT_ALWAYS = 1; public static final int ATTACHMENT_WIFI = 2; public static final int ATTACHMENT_ASK = 3; diff --git a/app/src/main/res/layout/drawer_status.xml b/app/src/main/res/layout/drawer_status.xml index bd90e6b37..f204158c0 100644 --- a/app/src/main/res/layout/drawer_status.xml +++ b/app/src/main/res/layout/drawer_status.xml @@ -392,5 +392,22 @@ tools:ignore="ContentDescription" /> + + + + \ 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 1e6aaf9e5..8c493fb7b 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -122,6 +122,11 @@ null null + + + et %d autre réponse + et %d autres réponses + Il y a %d seconde diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4c15bd92c..a6969c0e1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -124,6 +124,11 @@ null null + + + and one another reply + and %d other replies + %d second ago From 29758798fdc3111c6aeb7f34892fc6d8c421394f Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 16 Aug 2017 18:08:16 +0200 Subject: [PATCH 2/4] 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 From 19d4faf30a6109e832a615c4ed163732abca0371 Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 16 Aug 2017 19:01:53 +0200 Subject: [PATCH 3/4] Improves how replies are retrieved. --- .../activities/ShowConversationActivity.java | 4 -- .../asynctasks/RetrieveContextAsyncTask.java | 13 +--- .../asynctasks/RetrieveFeedsAsyncTask.java | 17 +++++ .../mastodon/drawers/StatusListAdapter.java | 65 +++++++------------ .../OnRetrieveContextInterface.java | 1 - app/src/main/res/layout/drawer_status.xml | 2 + 6 files changed, 42 insertions(+), 60 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 3f5e72059..2eb2f5073 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 @@ -273,8 +273,4 @@ 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 988ea48f1..13fd13c86 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,21 +33,13 @@ 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); @@ -57,10 +49,7 @@ public class RetrieveContextAsyncTask extends AsyncTask { @Override protected void onPostExecute(Void result) { - if( position == - 1) - listener.onRetrieveFeeds(statusContext, api.getError()); - else - listener.onRetrievedReplies(statusContext, api.getError(), position); + listener.onRetrieveFeeds(statusContext, api.getError()); } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java index ec191247a..37e934f6e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java @@ -15,9 +15,14 @@ package fr.gouv.etalab.mastodon.asynctasks; import android.content.Context; +import android.content.SharedPreferences; import android.os.AsyncTask; + +import java.util.List; + import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.APIResponse; +import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; @@ -79,6 +84,18 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { switch (action){ case HOME: apiResponse = api.getHomeTimeline(max_id); + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + boolean showPreview = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, true); + //Retrieves attached replies to a toot + if( showPreview){ + List statuses = apiResponse.getStatuses(); + if( statuses != null && statuses.size() > 0){ + for(fr.gouv.etalab.mastodon.client.Entities.Status status : statuses){ + fr.gouv.etalab.mastodon.client.Entities.Context statusContext = api.getStatusContext((status.getReblog() != null) ? status.getReblog().getId() : status.getId()); + status.setReplies(statusContext.getDescendants()); + } + } + } break; case LOCAL: apiResponse = api.getPublicTimeline(true, max_id); 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 160287d43..e61b1588d 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,7 +32,6 @@ 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; @@ -70,7 +69,6 @@ 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; @@ -79,7 +77,6 @@ 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; @@ -92,7 +89,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, OnRetrieveContextInterface { +public class StatusListAdapter extends BaseAdapter implements OnPostActionInterface, OnTranslatedInterface { private Context context; private List statuses; @@ -209,33 +206,29 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf //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); + if ( status.getReplies().size() == 0){ + holder.status_replies.setVisibility(View.GONE); + }else if(status.getReplies().size() > 0 ){ + ArrayList addedPictures = new ArrayList<>(); + holder.status_replies_profile_pictures.removeAllViews(); + int i = 0; + for(Status replies: status.getReplies()){ + if( i > 5 ) + break; + if( !addedPictures.contains(replies.getAccount().getAcct())){ + 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++; + addedPictures.add(replies.getAccount().getAcct()); } } - }else{ - holder.status_replies.setVisibility(View.GONE); + 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); } } int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 100); @@ -898,20 +891,6 @@ 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; 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 9f53a6f54..909211fca 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,5 +24,4 @@ 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 c7ba3061b..31123bb71 100644 --- a/app/src/main/res/layout/drawer_status.xml +++ b/app/src/main/res/layout/drawer_status.xml @@ -401,6 +401,8 @@ From 417cc6bdf76cb449d3749faaf5c2b437e973e869 Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 16 Aug 2017 19:10:49 +0200 Subject: [PATCH 4/4] Preview replies can be managed in settings --- .../etalab/mastodon/drawers/StatusListAdapter.java | 2 +- .../etalab/mastodon/fragments/SettingsFragment.java | 13 +++++++++++++ .../main/res/layout-sw600dp/fragment_settings.xml | 6 ++++++ app/src/main/res/layout/fragment_settings.xml | 5 +++++ app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 6 files changed, 27 insertions(+), 1 deletion(-) 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 e61b1588d..b9efe98c1 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 @@ -213,7 +213,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf holder.status_replies_profile_pictures.removeAllViews(); int i = 0; for(Status replies: status.getReplies()){ - if( i > 5 ) + if( i > 4 ) break; if( !addedPictures.contains(replies.getAccount().getAcct())){ final ImageView imageView = new ImageView(context); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java index 21549886d..2ad1dcf54 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java @@ -120,6 +120,19 @@ public class SettingsFragment extends Fragment { } }); + boolean preview_reply = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, true); + final CheckBox set_preview_reply = (CheckBox) rootView.findViewById(R.id.set_preview_reply); + set_preview_reply.setChecked(preview_reply); + + set_preview_reply.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(Helper.SET_PREVIEW_REPLIES, set_preview_reply.isChecked()); + editor.apply(); + } + }); + boolean notif_validation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true); final CheckBox set_share_validation = (CheckBox) rootView.findViewById(R.id.set_share_validation); set_share_validation.setChecked(notif_validation); diff --git a/app/src/main/res/layout-sw600dp/fragment_settings.xml b/app/src/main/res/layout-sw600dp/fragment_settings.xml index 9c9ba7c69..b763c3601 100644 --- a/app/src/main/res/layout-sw600dp/fragment_settings.xml +++ b/app/src/main/res/layout-sw600dp/fragment_settings.xml @@ -58,6 +58,12 @@ android:text="@string/set_auto_store_toot" android:layout_height="wrap_content" /> + + + Présentation… Enregistrer les modifications Choisissez une image d\'entête + Afficher le nombre de réponses sur la page d\'accueil Vous avez atteint les 160 caractères autorisés ! Vous avez atteint les 30 caractères autorisés ! Plage horaire pour les notifications : diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0a3cfefb1..6963c8768 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -300,6 +300,7 @@ Bio… Save changes Choose a header picture + Display the number of replies in hme timeline You have reached the 160 characters allowed! You have reached the 30 characters allowed!