diff options
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java')
-rw-r--r-- | app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java | 503 |
1 files changed, 290 insertions, 213 deletions
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 33a42f6b0..38ea50c91 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 @@ -20,7 +20,6 @@ import android.database.sqlite.SQLiteDatabase; import android.graphics.Bitmap; import android.os.Handler; import android.support.annotation.NonNull; -import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AlertDialog; import android.content.ClipData; import android.content.ClipboardManager; @@ -43,6 +42,7 @@ import android.text.Spannable; import android.text.Spanned; import android.text.method.LinkMovementMethod; import android.text.style.ForegroundColorSpan; +import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MenuItem; @@ -63,13 +63,18 @@ import android.widget.TextView; import android.widget.TimePicker; import android.widget.Toast; import com.bumptech.glide.Glide; +import com.bumptech.glide.load.resource.bitmap.CenterCrop; +import com.bumptech.glide.load.resource.bitmap.FitCenter; +import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions; +import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.transition.Transition; import com.github.stom79.mytransl.MyTransL; import com.github.stom79.mytransl.client.HttpsConnectionException; import com.github.stom79.mytransl.client.Results; import com.github.stom79.mytransl.translate.Translate; + import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; @@ -103,7 +108,6 @@ import fr.gouv.etalab.mastodon.helper.CustomTextView; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveCardInterface; -import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiAccountInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface; @@ -112,9 +116,11 @@ import fr.gouv.etalab.mastodon.sqlite.Sqlite; import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO; import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO; import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO; + import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale; import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK; import static fr.gouv.etalab.mastodon.helper.Helper.THEME_DARK; +import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT; import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; import static fr.gouv.etalab.mastodon.helper.Helper.getLiveInstance; @@ -140,22 +146,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct private int conversationPosition; private List<String> timedMute; private boolean redraft; - private Status status; private Status toot; - public StatusListAdapter(Context context, List<String> timedMute, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){ - super(); - this.context = context; - this.statuses = statuses; - this.isOnWifi = isOnWifi; - this.behaviorWithAttachments = behaviorWithAttachments; - layoutInflater = LayoutInflater.from(this.context); - statusListAdapter = this; - this.type = type; - this.targetedId = targetedId; - this.translator = translator; - this.timedMute = timedMute; - redraft = false; - } + public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){ super(); @@ -246,7 +238,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct TextView status_content_translated; LinearLayout status_content_translated_container; TextView status_account_username; - TextView status_account_displayname; + TextView status_account_displayname, status_account_displayname_owner; ImageView status_account_profile; ImageView status_account_profile_boost; ImageView status_account_profile_boost_by; @@ -269,15 +261,22 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct ImageView status_prev2_h; ImageView status_prev3_h; ImageView status_prev4_h; + LinearLayout conversation_pp_2_container, conversation_pp_3_container; ImageView status_prev1_play_h; ImageView status_prev2_play_h; ImageView status_prev3_play_h; ImageView status_prev4_play_h; + ImageView conversation_pp_1; + ImageView conversation_pp_2; + ImageView conversation_pp_3; + ImageView conversation_pp_4; + LinearLayout conversation_pp; + RelativeLayout status_prev4_container; TextView status_reply; ImageView status_pin; ImageView status_privacy; - FloatingActionButton status_translate, status_bookmark; + ImageButton status_translate, status_bookmark; LinearLayout status_container2; LinearLayout status_container3; LinearLayout main_container; @@ -295,7 +294,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct ImageView hide_preview, hide_preview_h; TextView status_toot_app; - public View getView(){ return itemView; } @@ -309,6 +307,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct status_content_translated = itemView.findViewById(R.id.status_content_translated); status_account_username = itemView.findViewById(R.id.status_account_username); status_account_displayname = itemView.findViewById(R.id.status_account_displayname); + status_account_displayname_owner = itemView.findViewById(R.id.status_account_displayname_owner); status_account_profile = itemView.findViewById(R.id.status_account_profile); status_account_profile_boost = itemView.findViewById(R.id.status_account_profile_boost); status_account_profile_boost_by = itemView.findViewById(R.id.status_account_profile_boost_by); @@ -362,78 +361,31 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct hide_preview = itemView.findViewById(R.id.hide_preview); hide_preview_h = itemView.findViewById(R.id.hide_preview_h); status_toot_app = itemView.findViewById(R.id.status_toot_app); + conversation_pp = itemView.findViewById(R.id.conversation_pp); + conversation_pp_1 = itemView.findViewById(R.id.conversation_pp_1); + conversation_pp_2 = itemView.findViewById(R.id.conversation_pp_2); + conversation_pp_3 = itemView.findViewById(R.id.conversation_pp_3); + conversation_pp_4 = itemView.findViewById(R.id.conversation_pp_4); + conversation_pp_2_container = itemView.findViewById(R.id.conversation_pp_2_container); + conversation_pp_3_container = itemView.findViewById(R.id.conversation_pp_3_container); } } public Status getItem(int position){ - return statuses.get(position); + if( statuses.size() > position && position >= 0) + return statuses.get(position); + else return null; } @Override public int getItemViewType(int position) { - status = statuses.get(position); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true); - int HIDDEN_STATUS = 0; - //If account related to status is null, the toot is hidden - if( status.getAccount() == null ) - return HIDDEN_STATUS; - String filter; - if( type == RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) - return isCompactMode?COMPACT_STATUS:DISPLAYED_STATUS; - else if( type == RetrieveFeedsAsyncTask.Type.CONTEXT && position == conversationPosition) + if( type == RetrieveFeedsAsyncTask.Type.CONTEXT && position == conversationPosition) return FOCUSED_STATUS; - else if( type == RetrieveFeedsAsyncTask.Type.HOME) - filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_HOME, null); - else if( type == RetrieveFeedsAsyncTask.Type.LOCAL) - filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_LOCAL, null); else - filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_PUBLIC, null); - - if( filter != null && filter.length() > 0){ - try { - Pattern filterPattern = Pattern.compile("(" + filter + ")", Pattern.CASE_INSENSITIVE); - String content; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); - else - //noinspection deprecation - content = Html.fromHtml(status.getContent()).toString(); - Matcher matcher = filterPattern.matcher(content); - if (matcher.find()) - return HIDDEN_STATUS; - }catch (Exception e){ - return DISPLAYED_STATUS; - } - } - if( type == RetrieveFeedsAsyncTask.Type.HOME) { - if (status.getReblog() != null && !sharedpreferences.getBoolean(Helper.SET_SHOW_BOOSTS, true)) - return HIDDEN_STATUS; - else if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null") && !sharedpreferences.getBoolean(Helper.SET_SHOW_REPLIES, true)) { - return HIDDEN_STATUS; - }else { - if( timedMute != null && timedMute.size() > 0) { - - if (timedMute.contains(status.getAccount().getId())) - return HIDDEN_STATUS; - else - return isCompactMode?COMPACT_STATUS:DISPLAYED_STATUS; - }else { - return isCompactMode?COMPACT_STATUS:DISPLAYED_STATUS; - } - } - }else { - if( context instanceof ShowAccountActivity){ - if (status.getReblog() != null && !((ShowAccountActivity)context).showBoosts()) - return HIDDEN_STATUS; - else if( status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null") && !((ShowAccountActivity)context).showReplies()) - return HIDDEN_STATUS; - else - return isCompactMode?COMPACT_STATUS:DISPLAYED_STATUS; - }else return isCompactMode?COMPACT_STATUS:DISPLAYED_STATUS; - } } @NonNull @@ -450,6 +402,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } + @SuppressLint("SetJavaScriptEnabled") @Override public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int position) { @@ -462,10 +415,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - boolean displayBookmarkButton = sharedpreferences.getBoolean(Helper.SET_SHOW_BOOKMARK, true); + boolean displayBookmarkButton = sharedpreferences.getBoolean(Helper.SET_SHOW_BOOKMARK, false); boolean fullAttachement = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false); + boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true); - if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && getItemViewType(position) != COMPACT_STATUS && displayBookmarkButton) + if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && !isCompactMode && displayBookmarkButton) holder.status_bookmark.setVisibility(View.VISIBLE); else holder.status_bookmark.setVisibility(View.GONE); @@ -480,10 +434,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct status.setBookmarked(true); else status.setBookmarked(false); - if( status.isBookmarked()) - holder.status_bookmark.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark)); - else - holder.status_bookmark.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark_border)); if( status.isNew()) holder.new_element.setVisibility(View.VISIBLE); @@ -496,20 +446,25 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.status_more.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context); holder.status_privacy.getLayoutParams().height = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context); holder.status_privacy.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context); - boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true); + if( type == RetrieveFeedsAsyncTask.Type.CONTEXT && getItemViewType(position) != FOCUSED_STATUS && position != 0 ){ + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT + ); + params.setMargins((int)Helper.convertDpToPixel(25, context), 0, 0, 0); + holder.main_container.setLayoutParams(params); + }else if(type == RetrieveFeedsAsyncTask.Type.CONTEXT && getItemViewType(position) == FOCUSED_STATUS && position != 0 ){ + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT + ); + params.setMargins((int)Helper.convertDpToPixel(20, context), 0, 0, 0); + holder.main_container.setLayoutParams(params); + } + - /* int status_account_profile = holder.status_account_profile.getWidth(); - int status_account_profile_boost = holder.status_account_profile_boost.getWidth(); - int status_account_profile_boost_by = holder.status_account_profile_boost_by.getWidth(); - RelativeLayout.LayoutParams lp_status_account_profile = new RelativeLayout.LayoutParams(status_account_profile*textSizePercent/110, status_account_profile*textSizePercent/110); - holder.status_account_profile.setLayoutParams(lp_status_account_profile); - RelativeLayout.LayoutParams lp_status_account_profile_boost = new RelativeLayout.LayoutParams(status_account_profile_boost*textSizePercent/110, status_account_profile*textSizePercent/110); - holder.status_account_profile_boost.setLayoutParams(lp_status_account_profile_boost); - RelativeLayout.LayoutParams lp_status_account_profile_boost_by = new RelativeLayout.LayoutParams(status_account_profile_boost_by*textSizePercent/110, status_account_profile*textSizePercent/110); - holder.status_account_profile_boost_by.setLayoutParams(lp_status_account_profile_boost_by); -*/ if( getItemViewType(position) == FOCUSED_STATUS ) { holder.status_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16*textSizePercent/100); holder.status_account_displayname.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16 * textSizePercent / 100); @@ -551,50 +506,75 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct boolean expand_cw = sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false); boolean expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false); - if( theme == Helper.THEME_DARK || theme == Helper.THEME_BLACK){ + if( theme == Helper.THEME_BLACK){ changeDrawableColor(context, R.drawable.ic_reply,R.color.dark_icon); changeDrawableColor(context, holder.status_more, R.color.dark_icon); changeDrawableColor(context, holder.status_privacy, R.color.dark_icon); changeDrawableColor(context, R.drawable.ic_repeat,R.color.dark_icon); + changeDrawableColor(context, R.drawable.ic_repeat_head_toot,R.color.black_text_toot_header); + changeDrawableColor(context, R.drawable.ic_star_border,R.color.dark_icon); + changeDrawableColor(context, R.drawable.ic_plus_one,R.color.dark_icon); + changeDrawableColor(context, R.drawable.ic_pin_drop, R.color.dark_icon); + changeDrawableColor(context, R.drawable.ic_photo,R.color.dark_text); + changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.dark_text); + changeDrawableColor(context, R.drawable.ic_translate,R.color.dark_text); + holder.status_favorite_count.setTextColor(ContextCompat.getColor(context, R.color.dark_icon)); + holder.status_reblog_count.setTextColor(ContextCompat.getColor(context, R.color.dark_icon)); + holder.status_reply.setTextColor(ContextCompat.getColor(context, R.color.dark_icon)); + }else if( theme == Helper.THEME_DARK ){ + changeDrawableColor(context, R.drawable.ic_reply,R.color.dark_icon); + changeDrawableColor(context, holder.status_more, R.color.dark_icon); + changeDrawableColor(context, R.drawable.ic_repeat,R.color.dark_icon); + changeDrawableColor(context, holder.status_privacy, R.color.dark_icon); + changeDrawableColor(context, R.drawable.ic_repeat_head_toot,R.color.dark_text_toot_header); changeDrawableColor(context, R.drawable.ic_star_border,R.color.dark_icon); changeDrawableColor(context, R.drawable.ic_plus_one,R.color.dark_icon); changeDrawableColor(context, R.drawable.ic_pin_drop, R.color.dark_icon); changeDrawableColor(context, R.drawable.ic_photo,R.color.dark_text); changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.dark_text); changeDrawableColor(context, R.drawable.ic_translate,R.color.dark_text); - holder.status_favorite_count.setTextColor(ContextCompat.getColor(context, R.color.dark_icon)); holder.status_reblog_count.setTextColor(ContextCompat.getColor(context, R.color.dark_icon)); holder.status_reply.setTextColor(ContextCompat.getColor(context, R.color.dark_icon)); - holder.status_toot_date.setTextColor(ContextCompat.getColor(context, R.color.dark_icon)); - if( status.getReblog() != null) - holder.status_account_displayname.setTextColor(ContextCompat.getColor(context, R.color.dark_icon)); - else - holder.status_account_displayname.setTextColor(ContextCompat.getColor(context, R.color.dark_text)); }else { changeDrawableColor(context, R.drawable.ic_reply,R.color.black); changeDrawableColor(context, R.drawable.ic_more_horiz,R.color.black); changeDrawableColor(context, holder.status_more, R.color.black); changeDrawableColor(context, holder.status_privacy, R.color.black); changeDrawableColor(context, R.drawable.ic_repeat,R.color.black); + changeDrawableColor(context, R.drawable.ic_repeat_head_toot,R.color.black); changeDrawableColor(context, R.drawable.ic_plus_one,R.color.black); changeDrawableColor(context, R.drawable.ic_star_border,R.color.black); changeDrawableColor(context, R.drawable.ic_pin_drop, R.color.black); changeDrawableColor(context, R.drawable.ic_photo,R.color.mastodonC4); changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.mastodonC4); - changeDrawableColor(context, R.drawable.ic_translate,R.color.white); - + changeDrawableColor(context, R.drawable.ic_translate,R.color.black); + changeDrawableColor(context, R.drawable.ic_bookmark,R.color.black); + changeDrawableColor(context, R.drawable.ic_bookmark_border,R.color.black); holder.status_favorite_count.setTextColor(ContextCompat.getColor(context, R.color.black)); holder.status_reblog_count.setTextColor(ContextCompat.getColor(context, R.color.black)); - holder.status_toot_date.setTextColor(ContextCompat.getColor(context, R.color.black)); holder.status_reply.setTextColor(ContextCompat.getColor(context, R.color.black)); + } + if( theme == THEME_DARK) { + holder.status_account_displayname.setTextColor(ContextCompat.getColor(context, R.color.dark_text_toot_header)); + holder.status_toot_date.setTextColor(ContextCompat.getColor(context, R.color.dark_text_toot_header)); + }else if( theme == THEME_BLACK) { + holder.status_account_displayname.setTextColor(ContextCompat.getColor(context, R.color.black_text_toot_header)); + holder.status_toot_date.setTextColor(ContextCompat.getColor(context, R.color.black_text_toot_header)); + }else if( theme == THEME_LIGHT) { holder.status_account_displayname.setTextColor(ContextCompat.getColor(context, R.color.black)); + holder.status_toot_date.setTextColor(ContextCompat.getColor(context, R.color.black)); } + if( status.isBookmarked()) + holder.status_bookmark.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark)); + else + holder.status_bookmark.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark_border)); + //Redraws top icons (boost/reply) final float scale = context.getResources().getDisplayMetrics().density; if( status.getReblog() != null){ - Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_repeat); + Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_repeat_head_toot); assert img != null; img.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (15 * iconSizePercent/100 * scale + 0.5f)); holder.status_account_displayname.setCompoundDrawables( img, null, null, null); @@ -617,41 +597,53 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } }); //Click on a conversation - if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && (getItemViewType(position) == DISPLAYED_STATUS || getItemViewType(position) == COMPACT_STATUS)) { + if( (getItemViewType(position) == DISPLAYED_STATUS || getItemViewType(position) == COMPACT_STATUS)) { holder.status_content.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(context, ShowConversationActivity.class); - Bundle b = new Bundle(); - if (status.getReblog() == null) - b.putString("statusId", status.getId()); - else - b.putString("statusId", status.getReblog().getId()); - intent.putExtras(b); - if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) - ((Activity) context).finish(); - context.startActivity(intent); + if(type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) { + Intent intent = new Intent(context, ShowConversationActivity.class); + Bundle b = new Bundle(); + if (status.getReblog() == null) + b.putString("statusId", status.getId()); + else + b.putString("statusId", status.getReblog().getId()); + intent.putExtras(b); + if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) + ((Activity) context).finish(); + context.startActivity(intent); + }else { + CrossActions.doCrossConversation(context,status); + } } }); holder.main_container.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(context, ShowConversationActivity.class); - Bundle b = new Bundle(); - if (status.getReblog() == null) - b.putString("statusId", status.getId()); - else - b.putString("statusId", status.getReblog().getId()); - intent.putExtras(b); - if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) - ((Activity) context).finish(); - context.startActivity(intent); + if(type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) { + Intent intent = new Intent(context, ShowConversationActivity.class); + Bundle b = new Bundle(); + if (status.getReblog() == null) + b.putString("statusId", status.getId()); + else + b.putString("statusId", status.getReblog().getId()); + intent.putExtras(b); + if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) + ((Activity) context).finish(); + context.startActivity(intent); + }else { + CrossActions.doCrossConversation(context,status); + } } }); } - - + if( status.getContent().trim().equals("") || status.getContent().trim().length() == 0){ + holder.status_content_container.setVisibility(View.GONE); + }else { + holder.status_content_container.setVisibility(View.VISIBLE); + } holder.status_content.setText(status.getContentSpan(), TextView.BufferType.SPANNABLE); + holder.status_spoiler.setText(status.getContentSpanCW(), TextView.BufferType.SPANNABLE); holder.status_content.setMovementMethod(LinkMovementMethod.getInstance()); @@ -669,14 +661,19 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct public void onClick(View v) { if( type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) { status.setBookmarked(!status.isBookmarked()); - if (status.isBookmarked()) { - new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status); - Toast.makeText(context, R.string.status_bookmarked, Toast.LENGTH_LONG).show(); - } else { - new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, status); - Toast.makeText(context, R.string.status_unbookmarked, Toast.LENGTH_LONG).show(); + try { + if (status.isBookmarked()) { + new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status); + Toast.makeText(context, R.string.status_bookmarked, Toast.LENGTH_LONG).show(); + } else { + new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, status); + Toast.makeText(context, R.string.status_unbookmarked, Toast.LENGTH_LONG).show(); + } + notifyStatusChanged(status); + }catch (Exception e){ + e.printStackTrace(); + Toast.makeText(context, R.string.toast_error, Toast.LENGTH_LONG).show(); } - notifyStatusChanged(status); }else { int position = 0; for (Status statustmp : statuses) { @@ -692,38 +689,64 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } } }); + holder.status_bookmark.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + CrossActions.doCrossBookmark(context, status, statusListAdapter); + return false; + } + }); holder.status_content_translated.setMovementMethod(LinkMovementMethod.getInstance()); //-------- END -> Manages translations - + if( status.getAccount() == null) { + Account account = new AccountDAO(context, db).getAccountByID(sharedpreferences.getString(Helper.PREF_KEY_ID, null)); + status.setAccount(account); + } //Displays name & emoji in toot header final String ppurl; if( status.getReblog() != null){ ppurl = status.getReblog().getAccount().getAvatar(); + holder.status_account_displayname.setVisibility(View.VISIBLE); holder.status_account_displayname.setText(context.getResources().getString(R.string.reblog_by, status.getAccount().getUsername())); + if( status.getReblog().getAccount().getDisplay_name().length() > 0) + holder.status_account_displayname_owner.setText( status.getReblog().getAccount().getDisplay_name()); + else + holder.status_account_displayname_owner.setText( status.getReblog().getAccount().getAcct().replace("@","")); + holder.status_account_displayname_owner.setVisibility(View.VISIBLE); + }else { ppurl = status.getAccount().getAvatar(); - holder.status_account_displayname.setText(status.getAccount().getdisplayNameSpan(), TextView.BufferType.SPANNABLE); + holder.status_account_displayname.setVisibility(View.GONE); + if( status.getAccount().getdisplayNameSpan() == null || status.getAccount().getdisplayNameSpan().toString().trim().length() == 0) + holder.status_account_displayname_owner.setText(status.getAccount().getUsername().replace("@",""), TextView.BufferType.SPANNABLE); + else + holder.status_account_displayname_owner.setText(status.getAccount().getdisplayNameSpan(), TextView.BufferType.SPANNABLE); } //-------- END -> Displays name & emoji in toot header //Change the color in gray for accounts in DARK Theme only Spannable wordtoSpan = status.getDisplayNameSpan(); - - if( theme == THEME_DARK || theme == Helper.THEME_BLACK) { - Pattern hashAcct; - if( status.getReblog() != null) - hashAcct = Pattern.compile("\\s(@"+status.getReblog().getAccount().getAcct()+")"); - else - hashAcct = Pattern.compile("(@"+status.getAccount().getAcct()+")"); - if( wordtoSpan != null && hashAcct != null){ - Matcher matcherAcct = hashAcct.matcher(wordtoSpan); - while (matcherAcct.find()){ - int matchStart = matcherAcct.start(1); - int matchEnd = matcherAcct.end(); - if( wordtoSpan.length() >= matchEnd && matchStart < matchEnd) + Pattern hashAcct; + if( status.getReblog() != null) { + hashAcct = Pattern.compile("(@" + status.getReblog().getAccount().getAcct() + ")"); + }else + hashAcct = Pattern.compile("(@"+status.getAccount().getAcct()+")"); + + if( wordtoSpan != null && hashAcct != null){ + Matcher matcherAcct = hashAcct.matcher(wordtoSpan); + while (matcherAcct.find()){ + int matchStart = matcherAcct.start(1); + int matchEnd = matcherAcct.end(); + if( wordtoSpan.length() >= matchEnd && matchStart < matchEnd){ + if( theme == THEME_LIGHT) wordtoSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.dark_icon)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + else if( theme == THEME_DARK) + wordtoSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.dark_text_toot_header)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + else if( theme == THEME_BLACK) + wordtoSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.black_text_toot_header)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } + } } holder.status_account_username.setText(wordtoSpan); @@ -784,12 +807,62 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.status_account_profile_boost_by.setVisibility(View.GONE); holder.status_account_profile.setVisibility(View.VISIBLE); } + if( type == RetrieveFeedsAsyncTask.Type.CONVERSATION && status.getConversationProfilePicture() != null){ + holder.status_account_profile.setVisibility(View.GONE); + holder.conversation_pp.setVisibility(View.VISIBLE); + if( status.getConversationProfilePicture().size() == 1) { + holder.conversation_pp_1.setVisibility(View.VISIBLE); + holder.conversation_pp_1.setScaleType(ImageView.ScaleType.CENTER_CROP); + holder.conversation_pp_2_container.setVisibility(View.GONE); + holder.conversation_pp_3_container.setVisibility(View.GONE); + holder.conversation_pp_2.setVisibility(View.GONE); + holder.conversation_pp_3.setVisibility(View.GONE); + holder.conversation_pp_4.setVisibility(View.GONE); + Glide.with(context) + .load(status.getConversationProfilePicture().get(0)) + .apply(new RequestOptions().transforms(new FitCenter(), new RoundedCorners(10))) + .into(holder.conversation_pp_1); + }else if( status.getConversationProfilePicture().size() == 2) { + holder.conversation_pp_2_container.setVisibility(View.VISIBLE); + holder.conversation_pp_3_container.setVisibility(View.GONE); + holder.conversation_pp_1.setVisibility(View.VISIBLE); + holder.conversation_pp_2.setVisibility(View.VISIBLE); + holder.conversation_pp_3.setVisibility(View.GONE); + holder.conversation_pp_4.setVisibility(View.GONE); + Helper.loadGiF(context, status.getConversationProfilePicture().get(0), holder.conversation_pp_1); + Helper.loadGiF(context, status.getConversationProfilePicture().get(1), holder.conversation_pp_2); + }else if( status.getConversationProfilePicture().size() == 3) { + holder.conversation_pp_4.setVisibility(View.GONE); + holder.conversation_pp_1.setVisibility(View.VISIBLE); + holder.conversation_pp_2.setVisibility(View.VISIBLE); + holder.conversation_pp_3.setVisibility(View.VISIBLE); + holder.conversation_pp_4.setVisibility(View.GONE); + holder.conversation_pp_2_container.setVisibility(View.VISIBLE); + holder.conversation_pp_3_container.setVisibility(View.VISIBLE); + Helper.loadGiF(context, status.getConversationProfilePicture().get(0), holder.conversation_pp_1); + Helper.loadGiF(context, status.getConversationProfilePicture().get(1), holder.conversation_pp_2); + Helper.loadGiF(context, status.getConversationProfilePicture().get(2), holder.conversation_pp_3); + }else if( status.getConversationProfilePicture().size() == 4) { + holder.conversation_pp_1.setVisibility(View.VISIBLE); + holder.conversation_pp_2.setVisibility(View.VISIBLE); + holder.conversation_pp_3.setVisibility(View.VISIBLE); + holder.conversation_pp_4.setVisibility(View.VISIBLE); + holder.conversation_pp_2_container.setVisibility(View.VISIBLE); + holder.conversation_pp_3_container.setVisibility(View.VISIBLE); + Helper.loadGiF(context, status.getConversationProfilePicture().get(0), holder.conversation_pp_1); + Helper.loadGiF(context, status.getConversationProfilePicture().get(1), holder.conversation_pp_2); + Helper.loadGiF(context, status.getConversationProfilePicture().get(2), holder.conversation_pp_3); + Helper.loadGiF(context, status.getConversationProfilePicture().get(3), holder.conversation_pp_4); + } + } holder.status_action_container.setVisibility(View.VISIBLE); if( ( getItemViewType(position) != COMPACT_STATUS ) && (trans_forced || (translator != Helper.TRANS_NONE && currentLocale != null && status.getLanguage() != null && !status.getLanguage().trim().equals(currentLocale)))){ holder.status_translate.setVisibility(View.VISIBLE); }else { holder.status_translate.setVisibility(View.GONE); } + if( expand_cw) + holder.status_spoiler_button.setVisibility(View.GONE); if( status.getReblog() == null) { if (status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 ) { holder.status_spoiler_container.setVisibility(View.VISIBLE); @@ -863,7 +936,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.status_show_more.setVisibility(View.GONE); } else { //If medias are loaded without any conditions or if device is on wifi - if (!status.getReblog().isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) { + if (expand_media || !status.getReblog().isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) { loadAttachments(status.getReblog(), holder); holder.status_show_more.setVisibility(View.GONE); status.setAttachmentShown(true); @@ -1040,22 +1113,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct - if( theme == Helper.THEME_LIGHT){ - holder.main_container.setBackgroundResource(R.color.mastodonC3__); - }else if (theme == Helper.THEME_DARK){ - holder.main_container.setBackgroundResource(R.color.mastodonC1_); - }else if (theme == Helper.THEME_BLACK){ - holder.main_container.setBackgroundResource(R.color.black); - } if( type == RetrieveFeedsAsyncTask.Type.CONTEXT ){ if( position == conversationPosition){ - if( theme == Helper.THEME_LIGHT |