mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 05:05:31 +03:00
Theme fast scrollbars
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
ea4de13d9f
commit
5cf85fd2c8
6 changed files with 51 additions and 47 deletions
|
@ -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 {
|
||||
|
|
|
@ -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(
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue