set content description for all avatars

This commit is contained in:
Daniel Gultsch 2020-08-31 13:05:10 +02:00
parent 3c0773c6e7
commit c48499253b
11 changed files with 55 additions and 2 deletions

View File

@ -615,6 +615,11 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
return UIHelper.getColorForName(jid.asBareJid().toString());
}
@Override
public String getAvatarName() {
throw new IllegalStateException("This method should not be called");
}
public enum State {
DISABLED(false, false),
OFFLINE(false),

View File

@ -248,4 +248,9 @@ public class Bookmark extends Element implements ListItem {
public int getAvatarBackgroundColor() {
return UIHelper.getColorForName(jid != null ? jid.asBareJid().toString() : getDisplayName());
}
@Override
public String getAvatarName() {
return getDisplayName();
}
}

View File

@ -558,6 +558,11 @@ public class Contact implements ListItem, Blockable {
return UIHelper.getColorForName(jid != null ? jid.asBareJid().toString() : getDisplayName());
}
@Override
public String getAvatarName() {
return getDisplayName();
}
public boolean hasAvatarOrPresenceName() {
return (avatar != null && avatar.getFilename() != null) || presenceName != null;
}

View File

@ -1066,6 +1066,11 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
return UIHelper.getColorForName(getName().toString());
}
@Override
public String getAvatarName() {
return getName().toString();
}
public interface OnMessageFound {
void onMessageFound(final Message message);
}

View File

@ -684,6 +684,11 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
}
}
@Override
public String getAvatarName() {
return UIHelper.getMessageDisplayName(this);
}
public boolean isOOb() {
return oob;
}

View File

@ -900,5 +900,10 @@ public class MucOptions {
final String seed = realJid != null ? realJid.asBareJid().toString() : null;
return UIHelper.getColorForName(seed == null ? getName() : seed);
}
@Override
public String getAvatarName() {
return getConversation().getName().toString();
}
}
}

View File

@ -79,6 +79,11 @@ public class RawBlockable implements ListItem, Blockable {
return UIHelper.getColorForName(jid.toEscapedString());
}
@Override
public String getAvatarName() {
return getDisplayName();
}
@Override
public int compareTo(ListItem o) {
return this.getDisplayName().compareToIgnoreCase(

View File

@ -55,6 +55,11 @@ public class Room implements AvatarService.Avatarable, Comparable<Room> {
return UIHelper.getColorForName(room != null ? room.asBareJid().toEscapedString() : name);
}
@Override
public String getAvatarName() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -685,5 +685,6 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
public interface Avatarable {
@ColorInt int getAvatarBackgroundColor();
String getAvatarName();
}
}

View File

@ -1,5 +1,6 @@
package eu.siacs.conversations.ui.util;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
@ -11,11 +12,10 @@ import android.widget.ImageView;
import java.lang.ref.WeakReference;
import java.util.concurrent.RejectedExecutionException;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.AvatarService;
import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.ui.adapter.AccountAdapter;
import eu.siacs.conversations.utils.UIHelper;
public class AvatarWorkerTask extends AsyncTask<AvatarService.Avatarable, Void, Bitmap> {
private final WeakReference<ImageView> imageViewReference;
@ -80,6 +80,7 @@ public class AvatarWorkerTask extends AsyncTask<AvatarService.Avatarable, Void,
return;
}
final Bitmap bm = activity.avatarService().get(avatarable, (int) activity.getResources().getDimension(size), true);
setContentDescription(avatarable, imageView);
if (bm != null) {
cancelPotentialWork(avatarable, imageView);
imageView.setImageBitmap(bm);
@ -98,6 +99,15 @@ public class AvatarWorkerTask extends AsyncTask<AvatarService.Avatarable, Void,
}
}
private static void setContentDescription(final AvatarService.Avatarable avatarable, final ImageView imageView) {
final Context context = imageView.getContext();
if (avatarable instanceof Account) {
imageView.setContentDescription(context.getString(R.string.your_avatar));
} else {
imageView.setContentDescription(context.getString(R.string.avatar_for_x, avatarable.getAvatarName()));
}
}
static class AsyncDrawable extends BitmapDrawable {
private final WeakReference<AvatarWorkerTask> avatarWorkerTaskReference;

View File

@ -929,6 +929,8 @@
<string name="could_not_correct_message">Could not correct message</string>
<string name="search_all_conversations">All conversations</string>
<string name="search_this_conversation">This conversation</string>
<string name="your_avatar">Your avatar</string>
<string name="avatar_for_x">Avatar for %s</string>
<plurals name="view_users">
<item quantity="one">View %1$d Participant</item>
<item quantity="other">View %1$d Participants</item>