feat: podcast

This commit is contained in:
antonio 2023-05-07 23:43:36 +02:00
parent e3a28fa914
commit e85d7f9198
23 changed files with 1390 additions and 131 deletions

View file

@ -0,0 +1,43 @@
package com.cappielloantonio.play.viewmodel;
import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.cappielloantonio.play.App;
import com.cappielloantonio.play.interfaces.MediaCallback;
import com.cappielloantonio.play.repository.PodcastRepository;
import com.cappielloantonio.play.subsonic.base.ApiResponse;
import com.cappielloantonio.play.subsonic.models.AlbumID3;
import com.cappielloantonio.play.subsonic.models.PodcastChannel;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
public class PodcastChannelCatalogueViewModel extends AndroidViewModel {
private final PodcastRepository podcastRepository;
private final MutableLiveData<List<PodcastChannel>> podcastChannels = new MutableLiveData<>(null);
public PodcastChannelCatalogueViewModel(@NonNull Application application) {
super(application);
podcastRepository = new PodcastRepository();
}
public LiveData<List<PodcastChannel>> getPodcastChannels(LifecycleOwner owner) {
if (podcastChannels.getValue() == null) {
podcastRepository.getPodcastChannels(false, null).observe(owner, podcastChannels::postValue);
}
return podcastChannels;
}
}

View file

@ -0,0 +1,43 @@
package com.cappielloantonio.play.viewmodel;
import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import com.cappielloantonio.play.repository.AlbumRepository;
import com.cappielloantonio.play.repository.ArtistRepository;
import com.cappielloantonio.play.repository.PodcastRepository;
import com.cappielloantonio.play.subsonic.models.AlbumID3;
import com.cappielloantonio.play.subsonic.models.ArtistID3;
import com.cappielloantonio.play.subsonic.models.ArtistInfo2;
import com.cappielloantonio.play.subsonic.models.Child;
import com.cappielloantonio.play.subsonic.models.PodcastChannel;
import com.cappielloantonio.play.subsonic.models.PodcastEpisode;
import java.util.List;
public class PodcastChannelPageViewModel extends AndroidViewModel {
private final PodcastRepository podcastRepository;
private PodcastChannel podcastChannel;
public PodcastChannelPageViewModel(@NonNull Application application) {
super(application);
podcastRepository = new PodcastRepository();
}
public LiveData<List<PodcastChannel>> getPodcastChannelEpisodes() {
return podcastRepository.getPodcastChannels(true, podcastChannel.getId());
}
public PodcastChannel getPodcastChannel() {
return podcastChannel;
}
public void setPodcastChannel(PodcastChannel podcastChannel) {
this.podcastChannel = podcastChannel;
}
}

View file

@ -0,0 +1,44 @@
package com.cappielloantonio.play.viewmodel;
import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.cappielloantonio.play.repository.PodcastRepository;
import com.cappielloantonio.play.subsonic.models.PodcastChannel;
import com.cappielloantonio.play.subsonic.models.PodcastEpisode;
import java.util.List;
public class PodcastViewModel extends AndroidViewModel {
private final PodcastRepository podcastRepository;
private final MutableLiveData<List<PodcastEpisode>> newestPodcastEpisodes = new MutableLiveData<>(null);
private final MutableLiveData<List<PodcastChannel>> podcastChannels = new MutableLiveData<>(null);
public PodcastViewModel(@NonNull Application application) {
super(application);
podcastRepository = new PodcastRepository();
}
public LiveData<List<PodcastEpisode>> getNewestPodcastEpisodes(LifecycleOwner owner) {
if (newestPodcastEpisodes.getValue() == null) {
podcastRepository.getNewestPodcastEpisodes(20).observe(owner, newestPodcastEpisodes::postValue);
}
return newestPodcastEpisodes;
}
public LiveData<List<PodcastChannel>> getPodcastChannels(LifecycleOwner owner) {
if (podcastChannels.getValue() == null) {
podcastRepository.getPodcastChannels(false, null).observe(owner, podcastChannels::postValue);
}
return podcastChannels;
}
}