diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2024-03-31 18:40:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-31 18:40:15 +0200 |
commit | edb440a5a9a05e24c344a71b272b9238217e9c55 (patch) | |
tree | 13623ca7d0dac052ac35d693aac940d0727c87f9 /app/src/main/java/de/danoeh/antennapod/actionbutton/ItemActionButton.java | |
parent | 4e47691e70e85736c7eeb30ce02c73176e565a86 (diff) | |
download | AntennaPod-edb440a5a9a05e24c344a71b272b9238217e9c55.zip |
Restructure related UI classes together (#7044)
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/actionbutton/ItemActionButton.java')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/actionbutton/ItemActionButton.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/actionbutton/ItemActionButton.java b/app/src/main/java/de/danoeh/antennapod/actionbutton/ItemActionButton.java new file mode 100644 index 000000000..84b246167 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/actionbutton/ItemActionButton.java @@ -0,0 +1,64 @@ +package de.danoeh.antennapod.actionbutton; + +import android.content.Context; +import android.widget.ImageView; +import androidx.annotation.DrawableRes; +import androidx.annotation.NonNull; +import androidx.annotation.StringRes; +import android.view.View; + +import de.danoeh.antennapod.playback.service.PlaybackStatus; +import de.danoeh.antennapod.model.feed.FeedItem; +import de.danoeh.antennapod.model.feed.FeedMedia; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; +import de.danoeh.antennapod.storage.preferences.UserPreferences; + +public abstract class ItemActionButton { + FeedItem item; + + ItemActionButton(FeedItem item) { + this.item = item; + } + + @StringRes + public abstract int getLabel(); + + @DrawableRes + public abstract int getDrawable(); + + public abstract void onClick(Context context); + + public int getVisibility() { + return View.VISIBLE; + } + + @NonNull + public static ItemActionButton forItem(@NonNull FeedItem item) { + final FeedMedia media = item.getMedia(); + if (media == null) { + return new MarkAsPlayedActionButton(item); + } + + final boolean isDownloadingMedia = DownloadServiceInterface.get().isDownloadingEpisode(media.getDownloadUrl()); + if (PlaybackStatus.isCurrentlyPlaying(media)) { + return new PauseActionButton(item); + } else if (item.getFeed().isLocalFeed()) { + return new PlayLocalActionButton(item); + } else if (media.isDownloaded()) { + return new PlayActionButton(item); + } else if (isDownloadingMedia) { + return new CancelDownloadActionButton(item); + } else if (UserPreferences.isStreamOverDownload()) { + return new StreamActionButton(item); + } else { + return new DownloadActionButton(item); + } + } + + public void configure(@NonNull View button, @NonNull ImageView icon, Context context) { + button.setVisibility(getVisibility()); + button.setContentDescription(context.getString(getLabel())); + button.setOnClickListener((view) -> onClick(context)); + icon.setImageResource(getDrawable()); + } +} |