feat: feat: advertise existing long press to refresh per section (#467)

* feat: advertise existing long press to refresh per section

---------

Co-authored-by: eddyizm <eddyizm@gmail.com>
This commit is contained in:
Tom 2026-03-02 00:36:03 -03:00 committed by GitHub
parent 88c2129cd4
commit c7f2524085
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 159 additions and 30 deletions

View file

@ -101,6 +101,7 @@ dependencies {
implementation 'androidx.room:room-runtime:2.6.1' implementation 'androidx.room:room-runtime:2.6.1'
implementation 'androidx.core:core-splashscreen:1.0.1' implementation 'androidx.core:core-splashscreen:1.0.1'
implementation 'androidx.appcompat:appcompat:1.7.0' implementation 'androidx.appcompat:appcompat:1.7.0'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.2.0"
// Android Material // Android Material
implementation 'com.google.android.material:material:1.10.0' implementation 'com.google.android.material:material:1.10.0'

View file

@ -9,6 +9,8 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.session.MediaBrowser; import androidx.media3.session.MediaBrowser;
@ -16,8 +18,11 @@ import androidx.media3.session.SessionToken;
import androidx.navigation.Navigation; import androidx.navigation.Navigation;
import android.content.ComponentName; import android.content.ComponentName;
import android.widget.Toast;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.cappielloantonio.tempo.R; import com.cappielloantonio.tempo.R;
import com.cappielloantonio.tempo.databinding.FragmentLibraryBinding; import com.cappielloantonio.tempo.databinding.FragmentLibraryBinding;
@ -43,6 +48,7 @@ import java.util.Objects;
@UnstableApi @UnstableApi
public class LibraryFragment extends Fragment implements ClickCallback { public class LibraryFragment extends Fragment implements ClickCallback {
private static final String TAG = "LibraryFragment"; private static final String TAG = "LibraryFragment";
private static final String TOAST_MSG = "Long press to refresh" ;
private FragmentLibraryBinding bind; private FragmentLibraryBinding bind;
private MainActivity activity; private MainActivity activity;
@ -81,6 +87,7 @@ public class LibraryFragment extends Fragment implements ClickCallback {
initArtistView(); initArtistView();
initGenreView(); initGenreView();
initPlaylistView(); initPlaylistView();
initSwipeToRefresh();
} }
@Override @Override
@ -112,22 +119,41 @@ public class LibraryFragment extends Fragment implements ClickCallback {
activity.navController.navigate(R.id.action_libraryFragment_to_playlistCatalogueFragment, bundle); activity.navController.navigate(R.id.action_libraryFragment_to_playlistCatalogueFragment, bundle);
}); });
// Album
bind.albumCatalogueSampleTextViewRefreshable.setOnLongClickListener(view -> { bind.albumCatalogueSampleTextViewRefreshable.setOnLongClickListener(view -> {
libraryViewModel.refreshAlbumSample(getViewLifecycleOwner()); libraryViewModel.refreshAlbumSample(getViewLifecycleOwner());
return true; return true;
}); });
bind.albumCatalogueSampleTextViewRefreshable.setOnClickListener( v ->
Toast.makeText(requireContext(), TOAST_MSG, Toast.LENGTH_SHORT).show()
);
// Artist
bind.artistCatalogueSampleTextViewRefreshable.setOnLongClickListener(view -> { bind.artistCatalogueSampleTextViewRefreshable.setOnLongClickListener(view -> {
libraryViewModel.refreshArtistSample(getViewLifecycleOwner()); libraryViewModel.refreshArtistSample(getViewLifecycleOwner());
return true; return true;
}); });
bind.artistCatalogueSampleTextViewRefreshable.setOnClickListener( v ->
Toast.makeText(requireContext(), TOAST_MSG, Toast.LENGTH_SHORT).show()
);
// Genre
bind.genreCatalogueSampleTextViewRefreshable.setOnLongClickListener(view -> { bind.genreCatalogueSampleTextViewRefreshable.setOnLongClickListener(view -> {
libraryViewModel.refreshGenreSample(getViewLifecycleOwner()); libraryViewModel.refreshGenreSample(getViewLifecycleOwner());
return true; return true;
}); });
bind.genreCatalogueSampleTextViewRefreshable.setOnClickListener(v ->
Toast.makeText(requireContext(), TOAST_MSG, Toast.LENGTH_SHORT).show()
);
// Playlist
bind.playlistCatalogueSampleTextViewRefreshable.setOnLongClickListener(view -> { bind.playlistCatalogueSampleTextViewRefreshable.setOnLongClickListener(view -> {
libraryViewModel.refreshPlaylistSample(getViewLifecycleOwner()); libraryViewModel.refreshPlaylistSample(getViewLifecycleOwner());
return true; return true;
}); });
bind.playlistCatalogueSampleTextViewRefreshable.setOnClickListener( v ->
Toast.makeText(requireContext(), TOAST_MSG, Toast.LENGTH_SHORT).show()
);
} }
private void initAppBar() { private void initAppBar() {
@ -304,4 +330,20 @@ public class LibraryFragment extends Fragment implements ClickCallback {
private void initializeMediaBrowser() { private void initializeMediaBrowser() {
mediaBrowserListenableFuture = new MediaBrowser.Builder(requireContext(), new SessionToken(requireContext(), new ComponentName(requireContext(), MediaService.class))).buildAsync(); mediaBrowserListenableFuture = new MediaBrowser.Builder(requireContext(), new SessionToken(requireContext(), new ComponentName(requireContext(), MediaService.class))).buildAsync();
} }
public void initSwipeToRefresh() {
bind.swipeLibraryToRefresh.setOnRefreshListener(() -> {
pullToRefresh();
bind.swipeLibraryToRefresh.setRefreshing(false);
});
}
private void pullToRefresh() {
LifecycleOwner lifecycleOwner = getViewLifecycleOwner();
libraryViewModel.refreshAlbumSample(lifecycleOwner);
libraryViewModel.refreshGenreSample(lifecycleOwner);
libraryViewModel.refreshArtistSample(lifecycleOwner);
libraryViewModel.refreshPlaylistSample(lifecycleOwner);
}
} }

View file

@ -11,6 +11,12 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_library_to_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:id="@+id/fragment_library_nested_scroll_view" android:id="@+id/fragment_library_nested_scroll_view"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -77,21 +83,41 @@
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:paddingBottom="8dp"> android:paddingBottom="8dp">
<TextView <!-- Refreshable area -->
<LinearLayout
android:id="@+id/album_catalogue_sample_text_view_refreshable" android:id="@+id/album_catalogue_sample_text_view_refreshable"
style="@style/TitleLarge" android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
style="@style/TitleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:text="@string/library_title_album" />
<ImageView
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="bottom"
android:layout_marginBottom="2dp"
android:alpha="0.4"
android:src="@drawable/ic_refresh"/>
</LinearLayout>
<View
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1" />
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:text="@string/library_title_album" />
<TextView <TextView
android:id="@+id/album_catalogue_text_view_clickable" android:id="@+id/album_catalogue_text_view_clickable"
style="@style/TitleMedium" style="@style/TitleMedium"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:paddingStart="8dp" android:paddingStart="8dp"
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:text="@string/library_title_album_see_all_button" /> android:text="@string/library_title_album_see_all_button" />
@ -130,22 +156,41 @@
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:paddingBottom="8dp"> android:paddingBottom="8dp">
<TextView <!-- Refreshable area -->
<LinearLayout
android:id="@+id/artist_catalogue_sample_text_view_refreshable" android:id="@+id/artist_catalogue_sample_text_view_refreshable"
style="@style/TitleLarge" android:layout_width="wrap_content"
android:layout_width="0dp" android:layout_height="wrap_content" >
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:text="@string/library_title_artist" />
<TextView
style="@style/TitleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:text="@string/library_title_artist" />
<ImageView
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="bottom"
android:layout_marginBottom="2dp"
android:alpha="0.4"
android:src="@drawable/ic_refresh"/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView <TextView
android:id="@+id/artist_catalogue_text_view_clickable" android:id="@+id/artist_catalogue_text_view_clickable"
style="@style/TitleMedium" style="@style/TitleMedium"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:paddingStart="8dp" android:paddingStart="8dp"
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:text="@string/library_title_artist_see_all_button" /> android:text="@string/library_title_artist_see_all_button" />
@ -184,25 +229,45 @@
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:paddingBottom="8dp"> android:paddingBottom="8dp">
<TextView <!-- Refreshable area -->
<LinearLayout
android:id="@+id/genre_catalogue_sample_text_view_refreshable" android:id="@+id/genre_catalogue_sample_text_view_refreshable"
style="@style/TitleLarge" android:layout_width="wrap_content"
android:layout_width="0dp" android:layout_height="wrap_content" >
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:text="@string/library_title_genre" />
<TextView
style="@style/TitleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:text="@string/library_title_genre" />
<ImageView
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="bottom"
android:layout_marginBottom="2dp"
android:alpha="0.4"
android:src="@drawable/ic_refresh"/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView <TextView
android:id="@+id/genre_catalogue_text_view_clickable" android:id="@+id/genre_catalogue_text_view_clickable"
style="@style/TitleMedium" style="@style/TitleMedium"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:paddingStart="8dp" android:paddingStart="8dp"
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:text="@string/library_title_genre_see_all_button" /> android:text="@string/library_title_genre_see_all_button" />
</LinearLayout> </LinearLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
@ -236,21 +301,41 @@
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:paddingBottom="8dp"> android:paddingBottom="8dp">
<TextView <!-- Refreshable area -->
<LinearLayout
android:id="@+id/playlist_catalogue_sample_text_view_refreshable" android:id="@+id/playlist_catalogue_sample_text_view_refreshable"
style="@style/TitleLarge" android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
style="@style/TitleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:text="@string/library_title_playlist" />
<ImageView
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="bottom"
android:layout_marginBottom="2dp"
android:alpha="0.4"
android:src="@drawable/ic_refresh"/>
</LinearLayout>
<View
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1" />
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:text="@string/library_title_playlist" />
<TextView <TextView
android:id="@+id/playlist_catalogue_text_view_clickable" android:id="@+id/playlist_catalogue_text_view_clickable"
style="@style/TitleMedium" style="@style/TitleMedium"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:paddingStart="8dp" android:paddingStart="8dp"
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:text="@string/library_title_playlist_see_all_button" /> android:text="@string/library_title_playlist_see_all_button" />
@ -270,4 +355,5 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>