fix db loading, add network log
This commit is contained in:
@@ -21,8 +21,8 @@ class SplashScreenActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val result = withContext(Dispatchers.IO) { fetchConfigUseCase() }
|
||||
|
||||
// val result = withContext(Dispatchers.IO) { fetchConfigUseCase() }
|
||||
val result = fetchConfigUseCase()
|
||||
when (result) {
|
||||
is DataResult.Data -> {
|
||||
Log.d(LOG_TAG, "SUCCESS: config=${result.data}")
|
||||
|
||||
@@ -1,22 +1,17 @@
|
||||
package ru.fincode.tsudesk
|
||||
|
||||
import android.app.Application
|
||||
import android.util.Log
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
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"
|
||||
|
||||
@HiltAndroidApp
|
||||
class TSUDeskApp : Application() {
|
||||
|
||||
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
// private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
||||
import okhttp3.OkHttpClient
|
||||
import ru.fincode.tsudesk.core.common.app.AppConfig
|
||||
import ru.fincode.tsudesk.core.network.interceptor.DebugInterceptor
|
||||
import ru.fincode.tsudesk.core.network.interceptor.NetEventLogger
|
||||
import java.security.SecureRandom
|
||||
import java.security.cert.X509Certificate
|
||||
import java.util.concurrent.TimeUnit
|
||||
@@ -22,11 +23,12 @@ class OkHttpClientFactory @Inject constructor(
|
||||
.connectTimeout(appConfig.networkTimeoutSec, TimeUnit.SECONDS)
|
||||
.readTimeout(appConfig.networkTimeoutSec, TimeUnit.SECONDS)
|
||||
.writeTimeout(appConfig.networkTimeoutSec, TimeUnit.SECONDS)
|
||||
.retryOnConnectionFailure(true)
|
||||
.retryOnConnectionFailure(false)
|
||||
|
||||
if (appConfig.isDebug) {
|
||||
builder.addInterceptor(debugInterceptor)
|
||||
applyUnsafeSslForDebug(builder)
|
||||
builder.eventListenerFactory { NetEventLogger() }
|
||||
}
|
||||
|
||||
return builder.build()
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,12 @@ package ru.fincode.tsudesk.feature.schedule.data.local
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
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 ru.fincode.tsudesk.core.database.schedule.ScheduleDao
|
||||
import ru.fincode.tsudesk.feature.schedule.data.datasource.ScheduleLocalDataSource
|
||||
@@ -24,16 +30,19 @@ class ScheduleLocalDataSourceImpl @Inject constructor(
|
||||
return schedule.toDomain(lessons)
|
||||
}
|
||||
|
||||
override fun observeSchedule(key: String): Flow<ScheduleEntity?> {
|
||||
val scheduleFlow = dao.observeSchedule(key) // Flow<ScheduleCacheEntity?>
|
||||
val lessonsFlow = dao.observeLessons(key)
|
||||
.onStart { emit(emptyList()) }
|
||||
return scheduleFlow
|
||||
.combine(lessonsFlow) { schedule, lessons ->
|
||||
schedule?.toDomain(lessons)
|
||||
override fun observeSchedule(key: String): Flow<ScheduleEntity?> = flow {
|
||||
emitAll(
|
||||
dao.observeSchedule(key).map { schedule ->
|
||||
if (schedule == null) {
|
||||
null
|
||||
} else {
|
||||
val lessons = dao.observeLessons(key)
|
||||
.first()
|
||||
schedule.toDomain(lessons)
|
||||
}
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
}
|
||||
)
|
||||
}.distinctUntilChanged()
|
||||
|
||||
override suspend fun removeSchedule(key: String) {
|
||||
dao.deleteLessonsByKey(key)
|
||||
|
||||
Reference in New Issue
Block a user