mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 01:53:31 +00:00
feat: added the ability to request download for an unplayed podcast episode
This commit is contained in:
parent
1ebe9ff8ba
commit
b267b904cc
10 changed files with 79 additions and 2 deletions
|
|
@ -20,6 +20,7 @@ public interface ClickCallback {
|
|||
default void onServerClick(Bundle bundle) {}
|
||||
default void onServerLongClick(Bundle bundle) {}
|
||||
default void onPodcastEpisodeClick(Bundle bundle) {}
|
||||
default void onPodcastEpisodeAltClick(Bundle bundle) {}
|
||||
default void onPodcastEpisodeLongClick(Bundle bundle) {}
|
||||
default void onPodcastChannelClick(Bundle bundle) {}
|
||||
default void onPodcastChannelLongClick(Bundle bundle) {}
|
||||
|
|
|
|||
|
|
@ -133,4 +133,21 @@ public class PodcastRepository {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void downloadPodcastEpisode(String episodeId) {
|
||||
App.getSubsonicClientInstance(false)
|
||||
.getPodcastClient()
|
||||
.downloadPodcastEpisode(episodeId)
|
||||
.enqueue(new Callback<ApiResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,4 +48,9 @@ public class PodcastClient {
|
|||
Log.d(TAG, "deletePodcastEpisode()");
|
||||
return podcastService.deletePodcastEpisode(subsonic.getParams(), episodeId);
|
||||
}
|
||||
|
||||
public Call<ApiResponse> downloadPodcastEpisode(String episodeId) {
|
||||
Log.d(TAG, "downloadPodcastEpisode()");
|
||||
return podcastService.downloadPodcastEpisode(subsonic.getParams(), episodeId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,4 +27,7 @@ public interface PodcastService {
|
|||
|
||||
@GET("deletePodcastEpisode")
|
||||
Call<ApiResponse> deletePodcastEpisode(@QueryMap Map<String, String> params, @Query("id") String id);
|
||||
|
||||
@GET("downloadPodcastEpisode")
|
||||
Call<ApiResponse> downloadPodcastEpisode(@QueryMap Map<String, String> params, @Query("id") String id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAd
|
|||
|
||||
holder.item.podcastPlayButton.setEnabled(podcastEpisode.getStatus().equals("completed"));
|
||||
holder.item.podcastMoreButton.setVisibility(podcastEpisode.getStatus().equals("completed") ? View.VISIBLE : View.GONE);
|
||||
holder.item.podcastDownloadRequestButton.setVisibility(podcastEpisode.getStatus().equals("completed") ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -93,6 +94,7 @@ public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAd
|
|||
|
||||
item.podcastPlayButton.setOnClickListener(v -> onClick());
|
||||
item.podcastMoreButton.setOnClickListener(v -> openMore());
|
||||
item.podcastDownloadRequestButton.setOnClickListener(v -> requestDownload());
|
||||
}
|
||||
|
||||
public void onClick() {
|
||||
|
|
@ -120,6 +122,17 @@ public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAd
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void requestDownload() {
|
||||
PodcastEpisode podcastEpisode = podcastEpisodes.get(getBindingAdapterPosition());
|
||||
|
||||
if (!podcastEpisode.getStatus().equals("completed")) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(Constants.PODCAST_OBJECT, podcastEpisodes.get(getBindingAdapterPosition()));
|
||||
|
||||
click.onPodcastEpisodeAltClick(bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sort(String order) {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.cappielloantonio.tempo.util.Constants;
|
|||
import com.cappielloantonio.tempo.util.MusicUtil;
|
||||
import com.cappielloantonio.tempo.util.UIUtil;
|
||||
import com.cappielloantonio.tempo.viewmodel.PodcastChannelPageViewModel;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -169,4 +170,14 @@ public class PodcastChannelPageFragment extends Fragment implements ClickCallbac
|
|||
public void onPodcastEpisodeLongClick(Bundle bundle) {
|
||||
Navigation.findNavController(requireView()).navigate(R.id.podcastEpisodeBottomSheetDialog, bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPodcastEpisodeAltClick(Bundle bundle) {
|
||||
PodcastEpisode episode = bundle.getParcelable(Constants.PODCAST_OBJECT);
|
||||
podcastChannelPageViewModel.requestPodcastEpisodeDownload(episode);
|
||||
|
||||
Snackbar.make(requireView(), R.string.podcast_episode_download_request_snackbar, Snackbar.LENGTH_SHORT)
|
||||
.setAnchorView(activity.bind.bottomNavigation)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ import androidx.lifecycle.LiveData;
|
|||
|
||||
import com.cappielloantonio.tempo.repository.PodcastRepository;
|
||||
import com.cappielloantonio.tempo.subsonic.models.PodcastChannel;
|
||||
import com.cappielloantonio.tempo.subsonic.models.PodcastEpisode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -33,4 +34,8 @@ public class PodcastChannelPageViewModel extends AndroidViewModel {
|
|||
public void setPodcastChannel(PodcastChannel podcastChannel) {
|
||||
this.podcastChannel = podcastChannel;
|
||||
}
|
||||
|
||||
public void requestPodcastEpisodeDownload(PodcastEpisode podcastEpisode) {
|
||||
podcastRepository.downloadPodcastEpisode(podcastEpisode.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue