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"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--<item>-->
<!--<nine-patch android:src="@drawable/bg_card_shadow_cr3dp"/>-->
<!--</item>-->
<item>
<nine-patch android:src="@drawable/bg_card_shadow_cr3dp" />
</item>
<item>
<shape>
<solid android:color="@color/card_bg_light"/>
<corners android:radius="3dp"/>
<solid android:color="@color/card_bg_light" />
<corners android:radius="3dp" />
</shape>
</item>
</layer-list>

View file

@ -13,7 +13,7 @@
android:background="?attr/card_bg_color">
<FrameLayout
android:id="@+id/background_image"
android:id="@+id/image_container"
android:layout_width="match_parent"
android:layout_height="@dimen/my_location_image_height"
app:layout_scrollFlags="scroll">
@ -132,81 +132,95 @@
</FrameLayout>
<FrameLayout
android:id="@+id/tab_title"
<LinearLayout
android:id="@+id/title_container"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height"
android:visibility="visible">
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/title_row"
<FrameLayout
android:id="@+id/tab_title"
android:layout_width="match_parent"
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
android:id="@+id/stop_all_sharing_title"
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_marginEnd="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:src="@drawable/ic_action_other_menu"
android:tint="@color/icon_light" />
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>
</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>
</android.support.design.widget.AppBarLayout>

View file

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

View file

@ -24,8 +24,8 @@
<dimen name="dialog_welcome_title_top_margin">85dp</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_big">64dp</dimen>
<dimen name="list_item_icon_size">40dp</dimen>
<dimen name="list_item_icon_margin_left">12dp</dimen>

View file

@ -1,5 +1,7 @@
<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="open_osmand">Open OsmAnd</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.ScheduledExecutorService
import java.util.concurrent.TimeUnit
import kotlin.collections.ArrayList
import kotlin.collections.HashSet
@ -67,6 +68,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 downloadChatFilesMap = ConcurrentHashMap<String, TdApi.Chat>()
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 getChat(id: Long) = chats[id]
@ -139,6 +153,8 @@ class TelegramHelper private constructor() {
fun getMessages() = usersLocationMessages.values.toList()
fun getChatLiveMessages() = chatLiveMessagesFull
fun getMessagesByChatIds(): Map<Long, List<TdApi.Message>> {
val res = mutableMapOf<Long, MutableList<TdApi.Message>>()
for (message in usersLocationMessages.values) {
@ -532,10 +548,12 @@ 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
}
}
onComplete?.invoke()
@ -704,6 +722,7 @@ class TelegramHelper private constructor() {
if (haveAuthorization) {
requestChats(true)
requestCurrentUser()
getActiveLiveLocationMessages {}
}
}
val newAuthState = getTelegramAuthorizationState()
@ -1067,6 +1086,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
}
TdApi.UpdateDeleteMessages.CONSTRUCTOR -> {
@ -1078,6 +1098,9 @@ class TelegramHelper private constructor() {
if (chatLiveMessages[chatId] == messageId) {
chatLiveMessages.remove(chatId)
}
if (chatLiveMessagesFull.contains(chatId)) {
chatLiveMessagesFull.remove(chatId)
}
usersLocationMessages.remove(messageId)?.also { deletedMessages.add(it) }
}
if (deletedMessages.isNotEmpty()) {

View file

@ -21,8 +21,12 @@ import net.osmand.telegram.helpers.TelegramUiHelper
import net.osmand.telegram.utils.AndroidUtils
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
private const val DEFAULT_CHAT = 0
class MyLocationTabFragment : Fragment(), TelegramListener {
@ -31,8 +35,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private var searchBoxHeight: Int = 0
private var searchBoxSidesMargin: Int = 0
private var appBarScrollRange: Int = -1
private val app: TelegramApplication
get() = activity?.application as TelegramApplication
@ -42,13 +44,15 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private lateinit var mainView: View
private lateinit var appBarLayout: AppBarLayout
private lateinit var userImage: ImageView
private lateinit var imageContainer: FrameLayout
private lateinit var titleContainer: LinearLayout
private lateinit var optionsBtn: ImageView
private lateinit var optionsBtnTitle: ImageView
private lateinit var textContainer: LinearLayout
private lateinit var title: TextView
private lateinit var description: TextView
private lateinit var searchBox: FrameLayout
private lateinit var recyclerView: RecyclerView
private lateinit var switch: Switch
private lateinit var stopSharingSwitcher: Switch
private lateinit var searchBoxBg: GradientDrawable
@ -61,7 +65,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private var actionButtonsListener: ActionButtonsListener? = null
private var hasAnyChatToShareLocation: Boolean = true
private var inSharingMode: Boolean = false
override fun onCreateView(
inflater: LayoutInflater,
@ -86,7 +90,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
}
mainView = inflater.inflate(R.layout.fragment_my_location_tab, container, false)
hasAnyChatToShareLocation = settings.hasAnyChatToShareLocation()
appBarLayout = mainView.findViewById<AppBarLayout>(R.id.app_bar_layout).apply {
if (Build.VERSION.SDK_INT >= 21) {
@ -94,10 +97,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
outlineProvider = null
}
addOnOffsetChangedListener { appBar, offset ->
// if (appBarScrollRange == -1) {
appBarScrollRange = appBar.totalScrollRange
// }
val collapsed = Math.abs(offset) == appBarScrollRange
val collapsed = Math.abs(offset) == appBar.totalScrollRange
if (collapsed != appBarCollapsed) {
appBarCollapsed = collapsed
adjustText()
@ -111,12 +111,15 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
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 {
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
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))
setOnClickListener { showPopupMenu() }
}
@ -150,11 +153,12 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
.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)
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()) {
isChecked = true
}
@ -165,22 +169,20 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
if (!app.settings.hasAnyChatToShareLocation()) {
app.shareLocationHelper.stopSharingLocation()
}
updateList()
updateSharingMode()
updateList()
}
}
}
}
updateSharingMode()
return mainView
}
override fun onResume() {
super.onResume()
updateList()
updateSharingMode()
updateList()
}
override fun onSaveInstanceState(outState: Bundle) {
@ -192,8 +194,8 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == SetTimeDialogFragment.LOCATION_SHARED_REQUEST_CODE) {
clearSelection()
updateList()
updateSharingMode()
updateList()
}
}
@ -203,35 +205,35 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
) {
when (newTelegramAuthorizationState) {
TelegramHelper.TelegramAuthorizationState.READY -> {
updateList()
updateSharingMode()
updateList()
}
TelegramHelper.TelegramAuthorizationState.CLOSED,
TelegramHelper.TelegramAuthorizationState.UNKNOWN -> {
adapter.chats = emptyList()
adapter.chats = mutableListOf()
}
else -> Unit
}
}
override fun onTelegramChatsRead() {
updateList()
updateSharingMode()
updateList()
}
override fun onTelegramChatsChanged() {
updateList()
updateSharingMode()
updateList()
}
override fun onTelegramChatChanged(chat: TdApi.Chat) {
updateList()
updateSharingMode()
updateList()
}
override fun onTelegramUserChanged(user: TdApi.User) {
updateList()
updateSharingMode()
updateList()
}
override fun onTelegramError(code: Int, message: String) {
@ -256,29 +258,27 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
}
private fun updateSharingMode() {
hasAnyChatToShareLocation = settings.hasAnyChatToShareLocation()
if (!hasAnyChatToShareLocation) {
mainView.findViewById<View>(R.id.tab_title).visibility = View.GONE
mainView.findViewById<View>(R.id.appbar_divider).visibility = View.GONE
mainView.findViewById<View>(R.id.stop_all_sharing_row).visibility = View.GONE
mainView.findViewById<View>(R.id.text_container).visibility = View.VISIBLE
mainView.findViewById<View>(R.id.background_image).visibility = View.VISIBLE
val headerParams = mainView.findViewById<View>(R.id.background_image).layoutParams as AppBarLayout.LayoutParams
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
}
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
}
}
@ -299,7 +299,11 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
ListPopupWindow(ctx).apply {
isModal = true
anchorView = optionsBtn
anchorView = if (app.settings.hasAnyChatToShareLocation()) {
optionsBtnTitle
} else {
optionsBtn
}
setContentWidth(AndroidUtils.getPopupMenuWidth(ctx, menuList))
setDropDownGravity(Gravity.END or Gravity.TOP)
setAdapter(ArrayAdapter(ctx, R.layout.popup_list_text_item, menuList))
@ -401,45 +405,47 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
}
private fun updateList() {
hasAnyChatToShareLocation = settings.hasAnyChatToShareLocation()
if (hasAnyChatToShareLocation) {
val chatList = settings.getShareLocationChats()
val chats: MutableList<TdApi.Chat> = mutableListOf()
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
val chats: MutableList<TdApi.Chat> = mutableListOf()
val currentUser = telegramHelper.getCurrentUser()
val chatList: ArrayList<Long> = if (settings.hasAnyChatToShareLocation()) {
settings.getShareLocationChats()
} else {
val chatList = telegramHelper.getChatList()
val chats: MutableList<TdApi.Chat> = mutableListOf()
val currentUser = telegramHelper.getCurrentUser()
for (orderedChat in chatList) {
val chat = telegramHelper.getChat(orderedChat.chatId)
if (chat != null) {
if (telegramHelper.isPrivateChat(chat)) {
if ((chat.type as TdApi.ChatTypePrivate).userId == currentUser?.id) {
continue
}
telegramHelper.getChatListIds()
}
for (chatId in chatList) {
val chat = telegramHelper.getChat(chatId)
if (chat != null) {
if (telegramHelper.isPrivateChat(chat)) {
if ((chat.type as TdApi.ChatTypePrivate).userId == currentUser?.id) {
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>() {
var chats: List<TdApi.Chat> = emptyList()
var chats = mutableListOf<TdApi.Chat>()
set(value) {
field = value
notifyDataSetChanged()
@ -447,17 +453,17 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
override fun getItemViewType(position: Int): Int {
return if (settings.isSharingLocationToChat(chats[position].id)) {
1
SHARE_LOCATION_CHAT
} else {
0
DEFAULT_CHAT
}
}
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)
.inflate(R.layout.live_now_chat_my_location, parent, false)
ChatViewHolder2(view)
.inflate(R.layout.my_location_sharing_chat, parent, false)
SharingChatViewHolder(view)
} else {
val view = LayoutInflater.from(parent.context)
.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(
app,
holder.icon,
@ -533,58 +539,64 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
if (!app.settings.hasAnyChatToShareLocation()) {
app.shareLocationHelper.stopSharingLocation()
}
updateList()
chats.remove(chat)
updateSharingMode()
if (chats.isEmpty()) {
updateList()
} else {
adapter.notifyDataSetChanged()
}
}
}
}
}
val duration = settings.getChatLivePeriod(chat.id)
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
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) {
val icon: ImageView? = view.findViewById(R.id.icon)
val title: TextView? = view.findViewById(R.id.title)
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 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 title: TextView? = view.findViewById(R.id.title)
val description: TextView? = view.findViewById(R.id.description)
val descriptionDuration: TextView? = view.findViewById(R.id.duration)
val textInArea: TextView? = view.findViewById(R.id.text_in_area)
val switcher: Switch? = view.findViewById(R.id.switcher)
val stopTranslation: TextView? = view.findViewById(R.id.stop_translation_in_tv_1)
val stopIn: TextView? = view.findViewById(R.id.stop_translation_in_tv_2)
val stopSharingDescr: TextView? = view.findViewById(R.id.ending_in)
val stopSharingFirstPart: TextView? = view.findViewById(R.id.ending_in_first_part)
val stopSharingSecondPart: TextView? = view.findViewById(R.id.ending_in_second_part)
}
}

View file

@ -85,6 +85,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 {
val txtSize = ctx.resources.getDimensionPixelSize(R.dimen.list_item_title_text_size)
val paint = Paint().apply { textSize = txtSize.toFloat() }