add support for expire time and improve ui

This commit is contained in:
Chumva 2018-08-08 17:53:50 +03:00
parent 1146a2f8ee
commit 488685a656
8 changed files with 263 additions and 202 deletions

View file

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--<item>--> <item>
<!--<nine-patch android:src="@drawable/bg_card_shadow_cr3dp"/>--> <nine-patch android:src="@drawable/bg_card_shadow_cr3dp" />
<!--</item>--> </item>
<item> <item>
<shape> <shape>
<solid android:color="@color/card_bg_light"/> <solid android:color="@color/card_bg_light" />
<corners android:radius="3dp"/> <corners android:radius="3dp" />
</shape> </shape>
</item> </item>
</layer-list> </layer-list>

View file

@ -13,7 +13,7 @@
android:background="?attr/card_bg_color"> android:background="?attr/card_bg_color">
<FrameLayout <FrameLayout
android:id="@+id/background_image" android:id="@+id/image_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/my_location_image_height" android:layout_height="@dimen/my_location_image_height"
app:layout_scrollFlags="scroll"> app:layout_scrollFlags="scroll">
@ -131,82 +131,96 @@
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>
<FrameLayout
android:id="@+id/tab_title"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height"
android:visibility="visible">
<LinearLayout <LinearLayout
android:id="@+id/title_row" android:id="@+id/title_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="@+id/tab_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height" android:layout_height="@dimen/action_bar_height"
android:gravity="center_vertical"> android:visibility="visible">
<LinearLayout
android:id="@+id/title_row"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height"
android:gravity="center_vertical">
<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" />
</LinearLayout>
</FrameLayout>
<View
android:id="@+id/appbar_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginStart="@dimen/content_padding_standard"
android:background="?attr/card_divider_color" />
<LinearLayout
android:id="@+id/stop_all_sharing_row"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height"
android:gravity="center_vertical"
android:paddingLeft="@dimen/content_padding_standard"
android:paddingRight="@dimen/content_padding_standard">
<net.osmand.telegram.ui.views.TextViewEx <net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/stop_all_sharing_title"
android:layout_width="0dp" 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_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding_standard" android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard" android:layout_marginRight="@dimen/content_padding_standard"
android:src="@drawable/ic_action_other_menu" android:layout_weight="1"
android:tint="@color/icon_light" /> android:ellipsize="end"
android:maxLines="1"
android:text="@string/stop_sharing_all"
android:textColor="?attr/ctrl_active_color"
android:textSize="@dimen/descr_text_size"
app:typeface="@string/font_roboto_medium" />
<Switch
android:id="@+id/stop_all_sharing_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout> </LinearLayout>
</FrameLayout>
<View
android:id="@+id/appbar_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginStart="@dimen/content_padding_standard"
android:background="?attr/card_divider_color" />
<LinearLayout
android:id="@+id/stop_all_sharing_row"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height"
android:gravity="center_vertical"
android:paddingLeft="@dimen/content_padding_standard"
android:paddingRight="@dimen/content_padding_standard">
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/stop_all_sharing_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/stop_sharing_all"
android:textColor="?attr/ctrl_active_color"
android:textSize="@dimen/descr_text_size"
app:typeface="@string/font_roboto_medium" />
<Switch
android:id="@+id/stop_all_sharing_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout> </LinearLayout>
</android.support.design.widget.AppBarLayout> </android.support.design.widget.AppBarLayout>

View file

