Fix "All" number for chat description
This commit is contained in:
parent
dcac4cb6a8
commit
c15f294dc4
2 changed files with 90 additions and 7 deletions
|
@ -85,6 +85,7 @@ class TelegramHelper private constructor() {
|
||||||
|
|
||||||
var listener: TelegramListener? = null
|
var listener: TelegramListener? = null
|
||||||
private val incomingMessagesListeners = HashSet<TelegramIncomingMessagesListener>()
|
private val incomingMessagesListeners = HashSet<TelegramIncomingMessagesListener>()
|
||||||
|
private val fullInfoUpdatesListeners = HashSet<FullInfoUpdatesListener>()
|
||||||
|
|
||||||
fun addIncomingMessagesListener(listener: TelegramIncomingMessagesListener) {
|
fun addIncomingMessagesListener(listener: TelegramIncomingMessagesListener) {
|
||||||
incomingMessagesListeners.add(listener)
|
incomingMessagesListeners.add(listener)
|
||||||
|
@ -94,6 +95,14 @@ class TelegramHelper private constructor() {
|
||||||
incomingMessagesListeners.remove(listener)
|
incomingMessagesListeners.remove(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addFullInfoUpdatesListener(listener: FullInfoUpdatesListener) {
|
||||||
|
fullInfoUpdatesListeners.add(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeFullInfoUpdatesListener(listener: FullInfoUpdatesListener) {
|
||||||
|
fullInfoUpdatesListeners.remove(listener)
|
||||||
|
}
|
||||||
|
|
||||||
fun getChatList(): TreeSet<OrderedChat> {
|
fun getChatList(): TreeSet<OrderedChat> {
|
||||||
synchronized(chatList) {
|
synchronized(chatList) {
|
||||||
return TreeSet(chatList.filter { !it.isChannel })
|
return TreeSet(chatList.filter { !it.isChannel })
|
||||||
|
@ -130,9 +139,21 @@ class TelegramHelper private constructor() {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getBasicGroupFullInfo(id: Int) = basicGroupsFullInfo[id]
|
fun getBasicGroupFullInfo(id: Int): TdApi.BasicGroupFullInfo? {
|
||||||
|
val res = basicGroupsFullInfo[id]
|
||||||
|
if (res == null) {
|
||||||
|
requestBasicGroupFullInfo(id)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
fun getSupergroupFullInfo(id: Int) = supergroupsFullInfo[id]
|
fun getSupergroupFullInfo(id: Int): TdApi.SupergroupFullInfo? {
|
||||||
|
val res = supergroupsFullInfo[id]
|
||||||
|
if (res == null) {
|
||||||
|
requestSupergroupFullInfo(id)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
fun isGroup(chat: TdApi.Chat): Boolean {
|
fun isGroup(chat: TdApi.Chat): Boolean {
|
||||||
return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup
|
return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup
|
||||||
|
@ -180,6 +201,11 @@ class TelegramHelper private constructor() {
|
||||||
fun updateLocationMessages()
|
fun updateLocationMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface FullInfoUpdatesListener {
|
||||||
|
fun onBasicGroupFullInfoUpdated(groupId: Int, info: TdApi.BasicGroupFullInfo)
|
||||||
|
fun onSupergroupFullInfoUpdated(groupId: Int, info: TdApi.SupergroupFullInfo)
|
||||||
|
}
|
||||||
|
|
||||||
interface TelegramAuthorizationRequestListener {
|
interface TelegramAuthorizationRequestListener {
|
||||||
fun onRequestTelegramAuthenticationParameter(parameterType: TelegramAuthenticationParameterType)
|
fun onRequestTelegramAuthenticationParameter(parameterType: TelegramAuthenticationParameterType)
|
||||||
fun onTelegramAuthorizationRequestError(code: Int, message: String)
|
fun onTelegramAuthorizationRequestError(code: Int, message: String)
|
||||||
|
@ -366,6 +392,42 @@ class TelegramHelper private constructor() {
|
||||||
listener?.onTelegramChatsRead()
|
listener?.onTelegramChatsRead()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun requestBasicGroupFullInfo(id: Int) {
|
||||||
|
client?.send(TdApi.GetBasicGroupFullInfo(id)) { obj ->
|
||||||
|
when (obj.constructor) {
|
||||||
|
TdApi.Error.CONSTRUCTOR -> {
|
||||||
|
val error = obj as TdApi.Error
|
||||||
|
if (error.code != IGNORED_ERROR_CODE) {
|
||||||
|
listener?.onTelegramError(error.code, error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TdApi.BasicGroupFullInfo.CONSTRUCTOR -> {
|
||||||
|
val info = obj as TdApi.BasicGroupFullInfo
|
||||||
|
basicGroupsFullInfo[id] = info
|
||||||
|
fullInfoUpdatesListeners.forEach { it.onBasicGroupFullInfoUpdated(id, info) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun requestSupergroupFullInfo(id: Int) {
|
||||||
|
client?.send(TdApi.GetSupergroupFullInfo(id)) { obj ->
|
||||||
|
when (obj.constructor) {
|
||||||
|
TdApi.Error.CONSTRUCTOR -> {
|
||||||
|
val error = obj as TdApi.Error
|
||||||
|
if (error.code != IGNORED_ERROR_CODE) {
|
||||||
|
listener?.onTelegramError(error.code, error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TdApi.SupergroupFullInfo.CONSTRUCTOR -> {
|
||||||
|
val info = obj as TdApi.SupergroupFullInfo
|
||||||
|
supergroupsFullInfo[id] = info
|
||||||
|
fullInfoUpdatesListeners.forEach { it.onSupergroupFullInfoUpdated(id, info) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun requestCurrentUser(){
|
private fun requestCurrentUser(){
|
||||||
client?.send(TdApi.GetMe()) { obj ->
|
client?.send(TdApi.GetMe()) { obj ->
|
||||||
when (obj.constructor) {
|
when (obj.constructor) {
|
||||||
|
@ -1013,11 +1075,21 @@ class TelegramHelper private constructor() {
|
||||||
}
|
}
|
||||||
TdApi.UpdateBasicGroupFullInfo.CONSTRUCTOR -> {
|
TdApi.UpdateBasicGroupFullInfo.CONSTRUCTOR -> {
|
||||||
val updateBasicGroupFullInfo = obj as TdApi.UpdateBasicGroupFullInfo
|
val updateBasicGroupFullInfo = obj as TdApi.UpdateBasicGroupFullInfo
|
||||||
basicGroupsFullInfo[updateBasicGroupFullInfo.basicGroupId] = updateBasicGroupFullInfo.basicGroupFullInfo
|
val id = updateBasicGroupFullInfo.basicGroupId
|
||||||
|
if (basicGroupsFullInfo.containsKey(id)) {
|
||||||
|
val info = updateBasicGroupFullInfo.basicGroupFullInfo
|
||||||
|
basicGroupsFullInfo[id] = info
|
||||||
|
fullInfoUpdatesListeners.forEach { it.onBasicGroupFullInfoUpdated(id, info) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TdApi.UpdateSupergroupFullInfo.CONSTRUCTOR -> {
|
TdApi.UpdateSupergroupFullInfo.CONSTRUCTOR -> {
|
||||||
val updateSupergroupFullInfo = obj as TdApi.UpdateSupergroupFullInfo
|
val updateSupergroupFullInfo = obj as TdApi.UpdateSupergroupFullInfo
|
||||||
supergroupsFullInfo[updateSupergroupFullInfo.supergroupId] = updateSupergroupFullInfo.supergroupFullInfo
|
val id = updateSupergroupFullInfo.supergroupId
|
||||||
|
if (supergroupsFullInfo.containsKey(id)) {
|
||||||
|
val info = updateSupergroupFullInfo.supergroupFullInfo
|
||||||
|
supergroupsFullInfo[id] = info
|
||||||
|
fullInfoUpdatesListeners.forEach { it.onSupergroupFullInfoUpdated(id, info) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ private const val CHAT_VIEW_TYPE = 0
|
||||||
private const val LOCATION_ITEM_VIEW_TYPE = 1
|
private const val LOCATION_ITEM_VIEW_TYPE = 1
|
||||||
|
|
||||||
class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessagesListener,
|
class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessagesListener,
|
||||||
TelegramLocationListener, TelegramCompassListener {
|
FullInfoUpdatesListener, TelegramLocationListener, TelegramCompassListener {
|
||||||
|
|
||||||
private val app: TelegramApplication
|
private val app: TelegramApplication
|
||||||
get() = activity?.application as TelegramApplication
|
get() = activity?.application as TelegramApplication
|
||||||
|
@ -75,12 +75,14 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
locationViewCache = app.uiUtils.getUpdateLocationViewCache()
|
locationViewCache = app.uiUtils.getUpdateLocationViewCache()
|
||||||
updateList()
|
updateList()
|
||||||
telegramHelper.addIncomingMessagesListener(this)
|
telegramHelper.addIncomingMessagesListener(this)
|
||||||
|
telegramHelper.addFullInfoUpdatesListener(this)
|
||||||
startLocationUpdate()
|
startLocationUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
telegramHelper.removeIncomingMessagesListener(this)
|
telegramHelper.removeIncomingMessagesListener(this)
|
||||||
|
telegramHelper.removeFullInfoUpdatesListener(this)
|
||||||
stopLocationUpdate()
|
stopLocationUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +132,14 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
|
|
||||||
override fun updateLocationMessages() {}
|
override fun updateLocationMessages() {}
|
||||||
|
|
||||||
|
override fun onBasicGroupFullInfoUpdated(groupId: Int, info: TdApi.BasicGroupFullInfo) {
|
||||||
|
app.runInUIThread { updateList() }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSupergroupFullInfoUpdated(groupId: Int, info: TdApi.SupergroupFullInfo) {
|
||||||
|
app.runInUIThread { updateList() }
|
||||||
|
}
|
||||||
|
|
||||||
override fun updateLocation(location: Location?) {
|
override fun updateLocation(location: Location?) {
|
||||||
val loc = this.location
|
val loc = this.location
|
||||||
val newLocation = loc == null && location != null
|
val newLocation = loc == null && location != null
|
||||||
|
@ -299,8 +309,9 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
item.privateChat -> "" // FIXME
|
item.privateChat -> "" // FIXME
|
||||||
else -> {
|
else -> {
|
||||||
val live = getString(R.string.shared_string_live)
|
val live = getString(R.string.shared_string_live)
|
||||||
// val all = getString(R.string.shared_string_all)
|
val all = getString(R.string.shared_string_all)
|
||||||
"$live ${item.liveMembersCount}"
|
val liveStr = "$live ${item.liveMembersCount}"
|
||||||
|
if (item.membersCount > 0) "$liveStr • $all ${item.membersCount}" else liveStr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue