diff --git a/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml b/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml index b5097fa352..1e17666d37 100644 --- a/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml +++ b/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml @@ -138,51 +138,43 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + 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" /> - + - - - - - + + android:textSize="14sp" + tools:text="Sharing:" /> + app:typeface="@string/font_roboto_medium" + tools:text="1 h" /> @@ -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"> () private val chatList = TreeSet() - private val chatLiveMessages = ConcurrentHashMap() - private val chatLiveMessagesFull = ConcurrentHashMap() + private val chatLiveMessages = ConcurrentHashMap() private val downloadChatFilesMap = ConcurrentHashMap() private val downloadUserFilesMap = ConcurrentHashMap() @@ -125,7 +124,7 @@ class TelegramHelper private constructor() { } } - fun getChatListIds(): ArrayList { + fun getChatListIds(): List { synchronized(chatList) { val chatsIds = ArrayList() chatList.forEach { @@ -153,7 +152,7 @@ class TelegramHelper private constructor() { fun getMessages() = usersLocationMessages.values.toList() - fun getChatLiveMessages() = chatLiveMessagesFull + fun getChatLiveMessages() = chatLiveMessages fun getMessagesByChatIds(): Map> { val res = mutableMapOf>() @@ -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() 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 { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index 1a135f275e..bf0c038ac9 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -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(R.id.app_bar_layout).apply { if (Build.VERSION.SDK_INT >= 21) { @@ -113,17 +110,19 @@ class MyLocationTabFragment : Fragment(), TelegramListener { optionsBtn = mainView.findViewById(R.id.options).apply { setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu)) - setOnClickListener { showPopupMenu() } + setOnClickListener { showPopupMenu(optionsBtn) } } optionsBtnTitle = mainView.findViewById(R.id.options_title).apply { setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu)) - setOnClickListener { showPopupMenu() } + setOnClickListener { showPopupMenu(optionsBtnTitle) } } - + imageContainer = mainView.findViewById(R.id.image_container) - titleContainer = mainView.findViewById(R.id.title_container) - + titleContainer = mainView.findViewById(R.id.title_container).apply { + AndroidUtils.addStatusBarPadding19v(context, this) + } + textContainer = mainView.findViewById(R.id.text_container).apply { if (Build.VERSION.SDK_INT >= 16) { layoutTransition.enableTransitionType(LayoutTransition.CHANGING) @@ -157,21 +156,17 @@ class MyLocationTabFragment : Fragment(), TelegramListener { layoutManager = LinearLayoutManager(context) adapter = this@MyLocationTabFragment.adapter } - + stopSharingSwitcher = mainView.findViewById(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() @@ -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 = mutableListOf() val currentUser = telegramHelper.getCurrentUser() - val chatList: ArrayList = 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 diff --git a/OsmAnd-telegram/src/net/osmand/telegram/utils/AndroidUtils.kt b/OsmAnd-telegram/src/net/osmand/telegram/utils/AndroidUtils.kt index 276fbf779d..4b7864d842 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/utils/AndroidUtils.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/utils/AndroidUtils.kt @@ -84,14 +84,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): Int { val txtSize = ctx.resources.getDimensionPixelSize(R.dimen.list_item_title_text_size)