Merge pull request #6517 from osmandapp/TelegramImprovements

Enable service for users locations and fix minor bugs
This commit is contained in:
Alexey 2019-02-05 19:20:33 +03:00 committed by GitHub
commit ec734672e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 333 additions and 162 deletions

View file

@ -129,13 +129,20 @@
android:visibility="gone" android:visibility="gone"
app:typeface="@string/font_roboto_regular" /> app:typeface="@string/font_roboto_regular" />
<android.support.v7.widget.RecyclerView <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/recycler_view" android:id="@+id/swipe_refresh"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:clipToPadding="false"
android:paddingBottom="@dimen/list_item_content_margin" <android.support.v7.widget.RecyclerView
android:scrollbars="vertical"/> android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="@dimen/list_item_content_margin"
android:scrollbars="vertical" />
</android.support.v4.widget.SwipeRefreshLayout>
<net.osmand.telegram.ui.views.TextViewEx <net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/open_osmand_btn" android:id="@+id/open_osmand_btn"

View file

@ -107,22 +107,11 @@
</android.support.design.widget.AppBarLayout> </android.support.design.widget.AppBarLayout>
<FrameLayout <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="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.support.v7.widget.RecyclerView
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -131,6 +120,6 @@
android:paddingBottom="@dimen/list_item_content_margin" android:paddingBottom="@dimen/list_item_content_margin"
android:scrollbars="vertical" /> android:scrollbars="vertical" />
</FrameLayout> </android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout> </LinearLayout>

View file

@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
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="match_parent" android:layout_height="match_parent"
android:background="?attr/card_bg_color"> android:background="?attr/card_bg_color">
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -73,7 +78,7 @@
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:text="@string/start_date" android:text="@string/start_date"
android:textColor="?attr/android:textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/list_item_description_text_size" android:textSize="@dimen/list_item_description_text_size"
app:firstBaselineToTopHeight="@dimen/list_item_baseline_to_top_height" app:firstBaselineToTopHeight="@dimen/list_item_baseline_to_top_height"
app:typeface="@string/font_roboto_regular" /> app:typeface="@string/font_roboto_regular" />
@ -89,7 +94,7 @@
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:text="@string/end_date" android:text="@string/end_date"
android:textColor="?attr/android:textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/list_item_description_text_size" android:textSize="@dimen/list_item_description_text_size"
app:firstBaselineToTopHeight="@dimen/list_item_baseline_to_top_height" app:firstBaselineToTopHeight="@dimen/list_item_baseline_to_top_height"
app:typeface="@string/font_roboto_regular" /> app:typeface="@string/font_roboto_regular" />
@ -498,8 +503,8 @@
android:id="@+id/share_gpx_icon" android:id="@+id/share_gpx_icon"
android:layout_width="@dimen/list_item_icon_size" android:layout_width="@dimen/list_item_icon_size"
android:layout_height="@dimen/list_item_icon_size" android:layout_height="@dimen/list_item_icon_size"
android:src="@drawable/ic_action_share" tools:src="@drawable/ic_action_share"
android:tint="@color/ctrl_active_light" /> tools:tint="@color/ctrl_active_light" />
<net.osmand.telegram.ui.views.TextViewEx <net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/share_gpx_title" android:id="@+id/share_gpx_title"
@ -513,6 +518,9 @@
app:typeface="@string/font_roboto_regular" /> app:typeface="@string/font_roboto_regular" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</android.support.design.widget.CoordinatorLayout>

View file

@ -40,7 +40,8 @@
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:layout_weight="1" android:layout_weight="1"
android:orientation="vertical"> android:orientation="vertical"
android:paddingBottom="@dimen/content_padding_half">
<net.osmand.telegram.ui.views.TextViewEx <net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/title" android:id="@+id/title"
@ -55,40 +56,78 @@
tools:text="Share location"/> tools:text="Share location"/>
<LinearLayout <LinearLayout
android:id="@+id/group_container" android:id="@+id/details_container"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical">
android:visibility="gone"
tools:visibility="visible">
<ImageView <LinearLayout
android:id="@+id/group_icon" android:id="@+id/distance_and_points_container"
android:layout_width="@dimen/list_item_icon_size_small"
android:layout_height="@dimen/list_item_icon_size_small"
android:layout_gravity="bottom"
android:layout_marginEnd="@dimen/content_padding_small"
android:layout_marginRight="@dimen/content_padding_small"
tools:src="@drawable/img_group_picture" />
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/group_title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end" android:orientation="horizontal"
android:maxLines="1" android:visibility="gone"
android:textColor="?attr/android:textColorSecondary" tools:visibility="visible">
android:textSize="@dimen/list_item_description_text_size"
app:firstBaselineToTopHeight="@dimen/list_item_baseline_to_top_height" <ImageView
app:typeface="@string/font_roboto_regular" android:id="@+id/distance_icon"
tools:text="@string/shared_string_group" /> android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginEnd="@dimen/content_padding_small"
android:layout_marginRight="@dimen/content_padding_small"
tools:src="@drawable/ic_action_distance_16dp"
tools:tint="@color/icon_light" />
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/distance_and_points_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/list_item_description_text_size"
app:firstBaselineToTopHeight="@dimen/list_item_baseline_to_top_height"
app:typeface="@string/font_roboto_regular"
tools:text="213 m" />
</LinearLayout>
<LinearLayout
android:id="@+id/group_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/group_icon"
android:layout_width="@dimen/list_item_icon_size_small"
android:layout_height="@dimen/list_item_icon_size_small"
android:layout_gravity="bottom"
android:layout_marginEnd="@dimen/content_padding_small"
android:layout_marginRight="@dimen/content_padding_small"
tools:src="@drawable/img_group_picture" />
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/group_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/list_item_description_text_size"
app:firstBaselineToTopHeight="@dimen/list_item_baseline_to_top_height"
app:typeface="@string/font_roboto_regular"
tools:text="@string/shared_string_group" />
</LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/location_with_descr_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:paddingBottom="@dimen/content_padding_half">
<LinearLayout <LinearLayout
android:id="@+id/location_view_container" android:id="@+id/location_view_container"

