split dependency to IconsProvider
This commit is contained in:
parent
1cee7e580f
commit
c17f8d10ad
7 changed files with 42 additions and 26 deletions
|
@ -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 {
|
||||
|
|
|
@ -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<Notification> = 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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -15,8 +15,6 @@ interface ResourceHelper {
|
|||
fun gsa(@ArrayRes id:Int): Array<String>
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue