refactor: Rename methods and variables

This commit is contained in:
Jaime García 2025-09-22 20:03:02 +02:00
parent f74813ef69
commit e1c5a60805
No known key found for this signature in database
GPG key ID: BC4E5F71A71BDA5B
8 changed files with 31 additions and 38 deletions

View file

@ -307,7 +307,7 @@ public class AlbumPageFragment extends Fragment implements ClickCallback {
}
private void observePlayback() {
playbackViewModel.getCurrentMediaId().observe(getViewLifecycleOwner(), id -> {
playbackViewModel.getCurrentSongId().observe(getViewLifecycleOwner(), id -> {
if (songHorizontalAdapter != null) {
Boolean playing = playbackViewModel.getIsPlaying().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
@ -315,7 +315,7 @@ public class AlbumPageFragment extends Fragment implements ClickCallback {
});
playbackViewModel.getIsPlaying().observe(getViewLifecycleOwner(), playing -> {
if (songHorizontalAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
}
});
@ -323,7 +323,7 @@ public class AlbumPageFragment extends Fragment implements ClickCallback {
private void reapplyPlayback() {
if (songHorizontalAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
Boolean playing = playbackViewModel.getIsPlaying().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
}

View file

@ -29,20 +29,16 @@ import com.cappielloantonio.tempo.service.MediaManager;
import com.cappielloantonio.tempo.service.MediaService;
import com.cappielloantonio.tempo.subsonic.models.ArtistID3;
import com.cappielloantonio.tempo.ui.activity.MainActivity;
import com.cappielloantonio.tempo.ui.adapter.AlbumArtistPageOrSimilarAdapter;
import com.cappielloantonio.tempo.ui.adapter.AlbumCatalogueAdapter;
import com.cappielloantonio.tempo.ui.adapter.ArtistCatalogueAdapter;
import com.cappielloantonio.tempo.ui.adapter.ArtistSimilarAdapter;
import com.cappielloantonio.tempo.ui.adapter.SongHorizontalAdapter;
import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.MusicUtil;
import com.cappielloantonio.tempo.util.Preferences;
import com.cappielloantonio.tempo.viewmodel.ArtistPageViewModel;
import com.cappielloantonio.tempo.viewmodel.PlaybackViewModel;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@UnstableApi
@ -282,7 +278,7 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
}
private void observePlayback() {
playbackViewModel.getCurrentMediaId().observe(getViewLifecycleOwner(), id -> {
playbackViewModel.getCurrentSongId().observe(getViewLifecycleOwner(), id -> {
if (songHorizontalAdapter != null) {
Boolean playing = playbackViewModel.getIsPlaying().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
@ -290,7 +286,7 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
});
playbackViewModel.getIsPlaying().observe(getViewLifecycleOwner(), playing -> {
if (songHorizontalAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
}
});
@ -298,7 +294,7 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
private void reapplyPlayback() {
if (songHorizontalAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
Boolean playing = playbackViewModel.getIsPlaying().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
}

View file

@ -1058,7 +1058,7 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
}
private void observeStarredSongsPlayback() {
playbackViewModel.getCurrentMediaId().observe(getViewLifecycleOwner(), id -> {
playbackViewModel.getCurrentSongId().observe(getViewLifecycleOwner(), id -> {
if (starredSongAdapter != null) {
Boolean playing = playbackViewModel.getIsPlaying().getValue();
starredSongAdapter.setPlaybackState(id, playing != null && playing);
@ -1066,14 +1066,14 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
});
playbackViewModel.getIsPlaying().observe(getViewLifecycleOwner(), playing -> {
if (starredSongAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
starredSongAdapter.setPlaybackState(id, playing != null && playing);
}
});
}
private void observeTopSongsPlayback() {
playbackViewModel.getCurrentMediaId().observe(getViewLifecycleOwner(), id -> {
playbackViewModel.getCurrentSongId().observe(getViewLifecycleOwner(), id -> {
if (topSongAdapter != null) {
Boolean playing = playbackViewModel.getIsPlaying().getValue();
topSongAdapter.setPlaybackState(id, playing != null && playing);
@ -1081,7 +1081,7 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
});
playbackViewModel.getIsPlaying().observe(getViewLifecycleOwner(), playing -> {
if (topSongAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
topSongAdapter.setPlaybackState(id, playing != null && playing);
}
});
@ -1089,7 +1089,7 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
private void reapplyStarredSongsPlayback() {
if (starredSongAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
Boolean playing = playbackViewModel.getIsPlaying().getValue();
starredSongAdapter.setPlaybackState(id, playing != null && playing);
}
@ -1097,7 +1097,7 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
private void reapplyTopSongsPlayback() {
if (topSongAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
Boolean playing = playbackViewModel.getIsPlaying().getValue();
topSongAdapter.setPlaybackState(id, playing != null && playing);
}

View file

@ -227,7 +227,7 @@ public class PlayerQueueFragment extends Fragment implements ClickCallback {
}
private void observePlayback() {
playbackViewModel.getCurrentMediaId().observe(getViewLifecycleOwner(), id -> {
playbackViewModel.getCurrentSongId().observe(getViewLifecycleOwner(), id -> {
if (playerSongQueueAdapter != null) {
Boolean playing = playbackViewModel.getIsPlaying().getValue();
playerSongQueueAdapter.setPlaybackState(id, playing != null && playing);
@ -235,7 +235,7 @@ public class PlayerQueueFragment extends Fragment implements ClickCallback {
});
playbackViewModel.getIsPlaying().observe(getViewLifecycleOwner(), playing -> {
if (playerSongQueueAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
playerSongQueueAdapter.setPlaybackState(id, playing != null && playing);
}
});
@ -243,7 +243,7 @@ public class PlayerQueueFragment extends Fragment implements ClickCallback {
private void reapplyPlayback() {
if (playerSongQueueAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
Boolean playing = playbackViewModel.getIsPlaying().getValue();
playerSongQueueAdapter.setPlaybackState(id, playing != null && playing);
}

View file

@ -282,7 +282,7 @@ public class PlaylistPageFragment extends Fragment implements ClickCallback {
}
private void observePlayback() {
playbackViewModel.getCurrentMediaId().observe(getViewLifecycleOwner(), id -> {
playbackViewModel.getCurrentSongId().observe(getViewLifecycleOwner(), id -> {
if (songHorizontalAdapter != null) {
Boolean playing = playbackViewModel.getIsPlaying().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
@ -290,7 +290,7 @@ public class PlaylistPageFragment extends Fragment implements ClickCallback {
});
playbackViewModel.getIsPlaying().observe(getViewLifecycleOwner(), playing -> {
if (songHorizontalAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
}
});
@ -298,7 +298,7 @@ public class PlaylistPageFragment extends Fragment implements ClickCallback {
private void reapplyPlayback() {
if (songHorizontalAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
Boolean playing = playbackViewModel.getIsPlaying().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
}

View file

@ -4,14 +4,11 @@ import android.content.ComponentName;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -303,7 +300,7 @@ public class SearchFragment extends Fragment implements ClickCallback {
}
private void observePlayback() {
playbackViewModel.getCurrentMediaId().observe(getViewLifecycleOwner(), id -> {
playbackViewModel.getCurrentSongId().observe(getViewLifecycleOwner(), id -> {
if (songHorizontalAdapter != null) {
Boolean playing = playbackViewModel.getIsPlaying().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
@ -311,7 +308,7 @@ public class SearchFragment extends Fragment implements ClickCallback {
});
playbackViewModel.getIsPlaying().observe(getViewLifecycleOwner(), playing -> {
if (songHorizontalAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
}
});
@ -319,7 +316,7 @@ public class SearchFragment extends Fragment implements ClickCallback {
private void reapplyPlayback() {
if (songHorizontalAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
Boolean playing = playbackViewModel.getIsPlaying().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
}

View file

@ -335,7 +335,7 @@ public class SongListPageFragment extends Fragment implements ClickCallback {
}
private void observePlayback() {
playbackViewModel.getCurrentMediaId().observe(getViewLifecycleOwner(), id -> {
playbackViewModel.getCurrentSongId().observe(getViewLifecycleOwner(), id -> {
if (songHorizontalAdapter != null) {
Boolean playing = playbackViewModel.getIsPlaying().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
@ -343,7 +343,7 @@ public class SongListPageFragment extends Fragment implements ClickCallback {
});
playbackViewModel.getIsPlaying().observe(getViewLifecycleOwner(), playing -> {
if (songHorizontalAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
}
});
@ -351,7 +351,7 @@ public class SongListPageFragment extends Fragment implements ClickCallback {
private void reapplyPlayback() {
if (songHorizontalAdapter != null) {
String id = playbackViewModel.getCurrentMediaId().getValue();
String id = playbackViewModel.getCurrentSongId().getValue();
Boolean playing = playbackViewModel.getIsPlaying().getValue();
songHorizontalAdapter.setPlaybackState(id, playing != null && playing);
}

View file

@ -8,20 +8,20 @@ import java.util.Objects;
public class PlaybackViewModel extends ViewModel {
private final MutableLiveData<String> currentMediaId = new MutableLiveData<>(null);
private final MutableLiveData<String> currentSongId = new MutableLiveData<>(null);
private final MutableLiveData<Boolean> isPlaying = new MutableLiveData<>(false);
public LiveData<String> getCurrentMediaId() {
return currentMediaId;
public LiveData<String> getCurrentSongId() {
return currentSongId;
}
public LiveData<Boolean> getIsPlaying() {
return isPlaying;
}
public void update(String mediaId, boolean playing) {
if (!Objects.equals(currentMediaId.getValue(), mediaId)) {
currentMediaId.postValue(mediaId);
public void update(String songId, boolean playing) {
if (!Objects.equals(currentSongId.getValue(), songId)) {
currentSongId.postValue(songId);
}
if (!Objects.equals(isPlaying.getValue(), playing)) {
isPlaying.postValue(playing);
@ -29,7 +29,7 @@ public class PlaybackViewModel extends ViewModel {
}
public void clear() {
currentMediaId.postValue(null);
currentSongId.postValue(null);
isPlaying.postValue(false);
}
}