add progress spinner

This commit is contained in:
sk
2022-12-09 03:05:17 +01:00
parent dee21222a7
commit d1479f142b
2 changed files with 32 additions and 8 deletions

View File

@@ -78,7 +78,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
public static class Holder extends StatusDisplayItem.Holder<TextStatusDisplayItem> implements ImageLoaderViewHolder{ public static class Holder extends StatusDisplayItem.Holder<TextStatusDisplayItem> implements ImageLoaderViewHolder{
private final LinkedTextView text; private final LinkedTextView text;
private final TextView spoilerTitle, translateInfo; private final TextView spoilerTitle, translateInfo;
private final View spoilerOverlay, textWrap, translateWrap; private final View spoilerOverlay, textWrap, translateWrap, translateProgress;
private final Button translateButton; private final Button translateButton;
public Holder(Activity activity, ViewGroup parent){ public Holder(Activity activity, ViewGroup parent){
@@ -90,6 +90,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
translateWrap=findViewById(R.id.translate_wrap); translateWrap=findViewById(R.id.translate_wrap);
translateButton=findViewById(R.id.translate_btn); translateButton=findViewById(R.id.translate_btn);
translateInfo=findViewById(R.id.translate_info); translateInfo=findViewById(R.id.translate_info);
translateProgress=findViewById(R.id.translate_progress);
itemView.setOnClickListener(v->item.parentFragment.onRevealSpoilerClick(this)); itemView.setOnClickListener(v->item.parentFragment.onRevealSpoilerClick(this));
} }
@@ -126,16 +127,22 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
translateInfo.setText(item.translated ? itemView.getResources().getString(R.string.translated_using, item.translation.provider) : ""); translateInfo.setText(item.translated ? itemView.getResources().getString(R.string.translated_using, item.translation.provider) : "");
translateButton.setOnClickListener(v->{ translateButton.setOnClickListener(v->{
if (item.translation == null) { if (item.translation == null) {
translateProgress.setVisibility(View.VISIBLE);
translateButton.setClickable(false);
new TranslateStatus(item.status.id).setCallback(new Callback<>() { new TranslateStatus(item.status.id).setCallback(new Callback<>() {
@Override @Override
public void onSuccess(TranslatedStatus translatedStatus) { public void onSuccess(TranslatedStatus translatedStatus) {
item.translation = translatedStatus; item.translation = translatedStatus;
item.translated = true; item.translated = true;
translateProgress.setVisibility(View.GONE);
translateButton.setClickable(true);
rebind(); rebind();
} }
@Override @Override
public void onError(ErrorResponse error) { public void onError(ErrorResponse error) {
translateProgress.setVisibility(View.GONE);
translateButton.setClickable(true);
error.showToast(itemView.getContext()); error.showToast(itemView.getContext());
} }
}).exec(item.parentFragment.getAccountID()); }).exec(item.parentFragment.getAccountID());

View File

@@ -27,16 +27,33 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:gravity="center_vertical"> android:gravity="center_vertical">
<Button <FrameLayout
style="?secondaryButtonStyle" android:id="@+id/action_btn_wrap"
android:background="?android:selectableItemBackground"
android:textColor="?android:textColorSecondary"
android:id="@+id/translate_btn"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp" android:layout_marginHorizontal="8dp"
android:paddingHorizontal="8dp" android:clipToPadding="false">
android:text="Translate"/> <org.joinmastodon.android.ui.views.ProgressBarButton
android:id="@+id/translate_btn"
style="?secondaryButtonStyle"
android:background="?android:selectableItemBackground"
android:textColor="?android:textColorSecondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="8dp"
tools:text="@string/translate_post"/>
<ProgressBar
android:id="@+id/translate_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"
style="?android:progressBarStyleSmall"
android:elevation="10dp"
android:outlineProvider="none"
android:indeterminateTint="?android:textColorPrimary"
android:visibility="gone"/>
</FrameLayout>
<TextView <TextView
android:id="@+id/translate_info" android:id="@+id/translate_info"