Add correct Content Description for the preview images at the Compose screen (#1188)

* Add correct Content Description for the preview images at the Compose screen. tuskyapp#1155

* Remove "unknown" string from resource. Format code

* Format code

* Update string resource for content description
This commit is contained in:
pandasoft0 2019-05-09 21:25:45 +03:00 committed by Konrad Pozniak
parent c75b046483
commit 5c61786e05
2 changed files with 105 additions and 56 deletions

View File

@ -133,6 +133,25 @@ import java.util.concurrent.CountDownLatch;
import javax.inject.Inject;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import androidx.annotation.StringRes;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.core.view.inputmethod.InputConnectionCompat;
import androidx.core.view.inputmethod.InputContentInfoCompat;
import androidx.lifecycle.Lifecycle;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.transition.TransitionManager;
import at.connyduck.sparkbutton.helpers.Utils;
import io.reactivex.Single;
import io.reactivex.SingleObserver;
@ -1169,9 +1188,9 @@ public final class ComposeActivity
.into(view);
}
view.setOnClickListener(v -> onMediaClick(item, v));
view.setContentDescription(getString(R.string.action_delete));
mediaPreviewBar.addView(view);
mediaQueued.add(item);
updateContentDescription(item);
int queuedCount = mediaQueued.size();
if (queuedCount == 1) {
// If there's one video in the queue it is full, so disable the button to queue more.
@ -1201,6 +1220,33 @@ public final class ComposeActivity
}
}
private void updateContentDescriptionForAllImages() {
List<QueuedMedia> items = new ArrayList<>(mediaQueued);
for (QueuedMedia media : items) {
updateContentDescription(media);
}
}
private void updateContentDescription(QueuedMedia item) {
if (item.preview != null) {
String imageId;
if (!TextUtils.isEmpty(item.description)) {
imageId = item.description;
} else {
int idx = getImageIdx(item);
if (idx < 0)
imageId = null;
else
imageId = Integer.toString(idx + 1);
}
item.preview.setContentDescription(getString(R.string.compose_preview_image_description, imageId));
}
}
private int getImageIdx(QueuedMedia item) {
return mediaQueued.indexOf(item);
}
private void onMediaClick(QueuedMedia item, View view) {
PopupMenu popup = new PopupMenu(this, view);
final int addCaptionId = 1;
@ -1239,7 +1285,8 @@ public final class ComposeActivity
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
.subscribe(new SingleObserver<Bitmap>() {
@Override
public void onSubscribe(Disposable d) {}
public void onSubscribe(Disposable d) {
}
@Override
public void onSuccess(Bitmap bitmap) {
@ -1247,7 +1294,8 @@ public final class ComposeActivity
}
@Override
public void onError(Throwable e) { }
public void onError(Throwable e) {
}
});
@ -1276,6 +1324,7 @@ public final class ComposeActivity
item.description = attachment.getDescription();
item.preview.setChecked(item.description != null && !item.description.isEmpty());
dialog.dismiss();
updateContentDescription(item);
} else {
showFailedCaptionMessage();
}
@ -1323,7 +1372,7 @@ public final class ComposeActivity
if (mediaQueued.size() == 0) {
updateHideMediaToggle();
}
updateContentDescriptionForAllImages();
enableButton(pickButton, true, true);
cancelReadyingMedia(item);
}
@ -1722,8 +1771,7 @@ public final class ComposeActivity
}
// Accessors for testing, hence package scope
int getMaximumTootCharacters()
{
int getMaximumTootCharacters() {
return maximumTootCharacters;
}

View File

@ -466,6 +466,7 @@
<string name="pref_title_bot_overlay">Show indicator for bots</string>
<string name="notification_clear_text">Are you sure you want to permanently clear all your notifications?</string>
<string name="compose_preview_image_description">Actions for image %s</string>
<string name="poll_info_format">
<!-- 15 votes • 1 hour left -->