Removed NestedScrollView where possible to speed-up scrolling performance

This commit is contained in:
CappielloAntonio 2021-04-17 19:25:55 +02:00
parent 8d637c9452
commit 68bec3d6ec
11 changed files with 125 additions and 173 deletions

View file

@ -55,7 +55,6 @@ dependencies {
implementation "androidx.room:room-runtime:2.2.6" implementation "androidx.room:room-runtime:2.2.6"
implementation "androidx.cardview:cardview:1.0.0" implementation "androidx.cardview:cardview:1.0.0"
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.paging:paging-runtime-ktx:2.1.2'
implementation "androidx.lifecycle:lifecycle-common-java8:2.3.1" implementation "androidx.lifecycle:lifecycle-common-java8:2.3.1"
// Android Material // Android Material

View file

@ -19,7 +19,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
public class ArtistCatalogueAdapter extends RecyclerView.Adapter<ArtistCatalogueAdapter.ViewHolder> { public class ArtistCatalogueAdapter extends
RecyclerView.Adapter<ArtistCatalogueAdapter.ViewHolder> {
private static final String TAG = "ArtistCatalogueAdapter"; private static final String TAG = "ArtistCatalogueAdapter";
private List<Artist> artists; private List<Artist> artists;

View file

@ -179,9 +179,7 @@ public class MainActivity extends BaseActivity {
break; break;
case BottomSheetBehavior.STATE_HIDDEN: case BottomSheetBehavior.STATE_HIDDEN:
MusicPlayerRemote.quitPlaying(); MusicPlayerRemote.quitPlaying();
mainViewModel.deleteQueue();
break; break;
} }
} }

View file

@ -58,7 +58,6 @@ public class AlbumCatalogueFragment extends Fragment {
bind.albumCatalogueRecyclerView.setAdapter(albumAdapter); bind.albumCatalogueRecyclerView.setAdapter(albumAdapter);
albumCatalogueViewModel.getAlbumList().observe(requireActivity(), albums -> { albumCatalogueViewModel.getAlbumList().observe(requireActivity(), albums -> {
bind.loadingProgressBar.setVisibility(View.GONE); bind.loadingProgressBar.setVisibility(View.GONE);
bind.albumCatalogueContainer.setVisibility(View.VISIBLE);
albumAdapter.setItems(albums); albumAdapter.setItems(albums);
}); });
} }

View file

@ -1,6 +1,7 @@
package com.cappielloantonio.play.ui.fragment; package com.cappielloantonio.play.ui.fragment;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -56,10 +57,9 @@ public class ArtistCatalogueFragment extends Fragment {
artistAdapter = new ArtistCatalogueAdapter(requireContext()); artistAdapter = new ArtistCatalogueAdapter(requireContext());
bind.artistCatalogueRecyclerView.setAdapter(artistAdapter); bind.artistCatalogueRecyclerView.setAdapter(artistAdapter);
artistCatalogueViewModel.getArtistList().observe(requireActivity(), artists -> { artistCatalogueViewModel.getArtistList().observe(requireActivity(), artistList -> {
bind.loadingProgressBar.setVisibility(View.GONE); bind.loadingProgressBar.setVisibility(View.GONE);
bind.artistCatalogueContainer.setVisibility(View.VISIBLE); artistAdapter.setItems(artistList);
artistAdapter.setItems(artists);
}); });
} }
} }

View file

