add isGroup method

This commit is contained in:
Chumva 2018-07-13 18:45:24 +03:00
parent 5a2e858934
commit 459f1ba37f
4 changed files with 15 additions and 21 deletions

View file

@ -129,6 +129,10 @@ class TelegramHelper private constructor() {
fun getSupergroupFullInfo(id: Int) = supergroupsFullInfo[id]
fun isGroup(chat: TdApi.Chat): Boolean {
return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup
}
private fun isChannel(chat: TdApi.Chat): Boolean {
return chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel
}

View file

@ -15,7 +15,8 @@ object TelegramUiHelper {
app: TelegramApplication,
iv: ImageView?,
photoPath: String?,
placeholderId: Int = R.drawable.img_user_picture
placeholderId: Int = R.drawable.img_user_picture,
useThemedIcon: Boolean = true
) {
if (iv == null) {
return
@ -26,12 +27,11 @@ object TelegramUiHelper {
bitmap = app.uiUtils.getCircleBitmap(photoPath)
}
if (bitmap == null) {
drawable =
if (placeholderId == R.drawable.img_user_picture || placeholderId == R.drawable.img_group_picture) {
app.uiUtils.getIcon(placeholderId)
} else {
app.uiUtils.getThemedIcon(placeholderId)
}
drawable = if (useThemedIcon) {
app.uiUtils.getThemedIcon(placeholderId)
} else {
app.uiUtils.getIcon(placeholderId)
}
}
if (bitmap != null) {
iv.setImageBitmap(bitmap)

View file

@ -344,14 +344,9 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
override fun onBindViewHolder(holder: ChatViewHolder, position: Int) {
val chat = chats[position]
val lastItem = position == itemCount - 1
val placeholderId: Int =
if (chat.type is TdApi.ChatTypeBasicGroup || chat.type is TdApi.ChatTypeSupergroup) {
R.drawable.img_group_picture
} else {
R.drawable.img_user_picture
}
val placeholderId: Int = if (telegramHelper.isGroup(chat)) R.drawable.img_group_picture else R.drawable.img_user_picture
TelegramUiHelper.setupPhoto(app, holder.icon, chat.photo?.small?.local?.path, placeholderId)
TelegramUiHelper.setupPhoto(app, holder.icon, chat.photo?.small?.local?.path, placeholderId, false)
holder.title?.text = chat.title
holder.description?.text = "Some description" // FIXME
holder.checkBox?.apply {

View file

@ -208,14 +208,9 @@ class SetTimeDialogFragment : DialogFragment() {
override fun onBindViewHolder(holder: ChatViewHolder, position: Int) {
val chat = chats[position]
val placeholderId: Int =
if (chat.type is TdApi.ChatTypeBasicGroup || chat.type is TdApi.ChatTypeSupergroup) {
R.drawable.img_group_picture
} else {
R.drawable.img_user_picture
}
val placeholderId: Int = if (telegramHelper.isGroup(chat)) R.drawable.img_group_picture else R.drawable.img_user_picture
TelegramUiHelper.setupPhoto(app, holder.icon, chat.photo?.small?.local?.path, placeholderId)
TelegramUiHelper.setupPhoto(app, holder.icon, chat.photo?.small?.local?.path, placeholderId, false)
holder.title?.text = chat.title
holder.description?.text = "Some description" // FIXME
holder.textInArea?.apply {