Merge pull request #6258 from osmandapp/TelegramImprovements

Add last update time from telegram
This commit is contained in:
Vitaliy 2018-11-06 15:18:44 +02:00 committed by GitHub
commit d0be5cd6c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 1 deletions

View file

@ -117,12 +117,24 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/last_telegram_update_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal"
android:gravity="center"
android:paddingTop="@dimen/content_padding_half"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/list_item_description_text_size"
android:visibility="gone"
app:typeface="@string/font_roboto_regular" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="@dimen/list_view_bottom_padding"
android:paddingBottom="@dimen/list_item_content_margin"
android:scrollbars="vertical"/>
<net.osmand.telegram.ui.views.TextViewEx

View file

@ -211,4 +211,16 @@
android:id="@+id/bottom_shadow"
layout="@layout/card_bottom_divider"/>
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/last_telegram_update_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:gravity="center"
android:paddingTop="@dimen/content_padding_half"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/list_item_description_text_size"
android:visibility="gone"
app:typeface="@string/font_roboto_regular" />
</LinearLayout>

View file

@ -144,4 +144,16 @@
android:id="@+id/bottom_shadow"
layout="@layout/card_bottom_divider"/>
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/last_telegram_update_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:gravity="center"
android:paddingTop="@dimen/content_padding_half"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/list_item_description_text_size"
android:visibility="gone"
app:typeface="@string/font_roboto_regular" />
</LinearLayout>

View file

@ -1,4 +1,5 @@
<resources>
<string name="last_update_from_telegram">Last update from Telegram</string>
<string name="enter_another_device_name">Pick a name you haven\'t already used</string>
<string name="device_added_successfully">%1$s added.</string>
<string name="shared_string_add">Add</string>

View file

@ -65,6 +65,8 @@ class TelegramHelper private constructor() {
var messageActiveTimeSec: Long = 0
var lastTelegramUpdateTime: Int = 0
private val users = ConcurrentHashMap<Int, TdApi.User>()
private val basicGroups = ConcurrentHashMap<Int, TdApi.BasicGroup>()
private val supergroups = ConcurrentHashMap<Int, TdApi.Supergroup>()
@ -572,6 +574,7 @@ class TelegramHelper private constructor() {
}
private fun addNewMessage(message: TdApi.Message) {
lastTelegramUpdateTime = Math.max(message.date, message.editDate)
if (message.isAppropriate()) {
val fromBot = isOsmAndBot(message.senderUserId)
val viaBot = isOsmAndBot(message.viaBotUserId)
@ -1235,6 +1238,7 @@ class TelegramHelper private constructor() {
} else {
synchronized(message) {
message.editDate = updateMessageEdited.editDate
lastTelegramUpdateTime = Math.max(message.date, message.editDate)
}
incomingMessagesListeners.forEach {
it.onReceiveChatLocationMessages(message.chatId, message)
@ -1250,6 +1254,7 @@ class TelegramHelper private constructor() {
}
} else {
synchronized(message) {
lastTelegramUpdateTime = Math.max(message.date, message.editDate)
val newContent = updateMessageContent.newContent
message.content = if (newContent is TdApi.MessageText) {
parseOsmAndBotLocation(newContent.text.text)

View file

@ -52,11 +52,14 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
private lateinit var openOsmAndBtn: TextView
private lateinit var sortByBtn: TextView
private lateinit var lastTelegramUpdateTime: TextView
private var location: Location? = null
private var heading: Float? = null
private var locationUiUpdateAllowed: Boolean = true
private var lastTelegramUpdateStr = ""
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@ -64,6 +67,10 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
): View? {
val mainView = inflater.inflate(R.layout.fragment_live_now_tab, container, false)
val appBarLayout = mainView.findViewById<View>(R.id.app_bar_layout)
lastTelegramUpdateTime = mainView.findViewById<TextView>(R.id.last_telegram_update_time)
lastTelegramUpdateStr = getString(R.string.last_update_from_telegram) + ": "
AndroidUtils.addStatusBarPadding19v(context!!, appBarLayout)
adapter = LiveNowListAdapter()
mainView.findViewById<RecyclerView>(R.id.recycler_view).apply {
@ -278,6 +285,12 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
}
}
if (res.isEmpty()) {
lastTelegramUpdateTime.visibility = View.VISIBLE
lastTelegramUpdateTime.text = OsmandFormatter.getListItemLiveTimeDescr(app, telegramHelper.lastTelegramUpdateTime, lastTelegramUpdateStr)
} else {
lastTelegramUpdateTime.visibility = View.GONE
}
adapter.items = sortAdapterItems(res)
}
@ -446,6 +459,13 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
}
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
if (lastItem) {
holder.lastTelegramUpdateTime?.visibility = View.VISIBLE
holder.lastTelegramUpdateTime?.text = OsmandFormatter.getListItemLiveTimeDescr(app, telegramHelper.lastTelegramUpdateTime, lastTelegramUpdateStr)
} else {
holder.lastTelegramUpdateTime?.visibility = View.GONE
}
if (item is ChatItem && holder is ChatViewHolder) {
val nextIsLocation = !lastItem && (items[position + 1] is LocationItem || !sortByGroup)
val chatId = item.chatId
@ -545,6 +565,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
val distanceText: TextView? = view.findViewById(R.id.distance_text)
val description: TextView? = view.findViewById(R.id.description)
val bottomShadow: View? = view.findViewById(R.id.bottom_shadow)
val lastTelegramUpdateTime: TextView? = view.findViewById(R.id.last_telegram_update_time)
abstract fun getOpenOnMapClickView(): View?
}