@ -138,14 +138,14 @@ public class SearchFragment extends Fragment {
} }
public void search(String query) { public void search(String query) {
if (!query.trim().equals("") && query.trim().length() > 1) { if (!query.trim().equals("") && query.trim().length() > 2) {
searchViewModel.insertNewSearch(query); searchViewModel.insertNewSearch(query);
bind.persistentSearchView.collapse(); bind.persistentSearchView.collapse();
bind.persistentSearchView.setInputQuery(query); bind.persistentSearchView.setInputQuery(query);
performSearch(query.trim()); performSearch(query.trim());
} else { } else {
Toast.makeText(requireContext(), "Enter at least two characters", Toast.LENGTH_SHORT).show(); Toast.makeText(requireContext(), "Enter at least three characters", Toast.LENGTH_SHORT).show();
} }
} }

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -12,46 +11,32 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:indeterminate="true" android:indeterminate="true"
android:minWidth="128dp" android:minWidth="128dp"
android:layout_centerInParent="true" android:layout_centerInParent="true" />
android:visibility="visible"/>
<androidx.core.widget.NestedScrollView <TextView
android:id="@+id/album_catalogue_container" android:id="@+id/album_catalogue_label"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior" android:fontFamily="@font/open_sans_font_family"
android:visibility="gone"> android:paddingStart="16dp"
android:paddingTop="20dp"
android:paddingEnd="16dp"
android:text="Album Catalogue"
android:textColor="@color/titleTextColor"
android:textSize="22sp"
android:textStyle="bold" />
<LinearLayout <androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent" android:id="@+id/album_catalogue_recycler_view"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:orientation="vertical" android:layout_height="wrap_content"
android:paddingBottom="@dimen/global_padding_bottom"> android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
<TextView android:clipToPadding="false"
android:layout_width="match_parent" android:paddingStart="16dp"
android:layout_height="wrap_content" android:paddingTop="8dp"
android:fontFamily="@font/open_sans_font_family" android:paddingEnd="16dp"
android:paddingStart="16dp" android:layout_below="@+id/album_catalogue_label"
android:paddingTop="20dp" android:paddingBottom="@dimen/global_padding_bottom"/>
android:paddingEnd="16dp"
android:text="Album Catalogue"
android:textColor="@color/titleTextColor"
android:textSize="22sp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/album_catalogue_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:clipToPadding="false"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout> </RelativeLayout>

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -14,43 +13,30 @@
android:minWidth="128dp" android:minWidth="128dp"
android:layout_centerInParent="true"/> android:layout_centerInParent="true"/>
<androidx.core.widget.NestedScrollView <TextView
android:id="@+id/artist_catalogue_container" android:id="@+id/artist_catalogue_label"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior" android:fontFamily="@font/open_sans_font_family"
android:visibility="gone"> android:paddingStart="16dp"
android:paddingTop="20dp"
android:paddingEnd="16dp"
android:text="Artist Catalogue"
android:textColor="@color/titleTextColor"
android:textSize="22sp"
android:textStyle="bold" />
<LinearLayout <androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent" android:id="@+id/artist_catalogue_recycler_view"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:orientation="vertical" android:layout_height="wrap_content"
android:paddingBottom="@dimen/global_padding_bottom"> android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
<TextView android:clipToPadding="false"
android:layout_width="match_parent" android:paddingStart="16dp"
android:layout_height="wrap_content" android:paddingTop="8dp"
android:fontFamily="@font/open_sans_font_family" android:paddingEnd="16dp"
android:paddingStart="16dp" android:layout_below="@+id/artist_catalogue_label"
android:paddingTop="20dp" android:paddingBottom="@dimen/global_padding_bottom"/>
android:paddingEnd="16dp"
android:text="Artist Catalogue"
android:textColor="@color/titleTextColor"
android:textSize="22sp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/artist_catalogue_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:clipToPadding="false"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout> </RelativeLayout>

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -14,67 +13,54 @@
android:minWidth="128dp" android:minWidth="128dp"
android:layout_centerInParent="true"/> android:layout_centerInParent="true"/>
<androidx.core.widget.NestedScrollView <!-- Label and button -->
<LinearLayout
android:id="@+id/genre_catalogue_container" android:id="@+id/genre_catalogue_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior" android:orientation="horizontal"
android:visibility="gone"> android:paddingStart="8dp"
android:paddingTop="8dp"
android:paddingEnd="8dp">
<LinearLayout <TextView
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:layout_weight="1"
android:paddingBottom="@dimen/global_padding_bottom"> android:fontFamily="@font/open_sans_font_family"
android:paddingStart="8dp"
<!-- Label and button --> android:paddingTop="12dp"
<LinearLayout android:paddingEnd="8dp"
android:layout_width="match_parent" android:text="Genre Catalogue"
android:layout_height="wrap_content" android:textColor="@color/titleTextColor"
android:orientation="horizontal" android:textSize="22sp"
android:paddingStart="8dp" android:textStyle="bold" />
android:paddingTop="8dp"
android:paddingEnd="8dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="@font/open_sans_font_family"
android:paddingStart="8dp"
android:paddingTop="12dp"
android:paddingEnd="8dp"
android:text="Genre Catalogue"
android:textColor="@color/titleTextColor"
android:textSize="22sp"
android:textStyle="bold" />
<TextView <TextView
android:id="@+id/filter_genres_text_view_clickable" android:id="@+id/filter_genres_text_view_clickable"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="@font/open_sans_font_family" android:fontFamily="@font/open_sans_font_family"
android:paddingStart="8dp" android:paddingStart="8dp"
android:paddingTop="12dp" android:paddingTop="12dp"
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:text="Filter" android:text="Filter"
android:textColor="@color/subtitleTextColor" android:textColor="@color/subtitleTextColor"
android:textSize="14sp" /> android:textSize="14sp" />
</LinearLayout> </LinearLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/genre_catalogue_recycler_view" android:id="@+id/genre_catalogue_recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:clipToPadding="false" android:clipToPadding="false"
android:paddingStart="16dp" android:paddingStart="16dp"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingEnd="16dp" android:paddingEnd="16dp"
android:paddingBottom="8dp" /> android:paddingBottom="@dimen/global_padding_bottom"
</LinearLayout> android:layout_below="@+id/genre_catalogue_container"/>
</androidx.core.widget.NestedScrollView>
</RelativeLayout> </RelativeLayout>

