UIの整理
This commit is contained in:
parent
f1be1e70fa
commit
0788112dc2
@ -115,7 +115,7 @@ class ActText : AppCompatActivity() {
|
|||||||
?.let { daoSavedAccount.loadAccount(it) }
|
?.let { daoSavedAccount.loadAccount(it) }
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
views.llSearchResult.gone()
|
searchHighlight(null)
|
||||||
|
|
||||||
val sv = intent.string(EXTRA_TEXT) ?: ""
|
val sv = intent.string(EXTRA_TEXT) ?: ""
|
||||||
val contentStart = intent.int(EXTRA_CONTENT_START) ?: 0
|
val contentStart = intent.int(EXTRA_CONTENT_START) ?: 0
|
||||||
@ -309,16 +309,8 @@ class ActText : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.searchResult = searchResult
|
this.searchResult = searchResult
|
||||||
|
|
||||||
views.btnSearchClear.isEnabledAlpha = keyword.isNotEmpty()
|
|
||||||
views.btnSearchPrev.isEnabledAlpha = searchResult.isNotEmpty()
|
|
||||||
views.btnSearchNext.isEnabledAlpha = searchResult.isNotEmpty()
|
|
||||||
when {
|
when {
|
||||||
searchResult.isEmpty() -> {
|
searchResult.isEmpty() -> searchHighlight(null)
|
||||||
views.llSearchResult.gone()
|
|
||||||
searchHighlight(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> searchNext(byTextUpdate = true)
|
else -> searchNext(byTextUpdate = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -350,28 +342,40 @@ class ActText : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun searchJump(newPos: IntRange?) {
|
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)
|
searchHighlight(newPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun searchHighlight(newPos: IntRange?) {
|
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 ->
|
views.etText.text?.let { e ->
|
||||||
for (span in e.getSpans(0, e.length, SearchResultSpan::class.java)) {
|
for (span in e.getSpans(0, e.length, SearchResultSpan::class.java)) {
|
||||||
try {
|
try {
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
android:background="?attr/colorSearchFormBackground"
|
android:background="?attr/colorSearchFormBackground"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingHorizontal="12dp"
|
android:paddingHorizontal="12dp"
|
||||||
android:paddingVertical="4dp">
|
android:paddingVertical="0dp">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -41,7 +41,6 @@
|
|||||||
android:id="@+id/btnToggleRegex"
|
android:id="@+id/btnToggleRegex"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="2dp"
|
|
||||||
android:disabledAlpha="0.3"
|
android:disabledAlpha="0.3"
|
||||||
android:elevation="0dp"
|
android:elevation="0dp"
|
||||||
android:minHeight="48dp"
|
android:minHeight="48dp"
|
||||||
@ -58,7 +57,6 @@
|
|||||||
android:id="@+id/btnSearchClear"
|
android:id="@+id/btnSearchClear"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:layout_marginStart="2dp"
|
|
||||||
android:contentDescription="@string/clear"
|
android:contentDescription="@string/clear"
|
||||||
android:src="@drawable/ic_close"
|
android:src="@drawable/ic_close"
|
||||||
app:tint="?attr/colorTextContent" />
|
app:tint="?attr/colorTextContent" />
|
||||||
@ -68,7 +66,8 @@
|
|||||||
android:id="@+id/tvSearchError"
|
android:id="@+id/tvSearchError"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="?attr/colorRegexFilterError" />
|
android:textColor="?attr/colorRegexFilterError"
|
||||||
|
tools:text="regex error" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/llSearchResult"
|
android:id="@+id/llSearchResult"
|
||||||
@ -84,13 +83,14 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="end"
|
android:gravity="end"
|
||||||
|
android:includeFontPadding="false"
|
||||||
tools:text="12/345" />
|
tools:text="12/345" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/btnSearchPrev"
|
android:id="@+id/btnSearchPrev"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:layout_marginStart="4dp"
|
android:background="@drawable/btn_bg_transparent_round6dp"
|
||||||
android:contentDescription="@string/previous"
|
android:contentDescription="@string/previous"
|
||||||
android:src="@drawable/ic_arrow_drop_up"
|
android:src="@drawable/ic_arrow_drop_up"
|
||||||
app:tint="?attr/colorTextContent" />
|
app:tint="?attr/colorTextContent" />
|
||||||
@ -99,7 +99,7 @@
|
|||||||
android:id="@+id/btnSearchNext"
|
android:id="@+id/btnSearchNext"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:layout_marginStart="4dp"
|
android:background="@drawable/btn_bg_transparent_round6dp"
|
||||||
android:contentDescription="@string/next"
|
android:contentDescription="@string/next"
|
||||||
android:src="@drawable/ic_arrow_drop_down"
|
android:src="@drawable/ic_arrow_drop_down"
|
||||||
app:tint="?attr/colorTextContent" />
|
app:tint="?attr/colorTextContent" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user