Update the glance support
This commit is contained in:
@ -1,19 +1,28 @@
|
||||
package com.tommasoberlose.anotherwidget.helpers
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.service.notification.StatusBarNotification
|
||||
import android.util.Log
|
||||
import com.chibatching.kotpref.Kotpref
|
||||
import com.chibatching.kotpref.blockingBulk
|
||||
import com.google.gson.Gson
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import java.lang.Exception
|
||||
|
||||
object ActiveNotificationsHelper {
|
||||
fun getLastNotification(context: Context): StatusBarNotification? {
|
||||
with(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager) {
|
||||
activeNotifications.forEach {
|
||||
Log.d("ciao", Gson().toJson(it).toString())
|
||||
}
|
||||
fun showLastNotification(): Boolean {
|
||||
return Preferences.lastNotificationId != -1 && Preferences.lastNotificationIcon != 0 && Preferences.lastNotificationPackage.isNotBlank() && Preferences.lastNotificationTitle.isNotBlank()
|
||||
}
|
||||
|
||||
return activeNotifications.lastOrNull()
|
||||
fun clearLastNotification(context: Context) {
|
||||
Kotpref.init(context)
|
||||
Preferences.blockingBulk {
|
||||
remove(Preferences::lastNotificationId)
|
||||
remove(Preferences::lastNotificationTitle)
|
||||
remove(Preferences::lastNotificationPackage)
|
||||
remove(Preferences::lastNotificationIcon)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.tommasoberlose.anotherwidget.helpers
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
@ -71,6 +70,18 @@ object GlanceProviderHelper {
|
||||
R.drawable.round_directions_walk
|
||||
)
|
||||
}
|
||||
Constants.GlanceProviderId.NOTIFICATIONS -> {
|
||||
GlanceProvider(providerId.id,
|
||||
context.getString(R.string.settings_show_notifications_title),
|
||||
R.drawable.round_notifications
|
||||
)
|
||||
}
|
||||
Constants.GlanceProviderId.GREETINGS -> {
|
||||
GlanceProvider(providerId.id,
|
||||
context.getString(R.string.settings_show_greetings_title),
|
||||
R.drawable.round_history_edu
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,12 +95,12 @@ object GlanceProviderHelper {
|
||||
|
||||
val showGlance = Preferences.showGlance && (eventRepository.getEventsCount() == 0 || !Preferences.showEvents)
|
||||
&& (
|
||||
(Preferences.showNotifications && ActiveNotificationsHelper.showLastNotification()) ||
|
||||
(Preferences.showNextAlarm && AlarmHelper.getNextAlarm(context) != "") ||
|
||||
(MediaPlayerHelper.isSomeonePlaying(context)) ||
|
||||
(Preferences.showBatteryCharging && Preferences.isCharging || Preferences.isBatteryLevelLow) ||
|
||||
(Preferences.customNotes.isNotEmpty()) ||
|
||||
(Preferences.showDailySteps && Preferences.googleFitSteps > 0) ||
|
||||
(Preferences.showNotifications && ActiveNotificationsHelper.getLastNotification(context) != null)
|
||||
(Preferences.showDailySteps && Preferences.googleFitSteps > 0)
|
||||
)
|
||||
eventRepository.close()
|
||||
return showGlance
|
||||
|
@ -222,4 +222,16 @@ object IntentHelper {
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
|
||||
fun getNotificationIntent(context: Context): Intent {
|
||||
val pm: PackageManager = context.packageManager
|
||||
return try {
|
||||
pm.getLaunchIntentForPackage(Preferences.lastNotificationPackage)!!.apply {
|
||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.toast(context.getString(R.string.error_opening_app))
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user