diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index add235384..d4416c54a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -457,6 +457,21 @@ public abstract class BaseStatusListFragment exten Status status=holder.getItem().status; revealSpoiler(status, holder.getItemID()); } + public void onRevealTranslationClick(HeaderStatusDisplayItem.Holder holder){ + Status status=holder.getItem().status; + revealTranslation(status, holder.getItemID()); + } + + protected void revealTranslation(Status status, String itemID){ + status.wantsTranslation=true; + TextStatusDisplayItem.Holder text=findHolderOfType(itemID, TextStatusDisplayItem.Holder.class); + if(text!=null) + adapter.notifyItemChanged(text.getAbsoluteAdapterPosition()-getMainAdapterOffset()); + HeaderStatusDisplayItem.Holder header=findHolderOfType(itemID, HeaderStatusDisplayItem.Holder.class); + if(header!=null) + header.rebind(); + updateImagesSpoilerState(status, itemID); + } protected void revealSpoiler(Status status, String itemID){ status.spoilerRevealed=true; diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Status.java b/mastodon/src/main/java/org/joinmastodon/android/model/Status.java index 31295c3d6..acf10e8c1 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Status.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Status.java @@ -40,6 +40,7 @@ public class Status extends BaseModel implements DisplayItemsParent{ public long favouritesCount; public long repliesCount; public Instant editedAt; + public boolean wantsTranslation; public String url; public String inReplyToId; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java index 0637a66a8..5007e25dc 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java @@ -109,7 +109,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ public static class Holder extends StatusDisplayItem.Holder implements ImageLoaderViewHolder{ private final TextView name, username, timestamp, extraText; - private final ImageView avatar, more, visibility; + private final ImageView avatar, more, visibility, translate; private final PopupMenu optionsMenu; private Relationship relationship; private APIRequest currentRelationshipRequest; @@ -123,6 +123,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ public Holder(Activity activity, ViewGroup parent){ super(activity, R.layout.display_item_header, parent); + translate=findViewById(R.id.translate); name=findViewById(R.id.name); username=findViewById(R.id.username); timestamp=findViewById(R.id.timestamp); @@ -135,6 +136,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ avatar.setClipToOutline(true); more.setOnClickListener(this::onMoreClick); visibility.setOnClickListener(v->item.parentFragment.onVisibilityIconClick(this)); + translate.setOnClickListener(v->item.parentFragment.onRevealTranslationClick(this)); optionsMenu=new PopupMenu(activity, more); optionsMenu.inflate(R.menu.post); @@ -214,22 +216,25 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ UiUtils.confirmToggleBlockDomain(activity, item.parentFragment.getAccountID(), account.getDomain(), relationship!=null && relationship.domainBlocking, ()->{}); }else if(id==R.id.bookmark){ AccountSessionManager.getInstance().getAccount(item.accountID).getStatusInteractionController().setBookmarked(item.status, !item.status.bookmarked); - }else if(id==R.id.translate){ - new GetStatusTranslation(item.status.id) - .setCallback(new Callback(){ - @Override - public void onSuccess(StatusTranslation status){ - System.out.println(status.getStrippedText()); - } - @Override - public void onError(ErrorResponse error){ - error.showToast(item.parentFragment.getActivity()); - } - - }) - .wrapProgress(item.parentFragment.getActivity(), R.string.loading, true) - .exec(item.parentFragment.getAccountID()); } +// else if(id==R.id.translate){ +// item.status.wantsTranslation = !item.status.wantsTranslation; + +// new GetStatusTranslation(item.status.id) +// .setCallback(new Callback(){ +// @Override +// public void onSuccess(StatusTranslation status){ +// System.out.println(status.getStrippedText()); +// } +// @Override +// public void onError(ErrorResponse error){ +// error.showToast(item.parentFragment.getActivity()); +// } +// +// }) +// .wrapProgress(item.parentFragment.getActivity(), R.string.loading, true) +// .exec(item.parentFragment.getAccountID()); +// } return true; }); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java index 1d34479e0..274b80511 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java @@ -8,17 +8,22 @@ import android.text.TextUtils; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; import org.joinmastodon.android.R; +import org.joinmastodon.android.api.requests.statuses.GetStatusTranslation; import org.joinmastodon.android.fragments.BaseStatusListFragment; import org.joinmastodon.android.model.Status; +import org.joinmastodon.android.model.StatusTranslation; import org.joinmastodon.android.ui.drawables.SpoilerStripesDrawable; import org.joinmastodon.android.ui.text.HtmlParser; import org.joinmastodon.android.ui.utils.CustomEmojiHelper; import org.joinmastodon.android.ui.views.LinkedTextView; +import me.grishka.appkit.api.Callback; +import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.imageloader.ImageLoaderViewHolder; import me.grishka.appkit.imageloader.MovieDrawable; import me.grishka.appkit.imageloader.requests.ImageLoaderRequest; @@ -35,6 +40,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{ super(parentID, parentFragment); this.text=text; this.status=status; +// this.wantsTranslation=wantsTranslation; emojiHelper.setText(text); if(!TextUtils.isEmpty(status.spoilerText)){ parsedSpoilerText=HtmlParser.parseCustomEmoji(status.spoilerText, status.emojis); @@ -68,6 +74,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{ private final TextView spoilerTitle, spoilerTitleInline; private final View spoilerOverlay, borderTop, borderBottom; private final Drawable backgroundColor, borderColor; + private final Button translateToggle; public Holder(Activity activity, ViewGroup parent){ super(activity, R.layout.display_item_text, parent); @@ -77,6 +84,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{ spoilerHeader=findViewById(R.id.spoiler_header); spoilerOverlay=findViewById(R.id.spoiler_overlay); borderTop=findViewById(R.id.border_top); + translateToggle=findViewById(R.id.translate); borderBottom=findViewById(R.id.border_bottom); itemView.setOnClickListener(v->item.parentFragment.onRevealSpoilerClick(this)); @@ -91,7 +99,24 @@ public class TextStatusDisplayItem extends StatusDisplayItem{ @Override public void onBind(TextStatusDisplayItem item){ - text.setText(item.text); + if(item.status.wantsTranslation){ + new GetStatusTranslation(item.status.id) + .setCallback(new Callback(){ + @Override + public void onSuccess(StatusTranslation status){ + text.setText(status.getStrippedText()); + } + @Override + public void onError(ErrorResponse error){ + error.showToast(item.parentFragment.getActivity()); + } + + }) + .wrapProgress(item.parentFragment.getActivity(), R.string.loading, true) + .exec(item.parentFragment.getAccountID()); + }else{ + text.setText(item.text); + } text.setTextIsSelectable(item.textSelectable); spoilerTitleInline.setTextIsSelectable(item.textSelectable); text.setInvalidateOnEveryFrame(false); diff --git a/mastodon/src/main/res/layout/display_item_header.xml b/mastodon/src/main/res/layout/display_item_header.xml index 9529d4c7b..ddc6f8cbd 100644 --- a/mastodon/src/main/res/layout/display_item_header.xml +++ b/mastodon/src/main/res/layout/display_item_header.xml @@ -33,6 +33,18 @@ android:src="@drawable/ic_visibility" android:tint="?android:textColorSecondary" /> + + + + + + + + + + + + + + + + + + + diff --git a/mastodon/src/main/res/menu/post.xml b/mastodon/src/main/res/menu/post.xml index 9bbcab8a2..b1df8f168 100644 --- a/mastodon/src/main/res/menu/post.xml +++ b/mastodon/src/main/res/menu/post.xml @@ -5,7 +5,6 @@ -