From 4de778d7d4d623dd08649f13aa4e7b29a4815a6e Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sat, 3 Dec 2022 12:16:54 +0100 Subject: [PATCH] Show Avatar next to tabs when main top bar is disabled (#2973) --- .../com/keylesspalace/tusky/MainActivity.kt | 160 ++++++++++++------ app/src/main/res/layout/activity_main.xml | 62 +++++-- app/src/main/res/values/styles.xml | 5 + 3 files changed, 157 insertions(+), 70 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt b/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt index a8056fbd3..4a3d2da1b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt @@ -384,9 +384,11 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje private fun setupDrawer(savedInstanceState: Bundle?, addSearchButton: Boolean) { - binding.mainToolbar.setNavigationOnClickListener { - binding.mainDrawerLayout.open() - } + val drawerOpenClickListener = View.OnClickListener { binding.mainDrawerLayout.open() } + + binding.mainToolbar.setNavigationOnClickListener(drawerOpenClickListener) + binding.topNavAvatar.setOnClickListener(drawerOpenClickListener) + binding.bottomNavAvatar.setOnClickListener(drawerOpenClickListener) header = AccountHeaderView(this).apply { headerBackgroundScaleType = ImageView.ScaleType.CENTER_CROP @@ -576,7 +578,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje val actionBarSize = ThemeUtils.getDimension(this, R.attr.actionBarSize) val fabMargin = resources.getDimensionPixelSize(R.dimen.fabMargin) (binding.composeButton.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = actionBarSize + fabMargin - binding.tabLayout.hide() + binding.topNav.hide() binding.bottomTabLayout } else { binding.bottomNav.hide() @@ -749,71 +751,117 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje } private fun loadDrawerAvatar(avatarUrl: String, showPlaceholder: Boolean) { - val navIconSize = resources.getDimensionPixelSize(R.dimen.avatar_toolbar_nav_icon_size) + val hideTopToolbar = preferences.getBoolean(PrefKeys.HIDE_TOP_TOOLBAR, false) val animateAvatars = preferences.getBoolean("animateGifAvatars", false) - if (animateAvatars) { - glide.asDrawable() - .load(avatarUrl) - .transform( - RoundedCorners(resources.getDimensionPixelSize(R.dimen.avatar_radius_36dp)) - ) - .apply { - if (showPlaceholder) { - placeholder(R.drawable.avatar_default) - } - } - .into(object : CustomTarget(navIconSize, navIconSize) { + if (hideTopToolbar) { + val navOnBottom = preferences.getString("mainNavPosition", "top") == "bottom" - override fun onLoadStarted(placeholder: Drawable?) { - if (placeholder != null) { - binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize) - } - } + val avatarView = if (navOnBottom) { + binding.bottomNavAvatar.show() + binding.bottomNavAvatar + } else { + binding.topNavAvatar.show() + binding.topNavAvatar + } - override fun onResourceReady(resource: Drawable, transition: Transition?) { - if (resource is Animatable) { - resource.start() - } - binding.mainToolbar.navigationIcon = FixedSizeDrawable(resource, navIconSize, navIconSize) - } - - override fun onLoadCleared(placeholder: Drawable?) { - if (placeholder != null) { - binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize) - } - } - }) + if (animateAvatars) { + Glide.with(this) + .load(avatarUrl) + .placeholder(R.drawable.avatar_default) + .into(avatarView) + } else { + Glide.with(this) + .asBitmap() + .load(avatarUrl) + .placeholder(R.drawable.avatar_default) + .into(avatarView) + } } else { - glide.asBitmap() - .load(avatarUrl) - .transform( - RoundedCorners(resources.getDimensionPixelSize(R.dimen.avatar_radius_36dp)) - ) - .apply { - if (showPlaceholder) { - placeholder(R.drawable.avatar_default) - } - } - .into(object : CustomTarget(navIconSize, navIconSize) { - override fun onLoadStarted(placeholder: Drawable?) { - if (placeholder != null) { - binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize) + binding.bottomNavAvatar.hide() + binding.topNavAvatar.hide() + + val navIconSize = resources.getDimensionPixelSize(R.dimen.avatar_toolbar_nav_icon_size) + + if (animateAvatars) { + glide.asDrawable() + .load(avatarUrl) + .transform( + RoundedCorners(resources.getDimensionPixelSize(R.dimen.avatar_radius_36dp)) + ) + .apply { + if (showPlaceholder) { + placeholder(R.drawable.avatar_default) } } + .into(object : CustomTarget(navIconSize, navIconSize) { - override fun onResourceReady(resource: Bitmap, transition: Transition?) { - binding.mainToolbar.navigationIcon = FixedSizeDrawable(BitmapDrawable(resources, resource), navIconSize, navIconSize) - } + override fun onLoadStarted(placeholder: Drawable?) { + if (placeholder != null) { + binding.mainToolbar.navigationIcon = + FixedSizeDrawable(placeholder, navIconSize, navIconSize) + } + } - override fun onLoadCleared(placeholder: Drawable?) { - if (placeholder != null) { - binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize) + override fun onResourceReady( + resource: Drawable, + transition: Transition? + ) { + if (resource is Animatable) { + resource.start() + } + binding.mainToolbar.navigationIcon = + FixedSizeDrawable(resource, navIconSize, navIconSize) + } + + override fun onLoadCleared(placeholder: Drawable?) { + if (placeholder != null) { + binding.mainToolbar.navigationIcon = + FixedSizeDrawable(placeholder, navIconSize, navIconSize) + } + } + }) + } else { + glide.asBitmap() + .load(avatarUrl) + .transform( + RoundedCorners(resources.getDimensionPixelSize(R.dimen.avatar_radius_36dp)) + ) + .apply { + if (showPlaceholder) { + placeholder(R.drawable.avatar_default) } } - }) + .into(object : CustomTarget(navIconSize, navIconSize) { + + override fun onLoadStarted(placeholder: Drawable?) { + if (placeholder != null) { + binding.mainToolbar.navigationIcon = + FixedSizeDrawable(placeholder, navIconSize, navIconSize) + } + } + + override fun onResourceReady( + resource: Bitmap, + transition: Transition? + ) { + binding.mainToolbar.navigationIcon = FixedSizeDrawable( + BitmapDrawable(resources, resource), + navIconSize, + navIconSize + ) + } + + override fun onLoadCleared(placeholder: Drawable?) { + if (placeholder != null) { + binding.mainToolbar.navigationIcon = + FixedSizeDrawable(placeholder, navIconSize, navIconSize) + } + } + }) + } } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3fcd87444..9c993615e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -29,14 +29,31 @@ app:layout_scrollFlags="scroll|enterAlways" app:navigationContentDescription="@string/action_open_drawer" /> - + android:orientation="horizontal"> + + + + + @@ -56,13 +73,30 @@ app:contentInsetStart="0dp" app:fabAlignmentMode="end"> - + android:layout_height="wrap_content" + android:orientation="horizontal"> + + + + + + @@ -82,8 +116,8 @@ android:id="@+id/progressBar" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:visibility="gone" - android:layout_gravity="center" /> + android:layout_gravity="center" + android:visibility="gone" /> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 4b59c733d..1f0704da9 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -167,4 +167,9 @@ false + +