Announce episode download start/end with Talkback (#7272)

This commit is contained in:
teleoflexuous 2024-07-18 23:14:59 +02:00 committed by GitHub
parent a2806562b5
commit 30dca237fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,27 @@
package de.danoeh.antennapod.net.download.service.episode;
import android.content.Context;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import de.danoeh.antennapod.net.download.service.R;
public abstract class DownloadAnnouncer {
public static void announceStart(Context context, String episodeTitle) {
announce(context, R.string.download_started_talkback, episodeTitle);
}
public static void announceCompleted(Context context, String episodeTitle) {
announce(context, R.string.download_completed_talkback, episodeTitle);
}
private static void announce(Context context, int messageTemplate, String episodeTitle) {
String message = context.getString(messageTemplate, episodeTitle);
AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
if (am != null && am.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain();
event.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT);
event.getText().add(message);
am.sendAccessibilityEvent(event);
}
}
}

View File

@ -167,6 +167,8 @@ public class EpisodeDownloadWorker extends Worker {
wifiLock = wifiManager.createWifiLock(TAG);
wifiLock.acquire();
}
DownloadAnnouncer.announceStart(getApplicationContext(), request.getTitle());
try {
downloader.call();
} catch (Exception e) {
@ -190,6 +192,7 @@ public class EpisodeDownloadWorker extends Worker {
getApplicationContext(), downloader.getResult(), request);
handler.run();
DBWriter.addDownloadStatus(handler.getUpdatedStatus());
DownloadAnnouncer.announceCompleted(getApplicationContext(), request.getTitle());
return Result.success();
}

View File

@ -710,6 +710,8 @@
<string name="next_chapter">Next chapter</string>
<string name="shuffle_suggestions">Shuffle suggestions</string>
<string name="add_preset">Add preset</string>
<string name="download_started_talkback">Download started for %1$s</string>
<string name="download_completed_talkback">Download completed for %1$s</string>
<!-- Feed settings/information screen -->
<string name="authentication_label">Authentication</string>