diff --git a/app/src/main/java/com/f0x1d/logfox/database/entity/UserFilter.kt b/app/src/main/java/com/f0x1d/logfox/database/entity/UserFilter.kt index a7f31296..a990bae1 100644 --- a/app/src/main/java/com/f0x1d/logfox/database/entity/UserFilter.kt +++ b/app/src/main/java/com/f0x1d/logfox/database/entity/UserFilter.kt @@ -27,6 +27,9 @@ interface UserFilterDao { @Query("SELECT * FROM UserFilter") fun getAllAsFlow(): Flow> + @Query("SELECT * FROM UserFilter") + suspend fun getAll(): List + @Query("SELECT * FROM UserFilter WHERE id = :id") fun get(id: Long): Flow diff --git a/app/src/main/java/com/f0x1d/logfox/repository/logging/CrashesRepository.kt b/app/src/main/java/com/f0x1d/logfox/repository/logging/CrashesRepository.kt index 4f1a3195..92b371c6 100644 --- a/app/src/main/java/com/f0x1d/logfox/repository/logging/CrashesRepository.kt +++ b/app/src/main/java/com/f0x1d/logfox/repository/logging/CrashesRepository.kt @@ -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 @@ -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( diff --git a/app/src/main/java/com/f0x1d/logfox/repository/logging/readers/crashes/DumpCollector.kt b/app/src/main/java/com/f0x1d/logfox/repository/logging/readers/crashes/DumpCollector.kt index 46ea0be1..e63f02cb 100644 --- a/app/src/main/java/com/f0x1d/logfox/repository/logging/readers/crashes/DumpCollector.kt +++ b/app/src/main/java/com/f0x1d/logfox/repository/logging/readers/crashes/DumpCollector.kt @@ -18,11 +18,7 @@ class DumpCollector @Inject constructor( field = value } - private val logsDump = LimitedArrayList(capacity) - - fun dump() = logsDump.joinToString("\n") { - it.original - } + val logsDump = LimitedArrayList(capacity) override suspend fun readLine(line: LogLine) { logsDump.add(line) diff --git a/app/src/main/java/com/f0x1d/logfox/viewmodel/LogsViewModel.kt b/app/src/main/java/com/f0x1d/logfox/viewmodel/LogsViewModel.kt index 4392c001..d4f70620 100644 --- a/app/src/main/java/com/f0x1d/logfox/viewmodel/LogsViewModel.kt +++ b/app/src/main/java/com/f0x1d/logfox/viewmodel/LogsViewModel.kt @@ -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 @@ -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 @@ -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) @@ -73,6 +74,10 @@ class LogsViewModel @Inject constructor( } }.flowOn( Dispatchers.IO + ).stateIn( + viewModelScope, + SharingStarted.Eagerly, + emptyList() ).asLiveData() val serviceRunningData = loggingRepository.serviceRunningFlow.asLiveData()