Merge pull request #6975 from osmandapp/gpxtrackersettings
Tracker gpx logging settings
This commit is contained in:
commit
f7765f3f74
5 changed files with 200 additions and 30 deletions
|
@ -131,6 +131,35 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/list_item_divider" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/card_bg_color"
|
||||
android:orientation="vertical">
|
||||
|
||||
<net.osmand.telegram.ui.views.TextViewEx
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/list_header_height"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:paddingLeft="@dimen/content_padding_standard"
|
||||
android:paddingRight="@dimen/content_padding_standard"
|
||||
android:text="@string/gpx_settings"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/list_item_title_text_size"
|
||||
app:typeface="@string/font_roboto_medium" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/gpx_settings_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/list_item_divider"/>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="shared_string_select">Select</string>
|
||||
<string name="min_logging_distance">Minimum logging distance</string>
|
||||
<string name="min_logging_distance_descr">Filter: minimum distance to log a new point</string>
|
||||
<string name="min_logging_accuracy">Minimum logging accuracy</string>
|
||||
<string name="min_logging_accuracy_descr">Filter: no logging unless the accuracy is reached</string>
|
||||
<string name="min_logging_speed">Minimum logging speed</string>
|
||||
<string name="min_logging_speed_descr">Filter: no logging below selected speed</string>
|
||||
<string name="gpx_settings">GPX settings</string>
|
||||
<string name="proxy_key">Key</string>
|
||||
<string name="proxy_password">Password</string>
|
||||
<string name="proxy_username">Username</string>
|
||||
|
|
|
@ -43,6 +43,9 @@ private val LOC_HISTORY_VALUES_SEC = listOf(
|
|||
12 * 60 * 60L,
|
||||
24 * 60 * 60L
|
||||
)
|
||||
private val MIN_LOCATION_DISTANCE = listOf(0f, 2.0f, 5.0f, 10.0f, 20.0f, 30.0f, 50.0f)
|
||||
private val MIN_LOCATION_ACCURACY = listOf(0f, 1.0f, 2.0f, 5.0f, 10.0f, 15.0f, 20.0f, 50.0f, 100.0f)
|
||||
private val MIN_LOCATION_SPEED = listOf(0f, 0.000001f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f)
|
||||
|
||||
const val SHARE_TYPE_MAP = "Map"
|
||||
const val SHARE_TYPE_TEXT = "Text"
|
||||
|
@ -53,6 +56,9 @@ private const val SEND_MY_LOC_DEFAULT_INDEX = 6
|
|||
private const val STALE_LOC_DEFAULT_INDEX = 0
|
||||
private const val LOC_HISTORY_DEFAULT_INDEX = 7
|
||||
private const val SHARE_TYPE_DEFAULT_INDEX = 2
|
||||
private const val MIN_LOCATION_DISTANCE_INDEX = 0
|
||||
private const val MIN_LOCATION_ACCURACY_INDEX = 0
|
||||
private const val MIN_LOCATION_SPEED_INDEX = 0
|
||||
|
||||
private const val SETTINGS_NAME = "osmand_telegram_settings"
|
||||
|
||||
|
@ -69,6 +75,10 @@ private const val STALE_LOC_TIME_KEY = "stale_loc_time"
|
|||
private const val LOC_HISTORY_TIME_KEY = "loc_history_time"
|
||||
private const val SHARE_TYPE_KEY = "share_type"
|
||||
|
||||
private const val MIN_LOCATION_DISTANCE_KEY = "min_location_distance"
|
||||
private const val MIN_LOCATION_ACCURACY_KEY = "min_location_accuracy"
|
||||
private const val MIN_LOCATION_SPEED_KEY = "min_location_speed"
|
||||
|
||||
private const val APP_TO_CONNECT_PACKAGE_KEY = "app_to_connect_package"
|
||||
|
||||
private const val DEFAULT_VISIBLE_TIME_SECONDS = 60 * 60L // 1 hour
|
||||
|
@ -117,12 +127,17 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
var locHistoryTime = LOC_HISTORY_VALUES_SEC[LOC_HISTORY_DEFAULT_INDEX]
|
||||
var shareTypeValue = SHARE_TYPE_VALUES[SHARE_TYPE_DEFAULT_INDEX]
|
||||
|
||||
var minLocationDistance = MIN_LOCATION_DISTANCE[MIN_LOCATION_DISTANCE_INDEX]
|
||||
var minLocationAccuracy = MIN_LOCATION_ACCURACY[MIN_LOCATION_ACCURACY_INDEX]
|
||||
var minLocationSpeed = MIN_LOCATION_SPEED[MIN_LOCATION_SPEED_INDEX]
|
||||
|
||||
var appToConnectPackage = ""
|
||||
private set
|
||||
|
||||
var liveNowSortType = LiveNowSortType.SORT_BY_DISTANCE
|
||||
|
||||
val gpsAndLocPrefs = listOf(SendMyLocPref(), StaleLocPref(), LocHistoryPref(), ShareTypePref())
|
||||
val gpxLoggingPrefs = listOf(MinLocationDistance(), MinLocationAccuracy(), MinLocationSpeed())
|
||||
|
||||
var batteryOptimisationAsked = false
|
||||
|
||||
|
@ -562,6 +577,10 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
edit.putLong(STALE_LOC_TIME_KEY, staleLocTime)
|
||||
edit.putLong(LOC_HISTORY_TIME_KEY, locHistoryTime)
|
||||
|
||||
edit.putFloat(MIN_LOCATION_DISTANCE_KEY, minLocationDistance)
|
||||
edit.putFloat(MIN_LOCATION_ACCURACY_KEY, minLocationAccuracy)
|
||||
edit.putFloat(MIN_LOCATION_SPEED_KEY, minLocationSpeed)
|
||||
|
||||
edit.putString(SHARE_TYPE_KEY, shareTypeValue)
|
||||
|
||||
edit.putString(APP_TO_CONNECT_PACKAGE_KEY, appToConnectPackage)
|
||||
|
@ -628,6 +647,13 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
val shareTypeDef = SHARE_TYPE_VALUES[SHARE_TYPE_DEFAULT_INDEX]
|
||||
shareTypeValue = prefs.getString(SHARE_TYPE_KEY, shareTypeDef)
|
||||
|
||||
val minLocationDistanceDef = MIN_LOCATION_DISTANCE[MIN_LOCATION_DISTANCE_INDEX]
|
||||
minLocationDistance = prefs.getFloat(MIN_LOCATION_DISTANCE_KEY, minLocationDistanceDef)
|
||||
val minLocationPrecisionDef = MIN_LOCATION_ACCURACY[MIN_LOCATION_ACCURACY_INDEX]
|
||||
minLocationAccuracy = prefs.getFloat(MIN_LOCATION_ACCURACY_KEY, minLocationPrecisionDef)
|
||||
val minLocationSpeedDef = MIN_LOCATION_SPEED[MIN_LOCATION_SPEED_INDEX]
|
||||
minLocationSpeed = prefs.getFloat(MIN_LOCATION_SPEED_KEY, minLocationSpeedDef)
|
||||
|
||||
val currentUserId = app.telegramHelper.getCurrentUserId()
|
||||
currentSharingMode = prefs.getString(SHARING_MODE_KEY, if (currentUserId != -1) currentUserId.toString() else "")
|
||||
|
||||
|
@ -792,7 +818,7 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
}
|
||||
}
|
||||
|
||||
inner class SendMyLocPref : DurationPref(
|
||||
inner class SendMyLocPref : NumericPref(
|
||||
R.drawable.ic_action_share_location,
|
||||
R.string.send_my_location,
|
||||
R.string.send_my_location_desc,
|
||||
|
@ -803,12 +829,15 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
OsmandFormatter.getFormattedDuration(app, sendMyLocInterval)
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
sendMyLocInterval = values[index]
|
||||
sendMyLocInterval = values[index].toLong()
|
||||
app.updateSendLocationInterval()
|
||||
}
|
||||
|
||||
override fun getMenuItems() =
|
||||
values.map { OsmandFormatter.getFormattedDuration(app, it.toLong()) }
|
||||
}
|
||||
|
||||
inner class StaleLocPref : DurationPref(
|
||||
inner class StaleLocPref : NumericPref(
|
||||
R.drawable.ic_action_time_span,
|
||||
R.string.stale_location,
|
||||
R.string.stale_location_desc,
|
||||
|
@ -819,11 +848,14 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
OsmandFormatter.getFormattedDuration(app, staleLocTime)
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
staleLocTime = values[index]
|
||||
}
|
||||
staleLocTime = values[index].toLong()
|
||||
}
|
||||
|
||||
inner class LocHistoryPref : DurationPref(
|
||||
override fun getMenuItems() =
|
||||
values.map { OsmandFormatter.getFormattedDuration(app, it.toLong()) }
|
||||
}
|
||||
|
||||
inner class LocHistoryPref : NumericPref(
|
||||
R.drawable.ic_action_location_history,
|
||||
R.string.location_history,
|
||||
R.string.location_history_desc,
|
||||
|
@ -835,12 +867,15 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
val value = values[index]
|
||||
locHistoryTime = value
|
||||
app.telegramHelper.messageActiveTimeSec = value
|
||||
}
|
||||
locHistoryTime = value.toLong()
|
||||
app.telegramHelper.messageActiveTimeSec = value.toLong()
|
||||
}
|
||||
|
||||
inner class ShareTypePref : DurationPref(
|
||||
override fun getMenuItems() =
|
||||
values.map { OsmandFormatter.getFormattedDuration(app, it.toLong()) }
|
||||
}
|
||||
|
||||
inner class ShareTypePref : NumericPref(
|
||||
R.drawable.ic_action_location_history,
|
||||
R.string.send_location_as,
|
||||
R.string.send_location_as_descr,
|
||||
|
@ -876,18 +911,87 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
}
|
||||
}
|
||||
|
||||
abstract inner class DurationPref(
|
||||
inner class MinLocationDistance : NumericPref(
|
||||
R.drawable.ic_action_location_history,
|
||||
R.string.min_logging_distance,
|
||||
R.string.min_logging_distance_descr,
|
||||
MIN_LOCATION_DISTANCE
|
||||
) {
|
||||
|
||||
override fun getCurrentValue() = getFormattedValue(minLocationDistance)
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
val value = values[index]
|
||||
minLocationDistance = value.toFloat()
|
||||
}
|
||||
|
||||
override fun getMenuItems() = values.map { getFormattedValue(it.toFloat()) }
|
||||
|
||||
private fun getFormattedValue(value: Float): String {
|
||||
return if (value == 0f) app.getString(R.string.shared_string_select)
|
||||
else OsmandFormatter.getFormattedDistance(value, app)
|
||||
}
|
||||
}
|
||||
|
||||
inner class MinLocationAccuracy : NumericPref(
|
||||
R.drawable.ic_action_location_history,
|
||||
R.string.min_logging_accuracy,
|
||||
R.string.min_logging_accuracy_descr,
|
||||
MIN_LOCATION_ACCURACY
|
||||
) {
|
||||
|
||||
override fun getCurrentValue() = getFormattedValue(minLocationAccuracy)
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
val value = values[index]
|
||||
minLocationAccuracy = value.toFloat()
|
||||
}
|
||||
|
||||
override fun getMenuItems() = values.map { getFormattedValue(it.toFloat()) }
|
||||
|
||||
private fun getFormattedValue(value: Float): String {
|
||||
return if (value == 0f) app.getString(R.string.shared_string_select)
|
||||
else OsmandFormatter.getFormattedDistance(value, app)
|
||||
}
|
||||
}
|
||||
|
||||
inner class MinLocationSpeed : NumericPref(
|
||||
R.drawable.ic_action_location_history,
|
||||
R.string.min_logging_speed,
|
||||
R.string.min_logging_speed_descr,
|
||||
MIN_LOCATION_SPEED
|
||||
) {
|
||||
|
||||
override fun getCurrentValue() = getFormattedValue(minLocationSpeed)
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
val value = values[index]
|
||||
minLocationSpeed = value.toFloat()
|
||||
}
|
||||
|
||||
override fun getMenuItems() = values.map { getFormattedValue(it.toFloat()) }
|
||||
|
||||
private fun getFormattedValue(value: Float): String {
|
||||
return when (value) {
|
||||
MIN_LOCATION_SPEED[0] -> app.getString(R.string.shared_string_select)
|
||||
MIN_LOCATION_SPEED[1] -> "> 0"
|
||||
else -> OsmandFormatter.getFormattedSpeed(value, app)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract inner class NumericPref(
|
||||
@DrawableRes val iconId: Int,
|
||||
@StringRes val titleId: Int,
|
||||
@StringRes val descriptionId: Int,
|
||||
val values: List<Long>
|
||||
val values: List<Number>
|
||||
) {
|
||||
|
||||
abstract fun getCurrentValue(): String
|
||||
|
||||
abstract fun setCurrentValue(index: Int)
|
||||
|
||||
open fun getMenuItems() = values.map { OsmandFormatter.getFormattedDuration(app, it) }
|
||||
abstract fun getMenuItems(): List<String>
|
||||
}
|
||||
|
||||
enum class AppConnect(
|
||||
|
|
|
@ -7,6 +7,7 @@ import net.osmand.telegram.helpers.LocationMessages.BufferMessage
|
|||
import net.osmand.telegram.notifications.TelegramNotification.NotificationType
|
||||
import net.osmand.telegram.utils.AndroidNetworkUtils
|
||||
import net.osmand.telegram.utils.BASE_URL
|
||||
import net.osmand.util.MapUtils
|
||||
import org.drinkless.td.libcore.telegram.TdApi
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
|
@ -52,14 +53,33 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
|||
private var lastTimeInMillis: Long = 0L
|
||||
|
||||
fun updateLocation(location: Location?) {
|
||||
lastLocation = location
|
||||
val lastPoint = lastLocation
|
||||
var record = true
|
||||
if (location != null) {
|
||||
val minDistance = app.settings.minLocationDistance
|
||||
if (minDistance > 0 && lastPoint != null) {
|
||||
val calculatedDistance = MapUtils.getDistance(lastPoint.latitude, lastPoint.longitude, location.latitude, location.longitude)
|
||||
if (calculatedDistance < minDistance) {
|
||||
record = false
|
||||
}
|
||||
}
|
||||
val accuracy = app.settings.minLocationAccuracy
|
||||
if (accuracy > 0 && (!location.hasAccuracy() || location.accuracy > accuracy)) {
|
||||
record = false
|
||||
}
|
||||
val minSpeed = app.settings.minLocationSpeed
|
||||
if (minSpeed > 0 && (!location.hasSpeed() || location.speed < minSpeed)) {
|
||||
record = false
|
||||
}
|
||||
|
||||
if (location != null && location.accuracy < UPDATE_LOCATION_ACCURACY) {
|
||||
if (record) {
|
||||
lastLocationUpdateTime = System.currentTimeMillis()
|
||||
lastLocation = location
|
||||
if (app.settings.getChatsShareInfo().isNotEmpty()) {
|
||||
shareLocationMessages(location, app.telegramHelper.getCurrentUserId())
|
||||
}
|
||||
}
|
||||
}
|
||||
app.settings.updateSharingStatusHistory()
|
||||
refreshNotification()
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import android.view.ViewGroup
|
|||
import android.widget.*
|
||||
import net.osmand.telegram.R
|
||||
import net.osmand.telegram.TelegramSettings
|
||||
import net.osmand.telegram.TelegramSettings.DurationPref
|
||||
import net.osmand.telegram.TelegramSettings.NumericPref
|
||||
import net.osmand.telegram.helpers.TelegramHelper.Companion.OSMAND_BOT_USERNAME
|
||||
import net.osmand.telegram.helpers.TelegramUiHelper
|
||||
import net.osmand.telegram.utils.AndroidUtils
|
||||
|
@ -49,18 +49,8 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
window.statusBarColor = ContextCompat.getColor(app, R.color.card_bg_light)
|
||||
}
|
||||
var container = mainView.findViewById<ViewGroup>(R.id.gps_and_loc_container)
|
||||
for (pref in settings.gpsAndLocPrefs) {
|
||||
inflater.inflate(R.layout.item_with_desc_and_right_value, container, false).apply {
|
||||
findViewById<ImageView>(R.id.icon).setImageDrawable(uiUtils.getThemedIcon(pref.iconId))
|
||||
findViewById<TextView>(R.id.title).setText(pref.titleId)
|
||||
findViewById<TextView>(R.id.description).setText(pref.descriptionId)
|
||||
val valueView = findViewById<TextView>(R.id.value)
|
||||
valueView.text = pref.getCurrentValue()
|
||||
setOnClickListener {
|
||||
showPopupMenu(pref, valueView)
|
||||
}
|
||||
container.addView(this)
|
||||
}
|
||||
settings.gpsAndLocPrefs.forEach {
|
||||
createNumericPref(inflater, container, it)
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
|
@ -148,6 +138,11 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
container = mainView.findViewById<ViewGroup>(R.id.gpx_settings_container)
|
||||
settings.gpxLoggingPrefs.forEach {
|
||||
createNumericPref(inflater, container, it)
|
||||
}
|
||||
|
||||
container = mainView.findViewById(R.id.osmand_connect_container)
|
||||
for (appConn in TelegramSettings.AppConnect.values()) {
|
||||
val pack = appConn.appPackage
|
||||
|
@ -249,6 +244,20 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun createNumericPref(inflater: LayoutInflater, container: ViewGroup, pref: NumericPref) {
|
||||
inflater.inflate(R.layout.item_with_desc_and_right_value, container, false).apply {
|
||||
findViewById<ImageView>(R.id.icon).setImageDrawable(uiUtils.getThemedIcon(pref.iconId))
|
||||
findViewById<TextView>(R.id.title).setText(pref.titleId)
|
||||
findViewById<TextView>(R.id.description).setText(pref.descriptionId)
|
||||
val valueView = findViewById<TextView>(R.id.value)
|
||||
valueView.text = pref.getCurrentValue()
|
||||
setOnClickListener {
|
||||
showPopupMenu(pref, valueView)
|
||||
}
|
||||
container.addView(this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addItemToContainer(inflater: LayoutInflater, container: ViewGroup, tag: String, title: String) {
|
||||
inflater.inflate(R.layout.item_with_rb_and_btn, container, false).apply {
|
||||
val checked = tag == settings.currentSharingMode
|
||||
|
@ -270,7 +279,7 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun showPopupMenu(pref: DurationPref, valueView: TextView) {
|
||||
private fun showPopupMenu(pref: NumericPref, valueView: TextView) {
|
||||
val menuList = pref.getMenuItems()
|
||||
val ctx = valueView.context
|
||||
ListPopupWindow(ctx).apply {
|
||||
|
|
Loading…
Reference in a new issue