Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit c0c276f

Browse files
committed
add indicator for missing alt texts
closes #355
1 parent d30b1f7 commit c0c276f

10 files changed

+80
-10
lines changed

mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class GlobalUserPreferences{
3333
public static boolean reduceMotion;
3434
public static boolean keepOnlyLatestNotification;
3535
public static boolean disableAltTextReminder;
36+
public static boolean showAltIndicator;
37+
public static boolean showNoAltIndicator;
3638
public static String publishButtonText;
3739
public static ThemePreference theme;
3840
public static ColorPreference color;
@@ -71,6 +73,8 @@ public static void load(){
7173
reduceMotion=prefs.getBoolean("reduceMotion", false);
7274
keepOnlyLatestNotification=prefs.getBoolean("keepOnlyLatestNotification", false);
7375
disableAltTextReminder=prefs.getBoolean("disableAltTextReminder", false);
76+
showAltIndicator =prefs.getBoolean("showAltIndicator", true);
77+
showNoAltIndicator =prefs.getBoolean("showNoAltIndicator", true);
7478
publishButtonText=prefs.getString("publishButtonText", "");
7579
theme=ThemePreference.values()[prefs.getInt("theme", 0)];
7680
recentLanguages=fromJson(prefs.getString("recentLanguages", null), recentLanguagesType, new HashMap<>());
@@ -102,6 +106,8 @@ public static void save(){
102106
.putBoolean("reduceMotion", reduceMotion)
103107
.putBoolean("keepOnlyLatestNotification", keepOnlyLatestNotification)
104108
.putBoolean("disableAltTextReminder", disableAltTextReminder)
109+
.putBoolean("showAltIndicator", showAltIndicator)
110+
.putBoolean("showNoAltIndicator", showNoAltIndicator)
105111
.putString("publishButtonText", publishButtonText)
106112
.putInt("theme", theme.ordinal())
107113
.putString("color", color.name())

mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java

+6
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ public void onCreate(Bundle savedInstanceState){
163163
GlobalUserPreferences.reduceMotion=i.checked;
164164
GlobalUserPreferences.save();
165165
}));
166+
items.add(new SwitchItem(R.string.sk_settings_show_alt_indicator, R.drawable.ic_fluent_scan_text_24_regular, GlobalUserPreferences.showAltIndicator, i->{
167+
GlobalUserPreferences.showAltIndicator=i.checked;
168+
}));
169+
items.add(new SwitchItem(R.string.sk_settings_show_no_alt_indicator, R.drawable.ic_fluent_important_24_regular, GlobalUserPreferences.showNoAltIndicator, i->{
170+
GlobalUserPreferences.showNoAltIndicator=i.checked;
171+
}));
166172

167173
items.add(new HeaderItem(R.string.settings_behavior));
168174
items.add(new SwitchItem(R.string.settings_gif, R.drawable.ic_fluent_gif_24_regular, GlobalUserPreferences.playGifs, i->{

mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PhotoStatusDisplayItem.java

+38-8
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import android.view.ViewTreeObserver;
1212
import android.widget.FrameLayout;
1313
import android.widget.ImageButton;
14+
import android.widget.ImageView;
1415
import android.widget.ScrollView;
1516
import android.widget.TextView;
1617

18+
import org.joinmastodon.android.GlobalUserPreferences;
1719
import org.joinmastodon.android.R;
1820
import org.joinmastodon.android.fragments.BaseStatusListFragment;
1921
import org.joinmastodon.android.model.Attachment;
@@ -22,6 +24,7 @@
2224

2325
import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest;
2426
import me.grishka.appkit.utils.CubicBezierInterpolator;
27+
import me.grishka.appkit.utils.V;
2528

2629
public class PhotoStatusDisplayItem extends ImageStatusDisplayItem{
2730
public PhotoStatusDisplayItem(String parentID, Status status, Attachment photo, BaseStatusListFragment parentFragment, int index, int totalPhotos, PhotoLayoutHelper.TiledLayoutResult tiledLayout, PhotoLayoutHelper.TiledLayoutResult.Tile thisTile){
@@ -37,46 +40,73 @@ public Type getType(){
3740
public static class Holder extends ImageStatusDisplayItem.Holder<PhotoStatusDisplayItem>{
3841
private final FrameLayout altTextWrapper;
3942
private final TextView altTextButton;
43+
private final ImageView noAltTextButton;
4044
private final View altTextScroller;
4145
private final ImageButton altTextClose;
4246
private final TextView altText;
4347

48+
private View altOrNoAltButton;
4449
private boolean altTextShown;
4550
private AnimatorSet currentAnim;
4651

4752
public Holder(Activity activity, ViewGroup parent){
4853
super(activity, R.layout.display_item_photo, parent);
4954
altTextWrapper=findViewById(R.id.alt_text_wrapper);
5055
altTextButton=findViewById(R.id.alt_button);
56+
noAltTextButton=findViewById(R.id.no_alt_button);
5157
altTextScroller=findViewById(R.id.alt_text_scroller);
5258
altTextClose=findViewById(R.id.alt_text_close);
5359
altText=findViewById(R.id.alt_text);
5460

5561
altTextButton.setOnClickListener(this::onShowHideClick);
62+
noAltTextButton.setOnClickListener(this::onShowHideClick);
5663
altTextClose.setOnClickListener(this::onShowHideClick);
5764
// altTextScroller.setNestedScrollingEnabled(true);
5865
}
5966

6067
@Override
6168
public void onBind(ImageStatusDisplayItem item){
6269
super.onBind(item);
70+
boolean altTextMissing = TextUtils.isEmpty(item.attachment.description);
71+
altOrNoAltButton = altTextMissing ? noAltTextButton : altTextButton;
6372
altTextShown=false;
6473
if(currentAnim!=null)
6574
currentAnim.cancel();
75+
6676
altTextScroller.setVisibility(View.GONE);
6777
altTextClose.setVisibility(View.GONE);
6878
altTextButton.setVisibility(View.VISIBLE);
79+
noAltTextButton.setVisibility(View.VISIBLE);
6980
altTextButton.setAlpha(1f);
70-
if(TextUtils.isEmpty(item.attachment.description)){
71-
altTextWrapper.setVisibility(View.GONE);
81+
noAltTextButton.setAlpha(1f);
82+
altTextWrapper.setVisibility(View.VISIBLE);
83+
84+
if (altTextMissing){
85+
if (GlobalUserPreferences.showNoAltIndicator) {
86+
noAltTextButton.setVisibility(View.VISIBLE);
87+
altTextWrapper.setBackgroundResource(R.drawable.bg_image_no_alt_overlay);
88+
altTextButton.setVisibility(View.GONE);
89+
altText.setText(R.string.sk_no_alt_text);
90+
altText.setPadding(V.dp(8), 0, 0, 0);
91+
} else {
92+
altTextWrapper.setVisibility(View.GONE);
93+
}
7294
}else{
73-
altTextWrapper.setVisibility(View.VISIBLE);
74-
altText.setText(item.attachment.description);
95+
if (GlobalUserPreferences.showAltIndicator) {
96+
noAltTextButton.setVisibility(View.GONE);
97+
altTextWrapper.setBackgroundResource(R.drawable.bg_image_alt_overlay);
98+
altTextButton.setVisibility(View.VISIBLE);
99+
altTextButton.setText(R.string.sk_alt_button);
100+
altText.setText(item.attachment.description);
101+
altText.setPadding(0, 0, 0, 0);
102+
} else {
103+
altTextWrapper.setVisibility(View.GONE);
104+
}
75105
}
76106
}
77107

78108
private void onShowHideClick(View v){
79-
boolean show=v.getId()==R.id.alt_button;
109+
boolean show=v.getId()==R.id.alt_button || v.getId()==R.id.no_alt_button;
80110

81111
if(altTextShown==show)
82112
return;
@@ -88,7 +118,7 @@ private void onShowHideClick(View v){
88118
altTextScroller.setVisibility(View.VISIBLE);
89119
altTextClose.setVisibility(View.VISIBLE);
90120
}else{
91-
altTextButton.setVisibility(View.VISIBLE);
121+
altOrNoAltButton.setVisibility(View.VISIBLE);
92122
// Hide these views temporarily so FrameLayout measures correctly
93123
altTextScroller.setVisibility(View.GONE);
94124
altTextClose.setVisibility(View.GONE);
@@ -115,7 +145,7 @@ public boolean onPreDraw(){
115145
ObjectAnimator.ofInt(altTextWrapper, "left", prevLeft, altTextWrapper.getLeft()),
116146
ObjectAnimator.ofInt(altTextWrapper, "right", prevRight, altTextWrapper.getRight()),
117147
ObjectAnimator.ofInt(altTextWrapper, "top", prevTop, altTextWrapper.getTop()),
118-
ObjectAnimator.ofFloat(altTextButton, View.ALPHA, show ? 1f : 0f, show ? 0f : 1f),
148+
ObjectAnimator.ofFloat(altOrNoAltButton, View.ALPHA, show ? 1f : 0f, show ? 0f : 1f),
119149
ObjectAnimator.ofFloat(altTextScroller, View.ALPHA, show ? 0f : 1f, show ? 1f : 0f),
120150
ObjectAnimator.ofFloat(altTextClose, View.ALPHA, show ? 0f : 1f, show ? 1f : 0f)
121151
);
@@ -125,7 +155,7 @@ public boolean onPreDraw(){
125155
@Override
126156
public void onAnimationEnd(Animator animation){
127157
if(show){
128-
altTextButton.setVisibility(View.GONE);
158+
altOrNoAltButton.setVisibility(View.GONE);
129159
}else{
130160
altTextScroller.setVisibility(View.GONE);
131161
altTextClose.setVisibility(View.GONE);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
<solid android:color="#E894000C"/>
4+
<corners android:radius="24dp"/>
5+
</shape>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="16dp" android:height="16dp" android:viewportWidth="16" android:viewportHeight="16">
2+
<path android:pathData="M5.96 4.457C5.722 3.18 6.7 2 8 2s2.279 1.18 2.04 2.457l-0.856 4.56C9.077 9.587 8.58 10 8 10S6.923 9.587 6.816 9.017L5.96 4.457zM9.5 12.5C9.5 13.328 8.828 14 8 14s-1.5-0.672-1.5-1.5S7.172 11 8 11s1.5 0.672 1.5 1.5z" android:fillColor="@color/fluent_default_icon_tint"/>
3+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="20dp" android:height="20dp" android:viewportWidth="20" android:viewportHeight="20">
2+
<path android:pathData="M10 2C8.343 2 7 3.343 7 5c0 2.227 0.789 5.204 1.225 6.685C8.459 12.48 9.19 13 10 13c0.81 0 1.54-0.518 1.775-1.31C12.212 10.213 13 7.25 13 5c0-1.657-1.343-3-3-3zm0 12c-1.105 0-2 0.895-2 2s0.895 2 2 2 2-0.895 2-2-0.895-2-2-2z" android:fillColor="@color/fluent_default_icon_tint"/>
3+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
2+
<path android:pathData="M12 2.002c-2.14 0-3.875 1.735-3.875 3.875 0 2.92 1.207 6.552 1.813 8.199 0.323 0.878 1.159 1.423 2.064 1.423 0.904 0 1.739-0.542 2.063-1.418 0.606-1.64 1.81-5.254 1.81-8.204 0-2.14-1.734-3.875-3.875-3.875zm0.001 14.999c-1.381 0-2.501 1.12-2.501 2.501 0 1.381 1.12 2.501 2.501 2.501 1.382 0 2.501-1.12 2.501-2.5 0-1.382-1.12-2.502-2.5-2.502z" android:fillColor="@color/fluent_default_icon_tint"/>
3+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
2+
<path android:pathData="M6.25 3C4.455 3 3 4.455 3 6.25v2.12c0 0.414 0.336 0.75 0.75 0.75S4.5 8.784 4.5 8.37V6.25c0-0.966 0.784-1.75 1.75-1.75h2.12c0.414 0 0.75-0.336 0.75-0.75S8.784 3 8.37 3H6.25zm9.38 1.5c-0.414 0-0.75-0.336-0.75-0.75S15.216 3 15.63 3h2.12C19.545 3 21 4.455 21 6.25v2.12c0 0.414-0.336 0.75-0.75 0.75S19.5 8.784 19.5 8.37V6.25c0-0.966-0.784-1.75-1.75-1.75h-2.12zM3 15.63c0-0.414 0.336-0.75 0.75-0.75s0.75 0.336 0.75 0.75v2.12c0 0.906 0.689 1.651 1.571 1.741C6.13 19.497 6.19 19.5 6.25 19.5h2.12c0.414 0 0.75 0.336 0.75 0.75S8.784 21 8.37 21H6.25C4.455 21 3 19.545 3 17.75v-2.12zm16.5 0c0-0.414 0.336-0.75 0.75-0.75S21 15.216 21 15.63v2.12c0 1.683-1.279 3.067-2.918 3.233C17.973 20.994 17.862 21 17.75 21h-2.12c-0.414 0-0.75-0.336-0.75-0.75s0.336-0.75 0.75-0.75h2.12c0.906 0 1.651-0.689 1.741-1.571 0.006-0.059 0.009-0.119 0.009-0.179v-2.12zM7 7.75C7 7.336 7.336 7 7.75 7h8.5C16.664 7 17 7.336 17 7.75S16.664 8.5 16.25 8.5h-8.5C7.336 8.5 7 8.164 7 7.75zM7.75 11C7.336 11 7 11.336 7 11.75s0.336 0.75 0.75 0.75h8.5c0.414 0 0.75-0.336 0.75-0.75S16.664 11 16.25 11h-8.5zM7 15.75C7 15.336 7.336 15 7.75 15h4.5c0.414 0 0.75 0.336 0.75 0.75s-0.336 0.75-0.75 0.75h-4.5C7.336 16.5 7 16.164 7 15.75z" android:fillColor="@color/fluent_default_icon_tint"/>
3+
</vector>

mastodon/src/main/res/layout/display_item_photo.xml

+10-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@
2020
android:layout_margin="12dp"
2121
android:importantForAccessibility="noHideDescendants"
2222
android:background="@drawable/bg_image_alt_overlay">
23+
24+
<ImageView
25+
android:id="@+id/no_alt_button"
26+
android:layout_width="wrap_content"
27+
android:layout_height="wrap_content"
28+
android:padding="4dp"
29+
android:src="@drawable/ic_fluent_important_20_filled"
30+
android:tint="@color/gray_25" />
2331

2432
<TextView
2533
android:id="@+id/alt_button"
2634
android:layout_width="wrap_content"
2735
android:layout_height="wrap_content"
2836
android:textAppearance="@style/m3_label_large"
29-
android:textColor="#FFF"
37+
android:textColor="@color/gray_25"
3038
android:gravity="center"
3139
android:includeFontPadding="false"
3240
android:paddingHorizontal="5dp"
@@ -40,7 +48,7 @@
4048
android:layout_gravity="end|top"
4149
android:src="@drawable/ic_baseline_close_24"
4250
android:tint="#FFF"
43-
android:background="?android:selectableItemBackgroundBorderless"/>
51+
android:background="?android:actionBarItemBackground"/>
4452

4553
<org.joinmastodon.android.ui.views.NestableScrollView
4654
android:id="@+id/alt_text_scroller"

mastodon/src/main/res/values/strings_sk.xml

+3
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,7 @@
231231
<string name="sk_no_results">No results</string>
232232
<string name="sk_save_draft">Save draft?</string>
233233
<string name="sk_save_draft_message">Do you want to save your changes to this draft or publish it now?</string>
234+
<string name="sk_no_alt_text">No alt text available</string>
235+
<string name="sk_settings_show_alt_indicator">Indicator for alt texts</string>
236+
<string name="sk_settings_show_no_alt_indicator">Indicator for missing alt texts</string>
234237
</resources>

0 commit comments

Comments
 (0)