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()
|
||||
lastLocation = location
|
||||
if (app.settings.getChatsShareInfo().isNotEmpty()) {
|
||||
app.showLocationHelper.shouldBlinkWidget = true
|
||||
shareLocationMessages(location, app.telegramHelper.getCurrentUserId())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,8 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
|
||||
private var forcedStop: Boolean = false
|
||||
|
||||
var shouldBlinkWidget: Boolean = false
|
||||
|
||||
init {
|
||||
app.osmandAidlHelper.addConnectionListener(object : OsmandAidlHelper.OsmandHelperListener {
|
||||
override fun onOsmandConnectionStateChanged(connected: Boolean) {
|
||||
|
@ -222,8 +224,10 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
}
|
||||
|
||||
fun addOrUpdateStatusWidget(time: Long, isSending: Boolean) {
|
||||
var noSubText = false
|
||||
var iconDay: String
|
||||
var iconNight: String
|
||||
val diffTime = (System.currentTimeMillis() - time) / 1000
|
||||
val menuIcon = if (isOsmandHasStatusWidgetIcon()) {
|
||||
STATUS_WIDGET_MENU_ICON
|
||||
} else {
|
||||
|
@ -233,14 +237,17 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
time > 0L && isSending -> {
|
||||
iconDay = STATUS_WIDGET_ON_ICON_DAY
|
||||
iconNight = STATUS_WIDGET_ON_ICON_NIGHT
|
||||
val diffTime = (System.currentTimeMillis() - time) / 1000
|
||||
OsmandFormatter.getFormattedDurationForWidget(diffTime)
|
||||
}
|
||||
time > 0L && !isSending -> {
|
||||
iconDay = STATUS_WIDGET_ICON_DAY
|
||||
iconNight = STATUS_WIDGET_ICON_NIGHT
|
||||
val diffTime = (System.currentTimeMillis() - time) / 1000
|
||||
if (diffTime >= 2 * 60) {
|
||||
OsmandFormatter.getFormattedDurationForWidget(diffTime)
|
||||
} else {
|
||||
noSubText = true
|
||||
app.getString(R.string.shared_string_error_short)
|
||||
}
|
||||
}
|
||||
time == 0L && isSending -> {
|
||||
iconDay = STATUS_WIDGET_ON_ICON_DAY
|
||||
|
@ -263,7 +270,7 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
iconNight = STATUS_WIDGET_ICON_OLD
|
||||
}
|
||||
val subText = when {
|
||||
time > 0 -> {
|
||||
time > 0 && !noSubText -> {
|
||||
if (text.length > 2) {
|
||||
app.getString(R.string.shared_string_hour_short)
|
||||
} else {
|
||||
|
@ -272,6 +279,10 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
}
|
||||
else -> ""
|
||||
}
|
||||
if (shouldBlinkWidget && isSending && isOsmandHasStatusWidgetIcon()) {
|
||||
BlinkWidgetTask(app, menuIcon, text, subText, getStatusWidgetIntent()).executeOnExecutor(executor)
|
||||
shouldBlinkWidget = false
|
||||
} else {
|
||||
osmandAidlHelper.addMapWidget(
|
||||
STATUS_WIDGET_ID,
|
||||
menuIcon,
|
||||
|
@ -280,6 +291,7 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
iconNight,
|
||||
text, subText, 50, getStatusWidgetIntent())
|
||||
}
|
||||
}
|
||||
|
||||
private fun getStatusWidgetIntent(): Intent {
|
||||
val startIntent = app.packageManager.getLaunchIntentForPackage(app.packageName)
|
||||
|
@ -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> {
|
||||
val details = mutableListOf<String>()
|
||||
if (bearing != null && bearing != 0.0f) {
|
||||
|
|
Loading…
Reference in a new issue