remove chatLiveMessagesFull
This commit is contained in:
parent
3c7c950e34
commit
494e40a59a
5 changed files with 74 additions and 136 deletions
|
@ -138,51 +138,43 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/tab_title"
|
||||
<LinearLayout
|
||||
android:id="@+id/title_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/action_bar_height"
|
||||
android:visibility="visible">
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/title_row"
|
||||
android:layout_width="match_parent"
|
||||
<net.osmand.telegram.ui.views.TextViewEx
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/action_bar_height"
|
||||
android:gravity="center_vertical">
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:letterSpacing="@dimen/title_letter_spacing"
|
||||
android:maxLines="1"
|
||||
android:paddingLeft="@dimen/content_padding_standard"
|
||||
android:paddingRight="@dimen/content_padding_standard"
|
||||
android:text="@string/my_location"
|
||||
android:textColor="@color/app_bar_title_light"
|
||||
android:textSize="@dimen/title_text_size"
|
||||
app:typeface="@string/font_roboto_mono_bold" />
|
||||
|
||||
<net.osmand.telegram.ui.views.TextViewEx
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/action_bar_height"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:letterSpacing="@dimen/title_letter_spacing"
|
||||
android:maxLines="1"
|
||||
android:paddingLeft="@dimen/content_padding_standard"
|
||||
android:paddingRight="@dimen/content_padding_standard"
|
||||
android:text="@string/my_location"
|
||||
android:textColor="@color/app_bar_title_light"
|
||||
android:textSize="@dimen/title_text_size"
|
||||
app:typeface="@string/font_roboto_mono_bold" />
|
||||
<ImageView
|
||||
android:id="@+id/options_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="@dimen/content_padding_standard"
|
||||
android:layout_marginLeft="@dimen/content_padding_standard"
|
||||
android:layout_marginRight="@dimen/content_padding_standard"
|
||||
android:layout_marginStart="@dimen/content_padding_standard"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:paddingLeft="@dimen/content_padding_half"
|
||||
android:paddingRight="@dimen/content_padding_half"
|
||||
tools:src="@drawable/ic_action_other_menu"
|
||||
tools:tint="@color/icon_light"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/options_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="@dimen/content_padding_standard"
|
||||
android:layout_marginLeft="@dimen/content_padding_standard"
|
||||
android:layout_marginRight="@dimen/content_padding_standard"
|
||||
android:layout_marginStart="@dimen/content_padding_standard"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:paddingLeft="@dimen/content_padding_half"
|
||||
android:paddingRight="@dimen/content_padding_half"
|
||||
tools:src="@drawable/ic_action_other_menu"
|
||||
tools:tint="@color/icon_light"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/appbar_divider"
|
||||
|
|
|
@ -23,10 +23,8 @@
|
|||
android:id="@+id/icon"
|
||||
android:layout_width="@dimen/list_item_icon_size"
|
||||
android:layout_height="@dimen/list_item_icon_size"
|
||||
android:layout_marginEnd="@dimen/list_item_icon_margin_left"
|
||||
android:layout_marginLeft="@dimen/list_item_icon_margin_left"
|
||||
android:layout_marginRight="@dimen/list_item_icon_margin_left"
|
||||
android:layout_marginStart="@dimen/list_item_icon_margin_left"
|
||||
tools:src="@drawable/img_user_picture" />
|
||||
|
||||
<LinearLayout
|
||||
|
@ -59,9 +57,9 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="Трансляция:"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textSize="14sp" />
|
||||
android:textSize="14sp"
|
||||
tools:text="Sharing:" />
|
||||
|
||||
<net.osmand.telegram.ui.views.TextViewEx
|
||||
android:id="@+id/duration"
|
||||
|
@ -71,10 +69,10 @@
|
|||
android:layout_marginRight="4dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="1 ч"
|
||||
android:textColor="?attr/ctrl_active_color"
|
||||
android:textSize="14sp"
|
||||
app:typeface="@string/font_roboto_medium" />
|
||||
app:typeface="@string/font_roboto_medium"
|
||||
tools:text="1 h" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -112,10 +110,8 @@
|
|||
android:layout_height="@dimen/list_item_height_big"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingEnd="@dimen/content_padding_standard"
|
||||
android:paddingLeft="@dimen/content_padding_standard"
|
||||
android:paddingRight="@dimen/content_padding_standard"
|
||||
android:paddingStart="@dimen/content_padding_standard">
|
||||
android:paddingRight="@dimen/content_padding_standard">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
|
|
|
@ -67,8 +67,7 @@ class TelegramHelper private constructor() {
|
|||
|
||||
private val chats = ConcurrentHashMap<Long, TdApi.Chat>()
|
||||
private val chatList = TreeSet<OrderedChat>()
|
||||
private val chatLiveMessages = ConcurrentHashMap<Long, Long>()
|
||||
private val chatLiveMessagesFull = ConcurrentHashMap<Long, TdApi.Message>()
|
||||
private val chatLiveMessages = ConcurrentHashMap<Long, TdApi.Message>()
|
||||
|
||||
private val downloadChatFilesMap = ConcurrentHashMap<String, TdApi.Chat>()
|
||||
private val downloadUserFilesMap = ConcurrentHashMap<String, TdApi.User>()
|
||||
|
@ -125,7 +124,7 @@ class TelegramHelper private constructor() {
|
|||
}
|
||||
}
|
||||
|
||||
fun getChatListIds(): ArrayList<Long> {
|
||||
fun getChatListIds(): List<Long> {
|
||||
synchronized(chatList) {
|
||||
val chatsIds = ArrayList<Long>()
|
||||
chatList.forEach {
|
||||
|
@ -153,7 +152,7 @@ class TelegramHelper private constructor() {
|
|||
|
||||
fun getMessages() = usersLocationMessages.values.toList()
|
||||
|
||||
fun getChatLiveMessages() = chatLiveMessagesFull
|
||||
fun getChatLiveMessages() = chatLiveMessages
|
||||
|
||||
fun getMessagesByChatIds(): Map<Long, List<TdApi.Message>> {
|
||||
val res = mutableMapOf<Long, MutableList<TdApi.Message>>()
|
||||
|
@ -548,12 +547,10 @@ class TelegramHelper private constructor() {
|
|||
TdApi.Messages.CONSTRUCTOR -> {
|
||||
val messages = (obj as TdApi.Messages).messages
|
||||
chatLiveMessages.clear()
|
||||
chatLiveMessagesFull.clear()
|
||||
if (messages.isNotEmpty()) {
|
||||
for (msg in messages) {
|
||||
val chatId = msg.chatId
|
||||
chatLiveMessages[chatId] = msg.id
|
||||
chatLiveMessagesFull[chatId] = msg
|
||||
chatLiveMessages[chatId] = msg
|
||||
}
|
||||
}
|
||||
onComplete?.invoke()
|
||||
|
@ -568,7 +565,7 @@ class TelegramHelper private constructor() {
|
|||
val location = TdApi.Location(latitude, longitude)
|
||||
chatLivePeriods.forEach { chatId, livePeriod ->
|
||||
val content = TdApi.InputMessageLocation(location, livePeriod.toInt())
|
||||
val msgId = chatLiveMessages[chatId]
|
||||
val msgId = chatLiveMessages[chatId]?.id
|
||||
if (msgId != null) {
|
||||
if (msgId != 0L) {
|
||||
client?.send(
|
||||
|
@ -577,7 +574,6 @@ class TelegramHelper private constructor() {
|
|||
)
|
||||
}
|
||||
} else {
|
||||
chatLiveMessages[chatId] = 0L
|
||||
client?.send(
|
||||
TdApi.SendMessage(chatId, 0, false, true, null, content),
|
||||
liveLocationMessageUpdatesHandler
|
||||
|
@ -722,7 +718,7 @@ class TelegramHelper private constructor() {
|
|||
if (haveAuthorization) {
|
||||
requestChats(true)
|
||||
requestCurrentUser()
|
||||
getActiveLiveLocationMessages {}
|
||||
getActiveLiveLocationMessages(null)
|
||||
}
|
||||
}
|
||||
val newAuthState = getTelegramAuthorizationState()
|
||||
|
@ -1086,8 +1082,7 @@ class TelegramHelper private constructor() {
|
|||
TdApi.UpdateMessageSendSucceeded.CONSTRUCTOR -> {
|
||||
val updateMessageSendSucceeded = obj as TdApi.UpdateMessageSendSucceeded
|
||||
val message = updateMessageSendSucceeded.message
|
||||
chatLiveMessagesFull[message.chatId] = message
|
||||
chatLiveMessages[message.chatId] = message.id
|
||||
chatLiveMessages[message.chatId] = message
|
||||
}
|
||||
TdApi.UpdateDeleteMessages.CONSTRUCTOR -> {
|
||||
val updateDeleteMessages = obj as TdApi.UpdateDeleteMessages
|
||||
|
@ -1095,13 +1090,11 @@ class TelegramHelper private constructor() {
|
|||
val chatId = updateDeleteMessages.chatId
|
||||
val deletedMessages = mutableListOf<TdApi.Message>()
|
||||
for (messageId in updateDeleteMessages.messageIds) {
|
||||
if (chatLiveMessages[chatId] == messageId) {
|
||||
if (chatLiveMessages[chatId]?.id == messageId) {
|
||||
chatLiveMessages.remove(chatId)
|
||||
}
|
||||
if (chatLiveMessagesFull.contains(chatId)) {
|
||||
chatLiveMessagesFull.remove(chatId)
|
||||
}
|
||||
usersLocationMessages.remove(messageId)?.also { deletedMessages.add(it) }
|
||||
usersLocationMessages.remove(messageId)
|
||||
?.also { deletedMessages.add(it) }
|
||||
}
|
||||
if (deletedMessages.isNotEmpty()) {
|
||||
incomingMessagesListeners.forEach {
|
||||
|
|
|
@ -19,10 +19,10 @@ import net.osmand.telegram.helpers.TelegramHelper
|
|||
import net.osmand.telegram.helpers.TelegramHelper.TelegramListener
|
||||
import net.osmand.telegram.helpers.TelegramUiHelper
|
||||
import net.osmand.telegram.utils.AndroidUtils
|
||||
import net.osmand.telegram.utils.OsmandFormatter
|
||||
import org.drinkless.td.libcore.telegram.TdApi
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.*
|
||||
import java.text.SimpleDateFormat
|
||||
|
||||
private const val SELECTED_CHATS_KEY = "selected_chats"
|
||||
private const val SHARE_LOCATION_CHAT = 1
|
||||
|
@ -41,7 +41,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
private val telegramHelper get() = app.telegramHelper
|
||||
private val settings get() = app.settings
|
||||
|
||||
private lateinit var mainView: View
|
||||
private lateinit var appBarLayout: AppBarLayout
|
||||
private lateinit var userImage: ImageView
|
||||
private lateinit var imageContainer: FrameLayout
|
||||
|
@ -65,8 +64,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
|
||||
private var actionButtonsListener: ActionButtonsListener? = null
|
||||
|
||||
private var inSharingMode: Boolean = false
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
@ -89,7 +86,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
}
|
||||
}
|
||||
|
||||
mainView = inflater.inflate(R.layout.fragment_my_location_tab, container, false)
|
||||
val mainView = inflater.inflate(R.layout.fragment_my_location_tab, container, false)
|
||||
|
||||
appBarLayout = mainView.findViewById<AppBarLayout>(R.id.app_bar_layout).apply {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
|
@ -113,16 +110,18 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
|
||||
optionsBtn = mainView.findViewById<ImageView>(R.id.options).apply {
|
||||
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
|
||||
setOnClickListener { showPopupMenu() }
|
||||
setOnClickListener { showPopupMenu(optionsBtn) }
|
||||
}
|
||||
|
||||
optionsBtnTitle = mainView.findViewById<ImageView>(R.id.options_title).apply {
|
||||
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
|
||||
setOnClickListener { showPopupMenu() }
|
||||
setOnClickListener { showPopupMenu(optionsBtnTitle) }
|
||||
}
|
||||
|
||||
imageContainer = mainView.findViewById<FrameLayout>(R.id.image_container)
|
||||
titleContainer = mainView.findViewById<LinearLayout>(R.id.title_container)
|
||||
titleContainer = mainView.findViewById<LinearLayout>(R.id.title_container).apply {
|
||||
AndroidUtils.addStatusBarPadding19v(context, this)
|
||||
}
|
||||
|
||||
textContainer = mainView.findViewById<LinearLayout>(R.id.text_container).apply {
|
||||
if (Build.VERSION.SDK_INT >= 16) {
|
||||
|
@ -159,19 +158,15 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
}
|
||||
|
||||
stopSharingSwitcher = mainView.findViewById<Switch>(R.id.stop_all_sharing_switcher).apply {
|
||||
if (settings.hasAnyChatToShareLocation()) {
|
||||
isChecked = true
|
||||
}
|
||||
isChecked = settings.hasAnyChatToShareLocation()
|
||||
setOnCheckedChangeListener { _, isChecked ->
|
||||
run {
|
||||
if (!isChecked) {
|
||||
app.settings.stopSharingLocationToChats()
|
||||
if (!app.settings.hasAnyChatToShareLocation()) {
|
||||
app.shareLocationHelper.stopSharingLocation()
|
||||
}
|
||||
updateSharingMode()
|
||||
updateList()
|
||||
if (!isChecked) {
|
||||
app.settings.stopSharingLocationToChats()
|
||||
if (!app.settings.hasAnyChatToShareLocation()) {
|
||||
app.shareLocationHelper.stopSharingLocation()
|
||||
}
|
||||
updateSharingMode()
|
||||
updateList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -258,31 +253,22 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
}
|
||||
|
||||
private fun updateSharingMode() {
|
||||
val headerParams = imageContainer.layoutParams as AppBarLayout.LayoutParams
|
||||
if (!settings.hasAnyChatToShareLocation()) {
|
||||
imageContainer.visibility = View.VISIBLE
|
||||
textContainer.visibility = View.VISIBLE
|
||||
titleContainer.visibility = View.GONE
|
||||
val headerParams = imageContainer.layoutParams as AppBarLayout.LayoutParams
|
||||
headerParams.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
|
||||
if (inSharingMode) {
|
||||
AndroidUtils.removeStatusBarPadding19v(context!!, titleContainer)
|
||||
}
|
||||
inSharingMode = false
|
||||
} else {
|
||||
imageContainer.visibility = View.GONE
|
||||
textContainer.visibility = View.GONE
|
||||
titleContainer.visibility = View.VISIBLE
|
||||
val headerParams = imageContainer.layoutParams as AppBarLayout.LayoutParams
|
||||
headerParams.scrollFlags = 0
|
||||
stopSharingSwitcher.apply { isChecked = true }
|
||||
if (!inSharingMode) {
|
||||
AndroidUtils.addStatusBarPadding19v(context!!, titleContainer)
|
||||
}
|
||||
inSharingMode = true
|
||||
stopSharingSwitcher.isChecked = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun showPopupMenu() {
|
||||
private fun showPopupMenu(anchor:View) {
|
||||
val ctx = context ?: return
|
||||
|
||||
val menuList = ArrayList<String>()
|
||||
|
@ -299,11 +285,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
|
||||
ListPopupWindow(ctx).apply {
|
||||
isModal = true
|
||||
anchorView = if (app.settings.hasAnyChatToShareLocation()) {
|
||||
optionsBtnTitle
|
||||
} else {
|
||||
optionsBtn
|
||||
}
|
||||
anchorView = anchor
|
||||
setContentWidth(AndroidUtils.getPopupMenuWidth(ctx, menuList))
|
||||
setDropDownGravity(Gravity.END or Gravity.TOP)
|
||||
setAdapter(ArrayAdapter(ctx, R.layout.popup_list_text_item, menuList))
|
||||
|
@ -407,7 +389,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
private fun updateList() {
|
||||
val chats: MutableList<TdApi.Chat> = mutableListOf()
|
||||
val currentUser = telegramHelper.getCurrentUser()
|
||||
val chatList: ArrayList<Long> = if (settings.hasAnyChatToShareLocation()) {
|
||||
val chatList = if (settings.hasAnyChatToShareLocation()) {
|
||||
settings.getShareLocationChats()
|
||||
} else {
|
||||
telegramHelper.getChatListIds()
|
||||
|
@ -478,14 +460,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
if (telegramHelper.isGroup(chat)) R.drawable.img_group_picture else R.drawable.img_user_picture
|
||||
val live = app.settings.isSharingLocationToChat(chat.id)
|
||||
|
||||
if (holder is ChatViewHolder) {
|
||||
TelegramUiHelper.setupPhoto(
|
||||
app,
|
||||
holder.icon,
|
||||
chat.photo?.small?.local?.path,
|
||||
placeholderId,
|
||||
false
|
||||
)
|
||||
if (holder is ChatViewHolder) { TelegramUiHelper.setupPhoto(app, holder.icon, chat.photo?.small?.local?.path, placeholderId, false)
|
||||
holder.title?.text = chat.title
|
||||
holder.description?.visibility = View.GONE
|
||||
if (live) {
|
||||
|
@ -520,13 +495,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
}
|
||||
}
|
||||
} else if (holder is SharingChatViewHolder) {
|
||||
TelegramUiHelper.setupPhoto(
|
||||
app,
|
||||
holder.icon,
|
||||
chat.photo?.small?.local?.path,
|
||||
placeholderId,
|
||||
false
|
||||
)
|
||||
TelegramUiHelper.setupPhoto(app, holder.icon, chat.photo?.small?.local?.path, placeholderId, false)
|
||||
holder.title?.text = chat.title
|
||||
holder.switcher?.apply {
|
||||
if (live) {
|
||||
|
@ -552,20 +521,16 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
}
|
||||
val duration = settings.getChatLivePeriod(chat.id)
|
||||
if (duration != null && duration > 0) {
|
||||
holder.descriptionDuration?.text = formatTime(duration, false)
|
||||
holder.descriptionDuration?.text = OsmandFormatter.getFormattedDuration(context!!, duration.toInt())
|
||||
}
|
||||
val map = telegramHelper.getChatLiveMessages()
|
||||
val message = map[chat.id]
|
||||
if (message != null) {
|
||||
val content = message.content
|
||||
if (content is TdApi.MessageLocation) {
|
||||
val time = formatTime(content.expiresIn.toLong(), true)
|
||||
val currentTime =
|
||||
Date(System.currentTimeMillis() + (content.expiresIn * 1000))
|
||||
val df = SimpleDateFormat("HH:mm", Locale.getDefault())
|
||||
val formattedDate = df.format(currentTime)
|
||||
holder.stopSharingFirstPart?.text = time
|
||||
holder.stopSharingSecondPart?.text = formattedDate
|
||||
val currentTime = (System.currentTimeMillis() / 1000 + content.expiresIn).toInt()
|
||||
holder.stopSharingFirstPart?.text = OsmandFormatter.getFormattedDuration(context!!, content.expiresIn)
|
||||
holder.stopSharingSecondPart?.text = OsmandFormatter.getFormattedDuration(context!!, currentTime)
|
||||
}
|
||||
} else {
|
||||
holder.textInArea?.visibility = View.INVISIBLE
|
||||
|
|
|
@ -85,14 +85,6 @@ object AndroidUtils {
|
|||
}
|
||||
}
|
||||
|
||||
fun removeStatusBarPadding19v(ctx: Context, view: View) {
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
view.apply {
|
||||
setPadding(paddingLeft, paddingTop - getStatusBarHeight(ctx), paddingRight, paddingBottom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getPopupMenuWidth(ctx: Context, titles: Collection<String>): Int {
|
||||
val txtSize = ctx.resources.getDimensionPixelSize(R.dimen.list_item_title_text_size)
|
||||
val paint = Paint().apply { textSize = txtSize.toFloat() }
|
||||
|
|
Loading…
Reference in a new issue