View file

@ -1,4 +1,6 @@
<resources> <resources>
<string name="please_update_osmand">Please update OsmAnd to view data on the map</string>
<string name="shared_string_update">Update</string>
<string name="gps_points_in_buffer">sent (%1$d in buffer)</string> <string name="gps_points_in_buffer">sent (%1$d in buffer)</string>
<string name="points_size">%1$d points</string> <string name="points_size">%1$d points</string>
<string name="shared_string_date">Date</string> <string name="shared_string_date">Date</string>

View file

@ -85,6 +85,10 @@ class TelegramApplication : Application(), OsmandHelperListener {
telegramHelper.stopSendingLiveLocationMessages(settings.getChatsShareInfo()) telegramHelper.stopSendingLiveLocationMessages(settings.getChatsShareInfo())
} }
fun isAnyOsmAndInstalled() = TelegramSettings.AppConnect.getInstalledApps(this).isNotEmpty()
fun isOsmAndChosen() = settings.appToConnectPackage.isNotEmpty()
fun isOsmAndInstalled() = AndroidUtils.isAppInstalled(this, settings.appToConnectPackage) fun isOsmAndInstalled() = AndroidUtils.isAppInstalled(this, settings.appToConnectPackage)
val isWifiConnected: Boolean val isWifiConnected: Boolean

View file

@ -528,7 +528,8 @@ class TelegramSettings(private val app: TelegramApplication) {
currentSharingMode = prefs.getString(SHARING_MODE_KEY, "") currentSharingMode = prefs.getString(SHARING_MODE_KEY, "")
appToConnectPackage = prefs.getString(APP_TO_CONNECT_PACKAGE_KEY, "") val defPackage = if (AppConnect.getInstalledApps(app).size == 1) AppConnect.getInstalledApps(app).first().appPackage else ""
appToConnectPackage = prefs.getString(APP_TO_CONNECT_PACKAGE_KEY, defPackage)
liveNowSortType = LiveNowSortType.valueOf( liveNowSortType = LiveNowSortType.valueOf(
prefs.getString(LIVE_NOW_SORT_TYPE_KEY, LiveNowSortType.SORT_BY_DISTANCE.name) prefs.getString(LIVE_NOW_SORT_TYPE_KEY, LiveNowSortType.SORT_BY_DISTANCE.name)
@ -772,6 +773,16 @@ class TelegramSettings(private val app: TelegramApplication) {
return 0 return 0
} }
@DrawableRes
fun getIconId(appPackage: String): Int {
for (item in values()) {
if (item.appPackage == appPackage) {
return item.iconId
}
}
return 0
}
fun getInstalledApps(context: Context) = fun getInstalledApps(context: Context) =
values().filter { AndroidUtils.isAppInstalled(context, it.appPackage) } values().filter { AndroidUtils.isAppInstalled(context, it.appPackage) }
} }

View file

