mirror of
https://github.com/twofas/2fas-android.git
synced 2024-11-25 03:40:18 +01:00
Optimize widget callbacks
This commit is contained in:
parent
a2987d888f
commit
97b546007b
@ -1,6 +1,6 @@
|
||||
package com.twofasapp.common.domain
|
||||
|
||||
interface WidgetCallbacks {
|
||||
fun onServiceChanged()
|
||||
fun onServiceDeleted(serviceId: Long)
|
||||
suspend fun onServiceChanged()
|
||||
suspend fun onServiceDeleted(serviceId: Long)
|
||||
}
|
@ -129,7 +129,6 @@ internal class ServicesRepositoryImpl(
|
||||
}
|
||||
|
||||
widgetCallbacks.onServiceChanged()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,23 @@
|
||||
package com.twofasapp.feature.widget.di
|
||||
|
||||
import com.twofasapp.common.domain.WidgetCallbacks
|
||||
import com.twofasapp.common.di.KoinModule
|
||||
import com.twofasapp.common.domain.WidgetCallbacks
|
||||
import com.twofasapp.feature.widget.sync.WidgetCallbacksImpl
|
||||
import com.twofasapp.feature.widget.ui.settings.WidgetSettingsViewModel
|
||||
import org.koin.android.ext.koin.androidApplication
|
||||
import org.koin.androidx.viewmodel.dsl.viewModelOf
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.core.module.dsl.bind
|
||||
import org.koin.core.module.dsl.singleOf
|
||||
import org.koin.dsl.module
|
||||
import javax.inject.Provider
|
||||
|
||||
class WidgetModule : KoinModule {
|
||||
override fun provide(): Module = module {
|
||||
singleOf(::WidgetCallbacksImpl) { bind<WidgetCallbacks>() }
|
||||
single<WidgetCallbacks> {
|
||||
WidgetCallbacksImpl(
|
||||
context = androidApplication(),
|
||||
widgetsRepository = Provider { get() }
|
||||
)
|
||||
}
|
||||
|
||||
viewModelOf(::WidgetSettingsViewModel)
|
||||
}
|
||||
|
@ -2,16 +2,23 @@ package com.twofasapp.feature.widget.sync
|
||||
|
||||
import android.app.Application
|
||||
import com.twofasapp.common.domain.WidgetCallbacks
|
||||
import com.twofasapp.data.services.WidgetsRepository
|
||||
import javax.inject.Provider
|
||||
|
||||
class WidgetCallbacksImpl(
|
||||
private val context: Application
|
||||
private val context: Application,
|
||||
private val widgetsRepository: Provider<WidgetsRepository>,
|
||||
) : WidgetCallbacks {
|
||||
|
||||
override fun onServiceChanged() {
|
||||
override suspend fun onServiceChanged() {
|
||||
if (widgetsRepository.get().getWidgets().list.isNotEmpty()) {
|
||||
WidgetsUpdateWork.dispatch(context)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onServiceDeleted(serviceId: Long) {
|
||||
override suspend fun onServiceDeleted(serviceId: Long) {
|
||||
if (widgetsRepository.get().getWidgets().list.isNotEmpty()) {
|
||||
WidgetsUpdateWork.dispatch(context)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user