2018-06-09 11:20:21 +02:00
|
|
|
package net.osmand.telegram
|
|
|
|
|
|
|
|
import android.content.Context
|
2018-08-31 13:22:46 +02:00
|
|
|
import android.support.annotation.DrawableRes
|
|
|
|
import android.support.annotation.StringRes
|
2018-08-10 14:31:34 +02:00
|
|
|
import net.osmand.telegram.helpers.OsmandAidlHelper
|
2018-07-13 14:53:58 +02:00
|
|
|
import net.osmand.telegram.helpers.TelegramHelper
|
2018-08-31 15:19:28 +02:00
|
|
|
import net.osmand.telegram.utils.AndroidUtils
|
2018-08-31 13:22:46 +02:00
|
|
|
import net.osmand.telegram.utils.OsmandFormatter
|
2018-06-09 11:20:21 +02:00
|
|
|
import net.osmand.telegram.utils.OsmandFormatter.MetricsConstants
|
|
|
|
import net.osmand.telegram.utils.OsmandFormatter.SpeedConstants
|
|
|
|
|
2018-08-31 13:22:46 +02:00
|
|
|
private val SEND_MY_LOC_VALUES_SEC =
|
2018-08-10 12:16:46 +02:00
|
|
|
listOf(1L, 2L, 3L, 5L, 10L, 15L, 30L, 60L, 90L, 2 * 60L, 3 * 60L, 5 * 60L)
|
2018-08-31 13:22:46 +02:00
|
|
|
private val STALE_LOC_VALUES_SEC =
|
2018-08-10 12:16:46 +02:00
|
|
|
listOf(1 * 60L, 2 * 60L, 5 * 60L, 10 * 60L, 15 * 60L, 30 * 60L, 60 * 60L)
|
2018-08-31 13:22:46 +02:00
|
|
|
private val LOC_HISTORY_VALUES_SEC = listOf(
|
2018-08-10 12:16:46 +02:00
|
|
|
5 * 60L,
|
|
|
|
15 * 60L,
|
|
|
|
30 * 60L,
|
|
|
|
1 * 60 * 60L,
|
|
|
|
2 * 60 * 60L,
|
|
|
|
3 * 60 * 60L,
|
|
|
|
5 * 60 * 60L,
|
|
|
|
8 * 60 * 60L,
|
|
|
|
12 * 60 * 60L,
|
|
|
|
24 * 60 * 60L
|
|
|
|
)
|
|
|
|
|
|
|
|
private const val SEND_MY_LOC_DEFAULT_INDEX = 6
|
|
|
|
private const val STALE_LOC_DEFAULT_INDEX = 4
|
|
|
|
private const val LOC_HISTORY_DEFAULT_INDEX = 2
|
|
|
|
|
2018-06-27 10:06:24 +02:00
|
|
|
private const val SETTINGS_NAME = "osmand_telegram_settings"
|
2018-06-09 11:20:21 +02:00
|
|
|
|
2018-06-27 10:06:24 +02:00
|
|
|
private const val SHARE_LOCATION_CHATS_KEY = "share_location_chats"
|
|
|
|
private const val SHOW_ON_MAP_CHATS_KEY = "show_on_map_chats"
|
2018-06-11 18:57:33 +02:00
|
|
|
|
2018-06-27 10:06:24 +02:00
|
|
|
private const val METRICS_CONSTANTS_KEY = "metrics_constants"
|
|
|
|
private const val SPEED_CONSTANTS_KEY = "speed_constants"
|
2018-06-09 11:20:21 +02:00
|
|
|
|
2018-08-10 12:16:46 +02:00
|
|
|
private const val SEND_MY_LOC_INTERVAL_KEY = "send_my_loc_interval"
|
|
|
|
private const val STALE_LOC_TIME_KEY = "stale_loc_time"
|
|
|
|
private const val LOC_HISTORY_TIME_KEY = "loc_history_time"
|
2018-07-13 15:28:37 +02:00
|
|
|
|
2018-08-10 14:31:34 +02:00
|
|
|
private const val APP_TO_CONNECT_PACKAGE_KEY = "app_to_connect_package"
|
|
|
|
|
2018-07-13 14:53:58 +02:00
|
|
|
private const val DEFAULT_VISIBLE_TIME_SECONDS = 60 * 60L // 1 hour
|
2018-06-16 13:55:14 +02:00
|
|
|
|
2018-07-13 13:32:11 +02:00
|
|
|
private const val TITLES_REPLACED_WITH_IDS = "changed_to_chat_id"
|
|
|
|
|
2018-09-04 16:43:42 +02:00
|
|
|
private const val LIVE_NOW_SORT_TYPE_KEY = "live_now_sort_type"
|
2018-09-04 15:43:27 +02:00
|
|
|
|
2018-06-27 10:06:24 +02:00
|
|
|
class TelegramSettings(private val app: TelegramApplication) {
|
2018-06-11 18:57:33 +02:00
|
|
|
|
2018-08-14 14:57:17 +02:00
|
|
|
private var chatLivePeriods = mutableMapOf<Long, Long>()
|
2018-08-31 13:22:46 +02:00
|
|
|
private var chatShareLocStartSec = mutableMapOf<Long, Long>()
|
2018-07-13 16:01:28 +02:00
|
|
|
|
2018-07-13 13:02:59 +02:00
|
|
|
private var shareLocationChats: Set<Long> = emptySet()
|
|
|
|
private var showOnMapChats: Set<Long> = emptySet()
|
2018-06-11 18:57:33 +02:00
|
|
|
|
|
|
|
var metricsConstants = MetricsConstants.KILOMETERS_AND_METERS
|
|
|
|
var speedConstants = SpeedConstants.KILOMETERS_PER_HOUR
|
|
|
|
|
2018-08-10 12:16:46 +02:00
|
|
|
var sendMyLocInterval = SEND_MY_LOC_VALUES_SEC[SEND_MY_LOC_DEFAULT_INDEX]
|
|
|
|
var staleLocTime = STALE_LOC_VALUES_SEC[STALE_LOC_DEFAULT_INDEX]
|
|
|
|
var locHistoryTime = LOC_HISTORY_VALUES_SEC[LOC_HISTORY_DEFAULT_INDEX]
|
2018-06-11 18:57:33 +02:00
|
|
|
|
2018-08-31 15:19:28 +02:00
|
|
|
var appToConnectPackage = ""
|
2018-08-31 15:28:14 +02:00
|
|
|
private set
|
2018-08-10 14:31:34 +02:00
|
|
|
|
2018-09-04 16:43:42 +02:00
|
|
|
var liveNowSortType = LiveNowSortType.SORT_BY_GROUP
|
2018-09-04 15:43:27 +02:00
|
|
|
|
2018-08-31 13:22:46 +02:00
|
|
|
val gpsAndLocPrefs = listOf(SendMyLocPref(), StaleLocPref(), LocHistoryPref())
|
|
|
|
|
2018-06-11 18:57:33 +02:00
|
|
|
init {
|
2018-07-13 13:32:11 +02:00
|
|
|
updatePrefs()
|
2018-06-11 18:57:33 +02:00
|
|
|
read()
|
|
|
|
}
|
|
|
|
|
2018-07-04 15:00:51 +02:00
|
|
|
fun hasAnyChatToShareLocation() = shareLocationChats.isNotEmpty()
|
2018-06-11 18:57:33 +02:00
|
|
|
|
2018-07-13 13:32:11 +02:00
|
|
|
fun isSharingLocationToChat(chatId: Long) = shareLocationChats.contains(chatId)
|
2018-06-11 18:57:33 +02:00
|
|
|
|
2018-07-04 15:00:51 +02:00
|
|
|
fun hasAnyChatToShowOnMap() = showOnMapChats.isNotEmpty()
|
2018-06-11 18:57:33 +02:00
|
|
|
|
2018-07-13 13:32:11 +02:00
|
|
|
fun isShowingChatOnMap(chatId: Long) = showOnMapChats.contains(chatId)
|
2018-06-11 18:57:33 +02:00
|
|
|
|
2018-07-13 13:02:59 +02:00
|
|
|
fun removeNonexistingChats(presentChatIds: List<Long>) {
|
2018-06-11 18:57:33 +02:00
|
|
|
val shareLocationChats = shareLocationChats.toMutableList()
|
2018-07-13 13:02:59 +02:00
|
|
|
shareLocationChats.intersect(presentChatIds)
|
2018-06-11 18:57:33 +02:00
|
|
|
this.shareLocationChats = shareLocationChats.toHashSet()
|
|
|
|
|
|
|
|
val showOnMapChats = showOnMapChats.toMutableList()
|
2018-07-13 13:02:59 +02:00
|
|
|
showOnMapChats.intersect(presentChatIds)
|
2018-06-11 18:57:33 +02:00
|
|
|
this.showOnMapChats = showOnMapChats.toHashSet()
|
2018-07-13 14:53:58 +02:00
|
|
|
|
2018-07-13 16:02:49 +02:00
|
|
|
chatLivePeriods = chatLivePeriods.filter { (key, _) ->
|
2018-07-13 15:28:37 +02:00
|
|
|
presentChatIds.contains(key)
|
|
|
|
}.toMutableMap()
|
2018-08-14 12:20:16 +02:00
|
|
|
|
2018-08-14 14:57:17 +02:00
|
|
|
chatShareLocStartSec = chatShareLocStartSec.filter { (key, _) ->
|
2018-08-14 12:20:16 +02:00
|
|
|
presentChatIds.contains(key)
|
|
|
|
}.toMutableMap()
|
2018-06-11 18:57:33 +02:00
|
|
|
}
|
|
|
|
|
2018-08-10 12:16:46 +02:00
|
|
|
fun shareLocationToChat(
|
|
|
|
chatId: Long,
|
|
|
|
share: Boolean,
|
|
|
|
livePeriod: Long = DEFAULT_VISIBLE_TIME_SECONDS
|
|
|
|
) {
|
2018-06-11 18:57:33 +02:00
|
|
|
val shareLocationChats = shareLocationChats.toMutableList()
|
|
|
|
if (share) {
|
2018-07-13 15:28:37 +02:00
|
|
|
val lp: Long = when {
|
2018-07-13 16:08:47 +02:00
|
|
|
livePeriod < TelegramHelper.MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> TelegramHelper.MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC.toLong()
|
|
|
|
livePeriod > TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC.toLong()
|
|
|
|
else -> livePeriod
|
2018-07-13 15:28:37 +02:00
|
|
|
}
|
2018-07-13 16:02:49 +02:00
|
|
|
chatLivePeriods[chatId] = lp
|
2018-08-31 13:22:46 +02:00
|
|
|
chatShareLocStartSec[chatId] = (System.currentTimeMillis() / 1000)
|
2018-07-13 13:32:11 +02:00
|
|
|
shareLocationChats.add(chatId)
|
2018-06-11 18:57:33 +02:00
|
|
|
} else {
|
2018-07-13 13:32:11 +02:00
|
|
|
shareLocationChats.remove(chatId)
|
2018-07-13 16:02:49 +02:00
|
|
|
chatLivePeriods.remove(chatId)
|
2018-08-14 14:57:17 +02:00
|
|
|
chatShareLocStartSec.remove(chatId)
|
2018-06-11 18:57:33 +02:00
|
|
|
}
|
|
|
|
this.shareLocationChats = shareLocationChats.toHashSet()
|
2018-07-13 14:53:58 +02:00
|
|
|
}
|
|
|
|
|
2018-07-13 16:06:05 +02:00
|
|
|
fun getChatLivePeriod(chatId: Long) = chatLivePeriods[chatId]
|
2018-06-11 18:57:33 +02:00
|
|
|
|
2018-08-14 14:57:17 +02:00
|
|
|
fun getChatLivePeriods(): Map<Long, Long> {
|
|
|
|
return chatLivePeriods.filter {
|
|
|
|
getChatLiveMessageExpireTime(it.key) > 0
|
|
|
|
}
|
|
|
|
}
|
2018-08-14 12:20:16 +02:00
|
|
|
|
2018-08-14 14:57:17 +02:00
|
|
|
fun getChatShareLocStartSec(chatId: Long) = chatShareLocStartSec[chatId]
|
|
|
|
|
|
|
|
fun getChatLiveMessageExpireTime(chatId: Long): Long {
|
|
|
|
val startTime = getChatShareLocStartSec(chatId)
|
|
|
|
val livePeriod = getChatLivePeriod(chatId)
|
|
|
|
return if (startTime != null && livePeriod != null) {
|
|
|
|
livePeriod - ((System.currentTimeMillis() / 1000) - startTime)
|
|
|
|
} else {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
}
|
2018-08-31 13:22:46 +02:00
|
|
|
|
2018-08-14 14:57:17 +02:00
|
|
|
fun updateChatShareLocStartSec(chatId: Long, startTime: Long) {
|
|
|
|
chatShareLocStartSec[chatId] = startTime
|
2018-08-31 13:22:46 +02:00
|
|
|
}
|
|
|
|
|
2018-06-19 15:00:13 +02:00
|
|
|
fun stopSharingLocationToChats() {
|
|
|
|
this.shareLocationChats = emptySet()
|
2018-07-13 16:02:49 +02:00
|
|
|
this.chatLivePeriods.clear()
|
2018-08-14 14:57:17 +02:00
|
|
|
this.chatShareLocStartSec.clear()
|
2018-06-19 15:00:13 +02:00
|
|
|
}
|
|
|
|
|
2018-08-28 19:10:59 +02:00
|
|
|
fun clearShowOnMapChats() {
|
|
|
|
showOnMapChats = emptySet()
|
|
|
|
}
|
|
|
|
|
2018-07-13 13:32:11 +02:00
|
|
|
fun showChatOnMap(chatId: Long, show: Boolean) {
|
2018-06-11 18:57:33 +02:00
|
|
|
val showOnMapChats = showOnMapChats.toMutableList()
|
|
|
|
if (show) {
|
2018-07-13 13:32:11 +02:00
|
|
|
showOnMapChats.add(chatId)
|
2018-06-11 18:57:33 +02:00
|
|
|
} else {
|
2018-07-13 13:32:11 +02:00
|
|
|
showOnMapChats.remove(chatId)
|
2018-06-11 18:57:33 +02:00
|
|
|
}
|
|
|
|
this.showOnMapChats = showOnMapChats.toHashSet()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun getShareLocationChats() = ArrayList(shareLocationChats)
|
2018-07-04 15:00:51 +02:00
|
|
|
|
2018-06-11 18:57:33 +02:00
|
|
|
fun getShowOnMapChats() = ArrayList(showOnMapChats)
|
|
|
|
|
|
|
|
fun getShowOnMapChatsCount() = showOnMapChats.size
|
|
|
|
|
2018-08-20 14:07:08 +02:00
|
|
|
fun clear() {
|
|
|
|
stopSharingLocationToChats()
|
2018-08-28 11:50:49 +02:00
|
|
|
app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE).edit().clear().apply()
|
2018-08-20 14:07:08 +02:00
|
|
|
}
|
2018-08-31 13:22:46 +02:00
|
|
|
|
2018-08-31 15:28:14 +02:00
|
|
|
fun updateAppToConnect(appToConnectPackage: String) {
|
|
|
|
this.appToConnectPackage = appToConnectPackage
|
|
|
|
app.showLocationHelper.stopShowingLocation()
|
|
|
|
app.osmandAidlHelper.reconnectOsmand()
|
|
|
|
}
|
|
|
|
|
2018-06-11 18:57:33 +02:00
|
|
|
fun save() {
|
|
|
|
val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE)
|
|
|
|
val edit = prefs.edit()
|
|
|
|
|
|
|
|
val shareLocationChatsSet = mutableSetOf<String>()
|
|
|
|
val shareLocationChats = ArrayList(shareLocationChats)
|
2018-07-13 13:02:59 +02:00
|
|
|
for (chatId in shareLocationChats) {
|
|
|
|
shareLocationChatsSet.add(chatId.toString())
|
2018-06-11 18:57:33 +02:00
|
|
|
}
|
|
|
|
edit.putStringSet(SHARE_LOCATION_CHATS_KEY, shareLocationChatsSet)
|
|
|
|
|
|
|
|
val showOnMapChatsSet = mutableSetOf<String>()
|
|
|
|
val showOnMapChats = ArrayList(showOnMapChats)
|
2018-07-13 13:02:59 +02:00
|
|
|
for (chatId in showOnMapChats) {
|
|
|
|
showOnMapChatsSet.add(chatId.toString())
|
2018-06-11 18:57:33 +02:00
|
|
|
}
|
|
|
|
edit.putStringSet(SHOW_ON_MAP_CHATS_KEY, showOnMapChatsSet)
|
|
|
|
|
|
|
|
edit.putString(METRICS_CONSTANTS_KEY, metricsConstants.name)
|
|
|
|
edit.putString(SPEED_CONSTANTS_KEY, speedConstants.name)
|
|
|
|
|
2018-08-10 12:16:46 +02:00
|
|
|
edit.putLong(SEND_MY_LOC_INTERVAL_KEY, sendMyLocInterval)
|
|
|
|
edit.putLong(STALE_LOC_TIME_KEY, staleLocTime)
|
|
|
|
edit.putLong(LOC_HISTORY_TIME_KEY, locHistoryTime)
|
2018-06-11 18:57:33 +02:00
|
|
|
|
2018-08-10 14:31:34 +02:00
|
|
|
edit.putString(APP_TO_CONNECT_PACKAGE_KEY, appToConnectPackage)
|
2018-09-04 15:43:27 +02:00
|
|
|
|
2018-09-04 16:43:42 +02:00
|
|
|
edit.putString(LIVE_NOW_SORT_TYPE_KEY, liveNowSortType.name)
|
2018-08-10 14:31:34 +02:00
|
|
|
|
2018-06-11 18:57:33 +02:00
|
|
|
edit.apply()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun read() {
|
|
|
|
val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE)
|
|
|
|
|
2018-07-13 13:02:59 +02:00
|
|
|
val shareLocationChats = mutableSetOf<Long>()
|
2018-06-11 18:57:33 +02:00
|
|
|
val shareLocationChatsSet = prefs.getStringSet(SHARE_LOCATION_CHATS_KEY, mutableSetOf())
|
2018-07-13 13:27:01 +02:00
|
|
|
for (chatId in shareLocationChatsSet) {
|
|
|
|
shareLocationChats.add(chatId.toLong())
|
|
|
|
}
|
|
|
|
this.shareLocationChats = shareLocationChats
|
|
|
|
|
2018-07-13 13:32:11 +02:00
|
|
|
val showOnMapChats = mutableSetOf<Long>()
|
|
|
|
val showOnMapChatsSet = prefs.getStringSet(SHOW_ON_MAP_CHATS_KEY, mutableSetOf())
|
2018-07-13 13:27:01 +02:00
|
|
|
for (chatId in showOnMapChatsSet) {
|
2018-07-13 13:02:59 +02:00
|
|
|
showOnMapChats.add(chatId.toLong())
|
2018-06-11 18:57:33 +02:00
|
|
|
}
|
|
|
|
this.showOnMapChats = showOnMapChats
|
|
|
|
|
2018-07-04 15:00:51 +02:00
|
|
|
metricsConstants = MetricsConstants.valueOf(
|
2018-07-13 13:32:11 +02:00
|
|
|
prefs.getString(METRICS_CONSTANTS_KEY, MetricsConstants.KILOMETERS_AND_METERS.name)
|
2018-07-04 15:00:51 +02:00
|
|
|
)
|
|
|
|
speedConstants = SpeedConstants.valueOf(
|
2018-07-13 13:32:11 +02:00
|
|
|
prefs.getString(SPEED_CONSTANTS_KEY, SpeedConstants.KILOMETERS_PER_HOUR.name)
|
2018-07-04 15:00:51 +02:00
|
|
|
)
|
|
|
|
|
2018-08-10 12:16:46 +02:00
|
|
|
val sendMyLocDef = SEND_MY_LOC_VALUES_SEC[SEND_MY_LOC_DEFAULT_INDEX]
|
|
|
|
sendMyLocInterval = prefs.getLong(SEND_MY_LOC_INTERVAL_KEY, sendMyLocDef)
|
|
|
|
val staleLocDef = STALE_LOC_VALUES_SEC[STALE_LOC_DEFAULT_INDEX]
|
|
|
|
staleLocTime = prefs.getLong(STALE_LOC_TIME_KEY, staleLocDef)
|
|
|
|
val locHistoryDef = LOC_HISTORY_VALUES_SEC[LOC_HISTORY_DEFAULT_INDEX]
|
|
|
|
locHistoryTime = prefs.getLong(LOC_HISTORY_TIME_KEY, locHistoryDef)
|
2018-08-10 14:31:34 +02:00
|
|
|
|
2018-09-04 15:57:19 +02:00
|
|
|
appToConnectPackage = prefs.getString(APP_TO_CONNECT_PACKAGE_KEY, "")
|
2018-09-04 17:44:42 +02:00
|
|
|
|
2018-09-04 16:43:42 +02:00
|
|
|
liveNowSortType = LiveNowSortType.valueOf(prefs.getString(LIVE_NOW_SORT_TYPE_KEY, LiveNowSortType.SORT_BY_GROUP.name))
|
2018-06-11 18:57:33 +02:00
|
|
|
}
|
2018-07-13 13:32:11 +02:00
|
|
|
|
|
|
|
private fun updatePrefs() {
|
|
|
|
val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE)
|
|
|
|
val idsInUse = prefs.getBoolean(TITLES_REPLACED_WITH_IDS, false)
|
|
|
|
if (!idsInUse) {
|
|
|
|
val edit = prefs.edit()
|
|
|
|
|
|
|
|
edit.putStringSet(SHARE_LOCATION_CHATS_KEY, emptySet())
|
|
|
|
edit.putStringSet(SHOW_ON_MAP_CHATS_KEY, emptySet())
|
|
|
|
edit.putBoolean(TITLES_REPLACED_WITH_IDS, true)
|
|
|
|
|
|
|
|
edit.apply()
|
|
|
|
}
|
|
|
|
}
|
2018-08-31 13:22:46 +02:00
|
|
|
|
|
|
|
inner class SendMyLocPref : DurationPref(
|
|
|
|
R.drawable.ic_action_share_location,
|
|
|
|
R.string.send_my_location,
|
|
|
|
R.string.send_my_location_desc,
|
|
|
|
SEND_MY_LOC_VALUES_SEC
|
|
|
|
) {
|
|
|
|
|
|
|
|
override fun getCurrentValue() =
|
|
|
|
OsmandFormatter.getFormattedDuration(app, sendMyLocInterval)
|
|
|
|
|
|
|
|
override fun setCurrentValue(index: Int) {
|
|
|
|
sendMyLocInterval = values[index]
|
|
|
|
app.updateSendLocationInterval()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inner class StaleLocPref : DurationPref(
|
|
|
|
R.drawable.ic_action_time_span,
|
|
|
|
R.string.stale_location,
|
|
|
|
R.string.stale_location_desc,
|
|
|
|
STALE_LOC_VALUES_SEC
|
|
|
|
) {
|
|
|
|
|
|
|
|
override fun getCurrentValue() =
|
|
|
|
OsmandFormatter.getFormattedDuration(app, staleLocTime)
|
|
|
|
|
|
|
|
override fun setCurrentValue(index: Int) {
|
|
|
|
staleLocTime = values[index]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inner class LocHistoryPref : DurationPref(
|
|
|
|
R.drawable.ic_action_location_history,
|
|
|
|
R.string.location_history,
|
|
|
|
R.string.location_history_desc,
|
|
|
|
LOC_HISTORY_VALUES_SEC
|
|
|
|
) {
|
|
|
|
|
|
|
|
override fun getCurrentValue() =
|
|
|
|
OsmandFormatter.getFormattedDuration(app, locHistoryTime)
|
|
|
|
|
|
|
|
override fun setCurrentValue(index: Int) {
|
|
|
|
val value = values[index]
|
|
|
|
locHistoryTime = value
|
|
|
|
app.telegramHelper.messageActiveTimeSec = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract inner class DurationPref(
|
|
|
|
@DrawableRes val iconId: Int,
|
|
|
|
@StringRes val titleId: Int,
|
|
|
|
@StringRes val descriptionId: Int,
|
|
|
|
val values: List<Long>
|
|
|
|
) {
|
|
|
|
|
|
|
|
abstract fun getCurrentValue(): String
|
|
|
|
|
|
|
|
abstract fun setCurrentValue(index: Int)
|
|
|
|
|
|
|
|
fun getMenuItems() = values.map { OsmandFormatter.getFormattedDuration(app, it) }
|
|
|
|
}
|
|
|
|
|
|
|
|
enum class AppConnect(
|
|
|
|
@DrawableRes val iconId: Int,
|
|
|
|
@DrawableRes val whiteIconId: Int,
|
|
|
|
val title: String,
|
2018-09-03 13:30:40 +02:00
|
|
|
val appPackage: String,
|
|
|
|
val showOnlyInstalled: Boolean
|
2018-08-31 13:22:46 +02:00
|
|
|
) {
|
|
|
|
OSMAND_PLUS(
|
|
|
|
R.drawable.ic_logo_osmand_plus,
|
|
|
|
R.drawable.ic_action_osmand_plus,
|
|
|
|
"OsmAnd+",
|
2018-09-03 13:30:40 +02:00
|
|
|
OsmandAidlHelper.OSMAND_PLUS_PACKAGE_NAME,
|
|
|
|
false
|
2018-08-31 13:22:46 +02:00
|
|
|
),
|
|
|
|
OSMAND_FREE(
|
|
|
|
R.drawable.ic_logo_osmand_free,
|
|
|
|
R.drawable.ic_action_osmand_free,
|
|
|
|
"OsmAnd",
|
2018-09-03 13:30:40 +02:00
|
|
|
OsmandAidlHelper.OSMAND_FREE_PACKAGE_NAME,
|
|
|
|
false
|
|
|
|
),
|
|
|
|
OSMAND_NIGHTLY(
|
2018-09-03 14:58:51 +02:00
|
|
|
R.drawable.ic_logo_osmand_nightly,
|
2018-09-03 13:30:40 +02:00
|
|
|
R.drawable.ic_action_osmand_free,
|
|
|
|
"OsmAnd Nightly",
|
|
|
|
OsmandAidlHelper.OSMAND_NIGHTLY_PACKAGE_NAME,
|
|
|
|
true
|
2018-08-31 13:22:46 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
@DrawableRes
|
|
|
|
fun getWhiteIconId(appPackage: String): Int {
|
|
|
|
for (item in values()) {
|
|
|
|
if (item.appPackage == appPackage) {
|
|
|
|
return item.whiteIconId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
2018-08-31 15:19:28 +02:00
|
|
|
|
|
|
|
fun getInstalledApps(context: Context) =
|
|
|
|
values().filter { AndroidUtils.isAppInstalled(context, it.appPackage) }
|
2018-08-31 13:22:46 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-04 16:43:42 +02:00
|
|
|
|
|
|
|
enum class LiveNowSortType(@DrawableRes val iconId: Int, @StringRes val titleId: Int, @StringRes val shortTitleId: Int) {
|
|
|
|
SORT_BY_GROUP(
|
|
|
|
R.drawable.ic_action_sort_by_group,
|
|
|
|
R.string.shared_string_group,
|
|
|
|
R.string.by_group
|
|
|
|
),
|
|
|
|
SORT_BY_NAME(
|
|
|
|
R.drawable.ic_action_sort_by_name,
|
|
|
|
R.string.shared_string_name,
|
|
|
|
R.string.by_name
|
|
|
|
),
|
|
|
|
SORT_BY_DISTANCE(
|
|
|
|
R.drawable.ic_action_sort_by_distance,
|
|
|
|
R.string.shared_string_distance,
|
|
|
|
R.string.by_distance
|
|
|
|
);
|
|
|
|
|
|
|
|
fun isSortByGroup() = this == SORT_BY_GROUP
|
|
|
|
}
|
2018-06-09 11:20:21 +02:00
|
|
|
}
|