Skip to content

Commit

Permalink
[fix]: few small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Oct 1, 2023
1 parent 9e30a18 commit cafb683
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
11 changes: 7 additions & 4 deletions app/src/main/java/com/f0x1d/logfox/extensions/UriExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<LogLine>> {
val uri = this@readFileContentsAsFlow

if (uri == null) {
emit(null)
emit(emptyList())
} else {
val logsDisplayLimit = appPreferences.logsDisplayLimit

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
18 changes: 8 additions & 10 deletions app/src/main/java/com/f0x1d/logfox/viewmodel/LogsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,24 @@ class LogsViewModel @Inject constructor(
paused
) { values ->
val logs = values[0] as List<LogLine>
val fileLogs = values[1] as List<LogLine>?
val fileLogs = values[1] as List<LogLine>
val viewingFile = values[2] as Boolean
val filters = values[3] as List<UserFilter>
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)
}
Expand Down Expand Up @@ -111,6 +108,7 @@ class LogsViewModel @Inject constructor(

data class LogsData(
val logs: List<LogLine>,
val viewingFile: Boolean,
val filters: List<UserFilter>,
val query: String?,
val paused: Boolean,
Expand Down

0 comments on commit cafb683

Please sign in to comment.