Option "Show media posts with missing alt text"
This commit is contained in:
@@ -11,7 +11,6 @@ import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.joinmastodon.android.model.ContentType;
|
||||
import org.joinmastodon.android.model.TimelineDefinition;
|
||||
import org.joinmastodon.android.ui.utils.ColorPalette;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
@@ -43,6 +42,7 @@ public class GlobalUserPreferences{
|
||||
public static boolean disableAltTextReminder;
|
||||
public static boolean showAltIndicator;
|
||||
public static boolean showNoAltIndicator;
|
||||
public static boolean showPostsWithoutAlt;
|
||||
public static boolean enablePreReleases;
|
||||
public static PrefixRepliesMode prefixReplies;
|
||||
public static boolean bottomEncoding;
|
||||
@@ -129,6 +129,7 @@ public class GlobalUserPreferences{
|
||||
disableAltTextReminder=prefs.getBoolean("disableAltTextReminder", false);
|
||||
showAltIndicator=prefs.getBoolean("showAltIndicator", true);
|
||||
showNoAltIndicator=prefs.getBoolean("showNoAltIndicator", true);
|
||||
showPostsWithoutAlt =prefs.getBoolean("showPostsWithoutAlt", true);
|
||||
enablePreReleases=prefs.getBoolean("enablePreReleases", false);
|
||||
prefixReplies=PrefixRepliesMode.valueOf(prefs.getString("prefixReplies", PrefixRepliesMode.NEVER.name()));
|
||||
bottomEncoding=prefs.getBoolean("bottomEncoding", false);
|
||||
@@ -205,6 +206,7 @@ public class GlobalUserPreferences{
|
||||
.putBoolean("disableAltTextReminder", disableAltTextReminder)
|
||||
.putBoolean("showAltIndicator", showAltIndicator)
|
||||
.putBoolean("showNoAltIndicator", showNoAltIndicator)
|
||||
.putBoolean("showPostsWithoutAlt", showPostsWithoutAlt)
|
||||
.putBoolean("enablePreReleases", enablePreReleases)
|
||||
.putString("prefixReplies", prefixReplies.name())
|
||||
.putBoolean("collapseLongPosts", collapseLongPosts)
|
||||
|
||||
@@ -296,6 +296,10 @@ public class SettingsFragment extends MastodonToolbarFragment implements Provide
|
||||
GlobalUserPreferences.showNoAltIndicator=i.checked;
|
||||
GlobalUserPreferences.save();
|
||||
}));
|
||||
items.add(new SwitchItem(R.string.sk_settings_show_posts_without_alt, R.drawable.ic_fluent_eye_tracking_on_24_regular, GlobalUserPreferences.showPostsWithoutAlt, i->{
|
||||
GlobalUserPreferences.showPostsWithoutAlt =i.checked;
|
||||
GlobalUserPreferences.save();
|
||||
}));
|
||||
items.add(new SwitchItem(R.string.sk_settings_collapse_long_posts, R.drawable.ic_fluent_chevron_down_24_regular, GlobalUserPreferences.collapseLongPosts, i->{
|
||||
GlobalUserPreferences.collapseLongPosts=i.checked;
|
||||
GlobalUserPreferences.save();
|
||||
|
||||
@@ -64,6 +64,11 @@ public class TimeLineFragment extends SettingsBaseFragment{
|
||||
GlobalUserPreferences.save();
|
||||
needAppRestart=true;
|
||||
}));
|
||||
items.add(new SwitchItem(R.string.sk_settings_show_posts_without_alt, R.drawable.ic_fluent_eye_tracking_on_24_regular, GlobalUserPreferences.showPostsWithoutAlt, i->{
|
||||
GlobalUserPreferences.showPostsWithoutAlt =i.checked;
|
||||
GlobalUserPreferences.save();
|
||||
needAppRestart=true;
|
||||
}));
|
||||
items.add(new SwitchItem(R.string.sk_settings_collapse_long_posts, R.drawable.ic_fluent_chevron_down_24_regular, GlobalUserPreferences.collapseLongPosts, i->{
|
||||
GlobalUserPreferences.collapseLongPosts=i.checked;
|
||||
GlobalUserPreferences.save();
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.joinmastodon.android.model;
|
||||
|
||||
import org.joinmastodon.android.GlobalUserPreferences;
|
||||
import org.joinmastodon.android.R;
|
||||
import org.jsoup.internal.StringUtil;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class AltTextFilter extends Filter {
|
||||
|
||||
public AltTextFilter(FilterAction filterAction, FilterContext firstContext, FilterContext... restContexts) {
|
||||
this.filterAction = filterAction;
|
||||
isRemote = false;
|
||||
context = EnumSet.of(firstContext, restContexts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Status status) {
|
||||
return !GlobalUserPreferences.showPostsWithoutAlt && status.getContentStatus().mediaAttachments.stream().map(attachment -> attachment.description).anyMatch(StringUtil::isBlank);
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,14 @@ import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.joinmastodon.android.R;
|
||||
import org.joinmastodon.android.fragments.BaseStatusListFragment;
|
||||
import org.joinmastodon.android.model.AltTextFilter;
|
||||
import org.joinmastodon.android.model.Filter;
|
||||
import org.joinmastodon.android.model.Status;
|
||||
import org.joinmastodon.android.ui.drawables.SawtoothTearDrawable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// Mind the gap!
|
||||
@@ -55,7 +51,11 @@ public class WarningFilteredStatusDisplayItem extends StatusDisplayItem{
|
||||
@Override
|
||||
public void onBind(WarningFilteredStatusDisplayItem item) {
|
||||
filteredItems = item.filteredItems;
|
||||
text.setText(item.parentFragment.getString(R.string.sk_filtered, item.applyingFilter.title));
|
||||
if(item.applyingFilter instanceof AltTextFilter){
|
||||
text.setText(item.parentFragment.getString(R.string.sk_filtered,item.parentFragment.getString(R.string.sk_no_alt_text)));
|
||||
}else{
|
||||
text.setText(item.parentFragment.getString(R.string.sk_filtered, item.applyingFilter.title));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
package org.joinmastodon.android.utils;
|
||||
|
||||
import static org.joinmastodon.android.model.Filter.FilterAction.HIDE;
|
||||
import static org.joinmastodon.android.model.Filter.FilterAction.WARN;
|
||||
import static org.joinmastodon.android.model.Filter.FilterContext.ACCOUNT;
|
||||
import static org.joinmastodon.android.model.Filter.FilterContext.HOME;
|
||||
import static org.joinmastodon.android.model.Filter.FilterContext.NOTIFICATIONS;
|
||||
import static org.joinmastodon.android.model.Filter.FilterContext.PUBLIC;
|
||||
import static org.joinmastodon.android.model.Filter.FilterContext.THREAD;
|
||||
|
||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||
import org.joinmastodon.android.model.AltTextFilter;
|
||||
import org.joinmastodon.android.model.Filter;
|
||||
import org.joinmastodon.android.model.Status;
|
||||
|
||||
@@ -11,7 +20,11 @@ import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class StatusFilterPredicate implements Predicate<Status>{
|
||||
public class StatusFilterPredicate implements Predicate<Status> {
|
||||
|
||||
//Hide in timelines and warn in threads
|
||||
private final List<Filter> clientFilters = List.of( new AltTextFilter(HIDE, HOME, PUBLIC, ACCOUNT),
|
||||
new AltTextFilter(WARN, THREAD, NOTIFICATIONS));
|
||||
private final List<Filter> filters;
|
||||
private final Filter.FilterContext context;
|
||||
private final Filter.FilterAction action;
|
||||
@@ -19,26 +32,26 @@ public class StatusFilterPredicate implements Predicate<Status>{
|
||||
|
||||
/**
|
||||
* @param context null makes the predicate pass automatically
|
||||
* @param action defines what the predicate should check:
|
||||
* status should not be hidden or should not display with warning
|
||||
* @param action defines what the predicate should check:
|
||||
* status should not be hidden or should not display with warning
|
||||
*/
|
||||
public StatusFilterPredicate(List<Filter> filters, Filter.FilterContext context, Filter.FilterAction action){
|
||||
public StatusFilterPredicate(List<Filter> filters, Filter.FilterContext context, Filter.FilterAction action) {
|
||||
this.filters = filters;
|
||||
this.context = context;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public StatusFilterPredicate(List<Filter> filters, Filter.FilterContext context){
|
||||
this(filters, context, Filter.FilterAction.HIDE);
|
||||
public StatusFilterPredicate(List<Filter> filters, Filter.FilterContext context) {
|
||||
this(filters, context, HIDE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context null makes the predicate pass automatically
|
||||
* @param action defines what the predicate should check:
|
||||
* status should not be hidden or should not display with warning
|
||||
* @param action defines what the predicate should check:
|
||||
* status should not be hidden or should not display with warning
|
||||
*/
|
||||
public StatusFilterPredicate(String accountID, Filter.FilterContext context, Filter.FilterAction action){
|
||||
filters=AccountSessionManager.getInstance().getAccount(accountID).wordFilters.stream().filter(f->f.context.contains(context)).collect(Collectors.toList());
|
||||
public StatusFilterPredicate(String accountID, Filter.FilterContext context, Filter.FilterAction action) {
|
||||
filters = AccountSessionManager.getInstance().getAccount(accountID).wordFilters.stream().filter(f -> f.context.contains(context)).collect(Collectors.toList());
|
||||
this.context = context;
|
||||
this.action = action;
|
||||
}
|
||||
@@ -46,8 +59,8 @@ public class StatusFilterPredicate implements Predicate<Status>{
|
||||
/**
|
||||
* @param context null makes the predicate pass automatically
|
||||
*/
|
||||
public StatusFilterPredicate(String accountID, Filter.FilterContext context){
|
||||
this(accountID, context, Filter.FilterAction.HIDE);
|
||||
public StatusFilterPredicate(String accountID, Filter.FilterContext context) {
|
||||
this(accountID, context, HIDE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +70,7 @@ public class StatusFilterPredicate implements Predicate<Status>{
|
||||
* false = filter this status
|
||||
*/
|
||||
@Override
|
||||
public boolean test(Status status){
|
||||
public boolean test(Status status) {
|
||||
if (context == null) return true;
|
||||
|
||||
Stream<Filter> matchingFilters = status.filtered != null
|
||||
@@ -72,9 +85,21 @@ public class StatusFilterPredicate implements Predicate<Status>{
|
||||
// only apply filters for given context
|
||||
.filter(filter -> filter.context.contains(context))
|
||||
// treating filterAction = null (from filters list) as FilterAction.HIDE
|
||||
.filter(filter -> filter.filterAction == null ? action == Filter.FilterAction.HIDE : filter.filterAction == action)
|
||||
.filter(filter -> filter.filterAction == null ? action == HIDE : filter.filterAction == action)
|
||||
.findAny();
|
||||
|
||||
//Apply client filters if no server filter is triggered
|
||||
if (applyingFilter.isEmpty()) {
|
||||
applyingFilter = clientFilters.stream()
|
||||
// only apply filters for given context
|
||||
.filter(filter -> filter.context.contains(context))
|
||||
// treating filterAction = null (from filters list) as FilterAction.HIDE
|
||||
.filter(filter -> filter.filterAction == null ? action == HIDE : filter.filterAction == action)
|
||||
//client filter has to match the status
|
||||
.filter(filter -> filter.matches(status))
|
||||
.findAny();
|
||||
}
|
||||
|
||||
this.applyingFilter = applyingFilter.orElse(null);
|
||||
return applyingFilter.isEmpty();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user