From cafb683cb3decb8821d1634c2f249a27a8408223 Mon Sep 17 00:00:00 2001 From: F0x1d Date: Sun, 1 Oct 2023 17:26:47 +0300 Subject: [PATCH] [fix]: few small fixes --- .../f0x1d/logfox/extensions/UriExtensions.kt | 11 +++++++---- .../logfox/utils/view/FontsInterceptor.kt | 1 + .../f0x1d/logfox/viewmodel/LogsViewModel.kt | 18 ++++++++---------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/f0x1d/logfox/extensions/UriExtensions.kt b/app/src/main/java/com/f0x1d/logfox/extensions/UriExtensions.kt index bec22835..4ca1edab 100644 --- a/app/src/main/java/com/f0x1d/logfox/extensions/UriExtensions.kt +++ b/app/src/main/java/com/f0x1d/logfox/extensions/UriExtensions.kt @@ -7,14 +7,15 @@ import com.f0x1d.logfox.extensions.logline.LogLine import com.f0x1d.logfox.model.LogLine import com.f0x1d.logfox.utils.preferences.AppPreferences import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOn -fun Uri?.readFileContentsAsFlow(context: Context, appPreferences: AppPreferences) = flow { +fun Uri?.readFileContentsAsFlow(context: Context, appPreferences: AppPreferences) = flow> { val uri = this@readFileContentsAsFlow if (uri == null) { - emit(null) + emit(emptyList()) } else { val logsDisplayLimit = appPreferences.logsDisplayLimit @@ -39,8 +40,10 @@ fun Uri?.readFileContentsAsFlow(context: Context, appPreferences: AppPreferences emit(logLines) } - } ?: emit(null) + } ?: emit(emptyList()) } -}.flowOn(Dispatchers.IO) +}.flowOn(Dispatchers.IO).catch { + emit(emptyList()) +} fun Uri.readFileName(context: Context) = DocumentFile.fromSingleUri(context, this)?.name \ No newline at end of file diff --git a/app/src/main/java/com/f0x1d/logfox/utils/view/FontsInterceptor.kt b/app/src/main/java/com/f0x1d/logfox/utils/view/FontsInterceptor.kt index 6a0c39ea..342c3ee9 100644 --- a/app/src/main/java/com/f0x1d/logfox/utils/view/FontsInterceptor.kt +++ b/app/src/main/java/com/f0x1d/logfox/utils/view/FontsInterceptor.kt @@ -28,6 +28,7 @@ class FontsInterceptor(context: Context): Interceptor { R.id.share_text to boldSansTypeface, R.id.zip_text to boldSansTypeface, R.id.export_text to boldSansTypeface, + R.id.view_text to boldSansTypeface, R.id.including_button to boldSansTypeface ) 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 23fbbd91..d24f4004 100644 --- a/app/src/main/java/com/f0x1d/logfox/viewmodel/LogsViewModel.kt +++ b/app/src/main/java/com/f0x1d/logfox/viewmodel/LogsViewModel.kt @@ -50,27 +50,24 @@ class LogsViewModel @Inject constructor( paused ) { values -> val logs = values[0] as List - val fileLogs = values[1] as List? + val fileLogs = values[1] as List val viewingFile = values[2] as Boolean val filters = values[3] as List val query = values[4] as String? - var paused = values[5] as Boolean + val paused = values[5] as Boolean val resultLogs = when { - viewingFile -> { - paused = false - fileLogs ?: logs - } + viewingFile -> fileLogs else -> logs } - LogsData(resultLogs, filters, query, paused) + LogsData(resultLogs, viewingFile, filters, query, paused) }.scan(null as LogsData?) { accumulator, data -> when { - !data.paused -> data + !data.paused || data.viewingFile != accumulator?.viewingFile -> data - data.query != accumulator?.query -> data.copy(logs = accumulator?.logs ?: data.logs) - data.filters != accumulator?.filters -> data.copy(logs = accumulator?.logs ?: data.logs) + data.query != accumulator.query -> data.copy(logs = accumulator.logs) + data.filters != accumulator.filters -> data.copy(logs = accumulator.logs) else -> data.copy(logs = accumulator.logs, passing = false) } @@ -111,6 +108,7 @@ class LogsViewModel @Inject constructor( data class LogsData( val logs: List, + val viewingFile: Boolean, val filters: List, val query: String?, val paused: Boolean,