Skip to content

Commit

Permalink
Fix Shortcut handling for API 25 and lower
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirWrites committed May 30, 2020
1 parent 96821c8 commit a943905
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
12 changes: 8 additions & 4 deletions app/src/main/java/com/vlad1m1r/bltaxi/ApplicationTaxi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -31,7 +32,7 @@ class ApplicationTaxi : Application() {
logger(Logger())
androidContext(this@ApplicationTaxi)
modules(
listOf(
mutableListOf(
appModule,
baseDataModule,
localModule,
Expand All @@ -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)
}
}
)
}

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ShortcutHandler> { ShortcutHandlerImpl(get(), get()) }
}
4 changes: 2 additions & 2 deletions taxi/src/main/java/com/vlad1m1r/bltaxi/taxi/TaxiViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -60,7 +60,7 @@ class TaxiViewModel(
fun setTaxiOrder(viewModelList: List<ItemTaxiViewModel>) {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
}

0 comments on commit a943905

Please sign in to comment.