@ -4,9 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding_half" android:layout_marginTop="@dimen/content_padding_half"
android:layout_marginRight="@dimen/content_padding_half"
android:layout_marginTop="@dimen/content_padding_standard"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
@ -61,7 +59,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:text="Трансляция: " android:text="Трансляция:"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:textSize="14sp" /> android:textSize="14sp" />
@ -69,6 +67,8 @@
android:id="@+id/duration" android:id="@+id/duration"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:text="1 ч" android:text="1 ч"
@ -94,10 +94,8 @@
android:paddingRight="@dimen/content_padding_half" android:paddingRight="@dimen/content_padding_half"
android:textColor="?attr/ctrl_active_color" android:textColor="?attr/ctrl_active_color"
android:textSize="14sp" android:textSize="14sp"
android:visibility="gone"
app:typeface="@string/font_roboto_medium" app:typeface="@string/font_roboto_medium"
tools:text="+ 30 min" tools:text="+ 30 min" />
tools:visibility="visible" />
</LinearLayout> </LinearLayout>
@ -121,6 +119,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_weight="1" android:layout_weight="1"
android:orientation="vertical"> android:orientation="vertical">
@ -142,35 +142,37 @@
android:orientation="horizontal"> android:orientation="horizontal">
<net.osmand.telegram.ui.views.TextViewEx <net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/stop_translation_in_tv" android:id="@+id/ending_in"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:text="Окончание через: " android:text="@string/ending_in"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:textSize="14sp" android:textSize="14sp"
app:typeface="@string/font_roboto_regular" /> app:typeface="@string/font_roboto_regular" />
<net.osmand.telegram.ui.views.TextViewEx <net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/stop_translation_in_tv_1" android:id="@+id/ending_in_first_part"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:text="01:15 " android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
android:textSize="14sp" android:textSize="14sp"
app:typeface="@string/font_roboto_mono_bold" /> app:typeface="@string/font_roboto_mono_bold"
tools:text="13:14" />
<net.osmand.telegram.ui.views.TextViewEx <net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/stop_translation_in_tv_2" android:id="@+id/ending_in_second_part"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:text="(в 12:34)"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:textSize="14sp" android:textSize="14sp"
app:typeface="@string/font_roboto_regular" /> app:typeface="@string/font_roboto_regular"
tools:text="(in 12:34)" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
@ -184,4 +186,4 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -24,8 +24,8 @@
<dimen name="dialog_welcome_title_top_margin">85dp</dimen> <dimen name="dialog_welcome_title_top_margin">85dp</dimen>
<dimen name="list_item_height">56dp</dimen> <dimen name="list_item_height">56dp</dimen>
<dimen name="list_item_height_big">64dp</dimen>
<dimen name="list_item_height_min">48dp</dimen> <dimen name="list_item_height_min">48dp</dimen>
<dimen name="list_item_height_big">64dp</dimen>
<dimen name="list_item_icon_size">40dp</dimen> <dimen name="list_item_icon_size">40dp</dimen>
<dimen name="list_item_icon_margin_left">12dp</dimen> <dimen name="list_item_icon_margin_left">12dp</dimen>

View file

@ -1,5 +1,7 @@
<resources> <resources>
<string name="stop_sharing_all">Stop all sharing</string> <string name="sharing_time">Sharing time:</string>
<string name="ending_in">Stop in:</string>
<string name="stop_sharing_all">Sharing is enabled (disable)</string>
<string name="stop_sharing_chat">Stop chat sharing</string> <string name="stop_sharing_chat">Stop chat sharing</string>
<string name="open_osmand">Open OsmAnd</string> <string name="open_osmand">Open OsmAnd</string>
<string name="shared_string_live">Live</string> <string name="shared_string_live">Live</string>

View file

