Skip to content

Commit

Permalink
[feat]: update v1.5.1
Browse files Browse the repository at this point in the history
* [feat]: applied search and filters are displayed now

* [feat]: update zh_rCN translation

* [fix]: crash with filters with no selected log levels

* [feat]: placeholders in empty lists

* [fix]: small placeholders UI improvements

* [feat]: update zh_rCN translation

* [build]: bumped version to 1.5.1

---------

Co-authored-by: ‭huajijam <strhuaji@gmail.com>
  • Loading branch information
F0x1d and huajijam authored Nov 22, 2023
1 parent 3a2427b commit 3633989
Show file tree
Hide file tree
Showing 30 changed files with 302 additions and 43 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "com.f0x1d.logfox"
minSdk 24
targetSdk 34
versionCode 52
versionName "1.5.0"
versionCode 53
versionName "1.5.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ interface UserFilterDao {
class AllowedLevelsConverter {

@TypeConverter
fun toAllowedLevels(data: String) = data.split(",").map { enumValues<LogLevel>()[it.toInt()] }
fun toAllowedLevels(data: String) = when (data.isEmpty()) {
true -> emptyList()

else -> data.split(",").map { enumValues<LogLevel>()[it.toInt()] }
}

@TypeConverter
fun fromAllowedLevels(allowedLevels: List<LogLevel>) = allowedLevels.joinToString(",") { it.ordinal.toString() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import androidx.core.view.isVisible
import androidx.hilt.navigation.fragment.hiltNavGraphViewModels
import com.f0x1d.logfox.R
import com.f0x1d.logfox.databinding.SheetSearchBinding
Expand All @@ -24,7 +25,7 @@ class SearchBottomSheet: BaseBottomSheet<SheetSearchBinding>() {

binding.queryText.setText(query)

binding.clearSearchButton.visibility = if (query == null) View.GONE else View.VISIBLE
binding.clearSearchButton.isVisible = query != null
binding.clearSearchButton.setOnClickListener {
search(null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
Expand Down Expand Up @@ -99,6 +100,8 @@ class RecordingsFragment: BaseViewModelFragment<RecordingsViewModel, FragmentRec
binding.recordingsRecycler.adapter = adapter

viewModel.recordings.observe(viewLifecycleOwner) {
binding.placeholderLayout.root.isVisible = it.isEmpty()

adapter.submitList(it)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
Expand Down Expand Up @@ -68,6 +69,8 @@ class CrashesFragment: BaseViewModelFragment<CrashesViewModel, FragmentCrashesBi
binding.crashesRecycler.adapter = adapter

viewModel.crashes.observe(viewLifecycleOwner) {
binding.placeholderLayout.root.isVisible = it.isEmpty()

adapter.submitList(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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 androidx.recyclerview.widget.LinearLayoutManager
Expand Down Expand Up @@ -84,6 +85,8 @@ class FiltersFragment: BaseViewModelFragment<FiltersViewModel, FragmentFiltersBi
}

viewModel.filters.observe(viewLifecycleOwner) {
binding.placeholderLayout.root.isVisible = it.isEmpty()

adapter.submitList(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.core.view.isVisible
import androidx.hilt.navigation.fragment.hiltNavGraphViewModels
import androidx.lifecycle.asLiveData
import androidx.navigation.fragment.findNavController
Expand Down Expand Up @@ -140,6 +141,31 @@ class LogsFragment: BaseViewModelFragment<LogsViewModel, FragmentLogsBinding>(),
scrollLogToBottom()
}

viewModel.queryAndFilters.asLiveData().observe(viewLifecycleOwner) {
val (query, filters) = it

val subtitle = buildString {
if (query != null) {
append(query)

if (filters.isNotEmpty())
append(", ")
}

if (filters.isNotEmpty())
append(resources.getQuantityString(R.plurals.filters_count, filters.size, filters.size))
}

binding.toolbar.subtitle = subtitle
binding.placeholderLayout.placeholderText.setText(
when (subtitle.isEmpty()) {
true -> R.string.no_logs

else -> R.string.all_logs_were_filtered_out
}
)
}

viewModel.selectedItems.asLiveData().observe(viewLifecycleOwner) {
val selecting = it.isNotEmpty()

Expand All @@ -150,6 +176,8 @@ class LogsFragment: BaseViewModelFragment<LogsViewModel, FragmentLogsBinding>(),
}

viewModel.logs.asLiveData().observe(viewLifecycleOwner) {
binding.placeholderLayout.root.isVisible = it.isEmpty()

adapter.submitList(null)
adapter.submitList(it) {
scrollLogToBottom()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ class FilterViewHolder(

override fun bindTo(data: UserFilter) {
binding.includingText.setText(if (data.including) R.string.including else R.string.excluding)
binding.allowedLevelsText.setTextOrMakeGoneIfNull(R.string.log_levels, data.allowedLevels.joinToString { it.letter })
binding.uidText.setTextOrMakeGoneIfNull(R.string.uid, data.uid)
binding.pidText.setTextOrMakeGoneIfNull(R.string.pid, data.pid)
binding.tidText.setTextOrMakeGoneIfNull(R.string.tid, data.tid)
binding.packageNameText.setTextOrMakeGoneIfNull(R.string.package_name, data.packageName)
binding.tagText.setTextOrMakeGoneIfNull(R.string.tag, data.tag)
binding.contentText.setTextOrMakeGoneIfNull(R.string.content_contains, data.content)
binding.allowedLevelsText.setTextOrMakeGoneIfEmpty(R.string.log_levels, data.allowedLevels.joinToString { it.letter })
binding.uidText.setTextOrMakeGoneIfEmpty(R.string.uid, data.uid)
binding.pidText.setTextOrMakeGoneIfEmpty(R.string.pid, data.pid)
binding.tidText.setTextOrMakeGoneIfEmpty(R.string.tid, data.tid)
binding.packageNameText.setTextOrMakeGoneIfEmpty(R.string.package_name, data.packageName)
binding.tagText.setTextOrMakeGoneIfEmpty(R.string.tag, data.tag)
binding.contentText.setTextOrMakeGoneIfEmpty(R.string.content_contains, data.content)

checkedListener.check(data.enabled)
}

private fun TextView.setTextOrMakeGoneIfNull(prefix: Int, content: String?) {
visibility = if (content == null) View.GONE else View.VISIBLE
private fun TextView.setTextOrMakeGoneIfEmpty(prefix: Int, content: String?) {
visibility = if (content.isNullOrEmpty()) View.GONE else View.VISIBLE

if (content != null) {
text = Html.fromHtml("<b>${context.getString(prefix)}:</b> $content")
Expand Down
21 changes: 12 additions & 9 deletions app/src/main/java/com/f0x1d/logfox/viewmodel/LogsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class LogsViewModel @Inject constructor(
): BaseViewModel(application) {

val query = MutableStateFlow<String?>(null)
val queryAndFilters = query.combine(database.userFilterDao().getAllAsFlow()) { query, filters ->
query to filters.filter { it.enabled }
}.flowOn(Dispatchers.IO)

val paused = MutableStateFlow(false)

Expand Down Expand Up @@ -117,12 +120,12 @@ class LogsViewModel @Inject constructor(

fun pause() = paused.update { true }
fun resume() = paused.update { false }
}

data class LogsData(
val logs: List<LogLine>,
val filters: List<UserFilter>,
val query: String?,
val paused: Boolean,
val passing: Boolean = true
)

private data class LogsData(
val logs: List<LogLine>,
val filters: List<UserFilter>,
val query: String?,
val paused: Boolean,
val passing: Boolean = true
)
}
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/placeholder_icon_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<solid android:color="@color/placeholder_icon_background" />

<padding
android:top="25dp"
android:left="25dp"
android:right="25dp"
android:bottom="25dp"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/layout/fragment_crashes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
app:titleCentered="true" />
</com.google.android.material.appbar.AppBarLayout>

<include
android:id="@+id/placeholder_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
layout="@layout/placeholder_crashes"
app:layout_anchor="@id/crashes_recycler"
app:layout_anchorGravity="center" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/crashes_recycler"
android:layout_width="match_parent"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_edit_filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@
android:layout_height="wrap_content"
android:src="@drawable/ic_save"
android:layout_margin="10dp"
app:layout_anchorGravity="bottom|right|end"
android:layout_gravity="end|bottom"
app:layout_anchor="@id/scroll_view"
app:layout_anchorGravity="bottom|end"
android:contentDescription="@string/save"
android:tooltipText="@string/save"
tools:targetApi="o" />
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/res/layout/fragment_filters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,23 @@
android:paddingBottom="71dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<include
android:id="@+id/placeholder_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
layout="@layout/placeholder_filters"
app:layout_anchor="@id/filters_recycler"
app:layout_anchorGravity="center" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/add_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add"
android:layout_margin="10dp"
app:layout_anchorGravity="bottom|right|end"
android:layout_gravity="end|bottom"
app:layout_anchor="@id/filters_recycler"
app:layout_anchorGravity="bottom|end"
android:contentDescription="@string/add"
android:tooltipText="@string/add"
tools:targetApi="o" />
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/res/layout/fragment_logs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
android:layout_height="?actionBarSize"
app:title="@string/app_name"
app:titleCentered="true"
app:subtitleCentered="true"
app:menu="@menu/logs_menu"
app:navigationIconTint="?colorOnSurface"/>
</com.google.android.material.appbar.AppBarLayout>
Expand All @@ -29,15 +30,24 @@
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<include
android:id="@+id/placeholder_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
layout="@layout/placeholder_logs"
app:layout_anchor="@id/logs_recycler"
app:layout_anchorGravity="center" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/scroll_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow_drop_down"
android:visibility="gone"
android:layout_margin="10dp"
app:layout_anchorGravity="bottom|right|end"
android:layout_gravity="end|bottom"
app:layout_anchor="@id/logs_recycler"
app:layout_anchorGravity="bottom|end"
android:contentDescription="@string/scroll_to_bottom"
android:tooltipText="@string/scroll_to_bottom"
tools:targetApi="o" />
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/res/layout/fragment_recordings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
android:paddingBottom="66dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<include
android:id="@+id/placeholder_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
layout="@layout/placeholder_recordings"
app:layout_anchor="@id/recordings_recycler"
app:layout_anchorGravity="center" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/pause_fab"
android:layout_width="wrap_content"
Expand All @@ -40,8 +49,8 @@
android:layout_marginBottom="76dp"
android:contentDescription="@string/pause"
android:tooltipText="@string/pause"
app:layout_anchorGravity="bottom|right|end"
android:layout_gravity="end|bottom"
app:layout_anchor="@id/recordings_recycler"
app:layout_anchorGravity="bottom|end"
tools:targetApi="o" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
Expand All @@ -50,8 +59,8 @@
android:layout_height="wrap_content"
android:src="@drawable/ic_recording"
android:layout_margin="10dp"
app:layout_anchorGravity="bottom|right|end"
android:layout_gravity="end|bottom"
app:layout_anchor="@id/recordings_recycler"
app:layout_anchorGravity="bottom|end"
android:contentDescription="@string/record"
android:tooltipText="@string/record"
tools:targetApi="o" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/allowed_levels_text"
app:layout_constraintStart_toEndOf="@id/including_text"
app:layout_constraintEnd_toStartOf="@id/delete_button"
app:layout_constraintBottom_toBottomOf="parent" />

Expand Down
34 changes: 34 additions & 0 deletions app/src/main/res/layout/placeholder_crashes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/placeholder_icon"
android:layout_width="120dp"
android:layout_height="120dp"
app:tint="?android:textColorSecondary"
app:srcCompat="@drawable/ic_android"
android:background="@drawable/placeholder_icon_background"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/placeholder_text"/>

<com.google.android.material.textview.MaterialTextView
android:id="@+id/placeholder_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_crashes"
android:textSize="16sp"
android:textColor="?android:textColorPrimary"
android:layout_marginTop="15dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:layout_constraintTop_toBottomOf="@id/placeholder_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 3633989

Please sign in to comment.