UIの整理

This commit is contained in:
tateisu 2023-05-06 21:55:33 +09:00
parent f1be1e70fa
commit 0788112dc2
2 changed files with 38 additions and 34 deletions

View File

@ -115,7 +115,7 @@ class ActText : AppCompatActivity() {
?.let { daoSavedAccount.loadAccount(it) }
if (savedInstanceState == null) {
views.llSearchResult.gone()
searchHighlight(null)
val sv = intent.string(EXTRA_TEXT) ?: ""
val contentStart = intent.int(EXTRA_CONTENT_START) ?: 0
@ -309,16 +309,8 @@ class ActText : AppCompatActivity() {
}
}
this.searchResult = searchResult
views.btnSearchClear.isEnabledAlpha = keyword.isNotEmpty()
views.btnSearchPrev.isEnabledAlpha = searchResult.isNotEmpty()
views.btnSearchNext.isEnabledAlpha = searchResult.isNotEmpty()
when {
searchResult.isEmpty() -> {
views.llSearchResult.gone()
searchHighlight(null)
}
searchResult.isEmpty() -> searchHighlight(null)
else -> searchNext(byTextUpdate = true)
}
}
@ -350,28 +342,40 @@ class ActText : AppCompatActivity() {
}
private fun searchJump(newPos: IntRange?) {
val idx = when (newPos) {
null -> null
else -> {
val end = views.etText.text?.length ?: 0
views.etText.setSelection(
newPos.first.clip(0, end),
(newPos.last + 1).clip(0, end),
)
searchResult.indexOf(newPos).takeIf { it >= 0 }?.plus(1)
}
}
views.llSearchResult.visible()
views.tvSearchCount.text = getString(
R.string.search_result,
idx?.toString() ?: "?",
searchResult.size
)
searchHighlight(newPos)
}
private fun searchHighlight(newPos: IntRange?) {
views.tvSearchError.vg(!searchError.isNullOrBlank())?.text = searchError
val hasKeyword = !views.etSearch.text.isNullOrEmpty()
views.btnSearchClear.isEnabledAlpha = hasKeyword
views.llSearchResult.vg(hasKeyword)?.let {
views.btnSearchPrev.isEnabledAlpha = searchResult.size > 1
views.btnSearchNext.isEnabledAlpha = searchResult.size > 1
val idx = when (newPos) {
null -> null
else -> {
val end = views.etText.text?.length ?: 0
views.etText.setSelection(
newPos.first.clip(0, end),
(newPos.last + 1).clip(0, end),
)
searchResult.indexOf(newPos).takeIf { it >= 0 }?.plus(1)
}
}
views.tvSearchCount.text = getString(
R.string.search_result,
idx?.toString() ?: "0",
searchResult.size
)
}
views.tvSearchError.vg(hasKeyword && !searchError.isNullOrBlank())
?.text = searchError
views.etText.text?.let { e ->
for (span in e.getSpans(0, e.length, SearchResultSpan::class.java)) {
try {

View File

@ -20,7 +20,7 @@
android:background="?attr/colorSearchFormBackground"
android:orientation="vertical"
android:paddingHorizontal="12dp"
android:paddingVertical="4dp">
android:paddingVertical="0dp">
<LinearLayout
android:layout_width="match_parent"
@ -41,7 +41,6 @@
android:id="@+id/btnToggleRegex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:disabledAlpha="0.3"
android:elevation="0dp"
android:minHeight="48dp"
@ -58,7 +57,6 @@
android:id="@+id/btnSearchClear"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="2dp"
android:contentDescription="@string/clear"
android:src="@drawable/ic_close"
app:tint="?attr/colorTextContent" />
@ -68,7 +66,8 @@
android:id="@+id/tvSearchError"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/colorRegexFilterError" />
android:textColor="?attr/colorRegexFilterError"
tools:text="regex error" />
<LinearLayout
android:id="@+id/llSearchResult"
@ -84,13 +83,14 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:includeFontPadding="false"
tools:text="12/345" />
<ImageButton
android:id="@+id/btnSearchPrev"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="4dp"
android:background="@drawable/btn_bg_transparent_round6dp"
android:contentDescription="@string/previous"
android:src="@drawable/ic_arrow_drop_up"
app:tint="?attr/colorTextContent" />
@ -99,7 +99,7 @@
android:id="@+id/btnSearchNext"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="4dp"
android:background="@drawable/btn_bg_transparent_round6dp"
android:contentDescription="@string/next"
android:src="@drawable/ic_arrow_drop_down"
app:tint="?attr/colorTextContent" />