Skip to content
Snippets Groups Projects
Commit bf764ecc authored by Amirhossein Naghshzan's avatar Amirhossein Naghshzan
Browse files

AccountSpinner: show online badge

Change-Id: I2897ade538dd1c7b6affe74ceeda7c3ac2acd2d7
parent 4f06d93e
No related branches found
No related tags found
No related merge requests found
......@@ -30,16 +30,26 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import android.widget.RelativeLayout
import cx.ring.databinding.ItemToolbarSelectedBinding
import cx.ring.databinding.ItemToolbarSpinnerBinding
import cx.ring.services.VCardServiceImpl
import io.reactivex.rxjava3.disposables.CompositeDisposable
import net.jami.model.Account
import net.jami.model.Profile
import net.jami.services.AccountService
class AccountSpinnerAdapter(context: Context, accounts: List<Account>, val disposable: CompositeDisposable) :
class AccountSpinnerAdapter(context: Context, accounts: List<Account>, val disposable: CompositeDisposable, var mAccountService: AccountService) :
ArrayAdapter<Account>(context, R.layout.item_toolbar_spinner, accounts) {
private val mInflater: LayoutInflater = LayoutInflater.from(context)
private val logoSize: Int = context.resources.getDimensionPixelSize(R.dimen.list_medium_icon_size)
private fun getTitle(account: Account, profile: Profile): String {
return profile.displayName.orEmpty().ifEmpty {
account.registeredName.ifEmpty {
account.alias.orEmpty().ifEmpty {
context.getString(R.string.ring_account)
}
}
}
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
var view = convertView
val type = getItemViewType(position)
......@@ -54,12 +64,11 @@ class AccountSpinnerAdapter(context: Context, accounts: List<Account>, val dispo
}
if (type == TYPE_ACCOUNT) {
val account = getItem(position)!!
holder.loader.add(VCardServiceImpl.loadProfile(context, account)
.map { profile -> Profile(profile.displayName ?: account.alias, AvatarDrawable.build(context, account, profile)) }
holder.loader.add(mAccountService.getObservableAccountProfile(account.accountId)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ profile ->
holder.binding.logo.setImageDrawable(profile.avatar as AvatarDrawable)
holder.binding.title.text = profile.displayName?.ifEmpty { context.getString(R.string.ring_account) }
holder.binding.logo.setImageDrawable(AvatarDrawable.build(holder.binding.root.context, profile.first, profile.second, true, profile.first.isRegistered))
holder.binding.title.text = getTitle(profile.first, profile.second)
}){ e: Throwable -> Log.e(TAG, "Error loading avatar", e) })
}
return view
......@@ -88,14 +97,13 @@ class AccountSpinnerAdapter(context: Context, accounts: List<Account>, val dispo
logoParam.width = logoSize
logoParam.height = logoSize
holder.binding.logo.layoutParams = logoParam
holder.loader.add(VCardServiceImpl.loadProfile(context, account)
.map { profile -> Profile(profile.displayName ?: account.alias, AvatarDrawable.build(context, account, profile)) }
holder.loader.add(mAccountService.getObservableAccountProfile(account.accountId)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ profile ->
val subtitle = getUri(account, ip2ipString)
holder.binding.logo.setImageDrawable(profile.avatar as AvatarDrawable)
holder.binding.title.text = profile.displayName?.ifEmpty { context.getString(R.string.ring_account) }
if (profile.displayName == subtitle) {
holder.binding.logo.setImageDrawable(AvatarDrawable.build(holder.binding.root.context, profile.first, profile.second, true, profile.first.isRegistered))
holder.binding.title.text = getTitle(profile.first, profile.second)
if (holder.binding.title.text == subtitle) {
holder.binding.subtitle.visibility = View.GONE
} else {
holder.binding.subtitle.visibility = View.VISIBLE
......
......@@ -281,7 +281,7 @@ class HomeActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListen
mBinding!!.spinnerToolbar.setSelection(0)
}
} ?: run {
AccountSpinnerAdapter(this@HomeActivity, ArrayList(accounts), mDisposable).apply {
AccountSpinnerAdapter(this@HomeActivity, ArrayList(accounts), mDisposable, mAccountService).apply {
mAccountAdapter = this
setNotifyOnChange(false)
mBinding?.spinnerToolbar?.adapter = this
......
......@@ -93,12 +93,13 @@ class AvatarDrawable : Drawable {
return VCardServiceImpl.loadProfile(context, account)
.map { profile -> build(context, account, profile, crop) }
}
fun build(context: Context, account: Account, profile: Profile, crop: Boolean = true): AvatarDrawable {
fun build(context: Context, account: Account, profile: Profile, crop: Boolean = true, isOnline: Boolean = false): AvatarDrawable {
return Builder()
.withPhoto(profile.avatar as Bitmap?)
.withNameData(profile.displayName, account.registeredName)
.withId(account.uri)
.withCircleCrop(crop)
.withOnlineState(isOnline)
.build(context)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment