diff --git a/core/ui/src/main/kotlin/com/f0x1d/logfox/ui/Colors.kt b/core/ui/src/main/kotlin/com/f0x1d/logfox/ui/Colors.kt new file mode 100644 index 00000000..17b78dc7 --- /dev/null +++ b/core/ui/src/main/kotlin/com/f0x1d/logfox/ui/Colors.kt @@ -0,0 +1,3 @@ +package com.f0x1d.logfox.ui + +typealias Colors = R.color diff --git a/core/ui/src/main/res/drawable/ic_search.xml b/core/ui/src/main/res/drawable/ic_search.xml index f9e527d9..ac752f9b 100644 --- a/core/ui/src/main/res/drawable/ic_search.xml +++ b/core/ui/src/main/res/drawable/ic_search.xml @@ -1,9 +1,10 @@ diff --git a/feature/crashes/src/main/kotlin/com/f0x1d/logfox/feature/crashes/ui/fragment/CrashDetailsFragment.kt b/feature/crashes/src/main/kotlin/com/f0x1d/logfox/feature/crashes/ui/fragment/CrashDetailsFragment.kt index a32dab13..a11af621 100644 --- a/feature/crashes/src/main/kotlin/com/f0x1d/logfox/feature/crashes/ui/fragment/CrashDetailsFragment.kt +++ b/feature/crashes/src/main/kotlin/com/f0x1d/logfox/feature/crashes/ui/fragment/CrashDetailsFragment.kt @@ -5,10 +5,17 @@ import android.content.Intent import android.net.Uri import android.os.Bundle import android.provider.Settings +import android.text.Spannable +import android.text.style.BackgroundColorSpan import android.view.LayoutInflater +import android.view.MenuItem import android.view.View import android.view.ViewGroup +import android.widget.TextView +import androidx.activity.OnBackPressedCallback import androidx.activity.result.contract.ActivityResultContracts +import androidx.appcompat.widget.SearchView +import androidx.core.text.toSpannable import androidx.core.view.isVisible import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController @@ -22,6 +29,7 @@ import com.f0x1d.logfox.feature.crashes.core.controller.notificationChannelId import com.f0x1d.logfox.feature.crashes.databinding.FragmentCrashDetailsBinding import com.f0x1d.logfox.feature.crashes.viewmodel.CrashDetailsViewModel import com.f0x1d.logfox.strings.Strings +import com.f0x1d.logfox.ui.Colors import com.f0x1d.logfox.ui.Icons import com.f0x1d.logfox.ui.dialog.showAreYouSureDeleteDialog import com.f0x1d.logfox.ui.dialog.showAreYouSureDialog @@ -30,6 +38,7 @@ import com.f0x1d.logfox.ui.view.setClickListenerOn import com.f0x1d.logfox.ui.view.setupBackButtonForNavController import dagger.hilt.android.AndroidEntryPoint import dev.chrisbanes.insetter.applyInsetter +import java.util.Locale @AndroidEntryPoint class CrashDetailsFragment: BaseViewModelFragment() { @@ -42,6 +51,12 @@ class CrashDetailsFragment: BaseViewModelFragment - crashes to query - }.collectLatest { (crashes, query) -> - - fun AppCrash.suits(query: String): Boolean = - packageName.contains(query, ignoreCase = true) - || appName?.contains(query, ignoreCase = true) == true - - val filteredCrashes = withContext(defaultDispatcher) { - crashes.filter { it.suits(query) }.map { AppCrashesCount(it) } - } - - send(filteredCrashes) - delay(SEARCH_DEBOUNCE_MILLIS) // Maybe no need to search content for now - - val deeplyFilteredCrashes = withContext(defaultDispatcher) { - crashes.filter { crash -> - val fileContentSettles = withContext(ioDispatcher) { - crash.logFile?.readText()?.contains(query, ignoreCase = true) == true - } - - crash.suits(query) || fileContentSettles - }.map { AppCrashesCount(it) } - } - send(deeplyFilteredCrashes) + val searchedCrashes = combine( + crashesRepository.getAllAsFlow(), + query, + ) { crashes, query -> crashes to query } + .map { (crashes, query) -> + crashes.filter { crash -> + crash.packageName.contains(query, ignoreCase = true) + || crash.appName?.contains(query, ignoreCase = true) == true + }.map { AppCrashesCount(it) } } - }.stateIn( - scope = viewModelScope, - started = SharingStarted.Eagerly, - initialValue = emptyList(), - ) + .distinctUntilChanged() + .flowOn(defaultDispatcher) + .stateIn( + scope = viewModelScope, + started = SharingStarted.Eagerly, + initialValue = emptyList(), + ) fun updateQuery(query: String) = this.query.update { query } diff --git a/feature/crashes/src/main/res/menu/crash_details_menu.xml b/feature/crashes/src/main/res/menu/crash_details_menu.xml index 7f49c646..39819cdd 100644 --- a/feature/crashes/src/main/res/menu/crash_details_menu.xml +++ b/feature/crashes/src/main/res/menu/crash_details_menu.xml @@ -2,6 +2,13 @@ + +