Skip to content

Commit

Permalink
[feat]: texts for accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse205 authored Oct 8, 2023
1 parent ebde1b2 commit 6ab9774
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import androidx.fragment.app.FragmentActivity
import com.f0x1d.logfox.R
import com.google.android.material.dialog.MaterialAlertDialogBuilder

fun FragmentActivity.showAreYouSureDialog(okClicked: () -> Unit) {
fun FragmentActivity.showAreYouSureDialog(
title: Int,
message: Int = R.string.are_you_sure,
okClicked: () -> Unit
) {
MaterialAlertDialogBuilder(this)
.setIcon(R.drawable.ic_dialog_warning)
.setTitle(R.string.are_you_sure)
.setTitle(title)
.setMessage(message)
.setPositiveButton(R.string.yes) { dialog, i -> okClicked() }
.setNeutralButton(R.string.no, null)
.show()
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/f0x1d/logfox/extensions/FABExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.f0x1d.logfox.extensions

import androidx.annotation.StringRes
import androidx.appcompat.widget.TooltipCompat
import com.google.android.material.floatingactionbutton.FloatingActionButton

fun FloatingActionButton.setDescription(@StringRes resId: Int) = setDescription(context.getString(resId))

fun FloatingActionButton.setDescription(text: String) {
contentDescription = text
TooltipCompat.setTooltipText(this, text)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.f0x1d.logfox.extensions

import androidx.fragment.app.Fragment
import com.f0x1d.logfox.R

fun Fragment.showAreYouSureDialog(okPressed: () -> Unit) = requireActivity().showAreYouSureDialog(okPressed)
fun Fragment.showAreYouSureDialog(
title: Int,
message: Int = R.string.are_you_sure,
okPressed: () -> Unit
) = requireActivity().showAreYouSureDialog(title, message, okPressed)
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CrashDetailsActivity: BaseViewModelActivity<CrashDetailsViewModel, Activit
private fun setupFor(appCrash: AppCrash) {
binding.toolbar.menu.apply {
setClickListenerOn(R.id.delete_item) {
showAreYouSureDialog {
showAreYouSureDialog(R.string.delete, R.string.delete_warning) {
viewModel.deleteCrash(appCrash)
finish()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ class LogsFragment: BaseViewModelFragment<LogsViewModel, FragmentLogsBinding>(),

viewModel.pausedData.observe(viewLifecycleOwner) { paused ->
changingState = true
binding.toolbar.menu.findItem(R.id.pause_item).setIcon(if (paused) R.drawable.ic_play else R.drawable.ic_pause)
binding.toolbar.menu.findItem(R.id.pause_item)
.setIcon(if (paused) R.drawable.ic_play else R.drawable.ic_pause)
.setTitle(if (paused) R.string.resume else R.string.pause)
if (paused) {
binding.scrollFab.show()
} else {
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.appcompat.widget.TooltipCompat
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -13,6 +14,7 @@ import com.f0x1d.logfox.database.entity.LogRecording
import com.f0x1d.logfox.databinding.FragmentRecordingsBinding
import com.f0x1d.logfox.extensions.isHorizontalOrientation
import com.f0x1d.logfox.extensions.setClickListenerOn
import com.f0x1d.logfox.extensions.setDescription
import com.f0x1d.logfox.extensions.showAreYouSureDialog
import com.f0x1d.logfox.extensions.startLoggingService
import com.f0x1d.logfox.repository.logging.RecordingState
Expand All @@ -33,7 +35,7 @@ class RecordingsFragment: BaseViewModelFragment<RecordingsViewModel, FragmentRec
private val adapter = RecordingsAdapter(click = {
openDetails(it)
}, delete = {
showAreYouSureDialog {
showAreYouSureDialog(R.string.delete, R.string.delete_warning) {
viewModel.delete(it)
}
})
Expand Down Expand Up @@ -65,7 +67,7 @@ class RecordingsFragment: BaseViewModelFragment<RecordingsViewModel, FragmentRec

binding.toolbar.inflateMenu(R.menu.recordings_menu)
binding.toolbar.menu.setClickListenerOn(R.id.clear_item) {
showAreYouSureDialog {
showAreYouSureDialog(R.string.clear, R.string.clear_warning) {
viewModel.clearRecordings()
}
}
Expand Down Expand Up @@ -101,36 +103,40 @@ class RecordingsFragment: BaseViewModelFragment<RecordingsViewModel, FragmentRec
adapter.submitList(it)
}

viewModel.recordingStateData.observe(viewLifecycleOwner) {
when (it) {
RecordingState.IDLE -> {
binding.recordFab.setImageResource(R.drawable.ic_recording)
binding.recordFab.isEnabled = true

binding.pauseFab.hide()
viewModel.recordingStateData.observe(viewLifecycleOwner) { state ->
binding.recordFab.apply {
when (state) {
RecordingState.IDLE, RecordingState.SAVING -> {
setImageResource(R.drawable.ic_recording)
setDescription(R.string.record)
isEnabled = state == RecordingState.IDLE
}

RecordingState.RECORDING, RecordingState.PAUSED -> {
setImageResource(R.drawable.ic_stop)
setDescription(R.string.stop)
isEnabled = true
}
}
}

RecordingState.RECORDING -> {
binding.recordFab.setImageResource(R.drawable.ic_stop)
binding.recordFab.isEnabled = true

binding.pauseFab.setImageResource(R.drawable.ic_pause)
binding.pauseFab.show()
}

RecordingState.PAUSED -> {
binding.recordFab.setImageResource(R.drawable.ic_stop)
binding.recordFab.isEnabled = true

binding.pauseFab.setImageResource(R.drawable.ic_play)
binding.pauseFab.show()
}

RecordingState.SAVING -> {
binding.recordFab.setImageResource(R.drawable.ic_recording)
binding.recordFab.isEnabled = false

binding.pauseFab.hide()
binding.pauseFab.apply {
when (state) {
RecordingState.IDLE, RecordingState.SAVING -> {
hide()
}

RecordingState.RECORDING -> {
setImageResource(R.drawable.ic_pause)
setDescription(R.string.pause)
show()
}

RecordingState.PAUSED -> {
setImageResource(R.drawable.ic_play)
setDescription(R.string.resume)
show()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.f0x1d.logfox.R
import com.f0x1d.logfox.adapter.CrashesAdapter
import com.f0x1d.logfox.databinding.FragmentAppCrashesBinding
import com.f0x1d.logfox.extensions.showAreYouSureDialog
Expand All @@ -27,7 +28,7 @@ class AppCrashesFragment: BaseViewModelFragment<AppCrashesViewModel, FragmentApp
AppCrashesFragmentDirections.actionAppCrashesFragmentToCrashDetailsActivity(it.lastCrash.id)
)
}, delete = {
showAreYouSureDialog {
showAreYouSureDialog(R.string.delete, R.string.delete_warning) {
viewModel.deleteCrash(it.lastCrash)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CrashesFragment: BaseViewModelFragment<CrashesViewModel, FragmentCrashesBi

findNavController().navigate(direction)
}, delete = {
showAreYouSureDialog {
showAreYouSureDialog(R.string.delete, R.string.delete_warning) {
viewModel.deleteCrashesByPackageName(it.lastCrash)
}
})
Expand All @@ -54,7 +54,7 @@ class CrashesFragment: BaseViewModelFragment<CrashesViewModel, FragmentCrashesBi

binding.toolbar.inflateMenu(R.menu.crashes_menu)
binding.toolbar.menu.setClickListenerOn(R.id.clear_item) {
showAreYouSureDialog {
showAreYouSureDialog(R.string.clear, R.string.clear_warning) {
viewModel.clearCrashes()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FiltersFragment: BaseViewModelFragment<FiltersViewModel, FragmentFiltersBi
FiltersFragmentDirections.actionFiltersFragmentToEditFilterFragment(it.id)
)
}, delete = {
showAreYouSureDialog {
showAreYouSureDialog(R.string.delete, R.string.delete_warning) {
viewModel.delete(it)
}
}, checked = { userFilter, checked ->
Expand Down Expand Up @@ -63,7 +63,7 @@ class FiltersFragment: BaseViewModelFragment<FiltersViewModel, FragmentFiltersBi
binding.toolbar.inflateMenu(R.menu.filters_menu)
binding.toolbar.menu.apply {
setClickListenerOn(R.id.clear_item) {
showAreYouSureDialog {
showAreYouSureDialog(R.string.clear, R.string.clear_warning) {
viewModel.clearAll()
}
}
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/layout/fragment_logs.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
Expand Down Expand Up @@ -35,6 +36,9 @@
android:visibility="gone"
android:layout_margin="10dp"
app:layout_anchorGravity="bottom|right|end"
android:layout_gravity="end|bottom"/>
android:layout_gravity="end|bottom"
android:contentDescription="@string/scroll_to_bottom"
android:tooltipText="@string/scroll_to_bottom"
tools:targetApi="o" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
11 changes: 9 additions & 2 deletions app/src/main/res/layout/fragment_recordings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
Expand Down Expand Up @@ -36,8 +37,11 @@
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="76dp"
android:contentDescription="@string/pause"
android:tooltipText="@string/pause"
app:layout_anchorGravity="bottom|right|end"
android:layout_gravity="end|bottom"/>
android:layout_gravity="end|bottom"
tools:targetApi="o" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/record_fab"
Expand All @@ -46,6 +50,9 @@
android:src="@drawable/ic_recording"
android:layout_margin="10dp"
app:layout_anchorGravity="bottom|right|end"
android:layout_gravity="end|bottom"/>
android:layout_gravity="end|bottom"
android:contentDescription="@string/record"
android:tooltipText="@string/record"
tools:targetApi="o" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,7 @@
<string name="apps">Приложения</string>
<string name="are_you_sure">Вы уверены?</string>
<string name="view">Просмотр</string>
<string name="delete_warning">Вы действительно хотите удалить это? Вы не сможете отменить это действие.</string>
<string name="clear_warning">Вы действительно хотите очистить это? Вы не сможете отменить это действие.</string>
<string name="scroll_to_bottom">Промотать вниз</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<string name="text_copied">已复制</string>
<string name="search">搜索</string>
<string name="clear">清除</string>
<string name="clear_warning">确定要清除吗?清除后无法恢复。</string>
<string name="query">查询</string>
<string name="logging_status">日志状态</string>
<string name="logging">记录中</string>
Expand All @@ -33,6 +34,7 @@
<string name="recordings">录制</string>
<string name="record_file">录制</string>
<string name="delete">删除</string>
<string name="delete_warning">确定要删除吗?删除后将无法恢复。</string>
<string name="resume">继续</string>
<string name="logs_update_interval">更新间隔</string>
<string name="in_ms">毫秒</string>
Expand Down Expand Up @@ -108,4 +110,5 @@
<string name="apps">应用</string>
<string name="are_you_sure">你确定?</string>
<string name="view">查看</string>
<string name="scroll_to_bottom">滚动到底部</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,7 @@
<string name="apps">Apps</string>
<string name="are_you_sure">Are you sure?</string>
<string name="view">View</string>
<string name="delete_warning">Are you sure want to delete it? This action cannot be undone.</string>
<string name="clear_warning">Are you sure want to clear it? This action cannot be undone.</string>
<string name="scroll_to_bottom">Scroll to the bottom</string>
</resources>

0 comments on commit 6ab9774

Please sign in to comment.