From 2175c17ce6065de73754d1696005aa88af4cb434 Mon Sep 17 00:00:00 2001
From: tom79
","");
- 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("
","");
+ 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 @@
+
+