|
|
|
|
@@ -8,6 +8,7 @@ import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.ScrollView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
@@ -50,6 +51,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
|
|
|
|
|
public boolean translated = false;
|
|
|
|
|
public TranslatedStatus translation = null;
|
|
|
|
|
private AccountSession session;
|
|
|
|
|
private boolean textIsRevealed;
|
|
|
|
|
public static final Pattern BOTTOM_TEXT_PATTERN = Pattern.compile("(?:[\uD83E\uDEC2\uD83D\uDC96✨\uD83E\uDD7A,]+|❤️)(?:\uD83D\uDC49\uD83D\uDC48(?:[\uD83E\uDEC2\uD83D\uDC96✨\uD83E\uDD7A,]+|❤️))*\uD83D\uDC49\uD83D\uDC48");
|
|
|
|
|
|
|
|
|
|
public TextStatusDisplayItem(String parentID, CharSequence text, BaseStatusListFragment parentFragment, Status status, boolean disableTranslate){
|
|
|
|
|
@@ -88,10 +90,14 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
|
|
|
|
|
public static class Holder extends StatusDisplayItem.Holder<TextStatusDisplayItem> implements ImageLoaderViewHolder{
|
|
|
|
|
private final LinkedTextView text;
|
|
|
|
|
private final LinearLayout spoilerHeader;
|
|
|
|
|
private final TextView spoilerTitle, spoilerTitleInline, translateInfo;
|
|
|
|
|
private final View spoilerOverlay, borderTop, borderBottom, textWrap, translateWrap, translateProgress;
|
|
|
|
|
private final TextView spoilerTitle, spoilerTitleInline, translateInfo, readMore;
|
|
|
|
|
private final View spoilerOverlay, borderTop, borderBottom, textWrap, translateWrap, translateProgress, spaceBelowText;
|
|
|
|
|
private final int backgroundColor, borderColor;
|
|
|
|
|
private final Button translateButton;
|
|
|
|
|
private final ScrollView textScrollView;
|
|
|
|
|
|
|
|
|
|
private final float textMaxHeight, textCollapsedHeight;
|
|
|
|
|
private final LinearLayout.LayoutParams collapseParams, wrapParams;
|
|
|
|
|
|
|
|
|
|
public Holder(Activity activity, ViewGroup parent){
|
|
|
|
|
super(activity, R.layout.display_item_text, parent);
|
|
|
|
|
@@ -110,6 +116,14 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
|
|
|
|
|
itemView.setOnClickListener(v->item.parentFragment.onRevealSpoilerClick(this));
|
|
|
|
|
backgroundColor=UiUtils.getThemeColor(activity, R.attr.colorBackgroundLight);
|
|
|
|
|
borderColor=UiUtils.getThemeColor(activity, R.attr.colorPollVoted);
|
|
|
|
|
textScrollView=findViewById(R.id.text_scroll_view);
|
|
|
|
|
readMore=findViewById(R.id.read_more);
|
|
|
|
|
spaceBelowText=findViewById(R.id.space_below_text);
|
|
|
|
|
textMaxHeight=activity.getResources().getDimension(R.dimen.text_max_height);
|
|
|
|
|
textCollapsedHeight=activity.getResources().getDimension(R.dimen.text_collapsed_height);
|
|
|
|
|
collapseParams=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) textCollapsedHeight);
|
|
|
|
|
wrapParams=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
readMore.setOnClickListener(this::onClickReadMore);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@@ -118,6 +132,9 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
|
|
|
|
|
? HtmlParser.parse(item.translation.content, item.status.emojis, item.status.mentions, item.status.tags, item.parentFragment.getAccountID())
|
|
|
|
|
: item.text);
|
|
|
|
|
text.setTextIsSelectable(item.textSelectable);
|
|
|
|
|
if (item.textSelectable) {
|
|
|
|
|
textScrollView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
|
|
|
|
|
}
|
|
|
|
|
spoilerTitleInline.setTextIsSelectable(item.textSelectable);
|
|
|
|
|
text.setInvalidateOnEveryFrame(false);
|
|
|
|
|
spoilerTitleInline.setBackgroundColor(item.inset ? 0 : backgroundColor);
|
|
|
|
|
@@ -151,14 +168,13 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
|
|
|
|
|
instanceInfo.v2.configuration.translation.enabled;
|
|
|
|
|
|
|
|
|
|
boolean isBottomText = BOTTOM_TEXT_PATTERN.matcher(item.status.getStrippedText()).find();
|
|
|
|
|
translateWrap.setVisibility((isBottomText || (
|
|
|
|
|
boolean translateVisible = (isBottomText || (
|
|
|
|
|
translateEnabled &&
|
|
|
|
|
!item.status.visibility.isLessVisibleThan(StatusPrivacy.UNLISTED) &&
|
|
|
|
|
item.status.language != null &&
|
|
|
|
|
(item.session.preferences == null || !item.status.language.equalsIgnoreCase(item.session.preferences.postingDefaultLanguage))))
|
|
|
|
|
&& (!GlobalUserPreferences.translateButtonOpenedOnly || item.textSelectable)
|
|
|
|
|
? View.VISIBLE : View.GONE
|
|
|
|
|
);
|
|
|
|
|
!item.status.visibility.isLessVisibleThan(StatusPrivacy.UNLISTED) &&
|
|
|
|
|
item.status.language != null &&
|
|
|
|
|
(item.session.preferences == null || !item.status.language.equalsIgnoreCase(item.session.preferences.postingDefaultLanguage))))
|
|
|
|
|
&& (!GlobalUserPreferences.translateButtonOpenedOnly || item.textSelectable);
|
|
|
|
|
translateWrap.setVisibility(translateVisible ? View.VISIBLE : View.GONE);
|
|
|
|
|
translateButton.setText(item.translated ? R.string.sk_translate_show_original : R.string.sk_translate_post);
|
|
|
|
|
translateInfo.setText(item.translated ? itemView.getResources().getString(R.string.sk_translated_using, isBottomText ? "bottom-java" : item.translation.provider) : "");
|
|
|
|
|
translateButton.setOnClickListener(v->{
|
|
|
|
|
@@ -203,6 +219,29 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
|
|
|
|
|
rebind();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
readMore.setText(item.textIsRevealed ? R.string.sk_collapse : R.string.sk_expand);
|
|
|
|
|
spaceBelowText.setVisibility(translateVisible ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
|
|
if (!GlobalUserPreferences.collapseLongPosts) {
|
|
|
|
|
textScrollView.setLayoutParams(wrapParams);
|
|
|
|
|
readMore.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (GlobalUserPreferences.collapseLongPosts) text.post(() -> {
|
|
|
|
|
boolean tooBig = text.getMeasuredHeight() > textMaxHeight;
|
|
|
|
|
boolean inTimeline = !item.textSelectable;
|
|
|
|
|
boolean hasSpoiler = !TextUtils.isEmpty(item.status.spoilerText);
|
|
|
|
|
boolean expandable = inTimeline && tooBig && !hasSpoiler;
|
|
|
|
|
readMore.setVisibility(expandable ? View.VISIBLE : View.GONE);
|
|
|
|
|
textScrollView.setLayoutParams(expandable && !item.textIsRevealed ? collapseParams : wrapParams);
|
|
|
|
|
if (expandable && !translateVisible) spaceBelowText.setVisibility(View.VISIBLE);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onClickReadMore(View v) {
|
|
|
|
|
item.textIsRevealed = !item.textIsRevealed;
|
|
|
|
|
rebind();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|