mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Implementation of playlist catalog recovery
This commit is contained in:
parent
98ffec9b72
commit
95bcbb0f61
4 changed files with 45 additions and 24 deletions
|
|
@ -24,6 +24,7 @@ import com.cappielloantonio.play.R;
|
||||||
import com.cappielloantonio.play.adapter.PlaylistCatalogueAdapter;
|
import com.cappielloantonio.play.adapter.PlaylistCatalogueAdapter;
|
||||||
import com.cappielloantonio.play.databinding.FragmentPlaylistCatalogueBinding;
|
import com.cappielloantonio.play.databinding.FragmentPlaylistCatalogueBinding;
|
||||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||||
|
import com.cappielloantonio.play.viewmodel.ArtistCatalogueViewModel;
|
||||||
import com.cappielloantonio.play.viewmodel.PlaylistCatalogueViewModel;
|
import com.cappielloantonio.play.viewmodel.PlaylistCatalogueViewModel;
|
||||||
|
|
||||||
public class PlaylistCatalogueFragment extends Fragment {
|
public class PlaylistCatalogueFragment extends Fragment {
|
||||||
|
|
@ -39,6 +40,8 @@ public class PlaylistCatalogueFragment extends Fragment {
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
|
initData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -47,7 +50,6 @@ public class PlaylistCatalogueFragment extends Fragment {
|
||||||
|
|
||||||
bind = FragmentPlaylistCatalogueBinding.inflate(inflater, container, false);
|
bind = FragmentPlaylistCatalogueBinding.inflate(inflater, container, false);
|
||||||
View view = bind.getRoot();
|
View view = bind.getRoot();
|
||||||
playlistCatalogueViewModel = new ViewModelProvider(requireActivity()).get(PlaylistCatalogueViewModel.class);
|
|
||||||
|
|
||||||
initAppBar();
|
initAppBar();
|
||||||
initArtistCatalogueView();
|
initArtistCatalogueView();
|
||||||
|
|
@ -67,6 +69,11 @@ public class PlaylistCatalogueFragment extends Fragment {
|
||||||
bind = null;
|
bind = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initData() {
|
||||||
|
playlistCatalogueViewModel = new ViewModelProvider(requireActivity()).get(PlaylistCatalogueViewModel.class);
|
||||||
|
playlistCatalogueViewModel.loadPlaylists(requireContext());
|
||||||
|
}
|
||||||
|
|
||||||
private void initAppBar() {
|
private void initAppBar() {
|
||||||
activity.setSupportActionBar(bind.toolbar);
|
activity.setSupportActionBar(bind.toolbar);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,13 +81,4 @@ public class AlbumCatalogueViewModel extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getQuery() {
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuery(String query) {
|
|
||||||
this.query = query;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ public class ArtistCatalogueViewModel extends AndroidViewModel {
|
||||||
|
|
||||||
private ArtistRepository artistRepository;
|
private ArtistRepository artistRepository;
|
||||||
private String query = "";
|
private String query = "";
|
||||||
private int page = 0;
|
|
||||||
|
|
||||||
public ArtistCatalogueViewModel(@NonNull Application application) {
|
public ArtistCatalogueViewModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
|
|
@ -67,12 +66,4 @@ public class ArtistCatalogueViewModel extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getQuery() {
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuery(String query) {
|
|
||||||
this.query = query;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,34 @@
|
||||||
package com.cappielloantonio.play.viewmodel;
|
package com.cappielloantonio.play.viewmodel;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.model.Artist;
|
||||||
import com.cappielloantonio.play.model.Playlist;
|
import com.cappielloantonio.play.model.Playlist;
|
||||||
import com.cappielloantonio.play.repository.PlaylistRepository;
|
import com.cappielloantonio.play.repository.PlaylistRepository;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.IndexID3;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||||
|
import com.cappielloantonio.play.util.MappingUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PlaylistCatalogueViewModel extends AndroidViewModel {
|
import retrofit2.Call;
|
||||||
private PlaylistRepository playlistRepository;
|
import retrofit2.Callback;
|
||||||
|
|
||||||
private LiveData<List<Playlist>> playlistList;
|
public class PlaylistCatalogueViewModel extends AndroidViewModel {
|
||||||
|
private MutableLiveData<List<Playlist>> playlists = new MutableLiveData<>(new ArrayList<>());
|
||||||
|
|
||||||
|
private PlaylistRepository playlistRepository;
|
||||||
|
private String query = "";
|
||||||
|
|
||||||
public PlaylistCatalogueViewModel(@NonNull Application application) {
|
public PlaylistCatalogueViewModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
|
|
@ -23,7 +37,25 @@ public class PlaylistCatalogueViewModel extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Playlist>> getPlaylistList() {
|
public LiveData<List<Playlist>> getPlaylistList() {
|
||||||
// playlistList = playlistRepository.getListLivePlaylists();
|
return playlists;
|
||||||
return playlistList;
|
}
|
||||||
|
|
||||||
|
public void loadPlaylists(Context context) {
|
||||||
|
App.getSubsonicClientInstance(context, false)
|
||||||
|
.getPlaylistClient()
|
||||||
|
.getPlaylists()
|
||||||
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<SubsonicResponse> call, retrofit2.Response<SubsonicResponse> response) {
|
||||||
|
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||||
|
playlists.setValue(MappingUtil.mapPlaylist(response.body().getPlaylists().getPlaylists()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue