Skip to content

Commit

Permalink
[feat]: select all button
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Nov 3, 2023
1 parent 2534a1c commit 374b8f2
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 32 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.f0x1d.logfox.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.hilt.navigation.fragment.hiltNavGraphViewModels
import com.f0x1d.logfox.R
import com.f0x1d.logfox.databinding.FragmentLogsExtendedCopyBinding
import com.f0x1d.logfox.extensions.views.widgets.setupBackButtonForNavController
import com.f0x1d.logfox.ui.fragment.base.BaseViewModelFragment
import com.f0x1d.logfox.viewmodel.LogsViewModel
import dev.chrisbanes.insetter.applyInsetter

class LogsExtendedCopyFragment: BaseViewModelFragment<LogsViewModel, FragmentLogsExtendedCopyBinding>() {

override val viewModel by hiltNavGraphViewModels<LogsViewModel>(R.id.logsFragment)

override fun inflateBinding(
inflater: LayoutInflater,
container: ViewGroup?
) = FragmentLogsExtendedCopyBinding.inflate(inflater, container, false)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.scrollView.applyInsetter {
type(navigationBars = true) {
padding(vertical = true)
}
}
binding.toolbar.setupBackButtonForNavController()

binding.logText.text = viewModel.selectedItemsContent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class LogsFragment: BaseViewModelFragment<LogsViewModel, FragmentLogsBinding>(),
setClickListenerOn(R.id.pause_item) {
viewModel.switchState()
}
setClickListenerOn(R.id.select_all_item) {
viewModel.selectAll()
}
setClickListenerOn(R.id.search_item) {
findNavController().navigate(LogsFragmentDirections.actionLogsFragmentToSearchBottomSheet())
}
Expand Down Expand Up @@ -183,6 +186,7 @@ class LogsFragment: BaseViewModelFragment<LogsViewModel, FragmentLogsBinding>(),
val visibleOnlyInDefault = { itemId: Int -> setVisibility(itemId, !selecting && !viewModel.viewingFile) }

visibleOnlyInDefault(R.id.pause_item)
visibleDuringSelection(R.id.select_all_item)
invisibleDuringSelection(R.id.search_item)
invisibleDuringSelection(R.id.filters_item)
visibleDuringSelection(R.id.selected_item)
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/f0x1d/logfox/viewmodel/LogsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ class LogsViewModel @Inject constructor(
)
}

fun selectAll() {
if (selectedItems.value == logs.value) selectedItems.update {
emptyList()
} else selectedItems.update {
logs.value ?: emptyList()
}
}

fun query(query: String?) = this.query.update { query }

fun clearLogs() = loggingRepository.clearLogs()
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_select_all.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="?colorOnSurface"
android:pathData="M3,5h2L5,3c-1.1,0 -2,0.9 -2,2zM3,13h2v-2L3,11v2zM7,21h2v-2L7,19v2zM3,9h2L5,7L3,7v2zM13,3h-2v2h2L13,3zM19,3v2h2c0,-1.1 -0.9,-2 -2,-2zM5,21v-2L3,19c0,1.1 0.9,2 2,2zM3,17h2v-2L3,15v2zM9,3L7,3v2h2L9,3zM11,21h2v-2h-2v2zM19,13h2v-2h-2v2zM19,21c1.1,0 2,-0.9 2,-2h-2v2zM19,9h2L21,7h-2v2zM19,17h2v-2h-2v2zM15,21h2v-2h-2v2zM15,5h2L17,3h-2v2zM7,17h10L17,7L7,7v10zM9,9h6v6L9,15L9,9z" />
</vector>
6 changes: 6 additions & 0 deletions app/src/main/res/menu/logs_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
android:title="@string/pause"
app:showAsAction="always" />

<item
android:id="@+id/select_all_item"
android:icon="@drawable/ic_select_all"
android:title="@string/select_all"
app:showAsAction="ifRoom" />

<item
android:id="@+id/search_item"
android:icon="@drawable/ic_search"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/navigation/logs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</fragment>
<fragment
android:id="@+id/logsExtendedCopyFragment"
android:name="com.f0x1d.logfox.ui.fragment.ExtendedCopyFragment"
android:name="com.f0x1d.logfox.ui.fragment.LogsExtendedCopyFragment"
android:label="ExtendedCopyFragment" >
<argument
android:name="content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@
<string name="logs_dump_lines_count">Количество строк в свалке логов</string>
<string name="releases">Релизы</string>
<string name="alpha_builds">Альфа сборки</string>
<string name="select_all">Выбрать всё</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@
<string name="telegram" translatable="false">Telegram</string>
<string name="releases">Releases</string>
<string name="alpha_builds">Alpha builds</string>
<string name="select_all">Select all</string>
</resources>

0 comments on commit 374b8f2

Please sign in to comment.