2019-02-06 10:23:02 +01:00
|
|
|
/* Copyright 2019 Levi Bard
|
|
|
|
*
|
|
|
|
* This file is a part of Tusky.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
package com.keylesspalace.tusky.adapter
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.ArrayAdapter
|
2019-10-22 21:18:20 +02:00
|
|
|
import androidx.preference.PreferenceManager
|
2019-02-06 10:23:02 +01:00
|
|
|
import com.keylesspalace.tusky.R
|
2021-03-07 19:24:01 +01:00
|
|
|
import com.keylesspalace.tusky.databinding.ItemAutocompleteAccountBinding
|
2019-02-06 10:23:02 +01:00
|
|
|
import com.keylesspalace.tusky.db.AccountEntity
|
2021-02-06 08:14:51 +01:00
|
|
|
import com.keylesspalace.tusky.settings.PrefKeys
|
2021-06-28 21:13:24 +02:00
|
|
|
import com.keylesspalace.tusky.util.emojify
|
|
|
|
import com.keylesspalace.tusky.util.loadAvatar
|
2019-02-06 10:23:02 +01:00
|
|
|
|
2019-05-26 08:46:08 +02:00
|
|
|
class AccountSelectionAdapter(context: Context) : ArrayAdapter<AccountEntity>(context, R.layout.item_autocomplete_account) {
|
2019-02-06 10:23:02 +01:00
|
|
|
|
2021-03-07 19:24:01 +01:00
|
|
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
|
|
|
val binding = if (convertView == null) {
|
|
|
|
ItemAutocompleteAccountBinding.inflate(LayoutInflater.from(context), parent, false)
|
|
|
|
} else {
|
|
|
|
ItemAutocompleteAccountBinding.bind(convertView)
|
2019-02-06 10:23:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
val account = getItem(position)
|
|
|
|
if (account != null) {
|
2021-03-07 19:24:01 +01:00
|
|
|
val pm = PreferenceManager.getDefaultSharedPreferences(binding.avatar.context)
|
2021-02-06 08:14:51 +01:00
|
|
|
val animateEmojis = pm.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
|
|
|
|
|
2021-03-07 19:24:01 +01:00
|
|
|
binding.username.text = account.fullName
|
|
|
|
binding.displayName.text = account.displayName.emojify(account.emojis, binding.displayName, animateEmojis)
|
2022-06-20 16:11:07 +02:00
|
|
|
binding.avatarBadge.visibility = View.GONE // We never want to display the bot badge here
|
2019-05-26 08:46:08 +02:00
|
|
|
|
2021-03-07 19:24:01 +01:00
|
|
|
val avatarRadius = context.resources.getDimensionPixelSize(R.dimen.avatar_radius_42dp)
|
2021-02-06 08:14:51 +01:00
|
|
|
val animateAvatar = pm.getBoolean("animateGifAvatars", false)
|
2019-05-26 08:46:08 +02:00
|
|
|
|
2021-03-07 19:24:01 +01:00
|
|
|
loadAvatar(account.profilePictureUrl, binding.avatar, avatarRadius, animateAvatar)
|
2019-02-06 10:23:02 +01:00
|
|
|
}
|
|
|
|
|
2021-03-07 19:24:01 +01:00
|
|
|
return binding.root
|
2019-02-06 10:23:02 +01:00
|
|
|
}
|
2021-06-28 21:13:24 +02:00
|
|
|
}
|