diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index 778d2cf985..adc325293c 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -53,6 +53,7 @@ import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.extensions.isRunningRealPumpTest import info.nightscout.androidaps.utils.protection.ProtectionCheck +import info.nightscout.androidaps.utils.resources.IconsProvider import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.android.schedulers.AndroidSchedulers @@ -77,6 +78,7 @@ class MainActivity : NoSplashAppCompatActivity() { @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var protectionCheck: ProtectionCheck + @Inject lateinit var iconsProvider: IconsProvider private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle private var pluginPreferencesMenuItem: MenuItem? = null @@ -283,7 +285,7 @@ class MainActivity : NoSplashAppCompatActivity() { Linkify.addLinks(messageSpanned, Linkify.WEB_URLS) AlertDialog.Builder(this) .setTitle(resourceHelper.gs(R.string.app_name) + " " + BuildConfig.VERSION) - .setIcon(resourceHelper.getIcon()) + .setIcon(iconsProvider.getIcon()) .setMessage(messageSpanned) .setPositiveButton(resourceHelper.gs(R.string.ok), null) .create().also { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt index fd1ca3fce1..b07e9756e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt @@ -24,6 +24,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification import info.nightscout.androidaps.services.AlarmSoundService import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.resources.IconsProvider import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import java.util.* @@ -36,7 +37,8 @@ class NotificationStore @Inject constructor( private val sp: SP, private val rxBus: RxBusWrapper, private val resourceHelper: ResourceHelper, - private val context: Context + private val context: Context, + private val iconsProvider: IconsProvider ) { var store: MutableList = ArrayList() @@ -109,8 +111,8 @@ class NotificationStore @Inject constructor( private fun raiseSystemNotification(n: Notification) { val mgr = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - val largeIcon = resourceHelper.decodeResource(resourceHelper.getIcon()) - val smallIcon = resourceHelper.getNotificationIcon() + val largeIcon = resourceHelper.decodeResource(iconsProvider.getIcon()) + val smallIcon = iconsProvider.getNotificationIcon() val sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM) val notificationBuilder = NotificationCompat.Builder(context, CHANNEL_ID) .setSmallIcon(smallIcon) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt index cabbf3b1ef..c1a203a343 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt @@ -28,6 +28,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutos import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.androidNotification.NotificationHolder +import info.nightscout.androidaps.utils.resources.IconsProvider import info.nightscout.androidaps.utils.resources.ResourceHelper import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers @@ -45,7 +46,8 @@ class PersistentNotificationPlugin @Inject constructor( private var iobCobCalculatorPlugin: IobCobCalculatorPlugin, private var rxBus: RxBusWrapper, private var context: Context, - private var notificationHolder: NotificationHolder + private var notificationHolder: NotificationHolder, + private val iconsProvider: IconsProvider ) : PluginBase(PluginDescription() .mainType(PluginType.GENERAL) .neverVisible(true) @@ -209,8 +211,8 @@ class PersistentNotificationPlugin @Inject constructor( builder.setOngoing(true) builder.setOnlyAlertOnce(true) builder.setCategory(NotificationCompat.CATEGORY_STATUS) - builder.setSmallIcon(resourceHelper.getNotificationIcon()) - builder.setLargeIcon(resourceHelper.decodeResource(resourceHelper.getIcon())) + builder.setSmallIcon(iconsProvider.getNotificationIcon()) + builder.setLargeIcon(resourceHelper.decodeResource(iconsProvider.getIcon())) if (line1 != null) builder.setContentTitle(line1) if (line2 != null) builder.setContentText(line2) if (line3 != null) builder.setSubText(line3) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/androidNotification/NotificationHolder.kt b/app/src/main/java/info/nightscout/androidaps/utils/androidNotification/NotificationHolder.kt index 9ec04d59d7..6ee23a85f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/androidNotification/NotificationHolder.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/androidNotification/NotificationHolder.kt @@ -10,6 +10,7 @@ import androidx.core.app.TaskStackBuilder import info.nightscout.androidaps.MainActivity import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.utils.resources.IconsProvider import info.nightscout.androidaps.utils.resources.ResourceHelper import javax.inject.Inject import javax.inject.Singleton @@ -17,7 +18,8 @@ import javax.inject.Singleton @Singleton class NotificationHolder @Inject constructor( private val resourceHelper: ResourceHelper, - private val context: Context + private val context: Context, + private val iconsProvider: IconsProvider ) { val channelID = "AndroidAPS-Ongoing" @@ -32,8 +34,8 @@ class NotificationHolder @Inject constructor( .setOngoing(true) .setOnlyAlertOnce(true) .setCategory(NotificationCompat.CATEGORY_STATUS) - .setSmallIcon(resourceHelper.getNotificationIcon()) - .setLargeIcon(resourceHelper.decodeResource(resourceHelper.getIcon())) + .setSmallIcon(iconsProvider.getNotificationIcon()) + .setLargeIcon(resourceHelper.decodeResource(iconsProvider.getIcon())) .setContentTitle(resourceHelper.gs(R.string.loading)) .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)) notification = builder.build() diff --git a/app/src/main/java/info/nightscout/androidaps/utils/resources/IconsProvider.kt b/app/src/main/java/info/nightscout/androidaps/utils/resources/IconsProvider.kt new file mode 100644 index 0000000000..d707caaaa1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/resources/IconsProvider.kt @@ -0,0 +1,24 @@ +package info.nightscout.androidaps.utils.resources + +import info.nightscout.androidaps.Config +import info.nightscout.androidaps.R +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class IconsProvider @Inject constructor() { + + fun getIcon(): Int = + when { + Config.NSCLIENT -> R.mipmap.ic_yellowowl + Config.PUMPCONTROL -> R.mipmap.ic_pumpcontrol + else -> R.mipmap.ic_launcher + } + + fun getNotificationIcon(): Int = + when { + Config.NSCLIENT -> R.drawable.ic_notif_nsclient + Config.PUMPCONTROL -> R.drawable.ic_notif_pumpcontrol + else -> R.drawable.ic_notif_aaps + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt b/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt index 9b03902883..8bb879fa80 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt @@ -15,8 +15,6 @@ interface ResourceHelper { fun gsa(@ArrayRes id:Int): Array fun openRawResourceFd(@RawRes id : Int) : AssetFileDescriptor? - fun getIcon() : Int - fun getNotificationIcon() : Int fun decodeResource(id : Int) : Bitmap fun getDisplayMetrics(): DisplayMetrics fun dpToPx(dp: Int): Int diff --git a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt b/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt index 0773b8a859..3cd72d5f4a 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt @@ -42,20 +42,6 @@ class ResourceHelperImplementation @Inject constructor(private val context: Cont override fun openRawResourceFd(id: Int): AssetFileDescriptor = context.resources.openRawResourceFd(id) - override fun getIcon(): Int = - when { - Config.NSCLIENT -> R.mipmap.ic_yellowowl - Config.PUMPCONTROL -> R.mipmap.ic_pumpcontrol - else -> R.mipmap.ic_launcher - } - - override fun getNotificationIcon(): Int = - when { - Config.NSCLIENT -> R.drawable.ic_notif_nsclient - Config.PUMPCONTROL -> R.drawable.ic_notif_pumpcontrol - else -> R.drawable.ic_notif_aaps - } - override fun decodeResource(id: Int): Bitmap = BitmapFactory.decodeResource(context.resources, id)