Merged in preview_replies (pull request #60)

Preview replies
This commit is contained in:
tom79 2017-08-16 17:11:28 +00:00
commit c46db45f79
11 changed files with 124 additions and 0 deletions

View File

@ -272,4 +272,5 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet
}
}
}

View File

@ -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<Void, Void, Void> {
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<fr.gouv.etalab.mastodon.client.Entities.Status> 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);

View File

@ -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;
}
}

View File

@ -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<String> 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;
}

View File

@ -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);

View File

@ -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;

View File

@ -58,6 +58,12 @@
android:text="@string/set_auto_store_toot"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_preview_reply"
android:layout_width="wrap_content"
android:text="@string/set_preview_reply"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -392,5 +392,26 @@
tools:ignore="ContentDescription" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:visibility="gone"
android:id="@+id/status_replies"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="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"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@ -58,6 +58,11 @@
android:text="@string/set_auto_store_toot"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_preview_reply"
android:layout_width="wrap_content"
android:text="@string/set_preview_reply"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -122,6 +122,11 @@
<item>null</item> <!-- Ugly hack to fix confirm box-->
<item>null</item>
</string-array>
<plurals name="preview_replies">
<item quantity="one">%d réponse</item>
<item quantity="other">%d réponses</item>
</plurals>
<!-- Date -->
<plurals name="date_seconds">
<item quantity="one">Il y a %d seconde</item>
@ -290,6 +295,7 @@
<string name="set_profile_description">Présentation…</string>
<string name="set_save_changes">Enregistrer les modifications</string>
<string name="set_header_picture_overlay">Choisissez une image d\'entête</string>
<string name="set_preview_reply">Afficher le nombre de réponses sur la page d\'accueil</string>
<string name="note_no_space">Vous avez atteint les 160 caractères autorisés !</string>
<string name="username_no_space">Vous avez atteint les 30 caractères autorisés !</string>
<string name="settings_title_hour">Plage horaire pour les notifications :</string>

View File

@ -124,6 +124,11 @@
<item>null</item> <!-- Ugly hack to fix confirm box-->
<item>null</item>
</string-array>
<plurals name="preview_replies">
<item quantity="one">%d reply</item>
<item quantity="other">%d replies</item>
</plurals>
<!-- Date -->
<plurals name="date_seconds">
<item quantity="one">%d second ago</item>
@ -295,6 +300,7 @@
<string name="set_profile_description">Bio…</string>
<string name="set_save_changes">Save changes</string>
<string name="set_header_picture_overlay">Choose a header picture</string>
<string name="set_preview_reply">Display the number of replies in hme timeline</string>
<string name="note_no_space">You have reached the 160 characters allowed!</string>
<string name="username_no_space">You have reached the 30 characters allowed!</string>