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..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 @@ -272,4 +272,5 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet } } + } 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/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..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 @@ -193,12 +193,44 @@ 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 ( 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 > 4 ) + 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()); + } + } + 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); int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 100); @@ -859,6 +891,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf return aJsonString; } + private class ViewHolder { LinearLayout status_content_container; LinearLayout status_spoiler_container; @@ -897,6 +930,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/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/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-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" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index d1d9bf65e..1b65aa86d 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -58,6 +58,11 @@ android:text="@string/set_auto_store_toot" android:layout_height="wrap_content" /> + null null + + + %d réponse + %d réponses + Il y a %d seconde @@ -290,6 +295,7 @@ 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 4c15bd92c..6963c8768 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -124,6 +124,11 @@ null null + + + %d reply + %d replies + %d second ago @@ -295,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!