From a94390593d651f5b69e1ac6991608610d0cf8a3a Mon Sep 17 00:00:00 2001 From: VladimirWrites Date: Sat, 30 May 2020 09:30:17 +0200 Subject: [PATCH] Fix Shortcut handling for API 25 and lower --- .../main/java/com/vlad1m1r/bltaxi/ApplicationTaxi.kt | 12 ++++++++---- buildSrc/src/main/java/Dependencies.kt | 4 ++-- .../vlad1m1r/bltaxi/shortcuts/di/ShortcutModul.kt | 7 ++++++- .../java/com/vlad1m1r/bltaxi/taxi/TaxiViewModel.kt | 4 ++-- .../java/com/vlad1m1r/bltaxi/taxi/di/TaxiModule.kt | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/vlad1m1r/bltaxi/ApplicationTaxi.kt b/app/src/main/java/com/vlad1m1r/bltaxi/ApplicationTaxi.kt index c281ea5..e0aad43 100644 --- a/app/src/main/java/com/vlad1m1r/bltaxi/ApplicationTaxi.kt +++ b/app/src/main/java/com/vlad1m1r/bltaxi/ApplicationTaxi.kt @@ -2,6 +2,7 @@ package com.vlad1m1r.bltaxi import android.app.Application import android.content.SharedPreferences +import android.os.Build import androidx.appcompat.app.AppCompatDelegate.* import com.vlad1m1r.actions.di.actionsModule import com.vlad1m1r.basedata.di.baseDataModule @@ -31,7 +32,7 @@ class ApplicationTaxi : Application() { logger(Logger()) androidContext(this@ApplicationTaxi) modules( - listOf( + mutableListOf( appModule, baseDataModule, localModule, @@ -42,9 +43,12 @@ class ApplicationTaxi : Application() { aboutModule, analyticsModule, settingsModule, - syncModule, - shortcutsModule - ) + syncModule + ).apply { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { + add(shortcutsModule) + } + } ) } diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index 1f9e847..068b365 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -49,8 +49,8 @@ object Versions { const val compile_sdk = 29 const val build_tools = "29.0.3" - const val version_code = 20111 - const val version_name = "2.1.1" + const val version_code = 20121 + const val version_name = "2.1.2" } object Deps { diff --git a/shortcuts/src/main/java/com/vlad1m1r/bltaxi/shortcuts/di/ShortcutModul.kt b/shortcuts/src/main/java/com/vlad1m1r/bltaxi/shortcuts/di/ShortcutModul.kt index b5af9c5..5ef70d4 100644 --- a/shortcuts/src/main/java/com/vlad1m1r/bltaxi/shortcuts/di/ShortcutModul.kt +++ b/shortcuts/src/main/java/com/vlad1m1r/bltaxi/shortcuts/di/ShortcutModul.kt @@ -1,14 +1,19 @@ package com.vlad1m1r.bltaxi.shortcuts.di import android.content.pm.ShortcutManager +import android.os.Build +import androidx.annotation.RequiresApi import com.vlad1m1r.bltaxi.shortcuts.ShortcutHandler import com.vlad1m1r.bltaxi.shortcuts.ShortcutHandlerImpl import com.vlad1m1r.bltaxi.shortcuts.ShortcutInfoProvider import org.koin.android.ext.koin.androidContext import org.koin.dsl.module +@RequiresApi(Build.VERSION_CODES.N_MR1) val shortcutsModule = module { - single { androidContext().getSystemService(ShortcutManager::class.java)!! } + single { + androidContext().getSystemService(ShortcutManager::class.java)!! + } single { ShortcutInfoProvider(androidContext()) } single { ShortcutHandlerImpl(get(), get()) } } diff --git a/taxi/src/main/java/com/vlad1m1r/bltaxi/taxi/TaxiViewModel.kt b/taxi/src/main/java/com/vlad1m1r/bltaxi/taxi/TaxiViewModel.kt index 607ce02..060571d 100644 --- a/taxi/src/main/java/com/vlad1m1r/bltaxi/taxi/TaxiViewModel.kt +++ b/taxi/src/main/java/com/vlad1m1r/bltaxi/taxi/TaxiViewModel.kt @@ -22,7 +22,7 @@ import kotlinx.coroutines.withContext class TaxiViewModel( private val saveTaxiOrder: SaveTaxiOrder, - private val shortcutHandler: ShortcutHandler, + private val shortcutHandler: ShortcutHandler?, private val getOrderedTaxiList: GetOrderedTaxiList, private val executeAction: ExecuteAction, private val tracker: Tracker, @@ -60,7 +60,7 @@ class TaxiViewModel( fun setTaxiOrder(viewModelList: List) { val taxis = viewModelList.map { it.itemTaxi } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { - shortcutHandler.addShortcutsForTaxis(taxis) + shortcutHandler!!.addShortcutsForTaxis(taxis) } viewModelScope.launch(dispatchers.io) { saveTaxiOrder(taxis) diff --git a/taxi/src/main/java/com/vlad1m1r/bltaxi/taxi/di/TaxiModule.kt b/taxi/src/main/java/com/vlad1m1r/bltaxi/taxi/di/TaxiModule.kt index c749444..1ee1661 100644 --- a/taxi/src/main/java/com/vlad1m1r/bltaxi/taxi/di/TaxiModule.kt +++ b/taxi/src/main/java/com/vlad1m1r/bltaxi/taxi/di/TaxiModule.kt @@ -13,5 +13,5 @@ val taxiModule = module { factory { GetTaxiPosition(get()) } factory { GetOrderedTaxiList(get(), get()) } factory { ExecuteAction(get()) } - viewModel { TaxiViewModel(get(), get(), get(), get(), get(), get()) } + viewModel { TaxiViewModel(get(), getOrNull(), get(), get(), get(), get()) } }