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