From 6a16159cf0adc6222e495fb937657f571871968c Mon Sep 17 00:00:00 2001 From: eddyizm Date: Sat, 30 Aug 2025 10:58:38 -0700 Subject: [PATCH] fix: forgot sync album dialog, bump version for release --- app/build.gradle | 4 +- .../tempo/ui/activity/MainActivity.java | 1 + .../ui/fragment/HomeTabMusicFragment.java | 59 ++++++++++++ .../tempo/viewmodel/HomeViewModel.java | 8 ++ .../viewmodel/StarredAlbumsSyncViewModel.java | 16 ++++ .../res/layout/fragment_home_tab_music.xml | 92 +++++++++++++++++++ app/src/main/res/values/strings.xml | 6 ++ 7 files changed, 184 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5926fa3f..1deaecca 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { minSdkVersion 24 targetSdk 35 - versionCode 29 - versionName '3.13.0' + versionCode 30 + versionName '3.14.1' testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/activity/MainActivity.java b/app/src/main/java/com/cappielloantonio/tempo/ui/activity/MainActivity.java index 085b2d17..c959648b 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/activity/MainActivity.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/activity/MainActivity.java @@ -316,6 +316,7 @@ public class MainActivity extends BaseActivity { Preferences.setSkipSilenceMode(false); Preferences.setDataSavingMode(false); Preferences.setStarredSyncEnabled(false); + Preferences.setStarredAlbumsSyncEnabled(false); } private void resetMusicSession() { diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/HomeTabMusicFragment.java b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/HomeTabMusicFragment.java index b71c27e8..4d30ce30 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/HomeTabMusicFragment.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/HomeTabMusicFragment.java @@ -39,6 +39,7 @@ import com.cappielloantonio.tempo.service.MediaManager; import com.cappielloantonio.tempo.service.MediaService; import com.cappielloantonio.tempo.subsonic.models.Child; import com.cappielloantonio.tempo.subsonic.models.Share; +import com.cappielloantonio.tempo.subsonic.models.AlbumID3; import com.cappielloantonio.tempo.ui.activity.MainActivity; import com.cappielloantonio.tempo.ui.adapter.AlbumAdapter; import com.cappielloantonio.tempo.ui.adapter.AlbumHorizontalAdapter; @@ -111,6 +112,7 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback { super.onViewCreated(view, savedInstanceState); initSyncStarredView(); + initSyncStarredAlbumsView(); initDiscoverSongSlideView(); initSimilarSongView(); initArtistRadio(); @@ -314,6 +316,63 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback { }); } + private void initSyncStarredAlbumsView() { + if (Preferences.isStarredAlbumsSyncEnabled()) { + homeViewModel.getStarredAlbums(getViewLifecycleOwner()).observeForever(new Observer>() { + @Override + public void onChanged(List albums) { + if (albums != null) { + DownloaderManager manager = DownloadUtil.getDownloadTracker(requireContext()); + List albumsToSync = new ArrayList<>(); + int albumCount = 0; + + for (AlbumID3 album : albums) { + boolean needsSync = false; + albumCount++; + albumsToSync.add(album.getName()); + } + + if (albumCount > 0) { + bind.homeSyncStarredAlbumsCard.setVisibility(View.VISIBLE); + String message = getResources().getQuantityString( + R.plurals.home_sync_starred_albums_count, + albumCount, + albumCount + ); + bind.homeSyncStarredAlbumsToSync.setText(message); + } + } + + homeViewModel.getStarredAlbums(getViewLifecycleOwner()).removeObserver(this); + } + }); + } + + bind.homeSyncStarredAlbumsCancel.setOnClickListener(v -> { + bind.homeSyncStarredAlbumsCard.setVisibility(View.GONE); + }); + + bind.homeSyncStarredAlbumsDownload.setOnClickListener(v -> { + homeViewModel.getAllStarredAlbumSongs().observeForever(new Observer>() { + @Override + public void onChanged(List allSongs) { + if (allSongs != null) { + DownloaderManager manager = DownloadUtil.getDownloadTracker(requireContext()); + + for (Child song : allSongs) { + if (!manager.isDownloaded(song.getId())) { + manager.download(MappingUtil.mapDownload(song), new Download(song)); + } + } + } + + homeViewModel.getAllStarredAlbumSongs().removeObserver(this); + bind.homeSyncStarredAlbumsCard.setVisibility(View.GONE); + } + }); + }); + } + private void initDiscoverSongSlideView() { if (homeViewModel.checkHomeSectorVisibility(Constants.HOME_SECTOR_DISCOVERY)) return; diff --git a/app/src/main/java/com/cappielloantonio/tempo/viewmodel/HomeViewModel.java b/app/src/main/java/com/cappielloantonio/tempo/viewmodel/HomeViewModel.java index b646bcf1..6477178c 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/viewmodel/HomeViewModel.java +++ b/app/src/main/java/com/cappielloantonio/tempo/viewmodel/HomeViewModel.java @@ -47,6 +47,8 @@ public class HomeViewModel extends AndroidViewModel { private final PlaylistRepository playlistRepository; private final SharingRepository sharingRepository; + private final StarredAlbumsSyncViewModel albumsSyncViewModel; + private final MutableLiveData> dicoverSongSample = new MutableLiveData<>(null); private final MutableLiveData> newReleasedAlbum = new MutableLiveData<>(null); private final MutableLiveData> starredTracksSample = new MutableLiveData<>(null); @@ -82,6 +84,8 @@ public class HomeViewModel extends AndroidViewModel { playlistRepository = new PlaylistRepository(); sharingRepository = new SharingRepository(); + albumsSyncViewModel = new StarredAlbumsSyncViewModel(application); + setOfflineFavorite(); } @@ -166,6 +170,10 @@ public class HomeViewModel extends AndroidViewModel { return starredAlbums; } + public LiveData> getAllStarredAlbumSongs() { + return albumsSyncViewModel.getAllStarredAlbumSongs(); + } + public LiveData> getStarredArtists(LifecycleOwner owner) { if (starredArtists.getValue() == null) { artistRepository.getStarredArtists(true, 20).observe(owner, starredArtists::postValue); diff --git a/app/src/main/java/com/cappielloantonio/tempo/viewmodel/StarredAlbumsSyncViewModel.java b/app/src/main/java/com/cappielloantonio/tempo/viewmodel/StarredAlbumsSyncViewModel.java index 492ed010..5967caf8 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/viewmodel/StarredAlbumsSyncViewModel.java +++ b/app/src/main/java/com/cappielloantonio/tempo/viewmodel/StarredAlbumsSyncViewModel.java @@ -34,6 +34,22 @@ public class StarredAlbumsSyncViewModel extends AndroidViewModel { return starredAlbums; } + public LiveData> getAllStarredAlbumSongs() { + albumRepository.getStarredAlbums(false, -1).observeForever(new Observer>() { + @Override + public void onChanged(List albums) { + if (albums != null && !albums.isEmpty()) { + collectAllAlbumSongs(albums, starredAlbumSongs::postValue); + } else { + starredAlbumSongs.postValue(new ArrayList<>()); + } + albumRepository.getStarredAlbums(false, -1).removeObserver(this); + } + }); + + return starredAlbumSongs; + } + public LiveData> getStarredAlbumSongs(Activity activity) { albumRepository.getStarredAlbums(false, -1).observe((LifecycleOwner) activity, albums -> { if (albums != null && !albums.isEmpty()) { diff --git a/app/src/main/res/layout/fragment_home_tab_music.xml b/app/src/main/res/layout/fragment_home_tab_music.xml index 06530614..e9811da3 100644 --- a/app/src/main/res/layout/fragment_home_tab_music.xml +++ b/app/src/main/res/layout/fragment_home_tab_music.xml @@ -106,6 +106,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + Download Downloading these tracks may involve significant data usage Looks like there are some starred tracks to sync + Sync Starred Albums + Albums marked with a star will be available offline Best of Discovery Shuffle all @@ -437,4 +439,8 @@ unDraw A special thanks goes to unDraw without whose illustrations we could not have made this application more beautiful. https://undraw.co/ + + %d album to sync + %d albums to sync +