diff --git a/app/build.gradle b/app/build.gradle index c3dfcb795d..2bef990cd4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -355,7 +355,7 @@ dependencies { gplayImplementation "com.google.firebase:firebase-messaging:23.0.7" // TODO change back to tag before merging - implementation 'com.github.nextcloud.android-common:ui:02c7b05' + implementation 'com.github.nextcloud.android-common:ui:32da702' } configurations.all { diff --git a/app/src/main/java/com/nextcloud/utils/view/FastScroll.kt b/app/src/main/java/com/nextcloud/utils/view/FastScrollUtils.kt similarity index 63% rename from app/src/main/java/com/nextcloud/utils/view/FastScroll.kt rename to app/src/main/java/com/nextcloud/utils/view/FastScrollUtils.kt index 1244de43e0..7064341837 100644 --- a/app/src/main/java/com/nextcloud/utils/view/FastScroll.kt +++ b/app/src/main/java/com/nextcloud/utils/view/FastScrollUtils.kt @@ -27,37 +27,26 @@ package com.nextcloud.utils.view -import android.content.Context -import android.graphics.drawable.Drawable import android.view.ViewGroup -import androidx.annotation.ColorInt -import androidx.core.content.res.ResourcesCompat import androidx.recyclerview.widget.RecyclerView import com.google.android.material.appbar.AppBarLayout -import com.owncloud.android.utils.theme.ThemeColorUtils -import com.owncloud.android.utils.theme.ThemeDrawableUtils +import com.owncloud.android.utils.theme.newm3.ViewThemeUtils import me.zhanghai.android.fastscroll.FastScroller import me.zhanghai.android.fastscroll.FastScrollerBuilder -import me.zhanghai.android.fastscroll.PopupStyles +import javax.inject.Inject -object FastScroll { - - @JvmStatic +class FastScrollUtils @Inject constructor(private val viewThemeUtils: ViewThemeUtils) { @JvmOverloads fun applyFastScroll( - context: Context, - themeColorUtils: ThemeColorUtils, - themeDrawableUtils: ThemeDrawableUtils, recyclerView: RecyclerView, viewHelper: FastScroller.ViewHelper? = null ) { - val primaryColor = themeColorUtils.primaryColor(context) - val builder = FastScrollerBuilder(recyclerView) - .useMd2Style() - .setThumbDrawable(getThumbDrawable(context, themeDrawableUtils, primaryColor)) - .setPopupStyle { - PopupStyles.MD2.accept(it) - it.background = FastScrollPopupBackground(context, primaryColor) + val builder = + FastScrollerBuilder(recyclerView).let { + viewThemeUtils.files.themeFastScrollerBuilder( + recyclerView.context, + it + ) } if (viewHelper != null) { builder.setViewHelper(viewHelper) @@ -65,22 +54,6 @@ object FastScroll { builder.build() } - private fun getThumbDrawable( - context: Context, - themeDrawableUtils: ThemeDrawableUtils, - @ColorInt color: Int - ): Drawable { - val thumbDrawable = - ResourcesCompat.getDrawable( - context.resources, - me.zhanghai.android.fastscroll.R.drawable.afs_md2_thumb, - null - ) - themeDrawableUtils.tintDrawable(thumbDrawable, color) - return thumbDrawable!! - } - - @JvmStatic fun fixAppBarForFastScroll(appBarLayout: AppBarLayout, content: ViewGroup) { val contentLayoutInitialPaddingBottom = content.paddingBottom appBarLayout.addOnOffsetChangedListener( diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index af11b84e88..9dda467bd1 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -65,7 +65,7 @@ import com.nextcloud.client.network.ConnectivityService; import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.utils.IntentUtil; import com.nextcloud.java.util.Optional; -import com.nextcloud.utils.view.FastScroll; +import com.nextcloud.utils.view.FastScrollUtils; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.databinding.FilesBinding; @@ -231,6 +231,9 @@ public class FileDisplayActivity extends FileActivity @Inject ConnectivityService connectivityService; + @Inject + FastScrollUtils fastScrollUtils; + public static Intent openFileIntent(Context context, User user, OCFile file) { final Intent intent = new Intent(context, PreviewImageActivity.class); intent.putExtra(FileActivity.EXTRA_FILE, file); @@ -272,7 +275,7 @@ public class FileDisplayActivity extends FileActivity mSwitchAccountButton.setOnClickListener(v -> showManageAccountsDialog()); - FastScroll.fixAppBarForFastScroll(binding.appbar.appbar, binding.rootLayout); + fastScrollUtils.fixAppBarForFastScroll(binding.appbar.appbar, binding.rootLayout); // Init Fragment without UI to retain AsyncTask across configuration changes diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java index a9ea041700..1b3883892b 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java @@ -34,7 +34,7 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import com.nextcloud.utils.view.FastScroll; +import com.nextcloud.utils.view.FastScrollUtils; import com.owncloud.android.R; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; @@ -74,6 +74,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme private GalleryFragmentBottomSheetDialog galleryFragmentBottomSheetDialog; @Inject FileDataStorageManager fileDataStorageManager; + @Inject FastScrollUtils fastScrollUtils; @Override public void onCreate(Bundle savedInstanceState) { @@ -148,11 +149,9 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme mAdapter.setLayoutManager(layoutManager); getRecyclerView().setLayoutManager(layoutManager); - FastScroll.applyFastScroll(requireContext(), - themeColorUtils, - themeDrawableUtils, - getRecyclerView(), - new GalleryFastScrollViewHelper(getRecyclerView(), mAdapter)); + fastScrollUtils.applyFastScroll( + getRecyclerView(), + new GalleryFastScrollViewHelper(getRecyclerView(), mAdapter)); } @Override diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index ce97754609..73438989f6 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -58,7 +58,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.nextcloud.utils.view.FastScrollUtils; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.ArbitraryDataProvider; @@ -198,6 +198,7 @@ public class OCFileListFragment extends ExtendedListFragment implements @Inject ArbitraryDataProvider arbitraryDataProvider; @Inject BackgroundJobManager backgroundJobManager; @Inject ViewThemeUtils viewThemeUtils; + @Inject FastScrollUtils fastScrollUtils; protected FileFragment.ContainerActivity mContainerActivity; @@ -429,7 +430,7 @@ public class OCFileListFragment extends ExtendedListFragment implements setRecyclerViewAdapter(mAdapter); - FastScroll.applyFastScroll(requireContext(), themeColorUtils, themeDrawableUtils, getRecyclerView()); + fastScrollUtils.applyFastScroll(getRecyclerView()); } protected void prepareCurrentSearch(SearchEvent event) { diff --git a/app/src/main/java/com/owncloud/android/utils/theme/newm3/FilesSpecificViewThemeUtils.kt b/app/src/main/java/com/owncloud/android/utils/theme/newm3/FilesSpecificViewThemeUtils.kt index cf7fcf7278..13f66962d7 100644 --- a/app/src/main/java/com/owncloud/android/utils/theme/newm3/FilesSpecificViewThemeUtils.kt +++ b/app/src/main/java/com/owncloud/android/utils/theme/newm3/FilesSpecificViewThemeUtils.kt @@ -24,6 +24,7 @@ package com.owncloud.android.utils.theme.newm3 import android.content.Context import android.graphics.PorterDuff +import android.graphics.drawable.Drawable import android.preference.PreferenceCategory import android.text.Spannable import android.text.SpannableString @@ -35,9 +36,12 @@ import androidx.core.content.res.ResourcesCompat import com.nextcloud.android.common.ui.theme.MaterialSchemes import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase import com.nextcloud.android.common.ui.theme.utils.AndroidViewThemeUtils +import com.nextcloud.utils.view.FastScrollPopupBackground import com.owncloud.android.R import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.shares.ShareType +import me.zhanghai.android.fastscroll.FastScrollerBuilder +import me.zhanghai.android.fastscroll.PopupStyles import javax.inject.Inject class FilesSpecificViewThemeUtils @Inject constructor( @@ -99,6 +103,30 @@ class FilesSpecificViewThemeUtils @Inject constructor( } } + fun themeFastScrollerBuilder(context: Context, builder: FastScrollerBuilder): FastScrollerBuilder { + return withScheme(context) { scheme -> + builder + .useMd2Style() + .setThumbDrawable(getThumbDrawable(context)) + .setPopupStyle { + PopupStyles.MD2.accept(it) + it.background = FastScrollPopupBackground(context, scheme.primary) + } + } + } + + private fun getThumbDrawable( + context: Context + ): Drawable { + val thumbDrawable = + ResourcesCompat.getDrawable( + context.resources, + me.zhanghai.android.fastscroll.R.drawable.afs_md2_thumb, + null + ) + return androidViewThemeUtils.tintPrimaryDrawable(context, thumbDrawable)!! + } + companion object { private val TAG = FilesSpecificViewThemeUtils::class.simpleName