status widget blink
This commit is contained in:
parent
2a9428013a
commit
42d5cc759f
2 changed files with 56 additions and 11 deletions
|
@ -83,6 +83,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
lastLocationUpdateTime = System.currentTimeMillis()
|
lastLocationUpdateTime = System.currentTimeMillis()
|
||||||
lastLocation = location
|
lastLocation = location
|
||||||
if (app.settings.getChatsShareInfo().isNotEmpty()) {
|
if (app.settings.getChatsShareInfo().isNotEmpty()) {
|
||||||
|
app.showLocationHelper.shouldBlinkWidget = true
|
||||||
shareLocationMessages(location, app.telegramHelper.getCurrentUserId())
|
shareLocationMessages(location, app.telegramHelper.getCurrentUserId())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,8 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
|
|
||||||
private var forcedStop: Boolean = false
|
private var forcedStop: Boolean = false
|
||||||
|
|
||||||
|
var shouldBlinkWidget: Boolean = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
app.osmandAidlHelper.addConnectionListener(object : OsmandAidlHelper.OsmandHelperListener {
|
app.osmandAidlHelper.addConnectionListener(object : OsmandAidlHelper.OsmandHelperListener {
|
||||||
override fun onOsmandConnectionStateChanged(connected: Boolean) {
|
override fun onOsmandConnectionStateChanged(connected: Boolean) {
|
||||||
|
@ -222,8 +224,10 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addOrUpdateStatusWidget(time: Long, isSending: Boolean) {
|
fun addOrUpdateStatusWidget(time: Long, isSending: Boolean) {
|
||||||
|
var noSubText = false
|
||||||
var iconDay: String
|
var iconDay: String
|
||||||
var iconNight: String
|
var iconNight: String
|
||||||
|
val diffTime = (System.currentTimeMillis() - time) / 1000
|
||||||
val menuIcon = if (isOsmandHasStatusWidgetIcon()) {
|
val menuIcon = if (isOsmandHasStatusWidgetIcon()) {
|
||||||
STATUS_WIDGET_MENU_ICON
|
STATUS_WIDGET_MENU_ICON
|
||||||
} else {
|
} else {
|
||||||
|
@ -233,14 +237,17 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
time > 0L && isSending -> {
|
time > 0L && isSending -> {
|
||||||
iconDay = STATUS_WIDGET_ON_ICON_DAY
|
iconDay = STATUS_WIDGET_ON_ICON_DAY
|
||||||
iconNight = STATUS_WIDGET_ON_ICON_NIGHT
|
iconNight = STATUS_WIDGET_ON_ICON_NIGHT
|
||||||
val diffTime = (System.currentTimeMillis() - time) / 1000
|
|
||||||
OsmandFormatter.getFormattedDurationForWidget(diffTime)
|
OsmandFormatter.getFormattedDurationForWidget(diffTime)
|
||||||
}
|
}
|
||||||
time > 0L && !isSending -> {
|
time > 0L && !isSending -> {
|
||||||
iconDay = STATUS_WIDGET_ICON_DAY
|
iconDay = STATUS_WIDGET_ICON_DAY
|
||||||
iconNight = STATUS_WIDGET_ICON_NIGHT
|
iconNight = STATUS_WIDGET_ICON_NIGHT
|
||||||
val diffTime = (System.currentTimeMillis() - time) / 1000
|
if (diffTime >= 2 * 60) {
|
||||||
OsmandFormatter.getFormattedDurationForWidget(diffTime)
|
OsmandFormatter.getFormattedDurationForWidget(diffTime)
|
||||||
|
} else {
|
||||||
|
noSubText = true
|
||||||
|
app.getString(R.string.shared_string_error_short)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
time == 0L && isSending -> {
|
time == 0L && isSending -> {
|
||||||
iconDay = STATUS_WIDGET_ON_ICON_DAY
|
iconDay = STATUS_WIDGET_ON_ICON_DAY
|
||||||
|
@ -263,7 +270,7 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
iconNight = STATUS_WIDGET_ICON_OLD
|
iconNight = STATUS_WIDGET_ICON_OLD
|
||||||
}
|
}
|
||||||
val subText = when {
|
val subText = when {
|
||||||
time > 0 -> {
|
time > 0 && !noSubText -> {
|
||||||
if (text.length > 2) {
|
if (text.length > 2) {
|
||||||
app.getString(R.string.shared_string_hour_short)
|
app.getString(R.string.shared_string_hour_short)
|
||||||
} else {
|
} else {
|
||||||
|
@ -272,13 +279,18 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
}
|
}
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
osmandAidlHelper.addMapWidget(
|
if (shouldBlinkWidget && isSending && isOsmandHasStatusWidgetIcon()) {
|
||||||
STATUS_WIDGET_ID,
|
BlinkWidgetTask(app, menuIcon, text, subText, getStatusWidgetIntent()).executeOnExecutor(executor)
|
||||||
menuIcon,
|
shouldBlinkWidget = false
|
||||||
app.getString(R.string.status_widget_title),
|
} else {
|
||||||
iconDay,
|
osmandAidlHelper.addMapWidget(
|
||||||
iconNight,
|
STATUS_WIDGET_ID,
|
||||||
text, subText, 50, getStatusWidgetIntent())
|
menuIcon,
|
||||||
|
app.getString(R.string.status_widget_title),
|
||||||
|
iconDay,
|
||||||
|
iconNight,
|
||||||
|
text, subText, 50, getStatusWidgetIntent())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getStatusWidgetIntent(): Intent {
|
private fun getStatusWidgetIntent(): Intent {
|
||||||
|
@ -545,6 +557,38 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class BlinkWidgetTask(private val app: TelegramApplication, private val menuIcon: String,
|
||||||
|
private val text: String, private val subText: String,
|
||||||
|
private val intent: Intent) : AsyncTask<Void, Void, Void?>() {
|
||||||
|
|
||||||
|
override fun onPreExecute() {
|
||||||
|
super.onPreExecute()
|
||||||
|
app.osmandAidlHelper.addMapWidget(
|
||||||
|
STATUS_WIDGET_ID,
|
||||||
|
menuIcon,
|
||||||
|
app.getString(R.string.status_widget_title),
|
||||||
|
STATUS_WIDGET_OFF_ICON_DAY,
|
||||||
|
STATUS_WIDGET_OFF_ICON_NIGHT,
|
||||||
|
text, subText, 50, intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun doInBackground(vararg params: Void?): Void? {
|
||||||
|
Thread.sleep(300)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPostExecute(result: Void?) {
|
||||||
|
super.onPostExecute(result)
|
||||||
|
app.osmandAidlHelper.addMapWidget(
|
||||||
|
STATUS_WIDGET_ID,
|
||||||
|
menuIcon,
|
||||||
|
app.getString(R.string.status_widget_title),
|
||||||
|
STATUS_WIDGET_ON_ICON_DAY,
|
||||||
|
STATUS_WIDGET_ON_ICON_NIGHT,
|
||||||
|
text, subText, 50, intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun generatePointDetails(bearing: Float?, altitude: Float?, precision: Float?): List<String> {
|
private fun generatePointDetails(bearing: Float?, altitude: Float?, precision: Float?): List<String> {
|
||||||
val details = mutableListOf<String>()
|
val details = mutableListOf<String>()
|
||||||
if (bearing != null && bearing != 0.0f) {
|
if (bearing != null && bearing != 0.0f) {
|
||||||
|
|
Loading…
Reference in a new issue