diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt index bcf1e712..3236e409 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt @@ -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 { diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt index 87b75758..9e4180fe 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt @@ -45,6 +45,8 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List, 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() diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/extensions/String.kt index 0cafc1e9..34ce5be1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/extensions/String.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/extensions/String.kt @@ -21,5 +21,9 @@ fun String.parseChecklistItems(): ArrayList? { } @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) diff --git a/app/src/main/res/layout/search_item.xml b/app/src/main/res/layout/search_item.xml index 05f81ca4..5d588e03 100644 --- a/app/src/main/res/layout/search_item.xml +++ b/app/src/main/res/layout/search_item.xml @@ -1,53 +1,68 @@ - - + android:orientation="horizontal" + android:paddingTop="@dimen/medium_margin" + android:paddingBottom="@dimen/medium_margin"> - + - + - - + + + + + + +