suggested list like one item in recycler
This commit is contained in:
parent
11e3da3701
commit
7eae6d1717
5 changed files with 234 additions and 215 deletions
|
@ -1,27 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="25dp" />
|
|
||||||
|
|
||||||
<net.osmand.telegram.ui.views.TextViewEx
|
|
||||||
android:id="@+id/header"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="54dp"
|
|
||||||
android:background="?attr/shared_chat_card_bg"
|
|
||||||
android:gravity="start|center_vertical"
|
|
||||||
android:paddingStart="@dimen/content_padding_standard"
|
|
||||||
android:paddingLeft="@dimen/content_padding_half"
|
|
||||||
android:paddingRight="@dimen/content_padding_half"
|
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
|
||||||
android:textSize="@dimen/hint_text_size"
|
|
||||||
app:typeface="@string/font_roboto_mono_bold"
|
|
||||||
tools:text="Suggested" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
|
@ -4,6 +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:orientation="vertical"
|
||||||
android:background="?attr/card_bg_color">
|
android:background="?attr/card_bg_color">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -25,53 +26,77 @@
|
||||||
android:layout_marginRight="@dimen/list_item_icon_margin_right"
|
android:layout_marginRight="@dimen/list_item_icon_margin_right"
|
||||||
tools:src="@drawable/img_user_picture" />
|
tools:src="@drawable/img_user_picture" />
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent">
|
||||||
android:layout_marginEnd="@dimen/content_padding_half"
|
|
||||||
android:layout_marginRight="@dimen/content_padding_half"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<net.osmand.telegram.ui.views.TextViewEx
|
<LinearLayout
|
||||||
android:id="@+id/title"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ellipsize="end"
|
android:layout_gravity="center_vertical"
|
||||||
android:maxLines="1"
|
android:orientation="horizontal">
|
||||||
android:textColor="?android:textColorPrimary"
|
|
||||||
android:textSize="@dimen/list_item_title_text_size"
|
|
||||||
app:typeface="@string/font_roboto_regular"
|
|
||||||
tools:text="Share to Share Location" />
|
|
||||||
|
|
||||||
<net.osmand.telegram.ui.views.TextViewEx
|
<LinearLayout
|
||||||
android:id="@+id/time"
|
android:layout_width="0dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_marginEnd="@dimen/content_padding_half"
|
||||||
android:ellipsize="end"
|
android:layout_marginRight="@dimen/content_padding_half"
|
||||||
android:maxLines="1"
|
android:layout_weight="1"
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:orientation="vertical">
|
||||||
android:textSize="@dimen/list_item_description_text_size"
|
|
||||||
app:typeface="@string/font_roboto_regular"
|
|
||||||
tools:text="for 1 hour" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
<net.osmand.telegram.ui.views.TextViewEx
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="?android:textColorPrimary"
|
||||||
|
android:textSize="@dimen/list_item_title_text_size"
|
||||||
|
app:typeface="@string/font_roboto_regular"
|
||||||
|
tools:text="Share to Share Location" />
|
||||||
|
|
||||||
<net.osmand.telegram.ui.views.TextViewEx
|
<net.osmand.telegram.ui.views.TextViewEx
|
||||||
android:id="@+id/start"
|
android:id="@+id/time"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="@dimen/dialog_button_height"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="@dimen/image_button_padding"
|
android:ellipsize="end"
|
||||||
android:layout_marginRight="@dimen/image_button_padding"
|
android:maxLines="1"
|
||||||
android:background="?attr/secondary_btn_bg"
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
android:gravity="center"
|
android:textSize="@dimen/list_item_description_text_size"
|
||||||
android:paddingLeft="@dimen/image_button_padding"
|
app:typeface="@string/font_roboto_regular"
|
||||||
android:paddingRight="@dimen/image_button_padding"
|
tools:text="for 1 hour" />
|
||||||
android:text="@string/shared_string_start"
|
|
||||||
android:textColor="?attr/ctrl_active_color"
|
</LinearLayout>
|
||||||
android:textSize="@dimen/text_button_text_size"
|
|
||||||
app:typeface="@string/font_roboto_medium"
|
<net.osmand.telegram.ui.views.TextViewEx
|
||||||
tools:text="Start" />
|
android:id="@+id/start"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="@dimen/dialog_button_height"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginEnd="@dimen/image_button_padding"
|
||||||
|
android:layout_marginRight="@dimen/image_button_padding"
|
||||||
|
android:background="?attr/secondary_btn_bg"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingLeft="@dimen/image_button_padding"
|
||||||
|
android:paddingRight="@dimen/image_button_padding"
|
||||||
|
android:text="@string/shared_string_start"
|
||||||
|
android:textColor="?attr/ctrl_active_color"
|
||||||
|
android:textSize="@dimen/text_button_text_size"
|
||||||
|
app:typeface="@string/font_roboto_medium"
|
||||||
|
tools:text="Start" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/divider"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:background="?attr/card_divider_color"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
51
OsmAnd-telegram/res/layout/suggested_list_item.xml
Normal file
51
OsmAnd-telegram/res/layout/suggested_list_item.xml
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/divider_top"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="26dp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/shared_chat_card_bg"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<net.osmand.telegram.ui.views.TextViewEx
|
||||||
|
android:id="@+id/header"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="54dp"
|
||||||
|
android:gravity="start|center_vertical"
|
||||||
|
android:paddingStart="@dimen/content_padding_standard"
|
||||||
|
android:paddingLeft="@dimen/content_padding_half"
|
||||||
|
android:paddingRight="@dimen/content_padding_half"
|
||||||
|
android:text="@string/shared_string_suggested"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
android:textSize="@dimen/hint_text_size"
|
||||||
|
app:typeface="@string/font_roboto_mono_bold"
|
||||||
|
tools:text="Suggested" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/last_items_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/divider_bottom"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="?attr/card_divider_color"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -7,7 +7,6 @@ import android.support.annotation.DrawableRes
|
||||||
import android.support.annotation.StringRes
|
import android.support.annotation.StringRes
|
||||||
import android.text.SpannableStringBuilder
|
import android.text.SpannableStringBuilder
|
||||||
import android.text.style.ForegroundColorSpan
|
import android.text.style.ForegroundColorSpan
|
||||||
import com.google.gson.JsonObject
|
|
||||||
import net.osmand.PlatformUtil
|
import net.osmand.PlatformUtil
|
||||||
import net.osmand.telegram.helpers.OsmandAidlHelper
|
import net.osmand.telegram.helpers.OsmandAidlHelper
|
||||||
import net.osmand.telegram.helpers.ShowLocationHelper
|
import net.osmand.telegram.helpers.ShowLocationHelper
|
||||||
|
@ -840,9 +839,8 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
lastChatsInfo.forEach { (chatId, lastInfo) ->
|
lastChatsInfo.forEach { (chatId, lastInfo) ->
|
||||||
val obj = JSONObject()
|
val obj = JSONObject()
|
||||||
obj.put(LastChatInfo.CHAT_ID_KEY, chatId)
|
obj.put(LastChatInfo.CHAT_ID_KEY, chatId)
|
||||||
obj.put(LastChatInfo.LIVE_PERIOD_KEY, lastInfo.livePeriod)
|
|
||||||
obj.put(LastChatInfo.PERIODS_KEY, convertPeriodsToJson(lastInfo.periods))
|
obj.put(LastChatInfo.PERIODS_KEY, convertPeriodsToJson(lastInfo.periods))
|
||||||
log.info("Periods to put: ${lastInfo.periods}")
|
log.info("Save last info: ${lastInfo.periods} / id: ${lastInfo.chatId}")
|
||||||
jArray.put(obj)
|
jArray.put(obj)
|
||||||
}
|
}
|
||||||
jArray
|
jArray
|
||||||
|
@ -855,12 +853,13 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
private fun convertPeriodsToJson(periods: LinkedList<Long>): JSONArray? {
|
private fun convertPeriodsToJson(periods: LinkedList<Long>): JSONArray? {
|
||||||
return try {
|
return try {
|
||||||
val jArray = JSONArray()
|
val jArray = JSONArray()
|
||||||
|
log.info("periods to convert : $periods")
|
||||||
for (i in 0 until periods.count()) {
|
for (i in 0 until periods.count()) {
|
||||||
val obj = JSONObject()
|
val obj = JSONObject()
|
||||||
obj.put(i.toString(), periods[i])
|
obj.put(i.toString(), periods[i])
|
||||||
jArray.put(obj)
|
jArray.put(obj)
|
||||||
}
|
}
|
||||||
log.info("Json array periods: $jArray")
|
log.info("Converted to json periods: $jArray")
|
||||||
jArray
|
jArray
|
||||||
} catch (e: JSONException) {
|
} catch (e: JSONException) {
|
||||||
log.error(e)
|
log.error(e)
|
||||||
|
@ -939,16 +938,14 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
val obj = json.getJSONObject(i)
|
val obj = json.getJSONObject(i)
|
||||||
val lastInfo = LastChatInfo().apply {
|
val lastInfo = LastChatInfo().apply {
|
||||||
chatId = obj.optLong(LastChatInfo.CHAT_ID_KEY)
|
chatId = obj.optLong(LastChatInfo.CHAT_ID_KEY)
|
||||||
// livePeriod = obj.optLong(LastChatInfo.LIVE_PERIOD_KEY)
|
|
||||||
periods = LinkedList<Long>()
|
periods = LinkedList<Long>()
|
||||||
val jsonArray = obj.getJSONArray(LastChatInfo.PERIODS_KEY)
|
val jsonArray = obj.getJSONArray(LastChatInfo.PERIODS_KEY)
|
||||||
log.info("getJson: $jsonArray")
|
log.info("get Json periods: $jsonArray")
|
||||||
for (j in 0 until jsonArray.length()) {
|
for (j in 0 until jsonArray.length()) {
|
||||||
val obj=jsonArray.get(j) as JSONObject
|
val o = jsonArray.get(j) as JSONObject
|
||||||
|
periods.addLast(o.optLong(j.toString()))
|
||||||
periods.add(obj.optLong(j.toString()))
|
|
||||||
}
|
}
|
||||||
log.info("Periods: $periods")
|
log.info("Converted from json periods: $periods")
|
||||||
livePeriod = calcLivePeriod(periods)
|
livePeriod = calcLivePeriod(periods)
|
||||||
}
|
}
|
||||||
lastChatsInfo[lastInfo.chatId] = lastInfo
|
lastChatsInfo[lastInfo.chatId] = lastInfo
|
||||||
|
@ -967,6 +964,7 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.info("added to periods: ${lastChatsInfo[id]?.periods}")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addTimeToPeriods(periods: LinkedList<Long>?, time: Long): LinkedList<Long> {
|
private fun addTimeToPeriods(periods: LinkedList<Long>?, time: Long): LinkedList<Long> {
|
||||||
|
@ -984,7 +982,6 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calcLivePeriod(periods: LinkedList<Long>): Long {
|
private fun calcLivePeriod(periods: LinkedList<Long>): Long {
|
||||||
periods.sort()
|
|
||||||
return if (periods.count() % 2 == 0) {
|
return if (periods.count() % 2 == 0) {
|
||||||
(periods[periods.count() / 2] + periods[periods.count() / 2 - 1]) / 2
|
(periods[periods.count() / 2] + periods[periods.count() / 2 - 1]) / 2
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,11 +3,7 @@ package net.osmand.telegram.ui
|
||||||
import android.animation.*
|
import android.animation.*
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Canvas
|
|
||||||
import android.graphics.Rect
|
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.graphics.drawable.ColorDrawable
|
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import android.graphics.drawable.GradientDrawable
|
import android.graphics.drawable.GradientDrawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
@ -21,6 +17,7 @@ import android.text.SpannableString
|
||||||
import android.text.SpannableStringBuilder
|
import android.text.SpannableStringBuilder
|
||||||
import android.text.style.ForegroundColorSpan
|
import android.text.style.ForegroundColorSpan
|
||||||
import android.text.style.StyleSpan
|
import android.text.style.StyleSpan
|
||||||
|
import android.util.TypedValue
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.view.animation.LinearInterpolator
|
import android.view.animation.LinearInterpolator
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
@ -37,8 +34,7 @@ import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
private const val SELECTED_CHATS_KEY = "selected_chats"
|
private const val SELECTED_CHATS_KEY = "selected_chats"
|
||||||
private const val SELECTED_CHATS_USERS = "selected_users"
|
private const val SELECTED_CHATS_USERS = "selected_users"
|
||||||
private const val HEADER = 3
|
private const val SUGGESTED = 2
|
||||||
private const val LAST_SHARE_CHAT = 2
|
|
||||||
private const val SHARE_LOCATION_CHAT = 1
|
private const val SHARE_LOCATION_CHAT = 1
|
||||||
private const val DEFAULT_CHAT = 0
|
private const val DEFAULT_CHAT = 0
|
||||||
|
|
||||||
|
@ -214,7 +210,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
addItemDecoration(createDividerItemDecoration(sharingMode))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mainView.findViewById<View>(R.id.stop_all_sharing_row).setOnClickListener {
|
mainView.findViewById<View>(R.id.stop_all_sharing_row).setOnClickListener {
|
||||||
|
@ -466,54 +461,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createDividerItemDecoration(sharingMode: Boolean): RecyclerView.ItemDecoration {
|
|
||||||
val divider: Drawable = ColorDrawable(ContextCompat.getColor(app, R.color.card_divider_dark))
|
|
||||||
val pluginDividerHeight: Int = AndroidUtils.dpToPx(app, 1f)
|
|
||||||
return object : RecyclerView.ItemDecoration() {
|
|
||||||
override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {
|
|
||||||
val dividerLeft = if (sharingMode){
|
|
||||||
AndroidUtils.dpToPx(app, 72f)
|
|
||||||
} else {
|
|
||||||
parent.paddingLeft
|
|
||||||
}
|
|
||||||
val dividerRight = parent.width - parent.paddingRight
|
|
||||||
val childCount = parent.childCount
|
|
||||||
for (i in 0 until childCount - 1) {
|
|
||||||
val child = parent.getChildAt(i)
|
|
||||||
if (shouldDrawDivider(i)) {
|
|
||||||
val params = child.layoutParams as RecyclerView.LayoutParams
|
|
||||||
val dividerTop = child.bottom + params.bottomMargin
|
|
||||||
val dividerBottom = dividerTop + pluginDividerHeight
|
|
||||||
divider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom)
|
|
||||||
divider.draw(canvas)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
|
|
||||||
val position = parent.getChildAdapterPosition(view)
|
|
||||||
if (shouldDrawDivider(position)) {
|
|
||||||
outRect[0, 0, 0] = pluginDividerHeight
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun shouldDrawDivider(position: Int): Boolean {
|
|
||||||
val item = adapter.items[position]
|
|
||||||
val nextP = position + 1
|
|
||||||
if (nextP < adapter.items.count()) {
|
|
||||||
val next = adapter.items[nextP]
|
|
||||||
if (!sharingMode && item is LastChat && next !is LastChat) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sharingMode && item is LastChat) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateContent() {
|
private fun updateContent() {
|
||||||
sharingMode = sharingMode && settings.hasAnyChatToShareLocation()
|
sharingMode = sharingMode && settings.hasAnyChatToShareLocation()
|
||||||
updateSharingStatus()
|
updateSharingStatus()
|
||||||
|
@ -579,14 +526,13 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
||||||
if (sharingMode && settings.hasAnyChatToShareLocation()) {
|
if (sharingMode && settings.hasAnyChatToShareLocation()) {
|
||||||
val filteredLastItems = lastItems.filter { !settings.isSharingLocationToChat(it.chat.id) }.toMutableList()
|
val filteredLastItems = lastItems.filter { !settings.isSharingLocationToChat(it.chat.id) }.toMutableList()
|
||||||
val sorted = sortAdapterItems(items as MutableList<TdApi.Object>)
|
val sorted = sortAdapterItems(items as MutableList<TdApi.Object>)
|
||||||
if (filteredLastItems.isNotEmpty()) {
|
val lastChats = LastChats(filteredLastItems)
|
||||||
sorted.add(getString(R.string.shared_string_suggested))
|
sorted.add(lastChats)
|
||||||
}
|
|
||||||
sorted.addAll(filteredLastItems)
|
|
||||||
adapter.items = sorted
|
adapter.items = sorted
|
||||||
} else {
|
} else {
|
||||||
val filteredLastItems = lastItems.filter { !settings.isSharingLocationToChat(it.chat.id) }.toMutableList()
|
val filteredLastItems = lastItems.filter { !settings.isSharingLocationToChat(it.chat.id) }.toMutableList()
|
||||||
items.addAll(0, filteredLastItems)
|
val lastChats = LastChats(filteredLastItems)
|
||||||
|
items.add(0, lastChats)
|
||||||
adapter.items = items
|
adapter.items = items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -635,10 +581,8 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
||||||
is TdApi.User -> item.id.toLong()
|
is TdApi.User -> item.id.toLong()
|
||||||
else -> -1
|
else -> -1
|
||||||
}
|
}
|
||||||
return if (item is LastChat) {
|
return if (item is LastChats) {
|
||||||
LAST_SHARE_CHAT
|
SUGGESTED
|
||||||
} else if (item is String) {
|
|
||||||
HEADER
|
|
||||||
} else if (settings.isSharingLocationToChat(id) && sharingMode) {
|
} else if (settings.isSharingLocationToChat(id) && sharingMode) {
|
||||||
SHARE_LOCATION_CHAT
|
SHARE_LOCATION_CHAT
|
||||||
} else {
|
} else {
|
||||||
|
@ -658,15 +602,10 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
||||||
.inflate(R.layout.user_list_item, parent, false)
|
.inflate(R.layout.user_list_item, parent, false)
|
||||||
ChatViewHolder(view)
|
ChatViewHolder(view)
|
||||||
}
|
}
|
||||||
LAST_SHARE_CHAT -> {
|
SUGGESTED -> {
|
||||||
val view = LayoutInflater.from(parent.context)
|
val view = LayoutInflater.from(parent.context)
|
||||||
.inflate(R.layout.last_share_list_item, parent, false)
|
.inflate(R.layout.suggested_list_item, parent, false)
|
||||||
LastChatViewHolder(view)
|
SuggestedViewHolder(view)
|
||||||
}
|
|
||||||
HEADER -> {
|
|
||||||
val view = LayoutInflater.from(parent.context)
|
|
||||||
.inflate(R.layout.header_list_item, parent, false)
|
|
||||||
HeaderViewHolder(view)
|
|
||||||
}
|
}
|
||||||
else -> throw RuntimeException("Unsupported view type: $viewType")
|
else -> throw RuntimeException("Unsupported view type: $viewType")
|
||||||
}
|
}
|
||||||
|
@ -685,47 +624,11 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
val lastItem = position == itemCount - 1
|
val lastItem = position == itemCount - 1
|
||||||
val placeholderId =
|
|
||||||
if (isChat && telegramHelper.isGroup(item as TdApi.Chat)) R.drawable.img_group_picture else R.drawable.img_user_picture
|
|
||||||
val live = (isChat && settings.isSharingLocationToChat(itemId))
|
val live = (isChat && settings.isSharingLocationToChat(itemId))
|
||||||
val shareInfo = if (isChat) settings.getChatsShareInfo()[itemId] else null
|
val shareInfo = if (isChat) settings.getChatsShareInfo()[itemId] else null
|
||||||
|
|
||||||
val photoPath = when (item) {
|
setupPhoto(item, holder.icon, isChat)
|
||||||
is LastChat -> item.chat.photo?.small?.local?.path
|
holder.title?.text = getTitleText(item)
|
||||||
is TdApi.Chat -> item.photo?.small?.local?.path
|
|
||||||
is TdApi.User -> item.profilePhoto?.small?.local?.path
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
TelegramUiHelper.setupPhoto(app, holder.icon, photoPath, placeholderId, false)
|
|
||||||
|
|
||||||
if (item is LastChat) {
|
|
||||||
TelegramUiHelper.applyGrayscaleFilter(holder.icon)
|
|
||||||
}
|
|
||||||
|
|
||||||
val currentUserId = telegramHelper.getCurrentUserId()
|
|
||||||
val title = when (item) {
|
|
||||||
is LastChat -> {
|
|
||||||
if (telegramHelper.isPrivateChat(item.chat) && (item.chat.type as TdApi.ChatTypePrivate).userId == currentUserId) {
|
|
||||||
getString(R.string.saved_messages)
|
|
||||||
} else {
|
|
||||||
item.chat.title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is TdApi.Chat -> {
|
|
||||||
if (telegramHelper.isPrivateChat(item) && (item.type as TdApi.ChatTypePrivate).userId == currentUserId) {
|
|
||||||
getString(R.string.saved_messages)
|
|
||||||
} else {
|
|
||||||
item.title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is TdApi.User -> {
|
|
||||||
if (item.id == currentUserId) getString(R.string.saved_messages) else TelegramUiHelper.getUserName(item)
|
|
||||||
}
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.title?.text = title
|
|
||||||
|
|
||||||
if (holder is ChatViewHolder) {
|
if (holder is ChatViewHolder) {
|
||||||
holder.description?.visibility = View.GONE
|
holder.description?.visibility = View.GONE
|
||||||
|
@ -854,32 +757,101 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
||||||
text = description
|
text = description
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (holder is LastChatViewHolder) {
|
} else if (holder is SuggestedViewHolder) {
|
||||||
val sharingTime = SpannableStringBuilder("${getString(R.string.sharing_time)}: ")
|
holder.list.removeAllViews()
|
||||||
val formattedTime = OsmandFormatter.getFormattedDuration(app, (item as LastChat).time, false)
|
val iterator = (item as LastChats).list.iterator()
|
||||||
val start = sharingTime.length
|
iterator.forEach {
|
||||||
sharingTime.append(formattedTime)
|
holder.list.addView(createLastChatView(it, iterator.hasNext()))
|
||||||
sharingTime.setSpan(StyleSpan(Typeface.BOLD), start, sharingTime.length, 0)
|
}
|
||||||
sharingTime.setSpan(ForegroundColorSpan(ContextCompat.getColor(app, R.color.ctrl_active_light)), start, sharingTime.length, 0)
|
if (!sharingMode) {
|
||||||
holder.time?.text = sharingTime
|
holder.dividerTop?.visibility = View.GONE
|
||||||
|
holder.dividerBottom?.visibility = View.VISIBLE
|
||||||
holder.container?.setOnClickListener {
|
holder.header?.visibility = View.GONE
|
||||||
if (!AndroidUtils.isLocationPermissionAvailable(view!!.context)) {
|
val storedValueInTheme = TypedValue()
|
||||||
AndroidUtils.requestLocationPermission(activity!!)
|
if (context?.theme?.resolveAttribute(R.attr.card_bg_color, storedValueInTheme, true) != null) {
|
||||||
} else {
|
holder.container?.setBackgroundColor(storedValueInTheme.data)
|
||||||
settings.shareLocationToChat((item as LastChat).chat.id, true, item.time)
|
|
||||||
app.shareLocationHelper.startSharingLocation()
|
|
||||||
(activity as DataSetListener).onDataSetChanged()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (holder is HeaderViewHolder) {
|
|
||||||
holder.header?.text = item as String
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getTitleText(item: Any): String? {
|
||||||
|
val currentUserId = telegramHelper.getCurrentUserId()
|
||||||
|
return when (item) {
|
||||||
|
is LastChat -> {
|
||||||
|
if (telegramHelper.isPrivateChat(item.chat) && (item.chat.type as TdApi.ChatTypePrivate).userId == currentUserId) {
|
||||||
|
getString(R.string.saved_messages)
|
||||||
|
} else {
|
||||||
|
item.chat.title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is TdApi.Chat -> {
|
||||||
|
if (telegramHelper.isPrivateChat(item) && (item.type as TdApi.ChatTypePrivate).userId == currentUserId) {
|
||||||
|
getString(R.string.saved_messages)
|
||||||
|
} else {
|
||||||
|
item.title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is TdApi.User -> {
|
||||||
|
if (item.id == currentUserId) getString(R.string.saved_messages) else TelegramUiHelper.getUserName(item)
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupPhoto(item: Any, icon: ImageView?, isChat: Boolean) {
|
||||||
|
val photoPath = when (item) {
|
||||||
|
is LastChat -> item.chat.photo?.small?.local?.path
|
||||||
|
is TdApi.Chat -> item.photo?.small?.local?.path
|
||||||
|
is TdApi.User -> item.profilePhoto?.small?.local?.path
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
val placeholderId =
|
||||||
|
if (isChat && telegramHelper.isGroup(item as TdApi.Chat)) R.drawable.img_group_picture else R.drawable.img_user_picture
|
||||||
|
|
||||||
|
TelegramUiHelper.setupPhoto(app, icon, photoPath, placeholderId, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createLastChatView(lastChat: LastChat, hasNext: Boolean): View {
|
||||||
|
val view = layoutInflater.inflate(R.layout.last_share_list_item, null)
|
||||||
|
val time: TextView = view.findViewById(R.id.time)
|
||||||
|
val container: LinearLayout = view.findViewById(R.id.container)
|
||||||
|
val icon: ImageView = view.findViewById(R.id.icon)
|
||||||
|
val title: TextView = view.findViewById(R.id.title)
|
||||||
|
val divider: View = view.findViewById(R.id.divider)
|
||||||
|
|
||||||
|
if (sharingMode && hasNext) {
|
||||||
|
divider.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
container.setOnClickListener {
|
||||||
|
if (!AndroidUtils.isLocationPermissionAvailable(view!!.context)) {
|
||||||
|
AndroidUtils.requestLocationPermission(activity!!)
|
||||||
|
} else {
|
||||||
|
settings.shareLocationToChat(lastChat.chat.id, true, lastChat.time)
|
||||||
|
app.shareLocationHelper.startSharingLocation()
|
||||||
|
(activity as DataSetListener).onDataSetChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
title.text = getTitleText(lastChat.chat)
|
||||||
|
setupPhoto(lastChat.chat, icon, true)
|
||||||
|
TelegramUiHelper.applyGrayscaleFilter(icon)
|
||||||
|
|
||||||
|
val sharingTime = SpannableStringBuilder("${getString(R.string.sharing_time)}: ")
|
||||||
|
val formattedTime = OsmandFormatter.getFormattedDuration(app, lastChat.time, false)
|
||||||
|
val start = sharingTime.length
|
||||||
|
sharingTime.append(formattedTime)
|
||||||
|
sharingTime.setSpan(StyleSpan(Typeface.BOLD), start, sharingTime.length, 0)
|
||||||
|
sharingTime.setSpan(ForegroundColorSpan(ContextCompat.getColor(app, R.color.ctrl_active_light)), start, sharingTime.length, 0)
|
||||||
|
time.text = sharingTime
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
private fun removeItem(chat: TdApi.Object) {
|
private fun removeItem(chat: TdApi.Object) {
|
||||||
items.remove(chat)
|
items.remove(chat)
|
||||||
if (items.isEmpty()) {
|
val filtered = items.filterIsInstance<TdApi.Object>()
|
||||||
|
if (filtered.isEmpty()) {
|
||||||
sharingMode = false
|
sharingMode = false
|
||||||
updateContent()
|
updateContent()
|
||||||
shareLocationHelper.stopSharingLocation()
|
shareLocationHelper.stopSharingLocation()
|
||||||
|
@ -910,12 +882,11 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
||||||
val gpsPointsLine: TextView? = view.findViewById(R.id.gps_points_line)
|
val gpsPointsLine: TextView? = view.findViewById(R.id.gps_points_line)
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class LastChatViewHolder(val view: View) : BaseViewHolder(view) {
|
inner class SuggestedViewHolder(val view: View) : BaseViewHolder(view) {
|
||||||
|
val list: LinearLayout = view.findViewById(R.id.last_items_list)
|
||||||
val container: LinearLayout? = view.findViewById(R.id.container)
|
val container: LinearLayout? = view.findViewById(R.id.container)
|
||||||
val time: TextView? = view.findViewById(R.id.time)
|
val dividerBottom: View? = view.findViewById(R.id.divider_bottom)
|
||||||
}
|
val dividerTop: View? = view.findViewById(R.id.divider_top)
|
||||||
|
|
||||||
inner class HeaderViewHolder(val view: View) : BaseViewHolder(view) {
|
|
||||||
val header: TextView? = view.findViewById(R.id.header)
|
val header: TextView? = view.findViewById(R.id.header)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -926,3 +897,5 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
class LastChat internal constructor(val chat: TdApi.Chat, val time: Long)
|
class LastChat internal constructor(val chat: TdApi.Chat, val time: Long)
|
||||||
|
|
||||||
|
class LastChats constructor(val list: MutableList<LastChat>)
|
Loading…
Reference in a new issue