add basic updater implementation in gigawear

This commit is contained in:
2026-09-14 16:52:27 +03:00
parent 1c573c4366
commit e77046018d
23 changed files with 230 additions and 90 deletions
@@ -3,8 +3,21 @@ package ru.shadowsparky.gigawear
import org.koin.core.annotation.ComponentScan
import org.koin.core.annotation.Configuration
import org.koin.core.annotation.Module
import org.koin.core.annotation.Singleton
import ru.shadowsparky.domain.AppConfig
@Module
@ComponentScan
@Configuration
class GigaWearModule
class GigaWearModule {
@Singleton
fun provideAppConfig(): AppConfig {
return object : AppConfig {
override val debug = BuildConfig.DEBUG
override val appId = "GigaWearClient"
override val versionCode = BuildConfig.VERSION_CODE.toLong()
override val versionName = BuildConfig.VERSION_NAME
}
}
}
@@ -8,13 +8,15 @@ import org.koin.core.annotation.Factory
import ru.shadowsparky.chat.domain.ChatRepository
import ru.shadowsparky.chat.domain.Message
const val ENDPOINT = "http://192.168.0.76:8181"
@Factory
class GigaChatRepository(
private val httpClient: HttpClient
) : ChatRepository {
override suspend fun query(afterId: Long?): List<Message> = emptyList()
override suspend fun send(message: Message): Message {
return httpClient.post("http://192.168.0.76:8181/chat") {
return httpClient.post("$ENDPOINT/chat") {
setBody(message)
}.body<Message>()
}
@@ -0,0 +1,18 @@
package ru.shadowsparky.gigawear.data
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import org.koin.core.annotation.Factory
import ru.shadowsparky.updater.domain.UpdateFetcher
import ru.shadowsparky.updater.domain.UpdateInfo
@Factory
class UpdateFetcherImpl(private val httpClient: HttpClient) : UpdateFetcher {
override suspend fun fetch(versionCode: Long): UpdateInfo {
return httpClient.get("$ENDPOINT/checkUpdates") {
parameter(UpdateFetcher.ARG_VERSION_CODE, versionCode)
}.body()
}
}
@@ -1,6 +1,7 @@
package ru.shadowsparky.gigawear.presentation
import android.app.Application
import org.koin.android.ext.koin.androidContext
import org.koin.core.annotation.KoinApplication
import org.koin.plugin.module.dsl.startKoin
@@ -11,6 +12,8 @@ class App : Application() {
override fun onCreate() {
super.onCreate()
startKoin<GigaWearApp>()
startKoin<GigaWearApp> {
androidContext(this@App)
}
}
}
@@ -1,6 +1,7 @@
package ru.shadowsparky.gigawear.presentation.chat
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.childContext
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import com.arkivanov.decompose.value.update
@@ -17,12 +18,15 @@ import ru.shadowsparky.gigawear.presentation.nav.Child
import ru.shadowsparky.gigawear.presentation.nav.Route
import ru.shadowsparky.ui.nav.ComponentFactory
import ru.shadowsparky.ui.nav.RouteNavigator
import ru.shadowsparky.updater.presentation.UpdateComponentFactory
class ChatComponent(
private val context: ComponentContext,
private val repository: ChatRepository
private val repository: ChatRepository,
private val updateComponentFactory: UpdateComponentFactory
) : ComponentContext by context {
private val scope = coroutineScope()
val updateComponent = updateComponentFactory.create(childContext("updater"))
private val _state = MutableValue(ChatUiState())
val state: Value<ChatUiState> = _state
@@ -30,6 +34,10 @@ class ChatComponent(
private val _events = Channel<ComponentEvent>(Channel.BUFFERED)
val events = _events.receiveAsFlow()
init {
updateComponent.checkUpdates(true)
}
fun onMicClicked() {
if (_state.value.isLoading) return
scope.launch {
@@ -75,14 +83,19 @@ class ChatComponent(
@Factory
@Named(Route.CHAT)
class ChatComponentFactory(
private val chatRepository: ChatRepository
private val chatRepository: ChatRepository,
private val updateComponentFactory: UpdateComponentFactory
) : ComponentFactory<Child, Route.ChatScreen, Route> {
override fun create(
route: Route.ChatScreen,
child: ComponentContext,
root: RouteNavigator<Route>
): Child {
val component = ChatComponent(child, chatRepository)
val component = ChatComponent(
child,
chatRepository,
updateComponentFactory
)
return Child.MainChild(component)
}
}
@@ -40,6 +40,7 @@ import com.arkivanov.decompose.extensions.compose.subscribeAsState
import kotlinx.coroutines.flow.collectLatest
import ru.shadowsparky.gigawear.R
import ru.shadowsparky.gigawear.presentation.WearErrorContent
import ru.shadowsparky.updater.presentation.UpdateDialog
import java.util.Locale
@Composable
@@ -171,6 +172,7 @@ fun ChatScreen(component: ChatComponent) {
}
}
) { contentPadding ->
UpdateDialog(component.updateComponent)
LazyColumn(
state = listState,
modifier = Modifier.fillMaxSize(),