From 965fcb9861247712f8288f216c40eec72d57c5cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sun, 17 May 2020 17:18:10 +0200 Subject: [PATCH] Remove DevicesManager --- .../managers/DevicesManager.kt | 35 ------------------ .../managers/KillerManager.kt | 36 +++++++++++++++---- 2 files changed, 29 insertions(+), 42 deletions(-) delete mode 100644 appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/DevicesManager.kt diff --git a/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/DevicesManager.kt b/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/DevicesManager.kt deleted file mode 100644 index 92ce71e..0000000 --- a/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/DevicesManager.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.thelittlefireman.appkillermanager.managers - -import com.thelittlefireman.appkillermanager.devices.* -import com.thelittlefireman.appkillermanager.utils.SystemUtils -import timber.log.Timber - -object DevicesManager { - - private val devices = listOf( - Asus(), - Huawei(), - Letv(), - Meizu(), - OnePlus(), - HTC(), - Samsung(), - Xiaomi(), - ZTE() - ) - - @JvmStatic - fun getDevice(): Device? { - val currentDevice = devices.filter { it.isThatRom } - - if (currentDevice.size > 1) { - val logDevices = currentDevice.joinToString(", ") { - it.manufacturer.toString() - } - - Timber.w("More than one corresponding device: %s. Debug info: %s", logDevices, SystemUtils.getDefaultDebugInformation()) - } - - return currentDevice.firstOrNull() - } -} diff --git a/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/KillerManager.kt b/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/KillerManager.kt index e224560..5b97644 100644 --- a/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/KillerManager.kt +++ b/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/KillerManager.kt @@ -2,7 +2,7 @@ package com.thelittlefireman.appkillermanager.managers import android.content.Context import android.content.Intent -import com.thelittlefireman.appkillermanager.devices.Device +import com.thelittlefireman.appkillermanager.devices.* import com.thelittlefireman.appkillermanager.utils.ActionsUtils import com.thelittlefireman.appkillermanager.utils.SystemUtils import timber.log.Timber @@ -15,16 +15,38 @@ object KillerManager { ACTION_NOTIFICATIONS } + private val devices = listOf( + Asus(), + Huawei(), + Letv(), + Meizu(), + OnePlus(), + HTC(), + Samsung(), + Xiaomi(), + ZTE() + ) + @JvmStatic - val device: Device? - get() = DevicesManager.getDevice() + fun isDeviceSupported() = getDevice() != null @JvmStatic - val isDeviceSupported: Boolean - get() = DevicesManager.getDevice() != null + fun getDevice(): Device? { + val currentDevice = devices.filter { it.isThatRom } + + if (currentDevice.size > 1) { + val logDevices = currentDevice.joinToString(", ") { + it.manufacturer.toString() + } + + Timber.w("More than one corresponding device: %s. Debug info: %s", logDevices, SystemUtils.getDefaultDebugInformation()) + } + + return currentDevice.firstOrNull() + } @JvmStatic - fun isActionAvailable(context: Context, action: Action?) = DevicesManager.getDevice()?.let { + fun isActionAvailable(context: Context, action: Action?) = getDevice()?.let { when (action) { Action.ACTION_AUTO_START -> it.isActionAutoStartAvailable(context) Action.ACTION_POWER_SAVING -> it.isActionPowerSavingAvailable(context) @@ -84,7 +106,7 @@ object KillerManager { * @return the intent */ private fun getIntentFromAction(context: Context, action: Action): Intent? { - val sDevice = DevicesManager.getDevice() + val sDevice = getDevice() return if (sDevice != null) { val intent = when (action) { Action.ACTION_AUTO_START -> sDevice.getActionAutoStart(context)