This commit is contained in:
Pavol Franek 2020-03-25 13:12:22 +01:00
parent 8b20ccde0b
commit 6793be0039
4 changed files with 88 additions and 52 deletions

View File

@ -15,6 +15,7 @@ import android.view.Gravity
import android.view.Menu
import android.view.MenuItem
import android.widget.TextView
import androidx.core.graphics.ColorUtils
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
@ -95,6 +96,15 @@ class MainActivity : SimpleActivity() {
}
currentTextFragment?.setTextWatcher()
if (searchMatches.isNotEmpty()) {
noteView.requestFocus()
noteView.setSelection(searchMatches.getOrNull(searchIndex) ?: 0)
}
search_query.postDelayed({
search_query.requestFocus()
}, 50)
}
}
@ -115,8 +125,7 @@ class MainActivity : SimpleActivity() {
currentNotesView()?.let { noteView ->
if (searchIndex < searchMatches.lastIndex) {
searchIndex++
}
else {
} else {
searchIndex = 0
}
@ -125,10 +134,8 @@ class MainActivity : SimpleActivity() {
}
search_clear.setOnClickListener {
if (search_query.value.isNotBlank())
search_query.text?.clear()
else
searchHide()
search_query.text?.clear()
searchHide()
}
view_pager.onPageChangeListener {
@ -171,10 +178,11 @@ class MainActivity : SimpleActivity() {
while (offset < content.length && indexOf != -1) {
indexOf = content.indexOf(textToHighlight, offset, ignoreCase = true)
if (indexOf == -1)
if (indexOf == -1) {
break
else
} else {
indexes.add(indexOf)
}
offset = indexOf + 1
}
@ -191,9 +199,10 @@ class MainActivity : SimpleActivity() {
while (offset < content.length && indexOf != -1) {
indexOf = content.indexOf(textToHighlight, offset, true)
if (indexOf == -1) break
else {
wordToSpan.setSpan(BackgroundColorSpan(color(R.color.color_accent)), indexOf, indexOf + textToHighlight.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
if (indexOf == -1) {
break
} else {
wordToSpan.setSpan(BackgroundColorSpan(ColorUtils.setAlphaComponent(config.primaryColor, 90)), indexOf, indexOf + textToHighlight.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
view.setText(wordToSpan, TextView.BufferType.SPANNABLE)
}
@ -235,6 +244,11 @@ class MainActivity : SimpleActivity() {
setTextColor(config.textColor)
}
updateTextColors(view_pager)
search_root.setBackgroundColor(config.primaryColor)
search_previous.applyColorFilter(config.primaryColor.getContrastColor())
search_next.applyColorFilter(config.primaryColor.getContrastColor())
search_clear.applyColorFilter(config.primaryColor.getContrastColor())
}
override fun onPause() {
@ -267,7 +281,7 @@ class MainActivity : SimpleActivity() {
findItem(R.id.open_note).isVisible = shouldBeVisible
findItem(R.id.delete_note).isVisible = shouldBeVisible
findItem(R.id.export_all_notes).isVisible = shouldBeVisible
findItem(R.id.open_search).isVisible = view_pager.currentItem != 0
findItem(R.id.open_search).isVisible = currentItemIsCheckList.not()
saveNoteButton = findItem(R.id.save_note)
saveNoteButton!!.isVisible = !config.autosaveNotes && showSaveButton && mCurrentNote.type == NoteType.TYPE_TEXT.value
@ -342,6 +356,7 @@ class MainActivity : SimpleActivity() {
view_pager.currentItem = getWantedNoteIndex(wantedNoteId)
checkIntents(intent)
}
private val currentItemIsCheckList get() = mAdapter?.isChecklistFragment(view_pager.currentItem) ?: false
private fun checkIntents(intent: Intent) {
intent.apply {

View File

@ -45,6 +45,8 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
}
}
fun isChecklistFragment(position: Int): Boolean = (fragments[position] is ChecklistFragment)
fun textFragment(position: Int): TextFragment? = (fragments[position] as? TextFragment)
fun getCurrentNotesView(position: Int) = (fragments[position] as? TextFragment)?.getNotesView()

View File

@ -21,5 +21,9 @@ fun String.parseChecklistItems(): ArrayList<ChecklistItem>? {
}
@RequiresApi(Build.VERSION_CODES.N)
fun String.toHtml() = if (isNougatPlus()) Html.fromHtml(this, Html.FROM_HTML_MODE_LEGACY) else Html.fromHtml(this)
fun String.toHtml() =
if (isNougatPlus())
Html.fromHtml(this, Html.FROM_HTML_MODE_LEGACY)
else
Html.fromHtml(this)

View File

@ -1,53 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/search_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_primary"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingTop="@dimen/small_margin"
android:paddingBottom="@dimen/small_margin"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/search_query"
android:layout_width="0dp"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/normal_margin"
android:layout_marginEnd="@dimen/normal_margin"
android:layout_weight="1"
android:maxLength="50"
android:maxLines="1"
android:singleLine="true"
android:textCursorDrawable="@null" />
android:orientation="horizontal"
android:paddingTop="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin">
<ImageView
android:id="@+id/search_previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/smaller_margin"
android:background="?selectableItemBackgroundBorderless"
android:padding="@dimen/small_margin"
android:src="@drawable/ic_chevron_left_vector" />
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/search_query"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/normal_margin"
android:layout_marginEnd="@dimen/normal_margin"
android:layout_weight="1"
android:background="@null"
android:hint="@string/search"
android:maxLength="50"
android:maxLines="1"
android:singleLine="true"
android:textCursorDrawable="@null" />
<ImageView
android:id="@+id/search_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/smaller_margin"
android:background="?selectableItemBackgroundBorderless"
android:padding="@dimen/small_margin"
android:src="@drawable/ic_chevron_right_vector" />
<ImageView
android:id="@+id/search_previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/smaller_margin"
android:background="?selectableItemBackgroundBorderless"
android:padding="@dimen/small_margin"
android:src="@drawable/ic_chevron_left_vector" />
<ImageView
android:id="@+id/search_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/medium_margin"
android:background="?selectableItemBackgroundBorderless"
android:padding="@dimen/small_margin"
android:src="@drawable/ic_cross_vector" />
</LinearLayout>
<ImageView
android:id="@+id/search_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/smaller_margin"
android:background="?selectableItemBackgroundBorderless"
android:padding="@dimen/small_margin"
android:src="@drawable/ic_chevron_right_vector" />
<ImageView
android:id="@+id/search_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/medium_margin"
android:background="?selectableItemBackgroundBorderless"
android:padding="@dimen/small_margin"
android:src="@drawable/ic_cross_vector" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="bottom"
android:alpha="0.1"
android:background="#fff" />
</FrameLayout>