Skip to content

Commit

Permalink
[feat]: filters affect log dump
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Nov 5, 2023
1 parent 4ff6470 commit 65f4231
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ interface UserFilterDao {
@Query("SELECT * FROM UserFilter")
fun getAllAsFlow(): Flow<List<UserFilter>>

@Query("SELECT * FROM UserFilter")
suspend fun getAll(): List<UserFilter>

@Query("SELECT * FROM UserFilter WHERE id = :id")
fun get(id: Long): Flow<UserFilter?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.SharedPreferences
import com.f0x1d.logfox.database.AppDatabase
import com.f0x1d.logfox.database.entity.AppCrash
import com.f0x1d.logfox.extensions.logline.filterAndSearch
import com.f0x1d.logfox.extensions.notifications.cancelAllCrashNotifications
import com.f0x1d.logfox.extensions.notifications.cancelCrashNotificationFor
import com.f0x1d.logfox.extensions.notifications.sendErrorNotification
Expand Down Expand Up @@ -32,7 +33,12 @@ class CrashesRepository @Inject constructor(
}
}

val appCrash = it.copy(logDump = dumpCollector.dump())
val logDump = dumpCollector
.logsDump
.filterAndSearch(database.userFilterDao().getAll())
.joinToString("\n") { logLine -> logLine.original }

val appCrash = it.copy(logDump = logDump)

if (appPreferences.collectingFor(appCrash.crashType)) {
val appCrashWithId = appCrash.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ class DumpCollector @Inject constructor(
field = value
}

private val logsDump = LimitedArrayList<LogLine>(capacity)

fun dump() = logsDump.joinToString("\n") {
it.original
}
val logsDump = LimitedArrayList<LogLine>(capacity)

override suspend fun readLine(line: LogLine) {
logsDump.add(line)
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/com/f0x1d/logfox/viewmodel/LogsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.f0x1d.logfox.viewmodel
import android.app.Application
import android.net.Uri
import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
import com.f0x1d.logfox.database.AppDatabase
import com.f0x1d.logfox.database.entity.UserFilter
import com.f0x1d.logfox.di.viewmodel.FileUri
Expand All @@ -17,12 +18,14 @@ import com.f0x1d.logfox.viewmodel.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.scan
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import javax.inject.Inject

Expand Down Expand Up @@ -55,12 +58,10 @@ class LogsViewModel @Inject constructor(
LogsData(logs, filters, query, paused)
}.scan(null as LogsData?) { accumulator, data ->
when {
accumulator == null -> data.copy(passing = false)

!data.paused -> data

data.query != accumulator.query || data.filters != accumulator.filters -> data.copy(
logs = accumulator.logs
data.query != accumulator?.query || data.filters != accumulator?.filters -> data.copy(
logs = accumulator?.logs ?: emptyList()
)

else -> data.copy(logs = accumulator.logs, passing = false)
Expand All @@ -73,6 +74,10 @@ class LogsViewModel @Inject constructor(
}
}.flowOn(
Dispatchers.IO
).stateIn(
viewModelScope,
SharingStarted.Eagerly,
emptyList()
).asLiveData()

val serviceRunningData = loggingRepository.serviceRunningFlow.asLiveData()
Expand Down

0 comments on commit 65f4231

Please sign in to comment.