View file

@ -97,7 +97,8 @@
android:clipToPadding="false" android:clipToPadding="false"
android:paddingStart="8dp" android:paddingStart="8dp"
android:paddingTop="4dp" android:paddingTop="4dp"
android:paddingEnd="8dp" /> android:paddingEnd="8dp"
android:nestedScrollingEnabled="false"/>
</LinearLayout> </LinearLayout>
<!-- Search result --> <!-- Search result -->
@ -142,7 +143,8 @@
android:clipToPadding="false" android:clipToPadding="false"
android:overScrollMode="never" android:overScrollMode="never"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingBottom="24dp" /> android:paddingBottom="24dp"
android:nestedScrollingEnabled="false"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -166,7 +168,8 @@
android:paddingStart="16dp" android:paddingStart="16dp"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:paddingBottom="16dp" /> android:paddingBottom="16dp"
android:nestedScrollingEnabled="false"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -190,7 +193,8 @@
android:paddingStart="16dp" android:paddingStart="16dp"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:paddingBottom="56dp" /> android:paddingBottom="56dp"
android:nestedScrollingEnabled="false"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>

View file

@ -1,36 +1,30 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout <TextView
android:id="@+id/page_title_label"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:fontFamily="@font/open_sans_font_family"
android:paddingStart="16dp"
android:paddingTop="20dp"
android:paddingEnd="16dp"
android:text="@string/label_placeholder"
android:textColor="@color/titleTextColor"
android:textSize="22sp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
<TextView android:id="@+id/song_list_recycler_view"
android:id="@+id/page_title_label" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_height="wrap_content" android:layout_marginTop="8dp"
android:fontFamily="@font/open_sans_font_family" android:layout_marginBottom="8dp"
android:paddingStart="16dp" android:clipToPadding="false"
android:paddingTop="20dp" android:paddingTop="8dp"
android:paddingEnd="16dp" android:paddingBottom="@dimen/global_padding_bottom"/>
android:text="@string/label_placeholder" </LinearLayout>
android:textColor="@color/titleTextColor"
android:textSize="22sp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/song_list_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:clipToPadding="false"
android:paddingTop="8dp"
android:paddingBottom="@dimen/global_padding_bottom"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>