Skip to content

Commit

Permalink
[feat]: disabling word wrap for log in details
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Aug 11, 2024
1 parent dc5074e commit 5a07a13
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class AppPreferences @Inject constructor(
var exportLogsInOriginalFormat
get() = get("pref_export_logs_in_original_format", true)
set(value) { put("pref_export_logs_in_original_format", value) }
var wrapCrashLogLines
get() = get("pref_wrap_crash_log_lines", true)
set(value) { put("pref_wrap_crash_log_lines", value) }

var showLogDate
get() = get("pref_show_log_date", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.f0x1d.logfox.arch.notificationsChannelsAvailable
Expand Down Expand Up @@ -107,6 +108,12 @@ class CrashDetailsFragment: BaseViewModelFragment<CrashDetailsViewModel, Fragmen
zipCrashLauncher.launch("crash-$pkg-$formattedDate.zip")
}

viewModel.appPreferences.wrapCrashLogLines.let { wrap ->
logText.isVisible = wrap
logTextScrollableContainer.isVisible = wrap.not()
}

logText.text = crashLog
logTextScrollable.text = crashLog
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.f0x1d.logfox.feature.crashes.viewmodel.list
import android.app.Application
import androidx.lifecycle.viewModelScope
import com.f0x1d.logfox.arch.di.DefaultDispatcher
import com.f0x1d.logfox.arch.di.IODispatcher
import com.f0x1d.logfox.arch.viewmodel.BaseViewModel
import com.f0x1d.logfox.database.entity.AppCrash
import com.f0x1d.logfox.database.entity.AppCrashesCount
Expand All @@ -11,6 +12,7 @@ import com.f0x1d.logfox.preferences.shared.AppPreferences
import com.f0x1d.logfox.preferences.shared.crashes.CrashesSort
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.combine
Expand All @@ -20,13 +22,15 @@ import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.withContext
import javax.inject.Inject

@HiltViewModel
class CrashesViewModel @Inject constructor(
private val crashesRepository: CrashesRepository,
private val appPreferences: AppPreferences,
@DefaultDispatcher private val defaultDispatcher: CoroutineDispatcher,
@IODispatcher private val ioDispatcher: CoroutineDispatcher,
application: Application,
): BaseViewModel(application) {

Expand Down Expand Up @@ -70,17 +74,23 @@ class CrashesViewModel @Inject constructor(

val query = MutableStateFlow("")

@OptIn(FlowPreview::class)
val searchedCrashes = combine(
crashesRepository.getAllAsFlow(),
query,
) { crashes, query ->
crashes to query
}.debounce(
timeoutMillis = 100,
timeoutMillis = SEARCH_DEBOUNCE_MILLIS,
).map { (crashes, query) ->
crashes.filter { crash ->
val fileContentSettles = withContext(ioDispatcher) {
crash.logDumpFile?.readText()?.contains(query, ignoreCase = false) == true
}

crash.packageName.contains(query, ignoreCase = true)
|| crash.appName?.contains(query, ignoreCase = true) == true
|| fileContentSettles
}.map { AppCrashesCount(it) }
}.flowOn(
defaultDispatcher,
Expand Down Expand Up @@ -114,4 +124,8 @@ class CrashesViewModel @Inject constructor(
val sortType: CrashesSort,
val sortInReversedOrder: Boolean,
)

companion object {
private const val SEARCH_DEBOUNCE_MILLIS = 500L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,29 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/actions_card">

<androidx.constraintlayout.widget.ConstraintLayout
<TextView
android:id="@+id/log_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:padding="15dp"
android:visibility="gone"
tools:text="@tools:sample/lorem/random" />

<HorizontalScrollView
android:id="@+id/log_text_scrollable_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:scrollbars="none">

<TextView
android:id="@+id/log_text"
android:layout_width="0dp"
android:id="@+id/log_text_scrollable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:textIsSelectable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:padding="15dp"
tools:text="@tools:sample/lorem/random" />
</androidx.constraintlayout.widget.ConstraintLayout>
</HorizontalScrollView>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.f0x1d.logfox.ui.view.CustomNestedScrollView>
Expand Down
7 changes: 7 additions & 0 deletions feature/feature-settings/src/main/res/xml/settings_ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
app:singleLineTitle="false"
app:widgetLayout="@layout/preference_material_switch"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
android:title="@string/wrap_log_lines_in_details"
android:key="pref_wrap_crash_log_lines"
android:defaultValue="true"
app:singleLineTitle="false"
app:widgetLayout="@layout/preference_material_switch"
app:iconSpaceReserved="false" />
<Preference
android:title="@string/logs_update_interval"
android:key="pref_logs_update_interval"
Expand Down
1 change: 1 addition & 0 deletions strings/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,5 @@
<string name="sort_by_count">По количеству сбоев</string>
<string name="use_separate_channels_for_crashes">Использовать разные каналы уведомлений для уведомлений о сбоях</string>
<string name="open_crashes_page_on_startup">Открывать вкладку сбоев при запуске</string>
<string name="wrap_log_lines_in_details">Перенос строк в деталях лога</string>
</resources>
1 change: 1 addition & 0 deletions strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,5 @@
<string name="sort_by_count">By crashes count</string>
<string name="use_separate_channels_for_crashes">Use separate notifications channels for crashes notifications</string>
<string name="open_crashes_page_on_startup">Open crashes page on startup</string>
<string name="wrap_log_lines_in_details">Wrap log lines in details</string>
</resources>

0 comments on commit 5a07a13

Please sign in to comment.