From 2175c17ce6065de73754d1696005aa88af4cb434 Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 11 Oct 2017 09:23:32 +0200 Subject: [PATCH] Filters boosts & replies in home timeline --- .../mastodon/client/Entities/Status.java | 9 + .../mastodon/drawers/StatusListAdapter.java | 1688 +++++++++-------- .../fragments/DisplayStatusFragment.java | 11 + .../gouv/etalab/mastodon/helper/Helper.java | 3 + app/src/main/res/menu/option_filter_toots.xml | 18 + app/src/main/res/values-de/strings.xml | 3 + app/src/main/res/values-fr/strings.xml | 3 +- app/src/main/res/values/strings.xml | 3 +- .../activities/MainActivity.java | 66 +- 9 files changed, 965 insertions(+), 839 deletions(-) create mode 100644 app/src/main/res/menu/option_filter_toots.xml 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 8d9e002c4..d1b9495e4 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 @@ -58,6 +58,7 @@ public class Status implements Parcelable { private boolean isTranslationShown = false; private boolean isNew = false; private boolean isTakingScreenShot = false; + private boolean isVisible = true; protected Status(Parcel in) { id = in.readString(); @@ -370,4 +371,12 @@ public class Status implements Parcelable { public void setTakingScreenShot(boolean takingScreenShot) { isTakingScreenShot = takingScreenShot; } + + public boolean isVisible() { + return isVisible; + } + + public void setVisible(boolean visible) { + isVisible = visible; + } } 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 7f33ac551..ef878267e 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 @@ -36,6 +36,7 @@ import android.support.v7.widget.PopupMenu; import android.text.Html; import android.text.SpannableString; import android.text.method.LinkMovementMethod; +import android.util.Log; import android.util.Patterns; import android.util.TypedValue; import android.view.LayoutInflater; @@ -118,7 +119,8 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf private String targetedId; private HashMap urlConversion; private HashMap tagConversion; - + private final int HIDDEN_STATUS = 0; + private final int DISPLAYED_STATUS = 1; private List pins; public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List statuses){ @@ -131,10 +133,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf this.type = type; this.targetedId = targetedId; this.translator = translator; - pins = new ArrayList<>(); - - } @@ -154,687 +153,703 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf return position; } + @Override + public int getViewTypeCount() { + return 2; + } + + @Override + public int getItemViewType(int position) { + Status status = statuses.get(position); + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + if(status.getReblog() != null && ! sharedpreferences.getBoolean(Helper.SET_SHOW_BOOSTS, true) ) + return HIDDEN_STATUS; + else if((status.getIn_reply_to_account_id()!= null && !status.getIn_reply_to_account_id().equals("null")) || (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null") ) && ! sharedpreferences.getBoolean(Helper.SET_SHOW_REPLIES, true)) + return HIDDEN_STATUS; + else + return DISPLAYED_STATUS; + } @Override public View getView(final int position, View convertView, ViewGroup parent) { + if( getItemViewType(position) == HIDDEN_STATUS){ + return new View(context); + }else { + final Status status = statuses.get(position); + imageLoader = ImageLoader.getInstance(); + File cacheDir = new File(context.getCacheDir(), context.getString(R.string.app_name)); + ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(context) + .imageDownloader(new PatchBaseImageDownloader(context)) + .threadPoolSize(5) + .threadPriority(Thread.MIN_PRIORITY + 3) + .denyCacheImageMultipleSizesInMemory() + .diskCache(new UnlimitedDiskCache(cacheDir)) + .build(); + if( !imageLoader.isInited()) + imageLoader.init(configImg); + options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false) + .cacheOnDisk(true).resetViewBeforeLoading(true).build(); - imageLoader = ImageLoader.getInstance(); - File cacheDir = new File(context.getCacheDir(), context.getString(R.string.app_name)); - ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(context) - .imageDownloader(new PatchBaseImageDownloader(context)) - .threadPoolSize(5) - .threadPriority(Thread.MIN_PRIORITY + 3) - .denyCacheImageMultipleSizesInMemory() - .diskCache(new UnlimitedDiskCache(cacheDir)) - .build(); - if( !imageLoader.isInited()) - imageLoader.init(configImg); - options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false) - .cacheOnDisk(true).resetViewBeforeLoading(true).build(); + if (convertView == null) { + convertView = layoutInflater.inflate(R.layout.drawer_status, parent, false); + holder = new ViewHolder(); + holder.loader_replies = (LinearLayout) convertView.findViewById(R.id.loader_replies); + holder.card_status_container = (CardView) convertView.findViewById(R.id.card_status_container); + holder.status_document_container = (LinearLayout) convertView.findViewById(R.id.status_document_container); + holder.status_content = (TextView) convertView.findViewById(R.id.status_content); + holder.status_content_translated = (TextView) convertView.findViewById(R.id.status_content_translated); + holder.status_account_username = (TextView) convertView.findViewById(R.id.status_account_username); + holder.status_account_displayname = (TextView) convertView.findViewById(R.id.status_account_displayname); + holder.status_account_profile = (ImageView) convertView.findViewById(R.id.status_account_profile); + holder.status_account_profile_boost = (ImageView) convertView.findViewById(R.id.status_account_profile_boost); + holder.status_account_profile_boost_by = (ImageView) convertView.findViewById(R.id.status_account_profile_boost_by); + holder.status_favorite_count = (TextView) convertView.findViewById(R.id.status_favorite_count); + holder.status_reblog_count = (TextView) convertView.findViewById(R.id.status_reblog_count); + holder.status_pin = (ImageView) convertView.findViewById(R.id.status_pin); + holder.status_toot_date = (TextView) convertView.findViewById(R.id.status_toot_date); + holder.status_show_more = (Button) convertView.findViewById(R.id.status_show_more); + holder.status_more = (ImageView) convertView.findViewById(R.id.status_more); + holder.status_reblog_user = (TextView) convertView.findViewById(R.id.status_reblog_user); + holder.status_prev1 = (ImageView) convertView.findViewById(R.id.status_prev1); + holder.status_prev2 = (ImageView) convertView.findViewById(R.id.status_prev2); + holder.status_prev3 = (ImageView) convertView.findViewById(R.id.status_prev3); + holder.status_prev4 = (ImageView) convertView.findViewById(R.id.status_prev4); + holder.status_prev1_play = (ImageView) convertView.findViewById(R.id.status_prev1_play); + holder.status_prev2_play = (ImageView) convertView.findViewById(R.id.status_prev2_play); + holder.status_prev3_play = (ImageView) convertView.findViewById(R.id.status_prev3_play); + holder.status_prev4_play = (ImageView) convertView.findViewById(R.id.status_prev4_play); + holder.status_container2 = (LinearLayout) convertView.findViewById(R.id.status_container2); + holder.status_container3 = (LinearLayout) convertView.findViewById(R.id.status_container3); + holder.status_prev4_container = (RelativeLayout) convertView.findViewById(R.id.status_prev4_container); + holder.status_reply = (ImageView) convertView.findViewById(R.id.status_reply); + holder.status_privacy = (ImageView) convertView.findViewById(R.id.status_privacy); + holder.status_translate = (FloatingActionButton) convertView.findViewById(R.id.status_translate); + holder.status_content_translated_container = (LinearLayout) convertView.findViewById(R.id.status_content_translated_container); + holder.main_container = (LinearLayout) convertView.findViewById(R.id.main_container); + holder.status_spoiler_container = (LinearLayout) convertView.findViewById(R.id.status_spoiler_container); + holder.status_content_container = (LinearLayout) convertView.findViewById(R.id.status_content_container); + 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.google_translate = (TextView) convertView.findViewById(R.id.google_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); + holder.new_element = (ImageView) convertView.findViewById(R.id.new_element); + holder.status_action_container = (LinearLayout) convertView.findViewById(R.id.status_action_container); + convertView.setTag(holder); + } else { + holder = (ViewHolder) convertView.getTag(); + } - final Status status = statuses.get(position); + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - if (convertView == null) { - convertView = layoutInflater.inflate(R.layout.drawer_status, parent, false); - holder = new ViewHolder(); - holder.loader_replies = (LinearLayout) convertView.findViewById(R.id.loader_replies); - holder.card_status_container = (CardView) convertView.findViewById(R.id.card_status_container); - holder.status_document_container = (LinearLayout) convertView.findViewById(R.id.status_document_container); - holder.status_content = (TextView) convertView.findViewById(R.id.status_content); - holder.status_content_translated = (TextView) convertView.findViewById(R.id.status_content_translated); - holder.status_account_username = (TextView) convertView.findViewById(R.id.status_account_username); - holder.status_account_displayname = (TextView) convertView.findViewById(R.id.status_account_displayname); - holder.status_account_profile = (ImageView) convertView.findViewById(R.id.status_account_profile); - holder.status_account_profile_boost = (ImageView) convertView.findViewById(R.id.status_account_profile_boost); - holder.status_account_profile_boost_by = (ImageView) convertView.findViewById(R.id.status_account_profile_boost_by); - holder.status_favorite_count = (TextView) convertView.findViewById(R.id.status_favorite_count); - holder.status_reblog_count = (TextView) convertView.findViewById(R.id.status_reblog_count); - holder.status_pin = (ImageView) convertView.findViewById(R.id.status_pin); - holder.status_toot_date = (TextView) convertView.findViewById(R.id.status_toot_date); - holder.status_show_more = (Button) convertView.findViewById(R.id.status_show_more); - holder.status_more = (ImageView) convertView.findViewById(R.id.status_more); - holder.status_reblog_user = (TextView) convertView.findViewById(R.id.status_reblog_user); - holder.status_prev1 = (ImageView) convertView.findViewById(R.id.status_prev1); - holder.status_prev2 = (ImageView) convertView.findViewById(R.id.status_prev2); - holder.status_prev3 = (ImageView) convertView.findViewById(R.id.status_prev3); - holder.status_prev4 = (ImageView) convertView.findViewById(R.id.status_prev4); - holder.status_prev1_play = (ImageView) convertView.findViewById(R.id.status_prev1_play); - holder.status_prev2_play = (ImageView) convertView.findViewById(R.id.status_prev2_play); - holder.status_prev3_play = (ImageView) convertView.findViewById(R.id.status_prev3_play); - holder.status_prev4_play = (ImageView) convertView.findViewById(R.id.status_prev4_play); - holder.status_container2 = (LinearLayout) convertView.findViewById(R.id.status_container2); - holder.status_container3 = (LinearLayout) convertView.findViewById(R.id.status_container3); - holder.status_prev4_container = (RelativeLayout) convertView.findViewById(R.id.status_prev4_container); - holder.status_reply = (ImageView) convertView.findViewById(R.id.status_reply); - holder.status_privacy = (ImageView) convertView.findViewById(R.id.status_privacy); - holder.status_translate = (FloatingActionButton) convertView.findViewById(R.id.status_translate); - holder.status_content_translated_container = (LinearLayout) convertView.findViewById(R.id.status_content_translated_container); - holder.main_container = (LinearLayout) convertView.findViewById(R.id.main_container); - holder.status_spoiler_container = (LinearLayout) convertView.findViewById(R.id.status_spoiler_container); - holder.status_content_container = (LinearLayout) convertView.findViewById(R.id.status_content_container); - 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.google_translate = (TextView) convertView.findViewById(R.id.google_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); - holder.new_element = (ImageView) convertView.findViewById(R.id.new_element); - holder.status_action_container = (LinearLayout) convertView.findViewById(R.id.status_action_container); - convertView.setTag(holder); - } else { - holder = (ViewHolder) convertView.getTag(); - } - - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - - final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - - //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, false); - if( showPreview){ - boolean showPreviewPP = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES_PP, true); - if( status.getReplies() == null){ - holder.loader_replies.setVisibility(View.VISIBLE); - }else if(status.getReplies().size() == 0){ - holder.status_replies.setVisibility(View.GONE); - holder.loader_replies.setVisibility(View.GONE); - }else if(status.getReplies().size() > 0 ){ - if(showPreviewPP) { - 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())) { - ImageView imageView = new ImageView(context); - imageView.setMaxHeight((int) Helper.convertDpToPixel(40, context)); - imageView.setMaxWidth((int) Helper.convertDpToPixel(40, 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(40, context); - imParams.width = (int) Helper.convertDpToPixel(40, context); - holder.status_replies_profile_pictures.addView(imageView, imParams); - i++; - addedPictures.add(replies.getAccount().getAcct()); + //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, false); + if( showPreview){ + boolean showPreviewPP = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES_PP, true); + if( status.getReplies() == null){ + holder.loader_replies.setVisibility(View.VISIBLE); + }else if(status.getReplies().size() == 0){ + holder.status_replies.setVisibility(View.GONE); + holder.loader_replies.setVisibility(View.GONE); + }else if(status.getReplies().size() > 0 ){ + if(showPreviewPP) { + 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())) { + ImageView imageView = new ImageView(context); + imageView.setMaxHeight((int) Helper.convertDpToPixel(40, context)); + imageView.setMaxWidth((int) Helper.convertDpToPixel(40, 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(40, context); + imParams.width = (int) Helper.convertDpToPixel(40, 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); + holder.loader_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); + }else{ holder.loader_replies.setVisibility(View.GONE); - } - }else{ - holder.loader_replies.setVisibility(View.GONE); - holder.status_replies.setVisibility(View.GONE); - } - } - changeDrawableColor(context, R.drawable.ic_fiber_new,R.color.mastodonC4); - if( status.isNew()) - holder.new_element.setVisibility(View.VISIBLE); - else - holder.new_element.setVisibility(View.INVISIBLE); - int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130); - int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110); - boolean trans_forced = sharedpreferences.getBoolean(Helper.SET_TRANS_FORCED, false); - holder.status_more.getLayoutParams().height = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context); - 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); - holder.status_reply.getLayoutParams().height = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context); - holder.status_reply.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context); - holder.status_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100); - holder.status_account_displayname.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100); - holder.status_account_username.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12*textSizePercent/100); - holder.status_reblog_user.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100); - holder.status_toot_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12*textSizePercent/100); - holder.status_spoiler.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100); - holder.status_content_translated.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100); - - - - switch (translator) - { - case Helper.TRANS_NONE: - holder.yandex_translate.setVisibility(View.GONE); - holder.google_translate.setVisibility(View.GONE); - break; - case Helper.TRANS_YANDEX: - holder.google_translate.setVisibility(View.GONE); - holder.yandex_translate.setVisibility(View.VISIBLE); - break; - case Helper.TRANS_GOOGLE: - holder.yandex_translate.setVisibility(View.GONE); - holder.google_translate.setVisibility(View.VISIBLE); - break; - default: - holder.yandex_translate.setVisibility(View.GONE); - holder.google_translate.setVisibility(View.GONE); - break; - } - - - - - //Manages theme for icon colors - int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); - if( theme == Helper.THEME_DARK){ - changeDrawableColor(context, R.drawable.ic_reply,R.color.dark_text); - changeDrawableColor(context, R.drawable.ic_action_more,R.color.dark_text); - changeDrawableColor(context, R.drawable.ic_action_globe,R.color.dark_text); - changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.dark_text); - changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.dark_text); - changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.dark_text); - changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.dark_text); - changeDrawableColor(context, R.drawable.ic_fav_black,R.color.dark_text); - changeDrawableColor(context, R.drawable.ic_action_pin_dark, R.color.dark_text); - 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); - }else { - changeDrawableColor(context, R.drawable.ic_reply,R.color.black); - changeDrawableColor(context, R.drawable.ic_action_more,R.color.black); - changeDrawableColor(context, R.drawable.ic_action_globe,R.color.black); - changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.black); - changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.black); - changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.black); - changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.black); - changeDrawableColor(context, R.drawable.ic_fav_black,R.color.black); - changeDrawableColor(context, R.drawable.ic_action_pin_dark, R.color.black); - changeDrawableColor(context, R.drawable.ic_photo,R.color.white); - changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.white); - changeDrawableColor(context, R.drawable.ic_translate,R.color.white); - } - - //Redraws top icons (boost/reply) - final float scale = context.getResources().getDisplayMetrics().density; - if( (status.getIn_reply_to_account_id()!= null && !status.getIn_reply_to_account_id().equals("null")) || (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null")) ){ - Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_reply); - 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); - }else if( status.getReblog() != null){ - Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_retweet_black); - 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); - }else{ - holder.status_account_displayname.setCompoundDrawables( null, null, null, null); - } - - - - String content; - final String displayName; - final String username; - final String ppurl; - if( status.getReblog() != null){ - content = status.getReblog().getContent(); - displayName = Helper.shortnameToUnicode(status.getReblog().getAccount().getDisplay_name(), true); - username = status.getReblog().getAccount().getUsername(); - holder.status_reblog_user.setText(displayName + " " +String.format("@%s",username)); - ppurl = status.getReblog().getAccount().getAvatar(); - holder.status_reblog_user.setVisibility(View.VISIBLE); - holder.status_account_displayname.setText(context.getResources().getString(R.string.reblog_by, status.getAccount().getUsername())); - holder.status_account_username.setText( ""); - }else { - ppurl = status.getAccount().getAvatar(); - content = status.getContent(); - displayName = Helper.shortnameToUnicode(status.getAccount().getDisplay_name(), true); - username = status.getAccount().getUsername(); - holder.status_reblog_user.setVisibility(View.GONE); - holder.status_account_displayname.setText(displayName); - holder.status_account_username.setText(String.format("@%s",username)); - } - - - - - - if( status.getContent_translated() != null && status.getContent_translated().length() > 0){ - holder.status_content_translated.setMovementMethod(null); - SpannableString spannableStringTrans = Helper.clickableElements(context, status.getContent_translated(), - status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), false); - holder.status_content_translated.setText(spannableStringTrans, TextView.BufferType.SPANNABLE); - holder.status_content_translated.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - holder.status_content_translated.setFocusableInTouchMode(true); - return false; - } - }); - holder.status_content_translated.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_DOWN) { - holder.status_content_translated.setFocusableInTouchMode(false); - holder.status_content_translated.clearFocus(); - } - return false; - } - }); - holder.status_content_translated.setMovementMethod(LinkMovementMethod.getInstance()); - } - content = content.replaceAll("

","

"); - content = content.replaceAll("

",""); - if( content.endsWith("

") ) - content = content.substring(0,content.length() -10); - holder.status_content.setMovementMethod(null); - final SpannableString spannableString = Helper.clickableElements(context,content, - status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), true); - holder.status_content.setText(spannableString, TextView.BufferType.SPANNABLE); - holder.status_content.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - holder.status_content.setFocusableInTouchMode(true); - return false; - } - }); - holder.status_content.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - - if (event.getAction() == MotionEvent.ACTION_DOWN) { - holder.status_content.setFocusableInTouchMode(false); - holder.status_content.clearFocus(); - } - return false; - } - }); - holder.status_content.setMovementMethod(LinkMovementMethod.getInstance()); - - if( status.getReblog() == null) - holder.status_favorite_count.setText(String.valueOf(status.getFavourites_count())); - else - holder.status_favorite_count.setText(String.valueOf(status.getReblog().getFavourites_count())); - if( status.getReblog() == null) - holder.status_reblog_count.setText(String.valueOf(status.getReblogs_count())); - else - holder.status_reblog_count.setText(String.valueOf(status.getReblog().getReblogs_count())); - - holder.status_toot_date.setText(Helper.dateDiff(context, status.getCreated_at())); - - - if( status.getReblog() != null) { - imageLoader.displayImage(ppurl, holder.status_account_profile_boost, options); - imageLoader.displayImage(status.getAccount().getAvatar(), holder.status_account_profile_boost_by, options); - holder.status_account_profile_boost.setVisibility(View.VISIBLE); - holder.status_account_profile_boost_by.setVisibility(View.VISIBLE); - holder.status_account_profile.setVisibility(View.GONE); - }else{ - imageLoader.displayImage(ppurl, holder.status_account_profile, options); - holder.status_account_profile_boost.setVisibility(View.GONE); - holder.status_account_profile_boost_by.setVisibility(View.GONE); - holder.status_account_profile.setVisibility(View.VISIBLE); - } - if( status.isTakingScreenShot()){ - holder.status_document_container.setVisibility(View.GONE); - holder.status_content.setVisibility(View.VISIBLE); - holder.status_content_translated_container.setVisibility(View.GONE); - holder.status_spoiler_button.setVisibility(View.GONE); - holder.status_content_container.setVisibility(View.VISIBLE); - holder.status_translate.setVisibility(View.GONE); - holder.status_show_more.setVisibility(View.GONE); - holder.status_action_container.setVisibility(View.GONE); - }else { - holder.status_action_container.setVisibility(View.VISIBLE); - if( 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( status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 && !status.isSpoilerShown()){ - holder.status_content_container.setVisibility(View.GONE); - holder.status_spoiler_container.setVisibility(View.VISIBLE); - holder.status_spoiler_button.setVisibility(View.VISIBLE); - holder.status_spoiler.setVisibility(View.VISIBLE); - }else { - holder.status_spoiler_button.setVisibility(View.GONE); - holder.status_content_container.setVisibility(View.VISIBLE); - if( status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 ) - holder.status_spoiler_container.setVisibility(View.VISIBLE); - else - holder.status_spoiler_container.setVisibility(View.GONE); - } - if( status.getSpoiler_text() != null) - holder.status_spoiler.setText(status.getSpoiler_text()); - if( status.getReblog() == null) { - if (status.getMedia_attachments().size() < 1) { - holder.status_document_container.setVisibility(View.GONE); - holder.status_show_more.setVisibility(View.GONE); - } else { - //If medias are loaded without any conditions or if device is on wifi - if (!status.isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) { - loadAttachments(status, holder); - holder.status_show_more.setVisibility(View.GONE); - status.setAttachmentShown(true); - } else { - //Text depending if toots is sensitive or not - String textShowMore = (status.isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment); - holder.status_show_more.setText(textShowMore); - if (!status.isAttachmentShown()) { - holder.status_show_more.setVisibility(View.VISIBLE); - holder.status_document_container.setVisibility(View.GONE); - } else { - loadAttachments(status, holder); - } - } - } - }else { //Attachments for reblogs - if (status.getReblog().getMedia_attachments().size() < 1) { - holder.status_document_container.setVisibility(View.GONE); - 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))) { - loadAttachments(status.getReblog(), holder); - holder.status_show_more.setVisibility(View.GONE); - status.getReblog().setAttachmentShown(true); - } else { - //Text depending if toots is sensitive or not - String textShowMore = (status.getReblog().isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment); - holder.status_show_more.setText(textShowMore); - if (!status.isAttachmentShown()) { - holder.status_show_more.setVisibility(View.VISIBLE); - holder.status_document_container.setVisibility(View.GONE); - } else { - loadAttachments(status.getReblog(), holder); - } - } + holder.status_replies.setVisibility(View.GONE); } } - //Toot was translated and user asked to see it - if( status.isTranslationShown()){ - holder.status_content.setVisibility(View.GONE); - holder.status_content_translated_container.setVisibility(View.VISIBLE); - }else { //Toot is not translated - holder.status_content.setVisibility(View.VISIBLE); - holder.status_content_translated_container.setVisibility(View.GONE); - } + changeDrawableColor(context, R.drawable.ic_fiber_new,R.color.mastodonC4); + if( status.isNew()) + holder.new_element.setVisibility(View.VISIBLE); + else + holder.new_element.setVisibility(View.INVISIBLE); + int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130); + int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110); + boolean trans_forced = sharedpreferences.getBoolean(Helper.SET_TRANS_FORCED, false); + holder.status_more.getLayoutParams().height = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context); + 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); + holder.status_reply.getLayoutParams().height = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context); + holder.status_reply.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context); + holder.status_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100); + holder.status_account_displayname.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100); + holder.status_account_username.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12*textSizePercent/100); + holder.status_reblog_user.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100); + holder.status_toot_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12*textSizePercent/100); + holder.status_spoiler.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100); + holder.status_content_translated.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100); - switch (status.getVisibility()){ - case "direct": - case "private": - holder.status_reblog_count.setVisibility(View.GONE); + + + switch (translator) + { + case Helper.TRANS_NONE: + holder.yandex_translate.setVisibility(View.GONE); + holder.google_translate.setVisibility(View.GONE); break; - case "public": - case "unlisted": - holder.status_reblog_count.setVisibility(View.VISIBLE); + case Helper.TRANS_YANDEX: + holder.google_translate.setVisibility(View.GONE); + holder.yandex_translate.setVisibility(View.VISIBLE); + break; + case Helper.TRANS_GOOGLE: + holder.yandex_translate.setVisibility(View.GONE); + holder.google_translate.setVisibility(View.VISIBLE); break; default: - holder.status_reblog_count.setVisibility(View.VISIBLE); - } - - switch (status.getVisibility()){ - case "public": - holder.status_privacy.setImageResource(R.drawable.ic_action_globe); - break; - case "unlisted": - holder.status_privacy.setImageResource(R.drawable.ic_action_lock_open); - break; - case "private": - holder.status_privacy.setImageResource(R.drawable.ic_action_lock_closed); - break; - case "direct": - holder.status_privacy.setImageResource(R.drawable.ic_local_post_office); + holder.yandex_translate.setVisibility(View.GONE); + holder.google_translate.setVisibility(View.GONE); break; } - Drawable imgFav, imgReblog, imgPinned; - if( status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited())) - imgFav = ContextCompat.getDrawable(context, R.drawable.ic_fav_yellow); - else - imgFav = ContextCompat.getDrawable(context, R.drawable.ic_fav_black); - if( status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged())) - imgReblog = ContextCompat.getDrawable(context, R.drawable.ic_retweet_yellow); - else - imgReblog = ContextCompat.getDrawable(context, R.drawable.ic_retweet_black); - if( status.isPinned()|| (status.getReblog() != null && status.getReblog().isPinned())) - imgPinned = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_yellow); - else - imgPinned = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_dark); - imgFav.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f)); - imgReblog.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f)); - imgPinned.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f)); - - holder.status_favorite_count.setCompoundDrawables(imgFav, null, null, null); - holder.status_reblog_count.setCompoundDrawables(imgReblog, null, null, null); - holder.status_pin.setImageDrawable(imgPinned); - - if( theme == Helper.THEME_LIGHT) { - holder.status_show_more.setTextColor(ContextCompat.getColor(context, R.color.white)); - holder.status_spoiler_button.setTextColor(ContextCompat.getColor(context, R.color.white)); - } - - boolean isOwner = status.getAccount().getId().equals(userId); - - // Pinning toots is only available on Mastodon 1._6_.0 instances. - if (isOwner && Helper.canPin && (status.getVisibility().equals("public") || status.getVisibility().equals("unlisted")) && status.getReblog() == null) { - Drawable imgPin; - if( status.isPinned()) - imgPin = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_yellow); - else - imgPin = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_dark); - imgPin.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f)); - holder.status_pin.setImageDrawable(imgPin); - - holder.status_pin.setVisibility(View.VISIBLE); - } - else { - holder.status_pin.setVisibility(View.GONE); - } - } - - //Click on a conversation - if( type != RetrieveFeedsAsyncTask.Type.CONTEXT ){ - 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); - context.startActivity(intent); - } - }); - holder.card_status_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); - context.startActivity(intent); - } - }); - }else { - if( theme == Helper.THEME_LIGHT){ - if( position == ShowConversationActivity.position){ - holder.main_container.setBackgroundResource(R.color.mastodonC3_); - }else { - holder.main_container.setBackgroundResource(R.color.mastodonC3__); - } + //Manages theme for icon colors + int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + if( theme == Helper.THEME_DARK){ + changeDrawableColor(context, R.drawable.ic_reply,R.color.dark_text); + changeDrawableColor(context, R.drawable.ic_action_more,R.color.dark_text); + changeDrawableColor(context, R.drawable.ic_action_globe,R.color.dark_text); + changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.dark_text); + changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.dark_text); + changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.dark_text); + changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.dark_text); + changeDrawableColor(context, R.drawable.ic_fav_black,R.color.dark_text); + changeDrawableColor(context, R.drawable.ic_action_pin_dark, R.color.dark_text); + 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); }else { - if( position == ShowConversationActivity.position){ - holder.main_container.setBackgroundResource(R.color.mastodonC1_); - }else { - holder.main_container.setBackgroundResource(R.color.mastodonC1); - } + changeDrawableColor(context, R.drawable.ic_reply,R.color.black); + changeDrawableColor(context, R.drawable.ic_action_more,R.color.black); + changeDrawableColor(context, R.drawable.ic_action_globe,R.color.black); + changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.black); + changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.black); + changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.black); + changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.black); + changeDrawableColor(context, R.drawable.ic_fav_black,R.color.black); + changeDrawableColor(context, R.drawable.ic_action_pin_dark, R.color.black); + changeDrawableColor(context, R.drawable.ic_photo,R.color.white); + changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.white); + changeDrawableColor(context, R.drawable.ic_translate,R.color.white); } - } - holder.status_reply.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - CrossActions.doCrossReply(context, status, type, true); + //Redraws top icons (boost/reply) + final float scale = context.getResources().getDisplayMetrics().density; + if( (status.getIn_reply_to_account_id()!= null && !status.getIn_reply_to_account_id().equals("null")) || (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null")) ){ + Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_reply); + 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); + }else if( status.getReblog() != null){ + Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_retweet_black); + 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); + }else{ + holder.status_account_displayname.setCompoundDrawables( null, null, null, null); } - }); - - holder.status_reply.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - CrossActions.doCrossReply(context, status, type, false); - return true; - } - }); - - holder.status_favorite_count.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - CrossActions.doCrossAction(context, status, (status.isFavourited()|| (status.getReblog() != null && status.getReblog().isFavourited()))? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, true); - } - }); - - holder.status_reblog_count.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - CrossActions.doCrossAction(context, status, (status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged()))? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, true); - } - }); - holder.status_pin.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - CrossActions.doCrossAction(context, status, (status.isPinned()|| (status.getReblog() != null && status.getReblog().isPinned()))? API.StatusAction.UNPIN:API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this, true); - } - }); - holder.status_favorite_count.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - CrossActions.doCrossAction(context, status, (status.isFavourited()|| (status.getReblog() != null && status.getReblog().isFavourited()))? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, false); - return true; - } - }); - holder.status_reblog_count.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - CrossActions.doCrossAction(context, status, (status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged()))? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, false); - return true; + String content; + final String displayName; + final String username; + final String ppurl; + if( status.getReblog() != null){ + content = status.getReblog().getContent(); + displayName = Helper.shortnameToUnicode(status.getReblog().getAccount().getDisplay_name(), true); + username = status.getReblog().getAccount().getUsername(); + holder.status_reblog_user.setText(displayName + " " +String.format("@%s",username)); + ppurl = status.getReblog().getAccount().getAvatar(); + holder.status_reblog_user.setVisibility(View.VISIBLE); + holder.status_account_displayname.setText(context.getResources().getString(R.string.reblog_by, status.getAccount().getUsername())); + holder.status_account_username.setText( ""); + }else { + ppurl = status.getAccount().getAvatar(); + content = status.getContent(); + displayName = Helper.shortnameToUnicode(status.getAccount().getDisplay_name(), true); + username = status.getAccount().getUsername(); + holder.status_reblog_user.setVisibility(View.GONE); + holder.status_account_displayname.setText(displayName); + holder.status_account_username.setText(String.format("@%s",username)); } - }); - holder.status_pin.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - CrossActions.doCrossAction(context, status, (status.isPinned()|| (status.getReblog() != null && status.getReblog().isPinned()))? API.StatusAction.UNPIN:API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this, true); - return false; - } - }); - holder.status_translate.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - try { - SpannableString spannableString; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - spannableString = new SpannableString(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - //noinspection deprecation - spannableString = new SpannableString(Html.fromHtml(status.getContent())); - String text = spannableString.toString(); - if( !status.isTranslated() ){ - tagConversion = new HashMap<>(); - urlConversion = new HashMap<>(); - Matcher matcher; - //Extracts urls - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) - matcher = Patterns.WEB_URL.matcher(spannableString.toString()); - else - matcher = Helper.urlPattern.matcher(spannableString.toString()); - int i = 0; - //replaces them by a kind of variable which shouldn't be translated ie: __u0__, __u1__, etc. - while (matcher.find()){ - String key = "__u" + String.valueOf(i) + "__"; - String value = matcher.group(0); - int end = matcher.end(); - if (spannableString.length() > end && spannableString.charAt(end) == '/') { - text = spannableString.toString().substring(0, end). - concat(spannableString.toString().substring(end+1, spannableString.length())); - } - if( value != null) { - urlConversion.put(key, value); - text = text.replace(value, key); - } - i++; - } - i = 0; - //Same for tags with __t0__, __t1__, etc. - matcher = Helper.hashtagPattern.matcher(text); - while (matcher.find()){ - String key = "__t" + String.valueOf(i) + "__"; - String value = matcher.group(0); - tagConversion.put(key, value); - if( value != null) { - tagConversion.put(key, value); - text = text.replace(value, key); - } - i++; - } - if (translator == Helper.TRANS_YANDEX) - new YandexQuery(StatusListAdapter.this).getYandexTextview(position, text, currentLocale); - else if( translator == Helper.TRANS_GOOGLE) { - while( text.charAt(text.length() -1) == '\n' && text.length() > 0) - text = text.substring(0, text.length() -1); - text += "."; - new GoogleTranslateQuery(StatusListAdapter.this).getGoogleTextview(position, text.trim(), currentLocale); - } - }else { - status.setTranslationShown(!status.isTranslationShown()); - statusListAdapter.notifyDataSetChanged(); + + + + if( status.getContent_translated() != null && status.getContent_translated().length() > 0){ + holder.status_content_translated.setMovementMethod(null); + SpannableString spannableStringTrans = Helper.clickableElements(context, status.getContent_translated(), + status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), false); + holder.status_content_translated.setText(spannableStringTrans, TextView.BufferType.SPANNABLE); + holder.status_content_translated.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + holder.status_content_translated.setFocusableInTouchMode(true); + return false; } - } catch (JSONException e) { - Toast.makeText(context, R.string.toast_error_translate, Toast.LENGTH_LONG).show(); + }); + holder.status_content_translated.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + holder.status_content_translated.setFocusableInTouchMode(false); + holder.status_content_translated.clearFocus(); + } + return false; + } + }); + holder.status_content_translated.setMovementMethod(LinkMovementMethod.getInstance()); + } + content = content.replaceAll("

","

"); + content = content.replaceAll("

",""); + if( content.endsWith("

") ) + content = content.substring(0,content.length() -10); + holder.status_content.setMovementMethod(null); + final SpannableString spannableString = Helper.clickableElements(context,content, + status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), true); + holder.status_content.setText(spannableString, TextView.BufferType.SPANNABLE); + holder.status_content.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + holder.status_content.setFocusableInTouchMode(true); + return false; + } + }); + holder.status_content.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + + if (event.getAction() == MotionEvent.ACTION_DOWN) { + holder.status_content.setFocusableInTouchMode(false); + holder.status_content.clearFocus(); + } + return false; + } + }); + holder.status_content.setMovementMethod(LinkMovementMethod.getInstance()); + + if( status.getReblog() == null) + holder.status_favorite_count.setText(String.valueOf(status.getFavourites_count())); + else + holder.status_favorite_count.setText(String.valueOf(status.getReblog().getFavourites_count())); + if( status.getReblog() == null) + holder.status_reblog_count.setText(String.valueOf(status.getReblogs_count())); + else + holder.status_reblog_count.setText(String.valueOf(status.getReblog().getReblogs_count())); + + holder.status_toot_date.setText(Helper.dateDiff(context, status.getCreated_at())); + + + if( status.getReblog() != null) { + imageLoader.displayImage(ppurl, holder.status_account_profile_boost, options); + imageLoader.displayImage(status.getAccount().getAvatar(), holder.status_account_profile_boost_by, options); + holder.status_account_profile_boost.setVisibility(View.VISIBLE); + holder.status_account_profile_boost_by.setVisibility(View.VISIBLE); + holder.status_account_profile.setVisibility(View.GONE); + }else{ + imageLoader.displayImage(ppurl, holder.status_account_profile, options); + holder.status_account_profile_boost.setVisibility(View.GONE); + holder.status_account_profile_boost_by.setVisibility(View.GONE); + holder.status_account_profile.setVisibility(View.VISIBLE); + } + if( status.isTakingScreenShot()){ + holder.status_document_container.setVisibility(View.GONE); + holder.status_content.setVisibility(View.VISIBLE); + holder.status_content_translated_container.setVisibility(View.GONE); + holder.status_spoiler_button.setVisibility(View.GONE); + holder.status_content_container.setVisibility(View.VISIBLE); + holder.status_translate.setVisibility(View.GONE); + holder.status_show_more.setVisibility(View.GONE); + holder.status_action_container.setVisibility(View.GONE); + }else { + holder.status_action_container.setVisibility(View.VISIBLE); + if( 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( status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 && !status.isSpoilerShown()){ + holder.status_content_container.setVisibility(View.GONE); + holder.status_spoiler_container.setVisibility(View.VISIBLE); + holder.status_spoiler_button.setVisibility(View.VISIBLE); + holder.status_spoiler.setVisibility(View.VISIBLE); + }else { + holder.status_spoiler_button.setVisibility(View.GONE); + holder.status_content_container.setVisibility(View.VISIBLE); + if( status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 ) + holder.status_spoiler_container.setVisibility(View.VISIBLE); + else + holder.status_spoiler_container.setVisibility(View.GONE); + } + if( status.getSpoiler_text() != null) + holder.status_spoiler.setText(status.getSpoiler_text()); + if( status.getReblog() == null) { + if (status.getMedia_attachments().size() < 1) { + holder.status_document_container.setVisibility(View.GONE); + holder.status_show_more.setVisibility(View.GONE); + } else { + //If medias are loaded without any conditions or if device is on wifi + if (!status.isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) { + loadAttachments(status, holder); + holder.status_show_more.setVisibility(View.GONE); + status.setAttachmentShown(true); + } else { + //Text depending if toots is sensitive or not + String textShowMore = (status.isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment); + holder.status_show_more.setText(textShowMore); + if (!status.isAttachmentShown()) { + holder.status_show_more.setVisibility(View.VISIBLE); + holder.status_document_container.setVisibility(View.GONE); + } else { + loadAttachments(status, holder); + } + } + } + }else { //Attachments for reblogs + if (status.getReblog().getMedia_attachments().size() < 1) { + holder.status_document_container.setVisibility(View.GONE); + 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))) { + loadAttachments(status.getReblog(), holder); + holder.status_show_more.setVisibility(View.GONE); + status.getReblog().setAttachmentShown(true); + } else { + //Text depending if toots is sensitive or not + String textShowMore = (status.getReblog().isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment); + holder.status_show_more.setText(textShowMore); + if (!status.isAttachmentShown()) { + holder.status_show_more.setVisibility(View.VISIBLE); + holder.status_document_container.setVisibility(View.GONE); + } else { + loadAttachments(status.getReblog(), holder); + } + } + } + } + //Toot was translated and user asked to see it + if( status.isTranslationShown()){ + holder.status_content.setVisibility(View.GONE); + holder.status_content_translated_container.setVisibility(View.VISIBLE); + }else { //Toot is not translated + holder.status_content.setVisibility(View.VISIBLE); + holder.status_content_translated_container.setVisibility(View.GONE); + } + + switch (status.getVisibility()){ + case "direct": + case "private": + holder.status_reblog_count.setVisibility(View.GONE); + break; + case "public": + case "unlisted": + holder.status_reblog_count.setVisibility(View.VISIBLE); + break; + default: + holder.status_reblog_count.setVisibility(View.VISIBLE); + } + + switch (status.getVisibility()){ + case "public": + holder.status_privacy.setImageResource(R.drawable.ic_action_globe); + break; + case "unlisted": + holder.status_privacy.setImageResource(R.drawable.ic_action_lock_open); + break; + case "private": + holder.status_privacy.setImageResource(R.drawable.ic_action_lock_closed); + break; + case "direct": + holder.status_privacy.setImageResource(R.drawable.ic_local_post_office); + break; + } + + Drawable imgFav, imgReblog, imgPinned; + if( status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited())) + imgFav = ContextCompat.getDrawable(context, R.drawable.ic_fav_yellow); + else + imgFav = ContextCompat.getDrawable(context, R.drawable.ic_fav_black); + + if( status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged())) + imgReblog = ContextCompat.getDrawable(context, R.drawable.ic_retweet_yellow); + else + imgReblog = ContextCompat.getDrawable(context, R.drawable.ic_retweet_black); + + if( status.isPinned()|| (status.getReblog() != null && status.getReblog().isPinned())) + imgPinned = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_yellow); + else + imgPinned = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_dark); + + imgFav.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f)); + imgReblog.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f)); + imgPinned.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f)); + + holder.status_favorite_count.setCompoundDrawables(imgFav, null, null, null); + holder.status_reblog_count.setCompoundDrawables(imgReblog, null, null, null); + holder.status_pin.setImageDrawable(imgPinned); + + if( theme == Helper.THEME_LIGHT) { + holder.status_show_more.setTextColor(ContextCompat.getColor(context, R.color.white)); + holder.status_spoiler_button.setTextColor(ContextCompat.getColor(context, R.color.white)); + } + + boolean isOwner = status.getAccount().getId().equals(userId); + + // Pinning toots is only available on Mastodon 1._6_.0 instances. + if (isOwner && Helper.canPin && (status.getVisibility().equals("public") || status.getVisibility().equals("unlisted")) && status.getReblog() == null) { + Drawable imgPin; + if( status.isPinned()) + imgPin = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_yellow); + else + imgPin = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_dark); + imgPin.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f)); + holder.status_pin.setImageDrawable(imgPin); + + holder.status_pin.setVisibility(View.VISIBLE); + } + else { + holder.status_pin.setVisibility(View.GONE); } } - }); - holder.yandex_translate.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://translate.yandex.com/")); - context.startActivity(browserIntent); + //Click on a conversation + if( type != RetrieveFeedsAsyncTask.Type.CONTEXT ){ + 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); + context.startActivity(intent); + } + }); + holder.card_status_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); + context.startActivity(intent); + } + }); + }else { + if( theme == Helper.THEME_LIGHT){ + if( position == ShowConversationActivity.position){ + holder.main_container.setBackgroundResource(R.color.mastodonC3_); + }else { + holder.main_container.setBackgroundResource(R.color.mastodonC3__); + } + }else { + if( position == ShowConversationActivity.position){ + holder.main_container.setBackgroundResource(R.color.mastodonC1_); + }else { + holder.main_container.setBackgroundResource(R.color.mastodonC1); + } + } } - }); - holder.google_translate.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://translate.google.com/")); - context.startActivity(browserIntent); - } - }); - //Spoiler opens - holder.status_spoiler_button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - status.setSpoilerShown(true); - holder.status_spoiler_button.setVisibility(View.GONE); - statusListAdapter.notifyDataSetChanged(); - } - }); - holder.status_show_more.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - loadAttachments(status, holder); - holder.status_show_more.setVisibility(View.GONE); - status.setAttachmentShown(true); - statusListAdapter.notifyDataSetChanged(); + holder.status_reply.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CrossActions.doCrossReply(context, status, type, true); + } + }); + + holder.status_reply.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View view) { + CrossActions.doCrossReply(context, status, type, false); + return true; + } + }); + + holder.status_favorite_count.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CrossActions.doCrossAction(context, status, (status.isFavourited()|| (status.getReblog() != null && status.getReblog().isFavourited()))? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, true); + } + }); + + holder.status_reblog_count.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CrossActions.doCrossAction(context, status, (status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged()))? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, true); + } + }); + holder.status_pin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CrossActions.doCrossAction(context, status, (status.isPinned()|| (status.getReblog() != null && status.getReblog().isPinned()))? API.StatusAction.UNPIN:API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this, true); + } + }); + + + holder.status_favorite_count.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View view) { + CrossActions.doCrossAction(context, status, (status.isFavourited()|| (status.getReblog() != null && status.getReblog().isFavourited()))? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, false); + return true; + } + }); + + holder.status_reblog_count.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View view) { + CrossActions.doCrossAction(context, status, (status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged()))? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, false); + return true; + } + }); + holder.status_pin.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View view) { + CrossActions.doCrossAction(context, status, (status.isPinned()|| (status.getReblog() != null && status.getReblog().isPinned()))? API.StatusAction.UNPIN:API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this, true); + return false; + } + }); + + holder.status_translate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + SpannableString spannableString; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + spannableString = new SpannableString(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + //noinspection deprecation + spannableString = new SpannableString(Html.fromHtml(status.getContent())); + String text = spannableString.toString(); + if( !status.isTranslated() ){ + tagConversion = new HashMap<>(); + urlConversion = new HashMap<>(); + Matcher matcher; + //Extracts urls + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) + matcher = Patterns.WEB_URL.matcher(spannableString.toString()); + else + matcher = Helper.urlPattern.matcher(spannableString.toString()); + int i = 0; + //replaces them by a kind of variable which shouldn't be translated ie: __u0__, __u1__, etc. + while (matcher.find()){ + String key = "__u" + String.valueOf(i) + "__"; + String value = matcher.group(0); + int end = matcher.end(); + if (spannableString.length() > end && spannableString.charAt(end) == '/') { + text = spannableString.toString().substring(0, end). + concat(spannableString.toString().substring(end+1, spannableString.length())); + } + if( value != null) { + urlConversion.put(key, value); + text = text.replace(value, key); + } + i++; + } + i = 0; + //Same for tags with __t0__, __t1__, etc. + matcher = Helper.hashtagPattern.matcher(text); + while (matcher.find()){ + String key = "__t" + String.valueOf(i) + "__"; + String value = matcher.group(0); + tagConversion.put(key, value); + if( value != null) { + tagConversion.put(key, value); + text = text.replace(value, key); + } + i++; + } + if (translator == Helper.TRANS_YANDEX) + new YandexQuery(StatusListAdapter.this).getYandexTextview(position, text, currentLocale); + else if( translator == Helper.TRANS_GOOGLE) { + + while( text.charAt(text.length() -1) == '\n' && text.length() > 0) + text = text.substring(0, text.length() -1); + text += "."; + new GoogleTranslateQuery(StatusListAdapter.this).getGoogleTextview(position, text.trim(), currentLocale); + } + }else { + status.setTranslationShown(!status.isTranslationShown()); + statusListAdapter.notifyDataSetChanged(); + } + } catch (JSONException e) { + Toast.makeText(context, R.string.toast_error_translate, Toast.LENGTH_LONG).show(); + } + } + }); + + holder.yandex_translate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://translate.yandex.com/")); + context.startActivity(browserIntent); + } + }); + holder.google_translate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://translate.google.com/")); + context.startActivity(browserIntent); + } + }); + //Spoiler opens + holder.status_spoiler_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + status.setSpoilerShown(true); + holder.status_spoiler_button.setVisibility(View.GONE); + statusListAdapter.notifyDataSetChanged(); + } + }); + + holder.status_show_more.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + loadAttachments(status, holder); + holder.status_show_more.setVisibility(View.GONE); + status.setAttachmentShown(true); + statusListAdapter.notifyDataSetChanged(); /* Added a Countdown Timer, so that Sensitive (NSFW) @@ -843,214 +858,215 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf if they want. Images are then hidden again. -> Default value is set to 5 seconds */ - final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5); + final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5); - if (timeout > 0) { + if (timeout > 0) { - new CountDownTimer((timeout * 1000), 1000) { + new CountDownTimer((timeout * 1000), 1000) { - public void onTick(long millisUntilFinished) { - } + public void onTick(long millisUntilFinished) { + } - public void onFinish() { - status.setAttachmentShown(false); - holder.status_show_more.setVisibility(View.VISIBLE); + public void onFinish() { + status.setAttachmentShown(false); + holder.status_show_more.setVisibility(View.VISIBLE); - statusListAdapter.notifyDataSetChanged(); - } - }.start(); - } - } - }); - - - - final View finalConvertView = convertView; - final View attached = holder.status_more; - holder.status_more.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - PopupMenu popup = new PopupMenu(context, attached); - final boolean isOwner = status.getAccount().getId().equals(userId); - popup.getMenuInflater() - .inflate(R.menu.option_toot, popup.getMenu()); - if( status.getVisibility().equals("private") || status.getVisibility().equals("direct")){ - popup.getMenu().findItem(R.id.action_mention).setVisible(false); - } - final String[] stringArrayConf; - if( isOwner) { - popup.getMenu().findItem(R.id.action_block).setVisible(false); - popup.getMenu().findItem(R.id.action_mute).setVisible(false); - popup.getMenu().findItem(R.id.action_report).setVisible(false); - stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); - }else { - popup.getMenu().findItem(R.id.action_remove).setVisible(false); - stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm); - } - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - public boolean onMenuItemClick(MenuItem item) { - AlertDialog.Builder builderInner; - final API.StatusAction doAction; - switch (item.getItemId()) { - case R.id.action_remove: - builderInner = new AlertDialog.Builder(context); - builderInner.setTitle(stringArrayConf[0]); - doAction = API.StatusAction.UNSTATUS; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - //noinspection deprecation - builderInner.setMessage(Html.fromHtml(status.getContent())); - break; - case R.id.action_mute: - builderInner = new AlertDialog.Builder(context); - builderInner.setTitle(stringArrayConf[0]); - doAction = API.StatusAction.MUTE; - break; - case R.id.action_block: - builderInner = new AlertDialog.Builder(context); - builderInner.setTitle(stringArrayConf[1]); - doAction = API.StatusAction.BLOCK; - break; - case R.id.action_report: - builderInner = new AlertDialog.Builder(context); - builderInner.setTitle(stringArrayConf[2]); - doAction = API.StatusAction.REPORT; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - //noinspection deprecation - builderInner.setMessage(Html.fromHtml(status.getContent())); - break; - case R.id.action_copy: - ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - 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(); - ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content); - clipboard.setPrimaryClip(clip); - Toast.makeText(context,R.string.clipboard,Toast.LENGTH_LONG).show(); - return true; - case R.id.action_share: - Intent sendIntent = new Intent(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); - sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl()); - sendIntent.setType("text/plain"); - context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); - return true; - case R.id.action_mention: - status.setTakingScreenShot(true); statusListAdapter.notifyDataSetChanged(); - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { + } + }.start(); + } + } + }); - @Override - public void run() { - Bitmap bitmap = Helper.convertTootIntoBitmap(context, finalConvertView); - status.setTakingScreenShot(false); - statusListAdapter.notifyDataSetChanged(); - Intent intent = new Intent(context, TootActivity.class); - Bundle b = new Bundle(); - String fname = "tootmention_" + status.getId() +".jpg"; - File file = new File (context.getCacheDir() + "/", fname); - if (file.exists ()) //noinspection ResultOfMethodCallIgnored - file.delete (); - try { - FileOutputStream out = new FileOutputStream(file); - bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); - out.flush(); - out.close(); - } catch (Exception e) { - e.printStackTrace(); + + + final View finalConvertView = convertView; + final View attached = holder.status_more; + holder.status_more.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + PopupMenu popup = new PopupMenu(context, attached); + final boolean isOwner = status.getAccount().getId().equals(userId); + popup.getMenuInflater() + .inflate(R.menu.option_toot, popup.getMenu()); + if( status.getVisibility().equals("private") || status.getVisibility().equals("direct")){ + popup.getMenu().findItem(R.id.action_mention).setVisible(false); + } + final String[] stringArrayConf; + if( isOwner) { + popup.getMenu().findItem(R.id.action_block).setVisible(false); + popup.getMenu().findItem(R.id.action_mute).setVisible(false); + popup.getMenu().findItem(R.id.action_report).setVisible(false); + stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); + }else { + popup.getMenu().findItem(R.id.action_remove).setVisible(false); + stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm); + } + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + public boolean onMenuItemClick(MenuItem item) { + AlertDialog.Builder builderInner; + final API.StatusAction doAction; + switch (item.getItemId()) { + case R.id.action_remove: + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(stringArrayConf[0]); + doAction = API.StatusAction.UNSTATUS; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + //noinspection deprecation + builderInner.setMessage(Html.fromHtml(status.getContent())); + break; + case R.id.action_mute: + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(stringArrayConf[0]); + doAction = API.StatusAction.MUTE; + break; + case R.id.action_block: + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(stringArrayConf[1]); + doAction = API.StatusAction.BLOCK; + break; + case R.id.action_report: + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(stringArrayConf[2]); + doAction = API.StatusAction.REPORT; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + //noinspection deprecation + builderInner.setMessage(Html.fromHtml(status.getContent())); + break; + case R.id.action_copy: + ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + 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(); + ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content); + clipboard.setPrimaryClip(clip); + Toast.makeText(context,R.string.clipboard,Toast.LENGTH_LONG).show(); + return true; + case R.id.action_share: + Intent sendIntent = new Intent(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); + sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl()); + sendIntent.setType("text/plain"); + context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); + return true; + case R.id.action_mention: + status.setTakingScreenShot(true); + statusListAdapter.notifyDataSetChanged(); + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + + @Override + public void run() { + Bitmap bitmap = Helper.convertTootIntoBitmap(context, finalConvertView); + status.setTakingScreenShot(false); + statusListAdapter.notifyDataSetChanged(); + Intent intent = new Intent(context, TootActivity.class); + Bundle b = new Bundle(); + String fname = "tootmention_" + status.getId() +".jpg"; + File file = new File (context.getCacheDir() + "/", fname); + if (file.exists ()) //noinspection ResultOfMethodCallIgnored + file.delete (); + try { + FileOutputStream out = new FileOutputStream(file); + bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); + out.flush(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + b.putString("fileMention", fname); + b.putString("tootMention", (status.getReblog() != null)?status.getReblog().getAccount().getAcct():status.getAccount().getAcct()); + b.putString("urlMention", (status.getReblog() != null)?status.getReblog().getUrl():status.getUrl()); + intent.putExtras(b); + context.startActivity(intent); } - b.putString("fileMention", fname); - b.putString("tootMention", (status.getReblog() != null)?status.getReblog().getAccount().getAcct():status.getAccount().getAcct()); - b.putString("urlMention", (status.getReblog() != null)?status.getReblog().getUrl():status.getUrl()); - intent.putExtras(b); - context.startActivity(intent); - } - }, 1000); - return true; - default: - return true; - } - - //Text for report - EditText input = null; - if( doAction == API.StatusAction.REPORT){ - input = new EditText(context); - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT); - input.setLayoutParams(lp); - builderInner.setView(input); - } - builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog,int which) { - dialog.dismiss(); + }, 1000); + return true; + default: + return true; } - }); - final EditText finalInput = input; - builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog,int which) { - if(doAction == API.StatusAction.UNSTATUS ){ - String targetedId = status.getId(); - new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - }else if(doAction == API.StatusAction.REPORT ){ - String comment = null; - if( finalInput.getText() != null) - comment = finalInput.getText().toString(); - new PostActionAsyncTask(context, doAction, status.getId(), status, comment, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - }else{ - String targetedId = status.getAccount().getId(); - new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + //Text for report + EditText input = null; + if( doAction == API.StatusAction.REPORT){ + input = new EditText(context); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + input.setLayoutParams(lp); + builderInner.setView(input); + } + builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog,int which) { + dialog.dismiss(); } - dialog.dismiss(); - } - }); - builderInner.show(); + }); + final EditText finalInput = input; + builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog,int which) { + if(doAction == API.StatusAction.UNSTATUS ){ + String targetedId = status.getId(); + new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }else if(doAction == API.StatusAction.REPORT ){ + String comment = null; + if( finalInput.getText() != null) + comment = finalInput.getText().toString(); + new PostActionAsyncTask(context, doAction, status.getId(), status, comment, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }else{ + String targetedId = status.getAccount().getId(); + new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + dialog.dismiss(); + } + }); + builderInner.show(); return true; } - }); - popup.show(); - } - }); - - - holder.status_account_profile.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - if( targetedId == null || !targetedId.equals(status.getAccount().getId())){ - Intent intent = new Intent(context, ShowAccountActivity.class); - Bundle b = new Bundle(); - b.putString("accountId", status.getAccount().getId()); - intent.putExtras(b); - context.startActivity(intent); + }); + popup.show(); } - } - }); + }); - holder.status_account_profile_boost.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if( targetedId == null || !targetedId.equals(status.getReblog().getAccount().getId())){ - Intent intent = new Intent(context, ShowAccountActivity.class); - Bundle b = new Bundle(); - b.putString("accountId", status.getReblog().getAccount().getId()); - intent.putExtras(b); - context.startActivity(intent); + + holder.status_account_profile.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + if( targetedId == null || !targetedId.equals(status.getAccount().getId())){ + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putString("accountId", status.getAccount().getId()); + intent.putExtras(b); + context.startActivity(intent); + } } - } - }); - //Profile picture - return convertView; + }); + + holder.status_account_profile_boost.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if( targetedId == null || !targetedId.equals(status.getReblog().getAccount().getId())){ + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putString("accountId", status.getReblog().getAccount().getId()); + intent.putExtras(b); + context.startActivity(intent); + } + } + }); + return convertView; + } + } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index 7c56fa6f2..215db5a59 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -370,6 +370,17 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn } } + /** + * Refresh status in list + */ + public void refreshFilter(){ + int index = lv_status.getFirstVisiblePosition() + 1; + View v = lv_status.getChildAt(0); + int top = (v == null) ? 0 : v.getTop(); + statusListAdapter.notifyDataSetChanged(); + lv_status.setSelectionFromTop(index, top); + } + @Override public void onResume(){ super.onResume(); 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 305827a0b..96b4307ca 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 @@ -209,6 +209,9 @@ public class Helper { public static final String SET_PREVIEW_REPLIES_PP = "set_preview_replies_pp"; public static final String SET_TRANSLATOR = "set_translator"; public static final String SET_LED_COLOUR = "set_led_colour"; + public static final String SET_SHOW_BOOSTS = "set_show_boost"; + public static final String SET_SHOW_REPLIES = "set_show_replies"; + public static final int ATTACHMENT_ALWAYS = 1; public static final int ATTACHMENT_WIFI = 2; diff --git a/app/src/main/res/menu/option_filter_toots.xml b/app/src/main/res/menu/option_filter_toots.xml new file mode 100644 index 000000000..d5b4edd78 --- /dev/null +++ b/app/src/main/res/menu/option_filter_toots.xml @@ -0,0 +1,18 @@ + +

+ + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index a6fa51615..b0e124653 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -63,6 +63,9 @@ Neue Folgende Erwähnungen Geteilte Beiträge + Geteilte Beiträge anzeigen + Antworten anzeigen + Home Lokale Zeitleiste diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index e9731e752..d6c748493 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -64,7 +64,8 @@ Nouveaux⋅elles abonn⋅é⋅s Mentions Partages - + Afficher les partages + Afficher les réponses Accueil Fil public local diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 30a6d7e9a..1042c28fb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -64,7 +64,8 @@ New followers Mentions Boosts - + Show boosts + Show replies Home Local timeline diff --git a/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java b/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java index 67434af0a..db2441c01 100644 --- a/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java +++ b/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java @@ -144,7 +144,7 @@ public class MainActivity extends AppCompatActivity private String userIdService; private Intent streamingIntent; public static String lastHomeId = null, lastNotificationId = null; - boolean notif_follow, notif_add, notif_mention, notif_share; + boolean notif_follow, notif_add, notif_mention, notif_share, show_boosts, show_replies; public MainActivity() { } @@ -318,6 +318,70 @@ public class MainActivity extends AppCompatActivity } }); + + tabStrip.getChildAt(0).setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + //Only shown if the tab has focus + if( homeFragment != null && homeFragment.getUserVisibleHint()){ + PopupMenu popup = new PopupMenu(MainActivity.this, tabStrip.getChildAt(0)); + popup.getMenuInflater() + .inflate(R.menu.option_filter_toots, popup.getMenu()); + Menu menu = popup.getMenu(); + final MenuItem itemShowBoosts = menu.findItem(R.id.action_show_boosts); + final MenuItem itemShowReplies = menu.findItem(R.id.action_show_replies); + + show_boosts = sharedpreferences.getBoolean(Helper.SET_SHOW_BOOSTS, true); + show_replies = sharedpreferences.getBoolean(Helper.SET_SHOW_REPLIES, true); + itemShowBoosts.setChecked(show_boosts); + itemShowReplies.setChecked(show_replies); + popup.setOnDismissListener(new PopupMenu.OnDismissListener() { + @Override + public void onDismiss(PopupMenu menu) { + if( homeFragment != null) + homeFragment.refreshFilter(); + } + }); + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + public boolean onMenuItemClick(MenuItem item) { + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); + item.setActionView(new View(getApplicationContext())); + item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + return false; + } + + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { + return false; + } + }); + switch (item.getItemId()) { + case R.id.action_show_boosts: + SharedPreferences.Editor editor = sharedpreferences.edit(); + show_boosts = !show_boosts; + editor.putBoolean(Helper.SET_SHOW_BOOSTS, show_boosts); + itemShowBoosts.setChecked(show_boosts); + editor.apply(); + break; + case R.id.action_show_replies: + editor = sharedpreferences.edit(); + show_replies = !show_replies; + editor.putBoolean(Helper.SET_SHOW_REPLIES, show_replies); + itemShowReplies.setChecked(show_replies); + editor.apply(); + break; + } + return false; + } + }); + popup.show(); + } + return true; + } + }); + viewPager = (ViewPager) findViewById(R.id.viewpager); int countPage = 2; if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true))