@ -301,7 +301,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
} }
} }
private fun checkNetworkType(){ fun checkNetworkType(){
if (app.isInternetConnectionAvailable) { if (app.isInternetConnectionAvailable) {
val networkType = when { val networkType = when {
app.isWifiConnected -> TdApi.NetworkTypeWiFi() app.isWifiConnected -> TdApi.NetworkTypeWiFi()

View file

@ -158,7 +158,7 @@ class ShowLocationHelper(private val app: TelegramApplication) {
fun startShowingLocation() { fun startShowingLocation() {
if (!showingLocation && !forcedStop) { if (!showingLocation && !forcedStop) {
showingLocation = if (isUseOsmandCallback()) { showingLocation = if (isUseOsmandCallback() && !app.settings.monitoringEnabled) {
osmandAidlHelper.registerForUpdates() osmandAidlHelper.registerForUpdates()
} else { } else {
app.startUserLocationService() app.startUserLocationService()

View file

@ -77,6 +77,6 @@ class LocationNotification(app: TelegramApplication) : TelegramNotification(app,
.setStyle(NotificationCompat.BigTextStyle().bigText(notificationText)) .setStyle(NotificationCompat.BigTextStyle().bigText(notificationText))
} }
private fun isShowingChatsNotificationEnabled() = !app.showLocationHelper.isUseOsmandCallback() private fun isShowingChatsNotificationEnabled() = (!app.showLocationHelper.isUseOsmandCallback() || app.settings.monitoringEnabled)
&& app.isOsmAndInstalled() && app.settings.hasAnyChatToShowOnMap() && app.isAnyOsmAndInstalled() && app.settings.hasAnyChatToShowOnMap()
} }

View file

@ -1,8 +1,10 @@
package net.osmand.telegram.ui package net.osmand.telegram.ui
import android.content.Intent import android.content.Intent
import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.ListPopupWindow import android.support.v7.widget.ListPopupWindow
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
@ -11,7 +13,10 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.animation.LinearInterpolator import android.view.animation.LinearInterpolator
import android.widget.* import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import net.osmand.Location import net.osmand.Location
import net.osmand.data.LatLon import net.osmand.data.LatLon
import net.osmand.telegram.R import net.osmand.telegram.R
@ -42,7 +47,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
get() = activity?.application as TelegramApplication get() = activity?.application as TelegramApplication
private val telegramHelper get() = app.telegramHelper private val telegramHelper get() = app.telegramHelper
private val osmandAidlHelper get() = app.osmandAidlHelper
private val settings get() = app.settings private val settings get() = app.settings
private lateinit var adapter: LiveNowListAdapter private lateinit var adapter: LiveNowListAdapter
@ -97,11 +101,19 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
} }
} }
mainView.findViewById<SwipeRefreshLayout>(R.id.swipe_refresh).apply {
setOnRefreshListener {
app.shareLocationHelper.checkNetworkType()
updateList()
isRefreshing = false
}
setColorSchemeColors(Color.RED, Color.GREEN, Color.BLUE, Color.CYAN)
}
openOsmAndBtn = mainView.findViewById<TextView>(R.id.open_osmand_btn).apply { openOsmAndBtn = mainView.findViewById<TextView>(R.id.open_osmand_btn).apply {
setOnClickListener { setOnClickListener {
val pack = settings.appToConnectPackage if (app.isOsmAndInstalled()) {
if (AndroidUtils.isAppInstalled(context, pack)) { activity?.packageManager?.getLaunchIntentForPackage(settings.appToConnectPackage)?.also { intent ->
activity?.packageManager?.getLaunchIntentForPackage(pack)?.also { intent ->
startActivity(intent) startActivity(intent)
} }
} else { } else {
@ -438,9 +450,11 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
openOnMapView?.isEnabled = canBeOpenedOnMap openOnMapView?.isEnabled = canBeOpenedOnMap
if (canBeOpenedOnMap) { if (canBeOpenedOnMap) {
openOnMapView?.setOnClickListener { openOnMapView?.setOnClickListener {
if (!app.isOsmAndInstalled()) { if (!app.isAnyOsmAndInstalled()) {
showOsmAndMissingDialog() showOsmAndMissingDialog()
} else { } else if (!app.isOsmAndChosen() || (app.isOsmAndChosen() && !app.isOsmAndInstalled())) {
fragmentManager?.also { ChooseOsmAndBottomSheet.showInstance(it, this@LiveNowTabFragment) }
} else if(app.isOsmAndInstalled()){
app.showLocationHelper.showLocationOnMap(item, staleLocation) app.showLocationHelper.showLocationOnMap(item, staleLocation)
} }
} }
@ -533,17 +547,21 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
settings.showChatOnMap(chatId, allSelected) settings.showChatOnMap(chatId, allSelected)
if (settings.hasAnyChatToShowOnMap()) { if (settings.hasAnyChatToShowOnMap()) {
if (!app.isOsmAndInstalled()) { if (!app.isAnyOsmAndInstalled()) {
if (allSelected) { if (allSelected) {
showOsmAndMissingDialog() showOsmAndMissingDialog()
} }
} else if (!app.isOsmAndChosen() || (app.isOsmAndChosen() && !app.isOsmAndInstalled())) {
fragmentManager?.also { ChooseOsmAndBottomSheet.showInstance(it, this@LiveNowTabFragment) }
} else { } else {
if (allSelected) { if (app.isOsmAndInstalled()) {
app.showLocationHelper.showChatMessages(chatId) if (allSelected) {
} else { app.showLocationHelper.showChatMessages(chatId)
app.showLocationHelper.hideChatMessages(chatId) } else {
app.showLocationHelper.hideChatMessages(chatId)
}
app.showLocationHelper.startShowingLocation()
} }
app.showLocationHelper.startShowingLocation()
} }
} else { } else {
app.showLocationHelper.stopShowingLocation() app.showLocationHelper.stopShowingLocation()

View file

@ -165,7 +165,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
if (AndroidUtils.isLocationPermissionAvailable(this)) { if (AndroidUtils.isLocationPermissionAvailable(this)) {
app.locationProvider.resumeAllUpdates() app.locationProvider.resumeAllUpdates()
} }
if (settings.hasAnyChatToShowOnMap() && !app.isOsmAndInstalled()) { if (settings.hasAnyChatToShowOnMap() && !app.isAnyOsmAndInstalled()) {
showOsmandMissingDialog() showOsmandMissingDialog()
} }
} }
@ -290,13 +290,6 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
if (!app.showLocationHelper.showingLocation && settings.hasAnyChatToShowOnMap()) { if (!app.showLocationHelper.showingLocation && settings.hasAnyChatToShowOnMap()) {
app.showLocationHelper.startShowingLocation() app.showLocationHelper.startShowingLocation()
} }
if (app.telegramService == null) {
messages.forEach {
if (!it.isOutgoing) {
app.locationMessages.addNewLocationMessage(it)
}
}
}
} }
override fun onDeleteChatLocationMessages(chatId: Long, messages: List<TdApi.Message>) {} override fun onDeleteChatLocationMessages(chatId: Long, messages: List<TdApi.Message>) {}
@ -455,7 +448,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
settings.stopSharingLocationToChats() settings.stopSharingLocationToChats()
app.shareLocationHelper.stopSharingLocation() app.shareLocationHelper.stopSharingLocation()
} }
if (settings.hasAnyChatToShowOnMap() && !app.isOsmAndInstalled()) { if (settings.hasAnyChatToShowOnMap() && !app.isAnyOsmAndInstalled()) {
showOsmandMissingDialog() showOsmandMissingDialog()
} }
} }

View file

@ -1,12 +1,15 @@
package net.osmand.telegram.ui package net.osmand.telegram.ui
import android.annotation.SuppressLint
import android.app.DatePickerDialog import android.app.DatePickerDialog
import android.graphics.Color
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.support.annotation.DrawableRes import android.support.annotation.DrawableRes
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater import android.view.LayoutInflater
@ -55,8 +58,9 @@ class TimelineTabFragment : Fragment() {
mainView = inflater.inflate(R.layout.fragment_timeline_tab, container, false) mainView = inflater.inflate(R.layout.fragment_timeline_tab, container, false)
val appBarLayout = mainView.findViewById<View>(R.id.app_bar_layout) val appBarLayout = mainView.findViewById<View>(R.id.app_bar_layout)
start = System.currentTimeMillis() val calendar = Calendar.getInstance()
end = System.currentTimeMillis() start = getStartOfDay(calendar)
end = getEndOfDay(calendar)
AndroidUtils.addStatusBarPadding19v(context!!, appBarLayout) AndroidUtils.addStatusBarPadding19v(context!!, appBarLayout)
adapter = LiveNowListAdapter() adapter = LiveNowListAdapter()
@ -67,6 +71,7 @@ class TimelineTabFragment : Fragment() {
val switcher = mainView.findViewById<Switch>(R.id.monitoring_switcher) val switcher = mainView.findViewById<Switch>(R.id.monitoring_switcher)
val monitoringTv = mainView.findViewById<TextView>(R.id.monitoring_title) val monitoringTv = mainView.findViewById<TextView>(R.id.monitoring_title)
switcher.isChecked = settings.monitoringEnabled
monitoringTv.setText(if (settings.monitoringEnabled) R.string.monitoring_is_enabled else R.string.monitoring_is_disabled) monitoringTv.setText(if (settings.monitoringEnabled) R.string.monitoring_is_enabled else R.string.monitoring_is_disabled)
mainView.findViewById<View>(R.id.monitoring_container).setOnClickListener { mainView.findViewById<View>(R.id.monitoring_container).setOnClickListener {
@ -82,8 +87,18 @@ class TimelineTabFragment : Fragment() {
} }
setCompoundDrawablesWithIntrinsicBounds(getPressedStateIcon(R.drawable.ic_action_date_start), null, null, null) setCompoundDrawablesWithIntrinsicBounds(getPressedStateIcon(R.drawable.ic_action_date_start), null, null, null)
setTextColor(AndroidUtils.createPressedColorStateList(app, true, R.color.ctrl_active_light, R.color.ctrl_light)) setTextColor(AndroidUtils.createPressedColorStateList(app, true, R.color.ctrl_active_light, R.color.ctrl_light))
text = OsmandFormatter.getFormattedDate(start / 1000)
} }
mainView.findViewById<SwipeRefreshLayout>(R.id.swipe_refresh).apply {
setOnRefreshListener {
updateList()
isRefreshing = false
}
setColorSchemeColors(Color.RED, Color.GREEN, Color.BLUE, Color.CYAN)
}
updateList()
return mainView return mainView
} }
@ -101,22 +116,13 @@ class TimelineTabFragment : Fragment() {
private fun selectDate() { private fun selectDate() {
val dateFromDialog = val dateFromDialog =
DatePickerDialog.OnDateSetListener { _, year, monthOfYear, dayOfMonth -> DatePickerDialog.OnDateSetListener { _, year, monthOfYear, dayOfMonth ->
val from = Calendar.getInstance() val calendar = Calendar.getInstance()
from.set(Calendar.YEAR, year) calendar.set(Calendar.YEAR, year)
from.set(Calendar.MONTH, monthOfYear) calendar.set(Calendar.MONTH, monthOfYear)
from.set(Calendar.DAY_OF_MONTH, dayOfMonth) calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth)
from.set(Calendar.HOUR_OF_DAY, 0) start = getStartOfDay(calendar)
from.clear(Calendar.MINUTE) end = getEndOfDay(calendar)
from.clear(Calendar.SECOND)
from.clear(Calendar.MILLISECOND)
start = from.timeInMillis
from.set(Calendar.HOUR_OF_DAY, 23)
from.set(Calendar.MINUTE, 59)
from.set(Calendar.SECOND, 59)
from.set(Calendar.MILLISECOND, 999)
end = from.timeInMillis
updateList() updateList()
updateDateButton() updateDateButton()
@ -130,6 +136,22 @@ class TimelineTabFragment : Fragment() {
).show() ).show()
} }
private fun getStartOfDay(calendar: Calendar): Long {
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.clear(Calendar.MINUTE)
calendar.clear(Calendar.SECOND)
calendar.clear(Calendar.MILLISECOND)
return calendar.timeInMillis
}
private fun getEndOfDay(calendar: Calendar): Long {
calendar.set(Calendar.HOUR_OF_DAY, 23)
calendar.set(Calendar.MINUTE, 59)
calendar.set(Calendar.SECOND, 59)
calendar.set(Calendar.MILLISECOND, 999)
return calendar.timeInMillis
}
private fun updateDateButton() { private fun updateDateButton() {
dateBtn.text = OsmandFormatter.getFormattedDate(start / 1000) dateBtn.text = OsmandFormatter.getFormattedDate(start / 1000)
} }
@ -157,23 +179,19 @@ class TimelineTabFragment : Fragment() {
private fun updateList() { private fun updateList() {
val res = mutableListOf<ListItem>() val res = mutableListOf<ListItem>()
val currentUserId = telegramHelper.getCurrentUser()?.id app.locationMessages.getIngoingUserLocations(start, end).forEach {
TelegramUiHelper.userLocationsToChatItem(telegramHelper, it)?.also { chatItem ->
val ingoingUserLocations = app.locationMessages.getIngoingUserLocations(start, end) res.add(chatItem)
ingoingUserLocations.forEach {
TelegramUiHelper.userLocationsToChatItem(telegramHelper, it)?.also { chatItem ->
res.add(chatItem)
}
} }
}
adapter.items = sortAdapterItems(res) adapter.items = sortAdapterItems(res)
} }
private fun sortAdapterItems(list: MutableList<ListItem>): MutableList<ListItem> { private fun sortAdapterItems(list: MutableList<ListItem>): MutableList<ListItem> {
val currentUserId = telegramHelper.getCurrentUser()?.id ?: 0 val currentUserId = telegramHelper.getCurrentUserId()
list.sortWith(java.util.Comparator { lhs, rhs -> list.sortWith(java.util.Comparator { lhs, rhs ->
when (currentUserId) { when (currentUserId) {
lhs.userId -> return@Comparator 1 lhs.userId -> return@Comparator -1
rhs.userId -> return@Comparator 1 rhs.userId -> return@Comparator 1
else -> return@Comparator lhs.name.compareTo(rhs.name) else -> return@Comparator lhs.name.compareTo(rhs.name)
} }
@ -194,25 +212,34 @@ class TimelineTabFragment : Fragment() {
return BaseViewHolder(inflater.inflate(R.layout.live_now_chat_card, parent, false)) return BaseViewHolder(inflater.inflate(R.layout.live_now_chat_card, parent, false))
} }
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: BaseViewHolder, position: Int) { override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
val lastItem = position == itemCount - 1 val lastItem = position == itemCount - 1
val item = items[position] val item = items[position]
val currentUserId = telegramHelper.getCurrentUser()?.id ?: 0 val currentUserId = telegramHelper.getCurrentUserId()
TelegramUiHelper.setupPhoto(app, holder.icon, item.photoPath, R.drawable.img_user_picture_active, false) TelegramUiHelper.setupPhoto(app, holder.icon, item.photoPath, R.drawable.img_user_picture_active, false)
holder.title?.text = item.name holder.title?.text = item.name
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
holder.lastTelegramUpdateTime?.visibility = View.GONE holder.lastTelegramUpdateTime?.visibility = View.GONE
if (item is TelegramUiHelper.LocationMessagesChatItem ) { if (item is TelegramUiHelper.LocationMessagesChatItem) {
val userLocations = item.userLocations val userLocations = item.userLocations
if (userLocations != null) {
if(userLocations!=null){
val trackData = getDistanceAndCountedPoints(userLocations) val trackData = getDistanceAndCountedPoints(userLocations)
val distance = OsmandFormatter.getFormattedDistance(trackData.dist,app) val distance = OsmandFormatter.getFormattedDistance(trackData.dist, app)
val name = if ((!item.privateChat || item.chatWithBot) && item.userId != currentUserId) item.getVisibleName() else "" val groupDescrRowVisible = (!item.privateChat || item.chatWithBot) && item.userId != currentUserId
holder.groupDescrContainer?.visibility = View.VISIBLE if (groupDescrRowVisible) {
holder.groupTitle?.text = "$distance (${getString(R.string.points_size, trackData.points)}) $name" holder.groupDescrContainer?.visibility = View.VISIBLE
TelegramUiHelper.setupPhoto(app, holder.groupImage, item.groupPhotoPath, item.placeholderId, false) holder.groupTitle?.text = item.getVisibleName()
TelegramUiHelper.setupPhoto(app, holder.groupImage, item.groupPhotoPath, item.placeholderId, false)
} else {
holder.groupDescrContainer?.visibility = View.GONE
}
holder.locationAndDescrContainer?.visibility = View.GONE
holder.distanceAndPointsContainer?.visibility = View.VISIBLE
holder.distanceImage?.setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_distance_16dp))
val point = if (groupDescrRowVisible) "" else ""
holder.distanceAndPointsTitle?.text = "$distance (${getString(R.string.points_size, trackData.points)}) $point "
holder.userRow?.setOnClickListener { holder.userRow?.setOnClickListener {
childFragmentManager.also { childFragmentManager.also {
UserGpxInfoFragment.showInstance(it, item.userId, item.chatId, trackData.minTime, trackData.maxTime) UserGpxInfoFragment.showInstance(it, item.userId, item.chatId, trackData.minTime, trackData.maxTime)
@ -229,11 +256,10 @@ class TimelineTabFragment : Fragment() {
private fun getDistanceAndCountedPoints(userLocations: LocationMessages.UserLocations): UITrackData { private fun getDistanceAndCountedPoints(userLocations: LocationMessages.UserLocations): UITrackData {
var uiTrackData= UITrackData(0.0f, 0, 0, 0) val uiTrackData = UITrackData(0.0f, 0, 0, 0)
userLocations.getUniqueSegments().forEach { userLocations.getUniqueSegments().forEach {
if(uiTrackData.minTime == 0L) { if (uiTrackData.minTime == 0L) {
uiTrackData.minTime = it.minTime uiTrackData.minTime = it.minTime
} }
uiTrackData.dist += it.distance.toFloat(); uiTrackData.dist += it.distance.toFloat();
@ -253,6 +279,10 @@ class TimelineTabFragment : Fragment() {
val lastTelegramUpdateTime: TextView? = view.findViewById(R.id.last_telegram_update_time) val lastTelegramUpdateTime: TextView? = view.findViewById(R.id.last_telegram_update_time)
val userRow: View? = view.findViewById(R.id.user_row) val userRow: View? = view.findViewById(R.id.user_row)
val distanceAndPointsContainer: View? = view.findViewById(R.id.distance_and_points_container)
val locationAndDescrContainer: View? = view.findViewById(R.id.location_with_descr_container)
val distanceImage: ImageView? = view.findViewById(R.id.distance_icon)
val distanceAndPointsTitle: TextView? = view.findViewById(R.id.distance_and_points_text)
val groupDescrContainer: View? = view.findViewById(R.id.group_container) val groupDescrContainer: View? = view.findViewById(R.id.group_container)
val groupImage: ImageView? = view.findViewById(R.id.group_icon) val groupImage: ImageView? = view.findViewById(R.id.group_icon)
val groupTitle: TextView? = view.findViewById(R.id.group_title) val groupTitle: TextView? = view.findViewById(R.id.group_title)

View file

@ -6,7 +6,10 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentManager
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.view.LayoutInflater import android.view.LayoutInflater
@ -20,6 +23,7 @@ import android.widget.Toast
import net.osmand.PlatformUtil import net.osmand.PlatformUtil
import net.osmand.aidl.gpx.AGpxBitmap import net.osmand.aidl.gpx.AGpxBitmap
import net.osmand.telegram.R import net.osmand.telegram.R
import net.osmand.telegram.TelegramSettings
import net.osmand.telegram.helpers.LocationMessages import net.osmand.telegram.helpers.LocationMessages
import net.osmand.telegram.helpers.OsmandAidlHelper import net.osmand.telegram.helpers.OsmandAidlHelper
import net.osmand.telegram.helpers.TelegramUiHelper import net.osmand.telegram.helpers.TelegramUiHelper
@ -37,6 +41,7 @@ class UserGpxInfoFragment : BaseDialogFragment() {
private var gpxFile = GPXUtilities.GPXFile() private var gpxFile = GPXUtilities.GPXFile()
private lateinit var mainView: View
private lateinit var dateStartBtn: TextView private lateinit var dateStartBtn: TextView
private lateinit var timeStartBtn: TextView private lateinit var timeStartBtn: TextView
private lateinit var dateEndBtn: TextView private lateinit var dateEndBtn: TextView
@ -60,7 +65,7 @@ class UserGpxInfoFragment : BaseDialogFragment() {
parent: ViewGroup?, parent: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View { ): View {
val mainView = inflater.inflate(R.layout.fragment_user_gpx_info, parent) mainView = inflater.inflate(R.layout.fragment_user_gpx_info, parent)
AndroidUtils.addStatusBarPadding19v(context!!, mainView) AndroidUtils.addStatusBarPadding19v(context!!, mainView)
readFromBundle(savedInstanceState ?: arguments) readFromBundle(savedInstanceState ?: arguments)
@ -71,19 +76,40 @@ class UserGpxInfoFragment : BaseDialogFragment() {
TelegramUiHelper.setupPhoto(app, mainView.findViewById<ImageView>(R.id.user_icon), TelegramUiHelper.setupPhoto(app, mainView.findViewById<ImageView>(R.id.user_icon),
telegramHelper.getUserPhotoPath(user), R.drawable.img_user_placeholder, false) telegramHelper.getUserPhotoPath(user), R.drawable.img_user_placeholder, false)
} }
val openGpxListener = View.OnClickListener {
val gpx = gpxFile
if (gpx.path.isNotEmpty()) {
openGpx(gpx.path)
} else {
saveCurrentGpxToFile(object :
OsmandLocationUtils.SaveGpxListener {
override fun onSavingGpxFinish(path: String) {
openGpx(path)
}
override fun onSavingGpxError(warnings: List<String>?) {
Toast.makeText(app, warnings?.firstOrNull(), Toast.LENGTH_LONG).show()
}
})
}
}
val iconMap = mainView.findViewById<ImageView>(R.id.gpx_map)
app.osmandAidlHelper.setGpxBitmapCreatedListener( app.osmandAidlHelper.setGpxBitmapCreatedListener(
object : OsmandAidlHelper.GpxBitmapCreatedListener { object : OsmandAidlHelper.GpxBitmapCreatedListener {
override fun onGpxBitmapCreated(bitmap: AGpxBitmap) { override fun onGpxBitmapCreated(bitmap: AGpxBitmap) {
activity?.runOnUiThread { activity?.runOnUiThread {
mainView.findViewById<ImageView>(R.id.gpx_map).setImageDrawable(BitmapDrawable(app.resources, bitmap.bitmap)) iconMap.setImageDrawable(BitmapDrawable(app.resources, bitmap.bitmap))
iconMap.setOnClickListener(openGpxListener)
} }
} }
}) })
val backBtn = mainView.findViewById<ImageView>(R.id.back_button) mainView.findViewById<ImageView>(R.id.back_button).apply {
backBtn.setImageDrawable(uiUtils.getThemedIcon(R.drawable.ic_arrow_back)) setImageDrawable(uiUtils.getThemedIcon(R.drawable.ic_arrow_back))
backBtn.setOnClickListener { setOnClickListener {
dismiss() dismiss()
}
} }
dateStartBtn = mainView.findViewById<TextView>(R.id.date_start_btn) dateStartBtn = mainView.findViewById<TextView>(R.id.date_start_btn)
@ -123,31 +149,18 @@ class UserGpxInfoFragment : BaseDialogFragment() {
updateGPXStatisticRow() updateGPXStatisticRow()
mainView.findViewById<ImageView>(R.id.open_in_osmand_icon).setImageResource(R.drawable.ic_logo_osmand_free) val imageRes = if (app.isOsmAndInstalled()) {
TelegramSettings.AppConnect.getIconId(settings.appToConnectPackage)
mainView.findViewById<LinearLayout>(R.id.open_in_osmand_btn).apply { } else {
setOnClickListener { R.drawable.ic_logo_osmand_free
val gpx = gpxFile
if (gpx.path.isNotEmpty()) {
openGpx(gpx.path)
} else {
saveCurrentGpxToFile(object :
OsmandLocationUtils.SaveGpxListener {
override fun onSavingGpxFinish(path: String) {
openGpx(path)
}
override fun onSavingGpxError(warnings: List<String>?) {
Toast.makeText(app, warnings?.firstOrNull(), Toast.LENGTH_LONG).show()
}
})
}
}
} }
mainView.findViewById<ImageView>(R.id.open_in_osmand_icon).setImageResource(imageRes)
mainView.findViewById<LinearLayout>(R.id.open_in_osmand_btn).setOnClickListener(openGpxListener)
mainView.findViewById<ImageView>(R.id.share_gpx_icon).setImageDrawable(uiUtils.getActiveIcon(R.drawable.ic_action_share)) mainView.findViewById<TextView>(R.id.open_in_osmand_title).setTextColor(AndroidUtils.createPressedColorStateList(app, true, R.color.primary_text_light, R.color.ctrl_light))
mainView.findViewById<TextView>(R.id.share_gpx_title).setTextColor(AndroidUtils.createPressedColorStateList(app, true, R.color.primary_text_light, R.color.ctrl_light))
mainView.findViewById<ImageView>(R.id.share_gpx_icon).setImageDrawable(getShareIcon())
mainView.findViewById<LinearLayout>(R.id.share_gpx_btn).apply { mainView.findViewById<LinearLayout>(R.id.share_gpx_btn).apply {
setOnClickListener { setOnClickListener {
val gpx = gpxFile val gpx = gpxFile
@ -179,6 +192,18 @@ class UserGpxInfoFragment : BaseDialogFragment() {
outState.putLong(END_KEY, endCalendar.timeInMillis) outState.putLong(END_KEY, endCalendar.timeInMillis)
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
ChooseOsmAndBottomSheet.OSMAND_CHOSEN_REQUEST_CODE -> updateGPXMap()
}
}
private fun canOsmandCreateBitmap(): Boolean {
val version = AndroidUtils.getAppVersionCode(app, app.settings.appToConnectPackage)
return version >= MIN_OSMAND_BITMAP_VERSION_CODE
}
private fun openGpx(path: String) { private fun openGpx(path: String) {
val fileUri = AndroidUtils.getUriForFile(app, File(path)) val fileUri = AndroidUtils.getUriForFile(app, File(path))
val openGpxIntent = Intent(Intent.ACTION_VIEW) val openGpxIntent = Intent(Intent.ACTION_VIEW)
@ -210,7 +235,19 @@ class UserGpxInfoFragment : BaseDialogFragment() {
textView.setTextColor(AndroidUtils.createPressedColorStateList(app, true, R.color.ctrl_active_light, R.color.ctrl_light)) textView.setTextColor(AndroidUtils.createPressedColorStateList(app, true, R.color.ctrl_active_light, R.color.ctrl_light))
} }
private fun getShareIcon(): Drawable? {
val normal = app.uiUtils.getActiveIcon(R.drawable.ic_action_share)
if (Build.VERSION.SDK_INT >= 21) {
val active = app.uiUtils.getIcon(R.drawable.ic_action_share, R.color.ctrl_light)
if (normal != null && active != null) {
return AndroidUtils.createPressedStateListDrawable(normal, active)
}
}
return normal
}
private fun updateGpxInfo() { private fun updateGpxInfo() {
checkTime()
locationMessages = app.locationMessages.getMessagesForUserInChat(userId, chatId, startCalendar.timeInMillis, endCalendar.timeInMillis) locationMessages = app.locationMessages.getMessagesForUserInChat(userId, chatId, startCalendar.timeInMillis, endCalendar.timeInMillis)
gpxFile = OsmandLocationUtils.convertLocationMessagesToGpxFiles(locationMessages).firstOrNull()?:GPXUtilities.GPXFile() gpxFile = OsmandLocationUtils.convertLocationMessagesToGpxFiles(locationMessages).firstOrNull()?:GPXUtilities.GPXFile()
@ -219,6 +256,14 @@ class UserGpxInfoFragment : BaseDialogFragment() {
updateGPXMap() updateGPXMap()
} }
private fun checkTime() {
if (startCalendar.timeInMillis > endCalendar.timeInMillis) {
val time = startCalendar.timeInMillis
startCalendar.timeInMillis = endCalendar.timeInMillis
endCalendar.timeInMillis = time
}
}
private fun updateDateAndTimeButtons() { private fun updateDateAndTimeButtons() {
dateStartBtn.text = SimpleDateFormat("dd MMM", Locale.getDefault()).format(startCalendar.timeInMillis) dateStartBtn.text = SimpleDateFormat("dd MMM", Locale.getDefault()).format(startCalendar.timeInMillis)
dateEndBtn.text = SimpleDateFormat("dd MMM", Locale.getDefault()).format(endCalendar.timeInMillis) dateEndBtn.text = SimpleDateFormat("dd MMM", Locale.getDefault()).format(endCalendar.timeInMillis)
@ -237,26 +282,42 @@ class UserGpxInfoFragment : BaseDialogFragment() {
} }
private fun updateGPXMap() { private fun updateGPXMap() {
saveCurrentGpxToFile(object : if (!app.isAnyOsmAndInstalled()) {
OsmandLocationUtils.SaveGpxListener { activity?.let {
override fun onSavingGpxFinish(path: String) { MainActivity.OsmandMissingDialogFragment().show(it.supportFragmentManager, null)
val mgr = activity?.getSystemService(Context.WINDOW_SERVICE) }
if (mgr != null) { } else if (!app.isOsmAndChosen() || (app.isOsmAndChosen() && !app.isOsmAndInstalled())) {
val dm = DisplayMetrics() fragmentManager?.also { ChooseOsmAndBottomSheet.showInstance(it, this) }
(mgr as WindowManager).defaultDisplay.getMetrics(dm) } else if (!canOsmandCreateBitmap()) {
val widthPixels = dm.widthPixels - (2 * app.resources.getDimensionPixelSize(R.dimen.content_padding_standard)) val snackbar = Snackbar.make(mainView, R.string.please_update_osmand, Snackbar.LENGTH_LONG).setAction(R.string.shared_string_update) {
val heightPixels = AndroidUtils.dpToPx(app, 152f) val packageName = if (app.settings.appToConnectPackage == OsmandAidlHelper.OSMAND_NIGHTLY_PACKAGE_NAME)
val gpxUri = AndroidUtils.getUriForFile(app, File(path)) OsmandAidlHelper.OSMAND_FREE_PACKAGE_NAME else app.settings.appToConnectPackage
app.osmandAidlHelper.execOsmandApi { startActivity(AndroidUtils.getPlayMarketIntent(app, packageName))
app.osmandAidlHelper.getBitmapForGpx(gpxUri, dm.density , widthPixels, heightPixels, GPX_TRACK_COLOR) }
AndroidUtils.setSnackbarTextColor(snackbar, R.color.ctrl_active_dark)
snackbar.show()
} else {
saveCurrentGpxToFile(object :
OsmandLocationUtils.SaveGpxListener {
override fun onSavingGpxFinish(path: String) {
val mgr = activity?.getSystemService(Context.WINDOW_SERVICE)
if (mgr != null) {
val dm = DisplayMetrics()
(mgr as WindowManager).defaultDisplay.getMetrics(dm)
val widthPixels = dm.widthPixels - (2 * app.resources.getDimensionPixelSize(R.dimen.content_padding_standard))
val heightPixels = AndroidUtils.dpToPx(app, 152f)
val gpxUri = AndroidUtils.getUriForFile(app, File(path))
app.osmandAidlHelper.execOsmandApi {
app.osmandAidlHelper.getBitmapForGpx(gpxUri, dm.density, widthPixels, heightPixels, GPX_TRACK_COLOR)
}
} }
} }
}
override fun onSavingGpxError(warnings: List<String>?) { override fun onSavingGpxError(warnings: List<String>?) {
log.debug("onSavingGpxError ${warnings?.firstOrNull()}") log.debug("onSavingGpxError ${warnings?.firstOrNull()}")
} }
}) })
}
} }
private fun selectStartDate() { private fun selectStartDate() {
@ -314,6 +375,7 @@ class UserGpxInfoFragment : BaseDialogFragment() {
private const val CHAT_ID_KEY = "chat_id_key" private const val CHAT_ID_KEY = "chat_id_key"
private const val GPX_TRACK_COLOR = -65536 private const val GPX_TRACK_COLOR = -65536
private const val MIN_OSMAND_BITMAP_VERSION_CODE = 330
fun showInstance(fm: FragmentManager,userId:Int,chatId:Long, start: Long, end: Long): Boolean { fun showInstance(fm: FragmentManager,userId:Int,chatId:Long, start: Long, end: Long): Boolean {
return try { return try {

View file

@ -17,6 +17,7 @@ import android.os.Build
import android.support.annotation.AttrRes import android.support.annotation.AttrRes
import android.support.annotation.ColorInt import android.support.annotation.ColorInt
import android.support.annotation.ColorRes import android.support.annotation.ColorRes
import android.support.design.widget.Snackbar
import android.support.v4.app.ActivityCompat import android.support.v4.app.ActivityCompat
import android.support.v4.app.DialogFragment import android.support.v4.app.DialogFragment
import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentManager
@ -27,6 +28,7 @@ import android.util.TypedValue.COMPLEX_UNIT_DIP
import android.view.View import android.view.View
import android.view.WindowManager import android.view.WindowManager
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.TextView
import net.osmand.telegram.R import net.osmand.telegram.R
import java.io.File import java.io.File
@ -136,6 +138,12 @@ object AndroidUtils {
return ctx.resources.getDimensionPixelSize(R.dimen.list_popup_window_height) return ctx.resources.getDimensionPixelSize(R.dimen.list_popup_window_height)
} }
fun setSnackbarTextColor(snackbar: Snackbar, @ColorRes colorId: Int) {
val view = snackbar.view
val tv = view.findViewById(android.support.design.R.id.snackbar_action) as TextView
tv.setTextColor(ContextCompat.getColor(view.context, colorId))
}
fun createPressedColorStateList( fun createPressedColorStateList(
ctx: Context, light: Boolean, ctx: Context, light: Boolean,
@ColorRes lightNormal: Int, @ColorRes lightPressed: Int, @ColorRes lightNormal: Int, @ColorRes lightPressed: Int,