Change icon and dd button to the notification
This commit is contained in:
parent
956606e3f6
commit
aecf98195c
5 changed files with 38 additions and 10 deletions
|
@ -79,6 +79,12 @@ class TelegramApplication : Application(), OsmandHelperListener {
|
|||
telegramHelper.close()
|
||||
}
|
||||
|
||||
fun stopSharingLocation() {
|
||||
settings.stopSharingLocationToChats()
|
||||
shareLocationHelper.stopSharingLocation()
|
||||
telegramHelper.stopSendingLiveLocationMessages()
|
||||
}
|
||||
|
||||
fun isOsmAndInstalled() = AndroidUtils.isAppInstalled(this, settings.appToConnectPackage)
|
||||
|
||||
val isWifiConnected: Boolean
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package net.osmand.telegram.notifications
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.support.v4.app.NotificationCompat
|
||||
import android.support.v4.content.ContextCompat
|
||||
import net.osmand.telegram.R
|
||||
|
@ -8,9 +13,18 @@ import net.osmand.telegram.utils.OsmandFormatter
|
|||
import net.osmand.util.Algorithms
|
||||
|
||||
private const val GROUP_NAME = "share_location"
|
||||
private const val DISABLE_SHARING_ACTION = "disable_sharing_action"
|
||||
|
||||
class LocationNotification(app: TelegramApplication) : TelegramNotification(app, GROUP_NAME) {
|
||||
|
||||
init {
|
||||
app.registerReceiver(object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
app.stopSharingLocation()
|
||||
}
|
||||
}, IntentFilter(DISABLE_SHARING_ACTION))
|
||||
}
|
||||
|
||||
override val type: TelegramNotification.NotificationType
|
||||
get() = TelegramNotification.NotificationType.LOCATION
|
||||
|
||||
|
@ -39,11 +53,18 @@ class LocationNotification(app: TelegramApplication) : TelegramNotification(app,
|
|||
if (shareLocationHelper.sharingLocation) {
|
||||
val sharedDistance = shareLocationHelper.distance.toFloat()
|
||||
color = ContextCompat.getColor(app, R.color.osmand_orange)
|
||||
icon = R.drawable.ic_action_polygom_dark
|
||||
icon = R.drawable.ic_action_share_location
|
||||
notificationTitle = (app.getString(R.string.sharing_location) + " • "
|
||||
+ Algorithms.formatDuration((shareLocationHelper.duration / 1000).toInt(), true))
|
||||
notificationText = (app.getString(R.string.shared_string_distance)
|
||||
+ ": " + OsmandFormatter.getFormattedDistance(sharedDistance, app))
|
||||
actionTextId = R.string.disable_all_sharing
|
||||
actionIntent = PendingIntent.getBroadcast(
|
||||
app,
|
||||
0,
|
||||
Intent(DISABLE_SHARING_ACTION),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
} else {
|
||||
notificationTitle = app.getString(R.string.show_users_on_map)
|
||||
notificationText = app.getString(R.string.active_chats) + ": " + app.settings.getShowOnMapChatsCount()
|
||||
|
|
|
@ -5,8 +5,8 @@ import android.app.PendingIntent
|
|||
import android.content.Intent
|
||||
import android.support.v4.app.NotificationCompat
|
||||
import android.support.v4.app.NotificationManagerCompat
|
||||
import net.osmand.telegram.ui.MainActivity
|
||||
import net.osmand.telegram.TelegramApplication
|
||||
import net.osmand.telegram.ui.MainActivity
|
||||
|
||||
|
||||
abstract class TelegramNotification(protected var app: TelegramApplication, val groupName: String) {
|
||||
|
@ -22,6 +22,10 @@ abstract class TelegramNotification(protected var app: TelegramApplication, val
|
|||
protected var color: Int = 0
|
||||
protected var icon: Int = 0
|
||||
|
||||
protected var actionIconId: Int = 0
|
||||
protected var actionTextId: Int = 0
|
||||
protected var actionIntent: PendingIntent? = null
|
||||
|
||||
abstract val type: NotificationType
|
||||
|
||||
abstract val telegramNotificationId: Int
|
||||
|
@ -59,6 +63,9 @@ abstract class TelegramNotification(protected var app: TelegramApplication, val
|
|||
if (icon != 0) {
|
||||
builder.setSmallIcon(icon)
|
||||
}
|
||||
if (actionTextId != 0 && actionIntent != null) {
|
||||
builder.addAction(actionIconId, app.getString(actionTextId), actionIntent)
|
||||
}
|
||||
|
||||
return builder
|
||||
}
|
||||
|
|
|
@ -291,19 +291,13 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
settings.removeNonexistingChats(presentChatTitles)
|
||||
}
|
||||
|
||||
fun stopSharingLocation() {
|
||||
settings.stopSharingLocationToChats()
|
||||
app.shareLocationHelper.stopSharingLocation()
|
||||
telegramHelper.stopSendingLiveLocationMessages()
|
||||
}
|
||||
|
||||
fun stopShowingChatsOnMap(forceStop: Boolean) {
|
||||
settings.getShowOnMapChats().forEach { app.showLocationHelper.hideChatMessages(it) }
|
||||
app.showLocationHelper.stopShowingLocation(forceStop)
|
||||
}
|
||||
|
||||
private fun closeApp() {
|
||||
stopSharingLocation()
|
||||
app.stopSharingLocation()
|
||||
stopShowingChatsOnMap(true)
|
||||
finish()
|
||||
android.os.Process.killProcess(android.os.Process.myPid())
|
||||
|
|
|
@ -225,7 +225,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
}
|
||||
DisableSharingBottomSheet.SHARING_DISABLED_REQUEST_CODE -> {
|
||||
sharingMode = false
|
||||
(activity as MainActivity).stopSharingLocation()
|
||||
app.stopSharingLocation()
|
||||
updateContent()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue