Display mastodon account domain

This commit is contained in:
Tlaster 2020-05-18 13:04:53 +08:00
parent f49b77bfce
commit 9ae74b04f7
5 changed files with 36 additions and 40 deletions

View File

@ -20,10 +20,10 @@
package org.mariotaku.twidere.adapter
import android.content.Context
import androidx.recyclerview.widget.RecyclerViewAccessor
import android.view.View
import android.view.ViewGroup
import android.widget.CompoundButton
import androidx.recyclerview.widget.RecyclerViewAccessor
import com.bumptech.glide.RequestManager
import org.mariotaku.twidere.R
import org.mariotaku.twidere.model.AccountDetails
@ -59,8 +59,9 @@ class AccountDetailsAdapter(
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val view = super.getView(position, convertView, parent)
val showType = objects.groupBy { it.type }.count().let { it > 1 }
val holder = view.tag as? AccountViewHolder ?: run {
val h = AccountViewHolder(this, view)
val h = AccountViewHolder(this, view, showType)
view.tag = h
return@run h
}

View File

@ -26,6 +26,7 @@ import com.bumptech.glide.RequestManager
import kotlinx.android.synthetic.main.list_item_simple_user.view.*
import org.mariotaku.ktextension.spannable
import org.mariotaku.twidere.R
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.extension.loadProfileImage
import org.mariotaku.twidere.model.AccountDetails
import org.mariotaku.twidere.model.UserKey
@ -63,7 +64,12 @@ class AccountsSpinnerAdapter(
text1?.visibility = View.VISIBLE
text1?.spannable = item.user.name
text2?.visibility = View.VISIBLE
text2?.spannable = "@${item.user.screen_name}"
val showType = objects.filter { it.type != null }.groupBy { it.type }.count().let { it > 1 }
text2?.spannable = if (item.type == AccountType.MASTODON) {
item.account.name
} else {
"${if (showType) item.type else ""}@${item.user.screen_name}"
}
if (icon != null) {
if (profileImageEnabled) {
icon.visibility = View.VISIBLE

View File

@ -38,20 +38,20 @@ import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Bundle
import com.google.android.material.navigation.NavigationView
import androidx.loader.app.LoaderManager.LoaderCallbacks
import androidx.core.content.ContextCompat
import androidx.loader.content.FixedAsyncTaskLoader
import androidx.loader.content.Loader
import androidx.core.view.MenuItemCompat
import androidx.viewpager.widget.ViewPager
import androidx.appcompat.view.SupportMenuInflater
import androidx.appcompat.widget.ActionMenuView.OnMenuItemClickListener
import android.view.*
import android.view.View.OnClickListener
import android.view.animation.DecelerateInterpolator
import android.widget.ImageView
import androidx.appcompat.view.SupportMenuInflater
import androidx.appcompat.widget.ActionMenuView.OnMenuItemClickListener
import androidx.core.content.ContextCompat
import androidx.core.view.MenuItemCompat
import androidx.core.view.isVisible
import androidx.loader.app.LoaderManager.LoaderCallbacks
import androidx.loader.content.FixedAsyncTaskLoader
import androidx.loader.content.Loader
import androidx.viewpager.widget.ViewPager
import com.google.android.material.navigation.NavigationView
import kotlinx.android.synthetic.main.header_drawer_account_selector.view.*
import org.mariotaku.chameleon.Chameleon
import org.mariotaku.kpreferences.get
@ -109,7 +109,6 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
private val floatingProfileImageSnapshot by lazy { accountsHeader.floatingProfileImageSnapshot }
private val accountProfileImageView by lazy { accountsHeader.profileImage }
private val accountProfileNameView by lazy { accountsHeader.name }
private val accountUserTypeView by lazy { accountsHeader.user_type }
private val accountProfileScreenNameView by lazy { accountsHeader.screenName }
private val accountDashboardMenu by lazy { accountsHeader.accountDashboardMenu }
private val profileContainer by lazy { accountsHeader.profileContainer }
@ -550,13 +549,14 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
if (context == null || isDetached || (activity?.isFinishing != false)) return
val account = accountsAdapter.selectedAccount ?: return
accountProfileNameView.spannable = account.user.name
accountsAdapter.accounts?.groupBy { it.type }?.count()?.let {
val showType = accountsAdapter.accounts?.groupBy { it.type }?.count()?.let {
it > 1
}?.let {
accountUserTypeView.isVisible = it
} ?: false
accountProfileScreenNameView.spannable = if (account.type == AccountType.MASTODON) {
account.account.name
} else {
"${if (showType) account.type else ""}@${account.user.screen_name}"
}
accountUserTypeView.spannable = account.type
accountProfileScreenNameView.spannable = "@${account.user.screen_name}"
requestManager.loadProfileImage(context!!, account, preferences[profileImageStyleKey],
accountProfileImageView.cornerRadius, accountProfileImageView.cornerRadiusRatio,
ProfileImageSize.REASONABLY_SMALL).placeholder(profileImageSnapshot).into(accountProfileImageView)

View File

@ -19,14 +19,15 @@
package org.mariotaku.twidere.view.holder
import androidx.recyclerview.widget.RecyclerView
import android.view.View
import android.widget.CompoundButton
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import org.mariotaku.ktextension.spannable
import org.mariotaku.twidere.R
import org.mariotaku.twidere.adapter.AccountDetailsAdapter
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.extension.loadProfileImage
import org.mariotaku.twidere.model.AccountDetails
import org.mariotaku.twidere.model.util.AccountUtils
@ -35,7 +36,8 @@ import org.mariotaku.twidere.view.iface.IColorLabelView
class AccountViewHolder(
val adapter: AccountDetailsAdapter,
itemView: View
itemView: View,
val showType: Boolean
) : RecyclerView.ViewHolder(itemView) {
private val content = itemView as IColorLabelView
@ -61,7 +63,11 @@ class AccountViewHolder(
fun display(details: AccountDetails) {
name.spannable = details.user.name
screenName.spannable = "@${details.user.screen_name}"
screenName.spannable = if (details.type == AccountType.MASTODON) {
details.account.name
} else {
"${if (showType) details.type else ""}@${details.user.screen_name}"
}
setAccountColor(details.color)
profileImage.visibility = View.VISIBLE
adapter.requestManager.loadProfileImage(adapter.context, details, adapter.profileImageStyle,

View File

@ -125,7 +125,7 @@
android:gravity="center_vertical"
android:orientation="horizontal">
<RelativeLayout
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -133,8 +133,6 @@
android:orientation="vertical">
<org.mariotaku.twidere.view.FixedTextView
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -147,8 +145,6 @@
tools:text="Name"/>
<org.mariotaku.twidere.view.FixedTextView
android:layout_below="@id/name"
android:layout_toEndOf="@id/user_type"
android:id="@+id/screenName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -159,20 +155,7 @@
android:textColor="@color/material_grey"
tools:text="\@username"/>
<org.mariotaku.twidere.view.FixedTextView
android:layout_alignParentStart="true"
android:layout_below="@id/name"
android:id="@+id/user_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:focusable="false"
android:maxLines="1"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="@color/material_grey"
tools:text="twidere"/>
</RelativeLayout>
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"