Show Avatar next to tabs when main top bar is disabled (#2973)
This commit is contained in:
parent
11cf420320
commit
4de778d7d4
|
@ -384,9 +384,11 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
|
||||||
|
|
||||||
private fun setupDrawer(savedInstanceState: Bundle?, addSearchButton: Boolean) {
|
private fun setupDrawer(savedInstanceState: Bundle?, addSearchButton: Boolean) {
|
||||||
|
|
||||||
binding.mainToolbar.setNavigationOnClickListener {
|
val drawerOpenClickListener = View.OnClickListener { binding.mainDrawerLayout.open() }
|
||||||
binding.mainDrawerLayout.open()
|
|
||||||
}
|
binding.mainToolbar.setNavigationOnClickListener(drawerOpenClickListener)
|
||||||
|
binding.topNavAvatar.setOnClickListener(drawerOpenClickListener)
|
||||||
|
binding.bottomNavAvatar.setOnClickListener(drawerOpenClickListener)
|
||||||
|
|
||||||
header = AccountHeaderView(this).apply {
|
header = AccountHeaderView(this).apply {
|
||||||
headerBackgroundScaleType = ImageView.ScaleType.CENTER_CROP
|
headerBackgroundScaleType = ImageView.ScaleType.CENTER_CROP
|
||||||
|
@ -576,7 +578,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
|
||||||
val actionBarSize = ThemeUtils.getDimension(this, R.attr.actionBarSize)
|
val actionBarSize = ThemeUtils.getDimension(this, R.attr.actionBarSize)
|
||||||
val fabMargin = resources.getDimensionPixelSize(R.dimen.fabMargin)
|
val fabMargin = resources.getDimensionPixelSize(R.dimen.fabMargin)
|
||||||
(binding.composeButton.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = actionBarSize + fabMargin
|
(binding.composeButton.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = actionBarSize + fabMargin
|
||||||
binding.tabLayout.hide()
|
binding.topNav.hide()
|
||||||
binding.bottomTabLayout
|
binding.bottomTabLayout
|
||||||
} else {
|
} else {
|
||||||
binding.bottomNav.hide()
|
binding.bottomNav.hide()
|
||||||
|
@ -749,71 +751,117 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadDrawerAvatar(avatarUrl: String, showPlaceholder: Boolean) {
|
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)
|
val animateAvatars = preferences.getBoolean("animateGifAvatars", false)
|
||||||
|
|
||||||
if (animateAvatars) {
|
if (hideTopToolbar) {
|
||||||
glide.asDrawable()
|
val navOnBottom = preferences.getString("mainNavPosition", "top") == "bottom"
|
||||||
.load(avatarUrl)
|
|
||||||
.transform(
|
|
||||||
RoundedCorners(resources.getDimensionPixelSize(R.dimen.avatar_radius_36dp))
|
|
||||||
)
|
|
||||||
.apply {
|
|
||||||
if (showPlaceholder) {
|
|
||||||
placeholder(R.drawable.avatar_default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.into(object : CustomTarget<Drawable>(navIconSize, navIconSize) {
|
|
||||||
|
|
||||||
override fun onLoadStarted(placeholder: Drawable?) {
|
val avatarView = if (navOnBottom) {
|
||||||
if (placeholder != null) {
|
binding.bottomNavAvatar.show()
|
||||||
binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
binding.bottomNavAvatar
|
||||||
}
|
} else {
|
||||||
}
|
binding.topNavAvatar.show()
|
||||||
|
binding.topNavAvatar
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
|
if (animateAvatars) {
|
||||||
if (resource is Animatable) {
|
Glide.with(this)
|
||||||
resource.start()
|
.load(avatarUrl)
|
||||||
}
|
.placeholder(R.drawable.avatar_default)
|
||||||
binding.mainToolbar.navigationIcon = FixedSizeDrawable(resource, navIconSize, navIconSize)
|
.into(avatarView)
|
||||||
}
|
} else {
|
||||||
|
Glide.with(this)
|
||||||
override fun onLoadCleared(placeholder: Drawable?) {
|
.asBitmap()
|
||||||
if (placeholder != null) {
|
.load(avatarUrl)
|
||||||
binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
.placeholder(R.drawable.avatar_default)
|
||||||
}
|
.into(avatarView)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
} else {
|
} 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<Bitmap>(navIconSize, navIconSize) {
|
|
||||||
|
|
||||||
override fun onLoadStarted(placeholder: Drawable?) {
|
binding.bottomNavAvatar.hide()
|
||||||
if (placeholder != null) {
|
binding.topNavAvatar.hide()
|
||||||
binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
|
||||||
|
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<Drawable>(navIconSize, navIconSize) {
|
||||||
|
|
||||||
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
|
override fun onLoadStarted(placeholder: Drawable?) {
|
||||||
binding.mainToolbar.navigationIcon = FixedSizeDrawable(BitmapDrawable(resources, resource), navIconSize, navIconSize)
|
if (placeholder != null) {
|
||||||
}
|
binding.mainToolbar.navigationIcon =
|
||||||
|
FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onLoadCleared(placeholder: Drawable?) {
|
override fun onResourceReady(
|
||||||
if (placeholder != null) {
|
resource: Drawable,
|
||||||
binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
transition: Transition<in Drawable>?
|
||||||
|
) {
|
||||||
|
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<Bitmap>(navIconSize, navIconSize) {
|
||||||
|
|
||||||
|
override fun onLoadStarted(placeholder: Drawable?) {
|
||||||
|
if (placeholder != null) {
|
||||||
|
binding.mainToolbar.navigationIcon =
|
||||||
|
FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResourceReady(
|
||||||
|
resource: Bitmap,
|
||||||
|
transition: Transition<in Bitmap>?
|
||||||
|
) {
|
||||||
|
binding.mainToolbar.navigationIcon = FixedSizeDrawable(
|
||||||
|
BitmapDrawable(resources, resource),
|
||||||
|
navIconSize,
|
||||||
|
navIconSize
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLoadCleared(placeholder: Drawable?) {
|
||||||
|
if (placeholder != null) {
|
||||||
|
binding.mainToolbar.navigationIcon =
|
||||||
|
FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,14 +29,31 @@
|
||||||
app:layout_scrollFlags="scroll|enterAlways"
|
app:layout_scrollFlags="scroll|enterAlways"
|
||||||
app:navigationContentDescription="@string/action_open_drawer" />
|
app:navigationContentDescription="@string/action_open_drawer" />
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabLayout
|
<LinearLayout
|
||||||
android:id="@+id/tabLayout"
|
android:id="@+id/topNav"
|
||||||
style="@style/TuskyTabAppearance"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:tabGravity="fill"
|
android:orientation="horizontal">
|
||||||
app:tabMaxWidth="0dp"
|
|
||||||
app:tabMode="fixed" />
|
<com.google.android.material.imageview.ShapeableImageView
|
||||||
|
android:id="@+id/topNavAvatar"
|
||||||
|
android:layout_width="36dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:background="@drawable/avatar_default"
|
||||||
|
app:shapeAppearance="@style/ShapeAppearance.Avatar" />
|
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabLayout
|
||||||
|
android:id="@+id/tabLayout"
|
||||||
|
style="@style/TuskyTabAppearance"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:tabGravity="fill"
|
||||||
|
app:tabMaxWidth="0dp"
|
||||||
|
app:tabMode="fixed" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
@ -56,13 +73,30 @@
|
||||||
app:contentInsetStart="0dp"
|
app:contentInsetStart="0dp"
|
||||||
app:fabAlignmentMode="end">
|
app:fabAlignmentMode="end">
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabLayout
|
<LinearLayout
|
||||||
android:id="@+id/bottomTabLayout"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="wrap_content"
|
||||||
app:tabIndicator="@null"
|
android:orientation="horizontal">
|
||||||
app:tabGravity="fill"
|
|
||||||
app:tabMode="fixed" />
|
<com.google.android.material.imageview.ShapeableImageView
|
||||||
|
android:id="@+id/bottomNavAvatar"
|
||||||
|
android:layout_width="36dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:background="@drawable/avatar_default"
|
||||||
|
app:shapeAppearance="@style/ShapeAppearance.Avatar" />
|
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabLayout
|
||||||
|
android:id="@+id/bottomTabLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
app:tabGravity="fill"
|
||||||
|
app:tabIndicator="@null"
|
||||||
|
app:tabMode="fixed" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</com.google.android.material.bottomappbar.BottomAppBar>
|
</com.google.android.material.bottomappbar.BottomAppBar>
|
||||||
|
|
||||||
|
@ -82,8 +116,8 @@
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progressBar"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone"
|
android:layout_gravity="center"
|
||||||
android:layout_gravity="center" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
|
||||||
|
|
|
@ -167,4 +167,9 @@
|
||||||
<item name="materialDrawerDrawCircularShadow">false</item>
|
<item name="materialDrawerDrawCircularShadow">false</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="ShapeAppearance.Avatar" parent="ShapeAppearance.MaterialComponents">
|
||||||
|
<item name="cornerFamily">rounded</item>
|
||||||
|
<item name="cornerSize">12.5%</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue