Fixed: A NotSerializableException was attached to the crash logs instead of the actual crash logs when there was an error in the coroutine.

* The serialization issue was fixed in coroutine version `1.7.0`, so we have upgraded the coroutine dependency to `1.7.0` to address this issue.
* In the new version of coroutines, `ConflatedBroadcastChannel` is replaced with `StateFlow`, so we have refactored our code to use `StateFlow`.
* Fixed some detekt issues which occurs after upgrading this dependency.
This commit is contained in:
MohitMaliFtechiz 2024-06-27 14:50:23 +05:30
parent e4c3d1a6e8
commit a2ac6429a7
4 changed files with 11 additions and 12 deletions

View File

@ -14,7 +14,7 @@ object Versions {
const val document_file_version: String = "1.0.1"
const val org_jetbrains_kotlinx_kotlinx_coroutines: String = "1.4.1"
const val org_jetbrains_kotlinx_kotlinx_coroutines: String = "1.7.3"
const val androidx_test_espresso: String = "3.5.1"

View File

@ -212,6 +212,7 @@ class ZimFileReader constructor(
fun getRandomArticleUrl(): String? = jniKiwixReader.randomEntry.path
@Suppress("UnreachableCode")
fun load(uri: String): InputStream? {
val extension = uri.substringAfterLast(".")
if (assetExtensions.any { it == extension }) {

View File

@ -22,11 +22,10 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
import kotlinx.coroutines.channels.consumeEach
import kotlinx.coroutines.channels.trySendBlocking
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.receiveAsFlow
@ -86,8 +85,8 @@ class SearchViewModel @Inject constructor(
private val _effects = Channel<SideEffect<*>>()
val effects = _effects.receiveAsFlow()
val actions = Channel<Action>(Channel.UNLIMITED)
private val filter = ConflatedBroadcastChannel("")
private val searchOrigin = ConflatedBroadcastChannel(FromWebView)
private val filter = MutableStateFlow("")
private val searchOrigin = MutableStateFlow(FromWebView)
init {
viewModelScope.launch { reducer() }
@ -97,10 +96,10 @@ class SearchViewModel @Inject constructor(
@Suppress("DEPRECATION")
private suspend fun reducer() {
combine(
filter.asFlow(),
filter.asStateFlow(),
searchResults(),
recentSearchRoomDao.recentSearches(zimReaderContainer.id),
searchOrigin.asFlow()
searchOrigin.asStateFlow()
) { searchTerm, searchResultsWithTerm, recentResults, searchOrigin ->
SearchState(
searchTerm, searchResultsWithTerm,
@ -111,7 +110,7 @@ class SearchViewModel @Inject constructor(
}
@Suppress("DEPRECATION")
private fun searchResults() = filter.asFlow()
private fun searchResults() = filter.asStateFlow()
.mapLatest {
SearchResultsWithTerm(
it,
@ -126,7 +125,7 @@ class SearchViewModel @Inject constructor(
is OnItemClick -> saveSearchAndOpenItem(it.searchListItem, false)
is OnOpenInNewTabClick -> saveSearchAndOpenItem(it.searchListItem, true)
is OnItemLongClick -> showDeleteDialog(it)
is Filter -> filter.trySendBlocking(it.term)
is Filter -> filter.tryEmit(it.term)
ClickedSearchInText -> searchPreviousScreenWhenStateIsValid()
is ConfirmedDelete -> deleteItemAndShowToast(it)
is CreatedWithArguments -> _effects.trySend(
@ -148,7 +147,7 @@ class SearchViewModel @Inject constructor(
)
).isSuccess
is ScreenWasStartedFrom -> searchOrigin.trySendBlocking(it.searchOrigin)
is ScreenWasStartedFrom -> searchOrigin.tryEmit(it.searchOrigin)
}
}

View File

@ -58,8 +58,7 @@ object ServerUtils {
val ipRegex =
"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
.toRegex()
val ipMatch = ipRegex.find(ip, 0) ?: throw IllegalArgumentException()
return ipMatch.value
return ipRegex.find(ip, 0)?.value ?: throw IllegalArgumentException()
}
@JvmStatic fun getSocketAddress(): String =