fix db loading, add network log

This commit is contained in:
2026-02-18 18:44:43 +03:00
parent 705b689c58
commit 764930a574
5 changed files with 75 additions and 18 deletions

View File

@@ -21,8 +21,8 @@ class SplashScreenActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
lifecycleScope.launchWhenCreated { lifecycleScope.launchWhenCreated {
val result = withContext(Dispatchers.IO) { fetchConfigUseCase() } // val result = withContext(Dispatchers.IO) { fetchConfigUseCase() }
val result = fetchConfigUseCase()
when (result) { when (result) {
is DataResult.Data -> { is DataResult.Data -> {
Log.d(LOG_TAG, "SUCCESS: config=${result.data}") Log.d(LOG_TAG, "SUCCESS: config=${result.data}")

View File

@@ -1,22 +1,17 @@
package ru.fincode.tsudesk package ru.fincode.tsudesk
import android.app.Application import android.app.Application
import android.util.Log
import dagger.hilt.android.HiltAndroidApp import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import ru.fincode.tsudesk.core.config.domain.usecase.GetConfigUseCase
import ru.fincode.tsudesk.core.common.model.DataResult
import javax.inject.Inject
const val LOG_TAG = "NETWORK_DEBUG" const val LOG_TAG = "NETWORK_DEBUG"
@HiltAndroidApp @HiltAndroidApp
class TSUDeskApp : Application() { class TSUDeskApp : Application() {
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) // private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()

View File

@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import ru.fincode.tsudesk.core.common.app.AppConfig import ru.fincode.tsudesk.core.common.app.AppConfig
import ru.fincode.tsudesk.core.network.interceptor.DebugInterceptor import ru.fincode.tsudesk.core.network.interceptor.DebugInterceptor
import ru.fincode.tsudesk.core.network.interceptor.NetEventLogger
import java.security.SecureRandom import java.security.SecureRandom
import java.security.cert.X509Certificate import java.security.cert.X509Certificate
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@@ -22,11 +23,12 @@ class OkHttpClientFactory @Inject constructor(
.connectTimeout(appConfig.networkTimeoutSec, TimeUnit.SECONDS) .connectTimeout(appConfig.networkTimeoutSec, TimeUnit.SECONDS)
.readTimeout(appConfig.networkTimeoutSec, TimeUnit.SECONDS) .readTimeout(appConfig.networkTimeoutSec, TimeUnit.SECONDS)
.writeTimeout(appConfig.networkTimeoutSec, TimeUnit.SECONDS) .writeTimeout(appConfig.networkTimeoutSec, TimeUnit.SECONDS)
.retryOnConnectionFailure(true) .retryOnConnectionFailure(false)
if (appConfig.isDebug) { if (appConfig.isDebug) {
builder.addInterceptor(debugInterceptor) builder.addInterceptor(debugInterceptor)
applyUnsafeSslForDebug(builder) applyUnsafeSslForDebug(builder)
builder.eventListenerFactory { NetEventLogger() }
} }
return builder.build() return builder.build()

View File

@@ -0,0 +1,51 @@
package ru.fincode.tsudesk.core.network.interceptor
import android.util.Log
import okhttp3.Call
import okhttp3.EventListener
import java.io.IOException
import java.net.InetAddress
private const val LOG_TAG = "NETWORK_DEBUG"
class NetEventLogger : EventListener() {
override fun dnsStart(call: Call, domainName: String) {
Log.d(LOG_TAG, "dnsStart: $domainName")
}
override fun dnsEnd(call: Call, domainName: String, inetAddressList: List<InetAddress>) {
Log.d(LOG_TAG, "dnsEnd: $domainName -> $inetAddressList")
}
override fun connectStart(
call: Call,
inetSocketAddress: java.net.InetSocketAddress,
proxy: java.net.Proxy
) {
Log.d(LOG_TAG, "connectStart: $inetSocketAddress proxy=$proxy")
}
override fun secureConnectStart(call: Call) {
Log.d(LOG_TAG, "tlsStart")
}
override fun secureConnectEnd(call: Call, handshake: okhttp3.Handshake?) {
Log.d(LOG_TAG, "tlsEnd: $handshake")
}
override fun requestHeadersStart(call: Call) {
Log.d(LOG_TAG, "reqHeadersStart")
}
override fun responseHeadersStart(call: Call) {
Log.d(LOG_TAG, "respHeadersStart")
}
override fun callFailed(call: Call, ioe: IOException) {
Log.e(LOG_TAG, "callFailed", ioe)
}
override fun callEnd(call: Call) {
Log.d(LOG_TAG, "callEnd")
}
}

View File

@@ -3,6 +3,12 @@ package ru.fincode.tsudesk.feature.schedule.data.local
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.onStart
import ru.fincode.tsudesk.core.database.schedule.ScheduleDao import ru.fincode.tsudesk.core.database.schedule.ScheduleDao
import ru.fincode.tsudesk.feature.schedule.data.datasource.ScheduleLocalDataSource import ru.fincode.tsudesk.feature.schedule.data.datasource.ScheduleLocalDataSource
@@ -24,16 +30,19 @@ class ScheduleLocalDataSourceImpl @Inject constructor(
return schedule.toDomain(lessons) return schedule.toDomain(lessons)
} }
override fun observeSchedule(key: String): Flow<ScheduleEntity?> { override fun observeSchedule(key: String): Flow<ScheduleEntity?> = flow {
val scheduleFlow = dao.observeSchedule(key) // Flow<ScheduleCacheEntity?> emitAll(
val lessonsFlow = dao.observeLessons(key) dao.observeSchedule(key).map { schedule ->
.onStart { emit(emptyList()) } if (schedule == null) {
return scheduleFlow null
.combine(lessonsFlow) { schedule, lessons -> } else {
schedule?.toDomain(lessons) val lessons = dao.observeLessons(key)
.first()
schedule.toDomain(lessons)
}
} }
.distinctUntilChanged() )
} }.distinctUntilChanged()
override suspend fun removeSchedule(key: String) { override suspend fun removeSchedule(key: String) {
dao.deleteLessonsByKey(key) dao.deleteLessonsByKey(key)