Almost there

This commit is contained in:
LucasGGamerM 2022-12-09 12:25:17 -03:00
parent 0ef0aa1a44
commit fc845685cc
7 changed files with 93 additions and 19 deletions

View File

@ -457,6 +457,21 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
Status status=holder.getItem().status; Status status=holder.getItem().status;
revealSpoiler(status, holder.getItemID()); 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){ protected void revealSpoiler(Status status, String itemID){
status.spoilerRevealed=true; status.spoilerRevealed=true;

View File

@ -40,6 +40,7 @@ public class Status extends BaseModel implements DisplayItemsParent{
public long favouritesCount; public long favouritesCount;
public long repliesCount; public long repliesCount;
public Instant editedAt; public Instant editedAt;
public boolean wantsTranslation;
public String url; public String url;
public String inReplyToId; public String inReplyToId;

View File

@ -109,7 +109,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
public static class Holder extends StatusDisplayItem.Holder<HeaderStatusDisplayItem> implements ImageLoaderViewHolder{ public static class Holder extends StatusDisplayItem.Holder<HeaderStatusDisplayItem> implements ImageLoaderViewHolder{
private final TextView name, username, timestamp, extraText; 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 final PopupMenu optionsMenu;
private Relationship relationship; private Relationship relationship;
private APIRequest<?> currentRelationshipRequest; private APIRequest<?> currentRelationshipRequest;
@ -123,6 +123,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
public Holder(Activity activity, ViewGroup parent){ public Holder(Activity activity, ViewGroup parent){
super(activity, R.layout.display_item_header, parent); super(activity, R.layout.display_item_header, parent);
translate=findViewById(R.id.translate);
name=findViewById(R.id.name); name=findViewById(R.id.name);
username=findViewById(R.id.username); username=findViewById(R.id.username);
timestamp=findViewById(R.id.timestamp); timestamp=findViewById(R.id.timestamp);
@ -135,6 +136,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
avatar.setClipToOutline(true); avatar.setClipToOutline(true);
more.setOnClickListener(this::onMoreClick); more.setOnClickListener(this::onMoreClick);
visibility.setOnClickListener(v->item.parentFragment.onVisibilityIconClick(this)); visibility.setOnClickListener(v->item.parentFragment.onVisibilityIconClick(this));
translate.setOnClickListener(v->item.parentFragment.onRevealTranslationClick(this));
optionsMenu=new PopupMenu(activity, more); optionsMenu=new PopupMenu(activity, more);
optionsMenu.inflate(R.menu.post); 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, ()->{}); UiUtils.confirmToggleBlockDomain(activity, item.parentFragment.getAccountID(), account.getDomain(), relationship!=null && relationship.domainBlocking, ()->{});
}else if(id==R.id.bookmark){ }else if(id==R.id.bookmark){
AccountSessionManager.getInstance().getAccount(item.accountID).getStatusInteractionController().setBookmarked(item.status, !item.status.bookmarked); 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<StatusTranslation>(){
@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<StatusTranslation>(){
// @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; return true;
}); });
} }

View File

@ -8,17 +8,22 @@ import android.text.TextUtils;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import org.joinmastodon.android.R; import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.statuses.GetStatusTranslation;
import org.joinmastodon.android.fragments.BaseStatusListFragment; import org.joinmastodon.android.fragments.BaseStatusListFragment;
import org.joinmastodon.android.model.Status; import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.model.StatusTranslation;
import org.joinmastodon.android.ui.drawables.SpoilerStripesDrawable; import org.joinmastodon.android.ui.drawables.SpoilerStripesDrawable;
import org.joinmastodon.android.ui.text.HtmlParser; import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.utils.CustomEmojiHelper; import org.joinmastodon.android.ui.utils.CustomEmojiHelper;
import org.joinmastodon.android.ui.views.LinkedTextView; 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.ImageLoaderViewHolder;
import me.grishka.appkit.imageloader.MovieDrawable; import me.grishka.appkit.imageloader.MovieDrawable;
import me.grishka.appkit.imageloader.requests.ImageLoaderRequest; import me.grishka.appkit.imageloader.requests.ImageLoaderRequest;
@ -35,6 +40,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
super(parentID, parentFragment); super(parentID, parentFragment);
this.text=text; this.text=text;
this.status=status; this.status=status;
// this.wantsTranslation=wantsTranslation;
emojiHelper.setText(text); emojiHelper.setText(text);
if(!TextUtils.isEmpty(status.spoilerText)){ if(!TextUtils.isEmpty(status.spoilerText)){
parsedSpoilerText=HtmlParser.parseCustomEmoji(status.spoilerText, status.emojis); parsedSpoilerText=HtmlParser.parseCustomEmoji(status.spoilerText, status.emojis);
@ -68,6 +74,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
private final TextView spoilerTitle, spoilerTitleInline; private final TextView spoilerTitle, spoilerTitleInline;
private final View spoilerOverlay, borderTop, borderBottom; private final View spoilerOverlay, borderTop, borderBottom;
private final Drawable backgroundColor, borderColor; private final Drawable backgroundColor, borderColor;
private final Button translateToggle;
public Holder(Activity activity, ViewGroup parent){ public Holder(Activity activity, ViewGroup parent){
super(activity, R.layout.display_item_text, parent); super(activity, R.layout.display_item_text, parent);
@ -77,6 +84,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
spoilerHeader=findViewById(R.id.spoiler_header); spoilerHeader=findViewById(R.id.spoiler_header);
spoilerOverlay=findViewById(R.id.spoiler_overlay); spoilerOverlay=findViewById(R.id.spoiler_overlay);
borderTop=findViewById(R.id.border_top); borderTop=findViewById(R.id.border_top);
translateToggle=findViewById(R.id.translate);
borderBottom=findViewById(R.id.border_bottom); borderBottom=findViewById(R.id.border_bottom);
itemView.setOnClickListener(v->item.parentFragment.onRevealSpoilerClick(this)); itemView.setOnClickListener(v->item.parentFragment.onRevealSpoilerClick(this));
@ -91,7 +99,24 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
@Override @Override
public void onBind(TextStatusDisplayItem item){ public void onBind(TextStatusDisplayItem item){
text.setText(item.text); if(item.status.wantsTranslation){
new GetStatusTranslation(item.status.id)
.setCallback(new Callback<StatusTranslation>(){
@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); text.setTextIsSelectable(item.textSelectable);
spoilerTitleInline.setTextIsSelectable(item.textSelectable); spoilerTitleInline.setTextIsSelectable(item.textSelectable);
text.setInvalidateOnEveryFrame(false); text.setInvalidateOnEveryFrame(false);

View File

@ -33,6 +33,18 @@
android:src="@drawable/ic_visibility" android:src="@drawable/ic_visibility"
android:tint="?android:textColorSecondary" /> android:tint="?android:textColorSecondary" />
<ImageView
android:id="@+id/translate"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginTop="-6dp"
android:layout_marginRight="6dp"
android:layout_toLeftOf="@id/visibility"
android:background="?android:selectableItemBackgroundBorderless"
android:scaleType="center"
android:src="@drawable/ic_visibility"
android:tint="?android:textColorSecondary" />
<ImageView <ImageView
android:id="@+id/avatar" android:id="@+id/avatar"
android:layout_width="46dp" android:layout_width="46dp"

View File

@ -31,9 +31,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_medium" android:textAppearance="@style/m3_title_medium"
android:background="?colorBackgroundLight" android:background="@color/error_900"
tools:text="CW title"/> tools:text="CW title"/>
<View <View
android:id="@+id/border_bottom" android:id="@+id/border_bottom"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -49,6 +50,22 @@
android:textSize="16sp" android:textSize="16sp"
android:textAppearance="@style/m3_body_large" android:textAppearance="@style/m3_body_large"
tools:text="setting up my mstdn"/> tools:text="setting up my mstdn"/>
<!-- <Button-->
<!-- android:id="@+id/translate"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="32dp"-->
<!-- android:background="@drawable/bg_inline_button"-->
<!-- android:elevation="0dp"-->
<!-- android:ellipsize="middle"-->
<!-- android:fontFamily="sans-serif-medium"-->
<!-- android:singleLine="true"-->
<!-- android:stateListAnimator="@null"-->
<!-- android:textColor="?android:textColorPrimary"-->
<!-- android:textSize="16sp"-->
<!-- tools:text="@string/pink_color" />-->
</LinearLayout> </LinearLayout>

View File

@ -5,7 +5,6 @@
<item android:id="@+id/delete_and_redraft" android:title="@string/delete_and_redraft"/> <item android:id="@+id/delete_and_redraft" android:title="@string/delete_and_redraft"/>
<item android:id="@+id/pin" android:title="@string/pin_post"/> <item android:id="@+id/pin" android:title="@string/pin_post"/>
<item android:id="@+id/unpin" android:title="@string/unpin_post"/> <item android:id="@+id/unpin" android:title="@string/unpin_post"/>
<item android:id="@+id/translate" android:title="@string/translate"/>
<item android:id="@+id/mute" android:title="@string/mute_user"/> <item android:id="@+id/mute" android:title="@string/mute_user"/>
<item android:id="@+id/block" android:title="@string/block_user"/> <item android:id="@+id/block" android:title="@string/block_user"/>
<item android:id="@+id/block_domain" android:title="@string/block_domain"/> <item android:id="@+id/block_domain" android:title="@string/block_domain"/>