瀏覽代碼

Replace fastscroll library

Smoother scrolling

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 3 年之前
父節點
當前提交
12312393b2

+ 1 - 1
app/build.gradle

@@ -272,7 +272,7 @@ dependencies {
     implementation "com.google.android.exoplayer:exoplayer:$exoplayerVersion"
     implementation "com.google.android.exoplayer:extension-okhttp:$exoplayerVersion"
 
-    implementation 'com.simplecityapps:recyclerview-fastscroll:2.0.1'
+    implementation 'me.zhanghai.android.fastscroll:library:1.1.8'
     
     // Shimmer animation
     implementation 'io.github.elye:loaderviewlibrary:3.0.0'

+ 38 - 0
app/src/main/java/com/nextcloud/utils/view/FastScroll.kt

@@ -0,0 +1,38 @@
+/*
+ *  Nextcloud Android Library is available under MIT license
+ *
+ *  @author Álvaro Brey Vilas
+ *  Copyright (C) 2022 Álvaro Brey Vilas
+ *  Copyright (C) 2022 Nextcloud GmbH
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
+ *  of this software and associated documentation files (the "Software"), to deal
+ *  in the Software without restriction, including without limitation the rights
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ *  copies of the Software, and to permit persons to whom the Software is
+ *  furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ *  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ *  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ *  THE SOFTWARE.
+ */
+
+package com.nextcloud.utils.view
+
+import androidx.recyclerview.widget.RecyclerView
+import me.zhanghai.android.fastscroll.FastScrollerBuilder
+
+object FastScroll {
+    @JvmStatic
+    fun applyFastScroll(rv: RecyclerView) {
+        FastScrollerBuilder(rv).useMd2Style().build()
+    }
+}

+ 2 - 3
app/src/main/java/com/owncloud/android/ui/EmptyRecyclerView.java

@@ -25,14 +25,13 @@ import android.content.Context;
 import android.util.AttributeSet;
 import android.view.View;
 
-import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
-
 import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.RecyclerView;
 
 /**
  * Extends RecyclerView to show a custom view if no data is available Inspired by http://alexzh.com/tutorials/how-to-setemptyview-to-recyclerview
  */
-public class EmptyRecyclerView extends FastScrollRecyclerView {
+public class EmptyRecyclerView extends RecyclerView {
     private View mEmptyView;
     private boolean hasFooter = false;
 

+ 3 - 3
app/src/main/java/com/owncloud/android/ui/adapter/GalleryAdapter.kt

@@ -45,7 +45,7 @@ import com.owncloud.android.utils.FileSortOrder
 import com.owncloud.android.utils.FileStorageUtils
 import com.owncloud.android.utils.theme.ThemeColorUtils
 import com.owncloud.android.utils.theme.ThemeDrawableUtils
-import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView.SectionedAdapter
+import me.zhanghai.android.fastscroll.PopupTextProvider
 import java.util.Calendar
 import java.util.Date
 
@@ -58,7 +58,7 @@ class GalleryAdapter(
     transferServiceGetter: ComponentsGetter,
     themeColorUtils: ThemeColorUtils,
     themeDrawableUtils: ThemeDrawableUtils
-) : SectionedRecyclerViewAdapter<SectionedViewHolder>(), CommonOCFileListAdapterInterface, SectionedAdapter {
+) : SectionedRecyclerViewAdapter<SectionedViewHolder>(), CommonOCFileListAdapterInterface, PopupTextProvider {
     private var files: List<GalleryItems> = mutableListOf()
     private val ocFileListDelegate: OCFileListDelegate
     private var storageManager: FileDataStorageManager
@@ -122,7 +122,7 @@ class GalleryAdapter(
         return files.size
     }
 
-    override fun getSectionName(position: Int): String {
+    override fun getPopupText(position: Int): String {
         return DisplayUtils.getDateByPattern(
             files[getRelativePosition(position).section()].date,
             context,

+ 3 - 4
app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -74,7 +74,6 @@ import com.owncloud.android.utils.theme.CapabilityUtils;
 import com.owncloud.android.utils.theme.ThemeAvatarUtils;
 import com.owncloud.android.utils.theme.ThemeColorUtils;
 import com.owncloud.android.utils.theme.ThemeDrawableUtils;
-import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
 
 import java.io.File;
 import java.text.SimpleDateFormat;
@@ -90,14 +89,14 @@ import androidx.annotation.Nullable;
 import androidx.annotation.VisibleForTesting;
 import androidx.recyclerview.widget.RecyclerView;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import me.zhanghai.android.fastscroll.PopupTextProvider;
 
 /**
  * This Adapter populates a RecyclerView with all files and folders in a Nextcloud instance.
  */
 public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
     implements DisplayUtils.AvatarGenerationListener,
-    CommonOCFileListAdapterInterface,
-    FastScrollRecyclerView.SectionedAdapter {
+    CommonOCFileListAdapterInterface, PopupTextProvider {
 
     private static final int showFilenameColumnThreshold = 4;
     private final String userId;
@@ -909,7 +908,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
 
     @NonNull
     @Override
-    public String getSectionName(int position) {
+    public String getPopupText(int position) {
         OCFile file = getItem(position);
 
         if (file == null) {

+ 3 - 14
app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java

@@ -27,6 +27,7 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 
+import com.nextcloud.utils.view.FastScroll;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.utils.Log_OC;
@@ -109,26 +110,14 @@ public class GalleryFragment extends OCFileListFragment {
                                       themeColorUtils,
                                       themeDrawableUtils);
 
-//        val spacing = resources.getDimensionPixelSize(R.dimen.media_grid_spacing)
-//        binding.list.addItemDecoration(MediaGridItemDecoration(spacing))
         setRecyclerViewAdapter(mAdapter);
 
 
         GridLayoutManager layoutManager = new GridLayoutManager(getContext(), getColumnsCount());
-//        ((GridLayoutManager) layoutManager).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
-//            @Override
-//            public int getSpanSize(int position) {
-//                if (position == getAdapter().getItemCount() - 1 ||
-//                    position == 0 && getAdapter().shouldShowHeader()) {
-//                    return ((GridLayoutManager) layoutManager).getSpanCount();
-//                } else {
-//                    return 1;
-//                }
-//            }
-//        });
-
         mAdapter.setLayoutManager(layoutManager);
         getRecyclerView().setLayoutManager(layoutManager);
+
+        FastScroll.applyFastScroll(getRecyclerView());
     }
 
     @Override

+ 3 - 0
app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -59,6 +59,7 @@ import com.nextcloud.client.network.ClientFactory;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.client.utils.Throttler;
 import com.nextcloud.common.NextcloudClient;
+import com.nextcloud.utils.view.FastScroll;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
@@ -429,6 +430,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
         );
 
         setRecyclerViewAdapter(mAdapter);
+
+        FastScroll.applyFastScroll(getRecyclerView());
     }
 
     protected void prepareCurrentSearch(SearchEvent event) {

+ 1 - 6
app/src/main/res/layout/list_fragment.xml

@@ -33,12 +33,7 @@
         <com.owncloud.android.ui.EmptyRecyclerView
             android:id="@+id/list_root"
             android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            app:fastScrollPopupBgColor="@color/color_accent"
-            app:fastScrollPopupTextColor="@color/login_text_color"
-            app:fastScrollThumbColor="@color/color_accent"
-            app:fastScrollAutoHide="true"
-            app:fastScrollAutoHideDelay="1500" />
+            android:layout_height="match_parent" />
     </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
 
     <include