@ -14,6 +14,7 @@ import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Executors import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.collections.ArrayList
import kotlin.collections.HashSet import kotlin.collections.HashSet
@ -67,6 +68,7 @@ class TelegramHelper private constructor() {
private val chats = ConcurrentHashMap<Long, TdApi.Chat>() private val chats = ConcurrentHashMap<Long, TdApi.Chat>()
private val chatList = TreeSet<OrderedChat>() private val chatList = TreeSet<OrderedChat>()
private val chatLiveMessages = ConcurrentHashMap<Long, Long>() private val chatLiveMessages = ConcurrentHashMap<Long, Long>()
private val chatLiveMessagesFull = ConcurrentHashMap<Long, TdApi.Message>()
private val downloadChatFilesMap = ConcurrentHashMap<String, TdApi.Chat>() private val downloadChatFilesMap = ConcurrentHashMap<String, TdApi.Chat>()
private val downloadUserFilesMap = ConcurrentHashMap<String, TdApi.User>() private val downloadUserFilesMap = ConcurrentHashMap<String, TdApi.User>()
@ -123,6 +125,18 @@ class TelegramHelper private constructor() {
} }
} }
fun getChatListIds(): ArrayList<Long> {
synchronized(chatList) {
val chatsIds = ArrayList<Long>()
chatList.forEach {
if (!it.isChannel) {
chatsIds.add(it.chatId)
}
}
return chatsIds
}
}
fun getChatIds() = chats.keys().toList() fun getChatIds() = chats.keys().toList()
fun getChat(id: Long) = chats[id] fun getChat(id: Long) = chats[id]
@ -138,6 +152,8 @@ class TelegramHelper private constructor() {
usersLocationMessages.values.filter { it.chatId == chatId } usersLocationMessages.values.filter { it.chatId == chatId }
fun getMessages() = usersLocationMessages.values.toList() fun getMessages() = usersLocationMessages.values.toList()
fun getChatLiveMessages() = chatLiveMessagesFull
fun getMessagesByChatIds(): Map<Long, List<TdApi.Message>> { fun getMessagesByChatIds(): Map<Long, List<TdApi.Message>> {
val res = mutableMapOf<Long, MutableList<TdApi.Message>>() val res = mutableMapOf<Long, MutableList<TdApi.Message>>()
@ -532,10 +548,12 @@ class TelegramHelper private constructor() {
TdApi.Messages.CONSTRUCTOR -> { TdApi.Messages.CONSTRUCTOR -> {
val messages = (obj as TdApi.Messages).messages val messages = (obj as TdApi.Messages).messages
chatLiveMessages.clear() chatLiveMessages.clear()
chatLiveMessagesFull.clear()
if (messages.isNotEmpty()) { if (messages.isNotEmpty()) {
for (msg in messages) { for (msg in messages) {
val chatId = msg.chatId val chatId = msg.chatId
chatLiveMessages[chatId] = msg.id chatLiveMessages[chatId] = msg.id
chatLiveMessagesFull[chatId] = msg
} }
} }
onComplete?.invoke() onComplete?.invoke()
@ -704,6 +722,7 @@ class TelegramHelper private constructor() {
if (haveAuthorization) { if (haveAuthorization) {
requestChats(true) requestChats(true)
requestCurrentUser() requestCurrentUser()
getActiveLiveLocationMessages {}
} }
} }
val newAuthState = getTelegramAuthorizationState() val newAuthState = getTelegramAuthorizationState()
@ -1067,6 +1086,7 @@ class TelegramHelper private constructor() {
TdApi.UpdateMessageSendSucceeded.CONSTRUCTOR -> { TdApi.UpdateMessageSendSucceeded.CONSTRUCTOR -> {
val updateMessageSendSucceeded = obj as TdApi.UpdateMessageSendSucceeded val updateMessageSendSucceeded = obj as TdApi.UpdateMessageSendSucceeded
val message = updateMessageSendSucceeded.message val message = updateMessageSendSucceeded.message
chatLiveMessagesFull[message.chatId] = message
chatLiveMessages[message.chatId] = message.id chatLiveMessages[message.chatId] = message.id
} }
TdApi.UpdateDeleteMessages.CONSTRUCTOR -> { TdApi.UpdateDeleteMessages.CONSTRUCTOR -> {
@ -1078,6 +1098,9 @@ class TelegramHelper private constructor() {
if (chatLiveMessages[chatId] == messageId) { if (chatLiveMessages[chatId] == messageId) {
chatLiveMessages.remove(chatId) 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()) { if (deletedMessages.isNotEmpty()) {

View file

@ -21,8 +21,12 @@ import net.osmand.telegram.helpers.TelegramUiHelper
import net.osmand.telegram.utils.AndroidUtils import net.osmand.telegram.utils.AndroidUtils
import org.drinkless.td.libcore.telegram.TdApi import org.drinkless.td.libcore.telegram.TdApi
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import java.util.*
import java.text.SimpleDateFormat
private const val SELECTED_CHATS_KEY = "selected_chats" private const val SELECTED_CHATS_KEY = "selected_chats"
private const val SHARE_LOCATION_CHAT = 1
private const val DEFAULT_CHAT = 0
class MyLocationTabFragment : Fragment(), TelegramListener { class MyLocationTabFragment : Fragment(), TelegramListener {
@ -31,8 +35,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private var searchBoxHeight: Int = 0 private var searchBoxHeight: Int = 0
private var searchBoxSidesMargin: Int = 0 private var searchBoxSidesMargin: Int = 0
private var appBarScrollRange: Int = -1
private val app: TelegramApplication private val app: TelegramApplication
get() = activity?.application as TelegramApplication get() = activity?.application as TelegramApplication
@ -42,13 +44,15 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private lateinit var mainView: View private lateinit var mainView: View
private lateinit var appBarLayout: AppBarLayout private lateinit var appBarLayout: AppBarLayout
private lateinit var userImage: ImageView private lateinit var userImage: ImageView
private lateinit var imageContainer: FrameLayout
private lateinit var titleContainer: LinearLayout
private lateinit var optionsBtn: ImageView private lateinit var optionsBtn: ImageView
private lateinit var optionsBtnTitle: ImageView
private lateinit var textContainer: LinearLayout private lateinit var textContainer: LinearLayout
private lateinit var title: TextView private lateinit var title: TextView
private lateinit var description: TextView private lateinit var description: TextView
private lateinit var searchBox: FrameLayout private lateinit var searchBox: FrameLayout
private lateinit var recyclerView: RecyclerView private lateinit var stopSharingSwitcher: Switch
private lateinit var switch: Switch
private lateinit var searchBoxBg: GradientDrawable private lateinit var searchBoxBg: GradientDrawable
@ -61,7 +65,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private var actionButtonsListener: ActionButtonsListener? = null private var actionButtonsListener: ActionButtonsListener? = null
private var hasAnyChatToShareLocation: Boolean = true private var inSharingMode: Boolean = false
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
@ -86,7 +90,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
} }
mainView = inflater.inflate(R.layout.fragment_my_location_tab, container, false) mainView = inflater.inflate(R.layout.fragment_my_location_tab, container, false)
hasAnyChatToShareLocation = settings.hasAnyChatToShareLocation()
appBarLayout = mainView.findViewById<AppBarLayout>(R.id.app_bar_layout).apply { appBarLayout = mainView.findViewById<AppBarLayout>(R.id.app_bar_layout).apply {
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21) {
@ -94,10 +97,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
outlineProvider = null outlineProvider = null
} }
addOnOffsetChangedListener { appBar, offset -> addOnOffsetChangedListener { appBar, offset ->
// if (appBarScrollRange == -1) { val collapsed = Math.abs(offset) == appBar.totalScrollRange
appBarScrollRange = appBar.totalScrollRange
// }
val collapsed = Math.abs(offset) == appBarScrollRange
if (collapsed != appBarCollapsed) { if (collapsed != appBarCollapsed) {
appBarCollapsed = collapsed appBarCollapsed = collapsed
adjustText() adjustText()
@ -111,12 +111,15 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
setImageResource(R.drawable.img_my_location_user) setImageResource(R.drawable.img_my_location_user)
} }
imageContainer = mainView.findViewById<FrameLayout>(R.id.image_container)
titleContainer = mainView.findViewById<LinearLayout>(R.id.title_container)
optionsBtn = mainView.findViewById<ImageView>(R.id.options).apply { optionsBtn = mainView.findViewById<ImageView>(R.id.options).apply {
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu)) setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
setOnClickListener { showPopupMenu() } setOnClickListener { showPopupMenu() }
} }
mainView.findViewById<ImageView>(R.id.options_icon).apply { optionsBtnTitle = mainView.findViewById<ImageView>(R.id.options_title).apply {
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu)) setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
setOnClickListener { showPopupMenu() } setOnClickListener { showPopupMenu() }
} }
@ -150,11 +153,12 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
.setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_search_dark)) .setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_search_dark))
} }
recyclerView = mainView.findViewById<RecyclerView>(R.id.recycler_view).apply { mainView.findViewById<RecyclerView>(R.id.recycler_view).apply {
layoutManager = LinearLayoutManager(context) layoutManager = LinearLayoutManager(context)
adapter = this@MyLocationTabFragment.adapter adapter = this@MyLocationTabFragment.adapter
} }
switch = mainView.findViewById<Switch>(R.id.stop_all_sharing_switcher).apply {
stopSharingSwitcher = mainView.findViewById<Switch>(R.id.stop_all_sharing_switcher).apply {
if (settings.hasAnyChatToShareLocation()) { if (settings.hasAnyChatToShareLocation()) {
isChecked = true isChecked = true
} }
@ -165,22 +169,20 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
if (!app.settings.hasAnyChatToShareLocation()) { if (!app.settings.hasAnyChatToShareLocation()) {
app.shareLocationHelper.stopSharingLocation() app.shareLocationHelper.stopSharingLocation()
} }
updateList()
updateSharingMode() updateSharingMode()
updateList()
} }
} }
} }
} }
updateSharingMode()
return mainView return mainView
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
updateList()
updateSharingMode() updateSharingMode()
updateList()
} }
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
@ -192,8 +194,8 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
if (requestCode == SetTimeDialogFragment.LOCATION_SHARED_REQUEST_CODE) { if (requestCode == SetTimeDialogFragment.LOCATION_SHARED_REQUEST_CODE) {
clearSelection() clearSelection()
updateList()
updateSharingMode() updateSharingMode()
updateList()
} }
} }
@ -203,35 +205,35 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
) { ) {
when (newTelegramAuthorizationState) { when (newTelegramAuthorizationState) {
TelegramHelper.TelegramAuthorizationState.READY -> { TelegramHelper.TelegramAuthorizationState.READY -> {
updateList()
updateSharingMode() updateSharingMode()
updateList()
} }
TelegramHelper.TelegramAuthorizationState.CLOSED, TelegramHelper.TelegramAuthorizationState.CLOSED,
TelegramHelper.TelegramAuthorizationState.UNKNOWN -> { TelegramHelper.TelegramAuthorizationState.UNKNOWN -> {
adapter.chats = emptyList() adapter.chats = mutableListOf()
} }
else -> Unit else -> Unit
} }
} }
override fun onTelegramChatsRead() { override fun onTelegramChatsRead() {
updateList()
updateSharingMode() updateSharingMode()
updateList()
} }
override fun onTelegramChatsChanged() { override fun onTelegramChatsChanged() {
updateList()
updateSharingMode() updateSharingMode()
updateList()
} }
override fun onTelegramChatChanged(chat: TdApi.Chat) { override fun onTelegramChatChanged(chat: TdApi.Chat) {
updateList()
updateSharingMode() updateSharingMode()
updateList()
} }
override fun onTelegramUserChanged(user: TdApi.User) { override fun onTelegramUserChanged(user: TdApi.User) {
updateList()
updateSharingMode() updateSharingMode()
updateList()
} }
override fun onTelegramError(code: Int, message: String) { override fun onTelegramError(code: Int, message: String) {
@ -256,29 +258,27 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
} }
private fun updateSharingMode() { private fun updateSharingMode() {
hasAnyChatToShareLocation = settings.hasAnyChatToShareLocation() if (!settings.hasAnyChatToShareLocation()) {
if (!hasAnyChatToShareLocation) { imageContainer.visibility = View.VISIBLE
mainView.findViewById<View>(R.id.tab_title).visibility = View.GONE textContainer.visibility = View.VISIBLE
mainView.findViewById<View>(R.id.appbar_divider).visibility = View.GONE titleContainer.visibility = View.GONE
mainView.findViewById<View>(R.id.stop_all_sharing_row).visibility = View.GONE val headerParams = imageContainer.layoutParams as AppBarLayout.LayoutParams
mainView.findViewById<View>(R.id.text_container).visibility = View.VISIBLE headerParams.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
mainView.findViewById<View>(R.id.background_image).visibility = View.VISIBLE if (inSharingMode) {
val headerParams = mainView.findViewById<View>(R.id.background_image).layoutParams as AppBarLayout.LayoutParams AndroidUtils.removeStatusBarPadding19v(context!!, titleContainer)
headerParams.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL or
AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS
} else {
val headerParams = mainView.findViewById<View>(R.id.background_image).layoutParams as AppBarLayout.LayoutParams
headerParams.scrollFlags = 0
mainView.findViewById<View>(R.id.background_image).visibility = View.GONE
mainView.findViewById<View>(R.id.text_container).visibility = View.GONE
mainView.findViewById<View>(R.id.tab_title).visibility = View.VISIBLE
mainView.findViewById<View>(R.id.appbar_divider).visibility = View.VISIBLE
mainView.findViewById<View>(R.id.stop_all_sharing_row).visibility = View.VISIBLE
switch.apply {
if (hasAnyChatToShareLocation) {
isChecked = true
}
} }
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
} }
} }
@ -299,7 +299,11 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
ListPopupWindow(ctx).apply { ListPopupWindow(ctx).apply {
isModal = true isModal = true
anchorView = optionsBtn anchorView = if (app.settings.hasAnyChatToShareLocation()) {
optionsBtnTitle
} else {
optionsBtn
}
setContentWidth(AndroidUtils.getPopupMenuWidth(ctx, menuList)) setContentWidth(AndroidUtils.getPopupMenuWidth(ctx, menuList))
setDropDownGravity(Gravity.END or Gravity.TOP) setDropDownGravity(Gravity.END or Gravity.TOP)
setAdapter(ArrayAdapter(ctx, R.layout.popup_list_text_item, menuList)) setAdapter(ArrayAdapter(ctx, R.layout.popup_list_text_item, menuList))
@ -401,45 +405,47 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
} }
private fun updateList() { private fun updateList() {
hasAnyChatToShareLocation = settings.hasAnyChatToShareLocation() val chats: MutableList<TdApi.Chat> = mutableListOf()
if (hasAnyChatToShareLocation) { val currentUser = telegramHelper.getCurrentUser()
val chatList = settings.getShareLocationChats() val chatList: ArrayList<Long> = if (settings.hasAnyChatToShareLocation()) {
val chats: MutableList<TdApi.Chat> = mutableListOf() settings.getShareLocationChats()
val currentUser = telegramHelper.getCurrentUser()
for (orderedChat in chatList) {
val chat = telegramHelper.getChat(orderedChat)
if (chat != null) {
if (telegramHelper.isPrivateChat(chat)) {
if ((chat.type as TdApi.ChatTypePrivate).userId == currentUser?.id) {
continue
}
}
chats.add(chat)
}
}
adapter.chats = chats
} else { } else {
val chatList = telegramHelper.getChatList() telegramHelper.getChatListIds()
val chats: MutableList<TdApi.Chat> = mutableListOf() }
val currentUser = telegramHelper.getCurrentUser() for (chatId in chatList) {
for (orderedChat in chatList) { val chat = telegramHelper.getChat(chatId)
val chat = telegramHelper.getChat(orderedChat.chatId) if (chat != null) {
if (chat != null) { if (telegramHelper.isPrivateChat(chat)) {
if (telegramHelper.isPrivateChat(chat)) { if ((chat.type as TdApi.ChatTypePrivate).userId == currentUser?.id) {
if ((chat.type as TdApi.ChatTypePrivate).userId == currentUser?.id) { continue
continue
}
} }
chats.add(chat)
} }
chats.add(chat)
} }
adapter.chats = chats }
adapter.chats = chats
}
private fun formatTime(timeSec: Long, short: Boolean): String {
val hours = TimeUnit.SECONDS.toHours(timeSec)
val minutes = TimeUnit.SECONDS.toMinutes(timeSec) % 60
return if (short) {
String.format("%02d:%02d", hours, minutes)
} else {
var hoursS = ""
var minutesS = ""
if (hours > 0) {
hoursS = String.format("%2d h ", hours)
}
if (minutes > 0) {
minutesS = String.format("%2d min", minutes)
}
hoursS + minutesS
} }
} }
inner class MyLocationListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() { inner class MyLocationListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
var chats = mutableListOf<TdApi.Chat>()
var chats: List<TdApi.Chat> = emptyList()
set(value) { set(value) {
field = value field = value
notifyDataSetChanged() notifyDataSetChanged()
@ -447,17 +453,17 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
override fun getItemViewType(position: Int): Int { override fun getItemViewType(position: Int): Int {
return if (settings.isSharingLocationToChat(chats[position].id)) { return if (settings.isSharingLocationToChat(chats[position].id)) {
1 SHARE_LOCATION_CHAT
} else { } else {
0 DEFAULT_CHAT
} }
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return if (viewType == 1) { return if (viewType == SHARE_LOCATION_CHAT) {
val view = LayoutInflater.from(parent.context) val view = LayoutInflater.from(parent.context)
.inflate(R.layout.live_now_chat_my_location, parent, false) .inflate(R.layout.my_location_sharing_chat, parent, false)
ChatViewHolder2(view) SharingChatViewHolder(view)
} else { } else {
val view = LayoutInflater.from(parent.context) val view = LayoutInflater.from(parent.context)
.inflate(R.layout.user_list_item, parent, false) .inflate(R.layout.user_list_item, parent, false)
@ -513,7 +519,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
} }
} }
} }
} else if (holder is ChatViewHolder2) { } else if (holder is SharingChatViewHolder) {
TelegramUiHelper.setupPhoto( TelegramUiHelper.setupPhoto(
app, app,
holder.icon, holder.icon,
@ -533,58 +539,64 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
if (!app.settings.hasAnyChatToShareLocation()) { if (!app.settings.hasAnyChatToShareLocation()) {
app.shareLocationHelper.stopSharingLocation() app.shareLocationHelper.stopSharingLocation()
} }
updateList() chats.remove(chat)
updateSharingMode() updateSharingMode()
if (chats.isEmpty()) {
updateList()
} else {
adapter.notifyDataSetChanged()
}
} }
} }
} }
} }
val duration = settings.getChatLivePeriod(chat.id) val duration = settings.getChatLivePeriod(chat.id)
if (duration != null && duration > 0) { if (duration != null && duration > 0) {
holder.descriptionDuration?.text = formatTime(duration) holder.descriptionDuration?.text = formatTime(duration, false)
}
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.textInArea?.text = "+ 30 min"
holder.stopSharingFirstPart?.text = time
holder.stopSharingSecondPart?.text = formattedDate
}
} else {
holder.textInArea?.visibility = View.INVISIBLE
holder.stopSharingFirstPart?.visibility = View.INVISIBLE
holder.stopSharingSecondPart?.visibility = View.INVISIBLE
} }
} }
} }
override fun getItemCount() = chats.size override fun getItemCount() = chats.size
private fun formatTime(timeSec: Long): String {
val hours = TimeUnit.SECONDS.toHours(timeSec)
val minutes = TimeUnit.SECONDS.toMinutes(timeSec) % 60
var hoursS = ""
var minutesS = ""
if (hours > 0) {
hoursS = String.format("%2d h ", hours)
}
if (minutes > 0) {
minutesS = String.format("%2d min", minutes)
}
return hoursS + minutesS
}
private fun formatTimeAt(timeSec: Long): String {
val hours = TimeUnit.SECONDS.toHours(timeSec)
val minutes = TimeUnit.SECONDS.toMinutes(timeSec) % 60
return String.format("%2d:%2d", hours, minutes)
}
inner class ChatViewHolder(val view: View) : RecyclerView.ViewHolder(view) { inner class ChatViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
val icon: ImageView? = view.findViewById(R.id.icon) val icon: ImageView? = view.findViewById(R.id.icon)
val title: TextView? = view.findViewById(R.id.title) val title: TextView? = view.findViewById(R.id.title)
val description: TextView? = view.findViewById(R.id.description) val description: TextView? = view.findViewById(R.id.description)
val textInArea: TextView? = view.findViewById(R.id.text_in_area)
val checkBox: CheckBox? = view.findViewById(R.id.check_box) val checkBox: CheckBox? = view.findViewById(R.id.check_box)
val bottomShadow: View? = view.findViewById(R.id.bottom_shadow) val bottomShadow: View? = view.findViewById(R.id.bottom_shadow)
} }
inner class ChatViewHolder2(val view: View) : RecyclerView.ViewHolder(view) { inner class SharingChatViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
val icon: ImageView? = view.findViewById(R.id.icon) val icon: ImageView? = view.findViewById(R.id.icon)
val title: TextView? = view.findViewById(R.id.title) val title: TextView? = view.findViewById(R.id.title)
val description: TextView? = view.findViewById(R.id.description) val description: TextView? = view.findViewById(R.id.description)
val descriptionDuration: TextView? = view.findViewById(R.id.duration) val descriptionDuration: TextView? = view.findViewById(R.id.duration)
val textInArea: TextView? = view.findViewById(R.id.text_in_area) val textInArea: TextView? = view.findViewById(R.id.text_in_area)
val switcher: Switch? = view.findViewById(R.id.switcher) val switcher: Switch? = view.findViewById(R.id.switcher)
val stopTranslation: TextView? = view.findViewById(R.id.stop_translation_in_tv_1) val stopSharingDescr: TextView? = view.findViewById(R.id.ending_in)
val stopIn: TextView? = view.findViewById(R.id.stop_translation_in_tv_2) val stopSharingFirstPart: TextView? = view.findViewById(R.id.ending_in_first_part)
val stopSharingSecondPart: TextView? = view.findViewById(R.id.ending_in_second_part)
} }
} }

View file

@ -84,6 +84,14 @@ 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 { fun getPopupMenuWidth(ctx: Context, titles: Collection<String>): Int {
val txtSize = ctx.resources.getDimensionPixelSize(R.dimen.list_item_title_text_size) val txtSize = ctx.resources.getDimensionPixelSize(R.dimen.list_item_title_text_size)