From 716953ec9d457d3965a431828e5844934534ea07 Mon Sep 17 00:00:00 2001 From: Pavol Franek <> Date: Sun, 22 Mar 2020 16:36:50 +0100 Subject: [PATCH 1/6] WIP - searching for strings in a given note, then highlighting and looping through the string occurrences with some arrows. --- app/build.gradle | 10 +- .../notes/pro/activities/MainActivity.kt | 173 ++++++++++++++++-- .../notes/pro/extensions/Context.kt | 3 + .../notes/pro/extensions/Fragment.kt | 1 + .../notes/pro/extensions/String.kt | 9 + app/src/main/res/layout/activity_main.xml | 29 +-- app/src/main/res/layout/search_item.xml | 53 ++++++ app/src/main/res/menu/menu.xml | 5 + 8 files changed, 248 insertions(+), 35 deletions(-) create mode 100644 app/src/main/res/layout/search_item.xml diff --git a/app/build.gradle b/app/build.gradle index 627f01cc..1682c41b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,10 +57,10 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.22.19' - implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' + implementation 'com.simplemobiletools:commons:5.23.7' + implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4' - kapt 'androidx.room:room-compiler:2.2.2' - implementation 'androidx.room:room-runtime:2.2.2' - annotationProcessor 'androidx.room:room-compiler:2.2.2' + kapt 'androidx.room:room-compiler:2.2.4' + implementation 'androidx.room:room-runtime:2.2.4' + annotationProcessor 'androidx.room:room-compiler:2.2.4' } 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 b0a82912..40882617 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 @@ -3,13 +3,17 @@ package com.simplemobiletools.notes.pro.activities import android.content.Intent import android.net.Uri import android.os.Bundle +import android.text.Spannable +import android.text.SpannableString import android.text.method.ArrowKeyMovementMethod import android.text.method.LinkMovementMethod +import android.text.style.BackgroundColorSpan import android.util.TypedValue import android.view.ActionMode import android.view.Gravity import android.view.Menu import android.view.MenuItem +import android.widget.TextView import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog @@ -26,9 +30,13 @@ import com.simplemobiletools.notes.pro.adapters.NotesPagerAdapter import com.simplemobiletools.notes.pro.databases.NotesDatabase import com.simplemobiletools.notes.pro.dialogs.* import com.simplemobiletools.notes.pro.extensions.* -import com.simplemobiletools.notes.pro.helpers.* +import com.simplemobiletools.notes.pro.helpers.MIME_TEXT_PLAIN +import com.simplemobiletools.notes.pro.helpers.NoteType +import com.simplemobiletools.notes.pro.helpers.NotesHelper +import com.simplemobiletools.notes.pro.helpers.OPEN_NOTE_ID import com.simplemobiletools.notes.pro.models.Note import kotlinx.android.synthetic.main.activity_main.* +import kotlinx.android.synthetic.main.search_item.* import java.io.File import java.nio.charset.Charset @@ -47,6 +55,9 @@ class MainActivity : SimpleActivity() { private var showSaveButton = false private var showUndoButton = false private var showRedoButton = false + private var searchIndex = 0 + private var searchMatches = emptyList() + private var searchIsActive = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -65,7 +76,127 @@ class MainActivity : SimpleActivity() { } wasInit = true + checkAppOnSDCard() + searchListeners() + } + + private fun searchListeners() { + search_query.onTextChangeListener { query -> + currentNotesView()?.let { noteView -> + noteView.setText(noteView.value) + + if (query.isNotBlank() && query.length > 1) { + searchMatches = searchMatches(query, noteView.value) + searchHighLightText(noteView, query) + } + } + } + + search_previous.setOnClickListener { + currentNotesView()?.let { noteView -> + if (searchIndex > 0) { + searchIndex-- + } + else { + searchIndex = searchMatches.lastIndex + } + + selectMatch(noteView) + } + } + + search_next.setOnClickListener { + currentNotesView()?.let { noteView -> + if (searchIndex < searchMatches.lastIndex) { + searchIndex++ + } + else { + searchIndex = 0 + } + + selectMatch(noteView) + } + } + + search_clear.setOnClickListener { + if (search_query.value.isNotBlank()) + search_query.text?.clear() + else + searchHide() + } + + view_pager.onPageChangeListener { + if (searchIsActive) searchHide() + } + } + + private fun selectMatch(noteView: MyEditText) { + if (searchMatches.isNotEmpty()) { + noteView.requestFocus() + noteView.setSelection(searchMatches.getOrNull(searchIndex) ?: 0) + } else { + hideKeyboard() + //toast("No matches")//TODO + } + } + + private fun searchMatches(textToHighlight: String, content: String): ArrayList { + val indexes = arrayListOf() + var indexOf = content.indexOf(textToHighlight, 0, ignoreCase = true) + + var offset = 0 + while (offset < content.length && indexOf != -1) { + indexOf = content.indexOf(textToHighlight, offset, ignoreCase = true) + + if (indexOf == -1) + break + else + indexes.add(indexOf) + + offset = indexOf + 1 + } + + return indexes + } + + private fun searchHighLightText(view: MyEditText, textToHighlight: String) { + val content = view.text.toString() + var indexOf = content.indexOf(textToHighlight, 0, true) + val wordToSpan = SpannableString(view.text) + + var offset = 0 + 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) + view.setText(wordToSpan, TextView.BufferType.SPANNABLE) + } + + offset = indexOf + 1 + } + } + + private fun searchShow() { + searchIsActive = true + search_root.beVisible() + showKeyboard(search_query) + + currentNotesView()?.let { noteView -> + noteView.requestFocus() + noteView.setSelection(0) + } + + search_query.postDelayed({ + search_query.requestFocus() + }, 250) + } + + private fun searchHide() { + searchIsActive = false + search_root.beGone() } override fun onResume() { @@ -129,6 +260,7 @@ class MainActivity : SimpleActivity() { } when (item.itemId) { + R.id.open_search -> searchShow() R.id.open_note -> displayOpenNoteDialog() R.id.save_note -> saveNote() R.id.undo -> undo() @@ -627,7 +759,8 @@ class MainActivity : SimpleActivity() { private fun saveCurrentNote(force: Boolean) { getPagerAdapter().saveCurrentNote(view_pager.currentItem, force) if (mCurrentNote.type == NoteType.TYPE_CHECKLIST.value) { - mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: "" + mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) + ?: "" } } @@ -730,26 +863,28 @@ class MainActivity : SimpleActivity() { } fun currentNoteTextChanged(newText: String, showUndo: Boolean, showRedo: Boolean) { - var shouldRecreateMenu = false - if (showUndo != showUndoButton) { - showUndoButton = showUndo - shouldRecreateMenu = true - } - - if (showRedo != showRedoButton) { - showRedoButton = showRedo - shouldRecreateMenu = true - } - - if (!config.autosaveNotes) { - showSaveButton = newText != mCurrentNote.value - if (showSaveButton != saveNoteButton?.isVisible) { + if (searchIsActive.not()) { + var shouldRecreateMenu = false + if (showUndo != showUndoButton) { + showUndoButton = showUndo shouldRecreateMenu = true } - } - if (shouldRecreateMenu) { - invalidateOptionsMenu() + if (showRedo != showRedoButton) { + showRedoButton = showRedo + shouldRecreateMenu = true + } + + if (!config.autosaveNotes) { + showSaveButton = newText != mCurrentNote.value + if (showSaveButton != saveNoteButton?.isVisible) { + shouldRecreateMenu = true + } + } + + if (shouldRecreateMenu) { + invalidateOptionsMenu() + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/extensions/Context.kt index ee459e6d..c213f570 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/extensions/Context.kt @@ -4,6 +4,7 @@ import android.appwidget.AppWidgetManager import android.content.ComponentName import android.content.Context import android.content.Intent +import androidx.core.content.ContextCompat import com.simplemobiletools.notes.pro.databases.NotesDatabase import com.simplemobiletools.notes.pro.helpers.Config import com.simplemobiletools.notes.pro.helpers.MyWidgetProvider @@ -26,3 +27,5 @@ fun Context.updateWidgets() { } } } + +fun Context.color(id: Int) = ContextCompat.getColor(this, id) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/extensions/Fragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/extensions/Fragment.kt index 3524f4f5..4be475f7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/extensions/Fragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/extensions/Fragment.kt @@ -7,3 +7,4 @@ import com.simplemobiletools.notes.pro.helpers.Config val Fragment.config: Config? get() = if (context != null) Config.newInstance(context!!) else null val Fragment.requiredActivity: FragmentActivity get() = this.activity!! + 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 a7be6176..0cafc1e9 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 @@ -1,7 +1,12 @@ package com.simplemobiletools.notes.pro.extensions +import android.os.Build +import android.text.Html +import androidx.annotation.RequiresApi import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.simplemobiletools.commons.helpers.isMarshmallowPlus +import com.simplemobiletools.commons.helpers.isNougatPlus import com.simplemobiletools.notes.pro.models.ChecklistItem fun String.parseChecklistItems(): ArrayList? { @@ -14,3 +19,7 @@ fun String.parseChecklistItems(): ArrayList? { } return null } + +@RequiresApi(Build.VERSION_CODES.N) +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/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a73f4561..b457e45e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,16 +1,23 @@ - + android:layout_height="match_parent" + android:orientation="vertical"> - + + + android:layout_height="match_parent"> - + + + + diff --git a/app/src/main/res/layout/search_item.xml b/app/src/main/res/layout/search_item.xml new file mode 100644 index 00000000..05f81ca4 --- /dev/null +++ b/app/src/main/res/layout/search_item.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + diff --git a/app/src/main/res/menu/menu.xml b/app/src/main/res/menu/menu.xml index fe032a88..b6e49a5a 100644 --- a/app/src/main/res/menu/menu.xml +++ b/app/src/main/res/menu/menu.xml @@ -16,6 +16,11 @@ android:icon="@drawable/ic_redo_vector" android:title="@string/redo" app:showAsAction="ifRoom"/> + Date: Tue, 24 Mar 2020 08:46:59 +0100 Subject: [PATCH 2/6] searching for strings in a given note, then highlighting and looping through the string occurrences with some arrows. --- .../notes/pro/activities/MainActivity.kt | 33 ++++++++++++++++--- .../notes/pro/adapters/NotesPagerAdapter.kt | 2 ++ .../notes/pro/fragments/TextFragment.kt | 8 +++-- 3 files changed, 36 insertions(+), 7 deletions(-) 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 40882617..bcf1e712 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 @@ -3,6 +3,7 @@ package com.simplemobiletools.notes.pro.activities import android.content.Intent import android.net.Uri import android.os.Bundle +import android.text.Editable import android.text.Spannable import android.text.SpannableString import android.text.method.ArrowKeyMovementMethod @@ -30,6 +31,7 @@ import com.simplemobiletools.notes.pro.adapters.NotesPagerAdapter import com.simplemobiletools.notes.pro.databases.NotesDatabase import com.simplemobiletools.notes.pro.dialogs.* import com.simplemobiletools.notes.pro.extensions.* +import com.simplemobiletools.notes.pro.fragments.TextFragment import com.simplemobiletools.notes.pro.helpers.MIME_TEXT_PLAIN import com.simplemobiletools.notes.pro.helpers.NoteType import com.simplemobiletools.notes.pro.helpers.NotesHelper @@ -84,12 +86,15 @@ class MainActivity : SimpleActivity() { private fun searchListeners() { search_query.onTextChangeListener { query -> currentNotesView()?.let { noteView -> - noteView.setText(noteView.value) + currentTextFragment?.removeTextWatcher() + searchClearSpans(noteView.text) if (query.isNotBlank() && query.length > 1) { searchMatches = searchMatches(query, noteView.value) searchHighLightText(noteView, query) } + + currentTextFragment?.setTextWatcher() } } @@ -127,7 +132,26 @@ class MainActivity : SimpleActivity() { } view_pager.onPageChangeListener { - if (searchIsActive) searchHide() + currentTextFragment?.removeTextWatcher() + currentNotesView()?.let { noteView -> + searchClearSpans(noteView.text) + } + + search_query.text?.clear() + searchHide() + + currentTextFragment?.setTextWatcher() + } + } + + private val currentTextFragment: TextFragment? get() = mAdapter?.textFragment(view_pager.currentItem) + + private fun searchClearSpans(editable: Editable) { + val spans = editable.getSpans(0, editable.length, Any::class.java) + for (span in spans) { + if (span is BackgroundColorSpan) { + editable.removeSpan(span) + } } } @@ -135,10 +159,8 @@ class MainActivity : SimpleActivity() { if (searchMatches.isNotEmpty()) { noteView.requestFocus() noteView.setSelection(searchMatches.getOrNull(searchIndex) ?: 0) - } else { + } else hideKeyboard() - //toast("No matches")//TODO - } } private fun searchMatches(textToHighlight: String, content: String): ArrayList { @@ -245,6 +267,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 saveNoteButton = findItem(R.id.save_note) saveNoteButton!!.isVisible = !config.autosaveNotes && showSaveButton && mCurrentNote.type == NoteType.TYPE_TEXT.value 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 1d183faf..87b75758 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 textFragment(position: Int): TextFragment? = (fragments[position] as? TextFragment) + fun getCurrentNotesView(position: Int) = (fragments[position] as? TextFragment)?.getNotesView() fun getCurrentNoteViewText(position: Int) = (fragments[position] as? TextFragment)?.getCurrentNoteViewText() diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt index a813a878..9cb22532 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt @@ -77,7 +77,8 @@ class TextFragment : NoteFragment() { if (config!!.autosaveNotes) { saveText(false) } - view.text_note_view.removeTextChangedListener(textWatcher) + + removeTextWatcher() } override fun setMenuVisibility(menuVisible: Boolean) { @@ -154,9 +155,12 @@ class TextFragment : NoteFragment() { view.notes_counter.beGone() } - view.text_note_view.addTextChangedListener(textWatcher) + setTextWatcher() } + fun setTextWatcher() = view.text_note_view.addTextChangedListener(textWatcher) + fun removeTextWatcher() = view.text_note_view.removeTextChangedListener(textWatcher) + fun updateNoteValue(value: String) { note?.value = value } From 6793be0039174b1ed6e8b74f65b4e57871163ac0 Mon Sep 17 00:00:00 2001 From: Pavol Franek <> Date: Wed, 25 Mar 2020 13:12:22 +0100 Subject: [PATCH 3/6] fixes --- .../notes/pro/activities/MainActivity.kt | 39 +++++--- .../notes/pro/adapters/NotesPagerAdapter.kt | 2 + .../notes/pro/extensions/String.kt | 6 +- app/src/main/res/layout/search_item.xml | 93 +++++++++++-------- 4 files changed, 88 insertions(+), 52 deletions(-) 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"> - + - + - - + + + + + + + From 0e3ae48386bfe62a8dffcc08df154e1be8d92e33 Mon Sep 17 00:00:00 2001 From: Pavol Franek <> Date: Wed, 25 Mar 2020 13:30:16 +0100 Subject: [PATCH 4/6] fixed review issues 1 --- .../notes/pro/activities/MainActivity.kt | 18 +++++++++++------- .../notes/pro/extensions/String.kt | 5 +++-- app/src/main/res/layout/search_item.xml | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) 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 3236e409..fc2e62d5 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 @@ -190,19 +190,21 @@ class MainActivity : SimpleActivity() { return indexes } - private fun searchHighLightText(view: MyEditText, textToHighlight: String) { + private fun searchHighLightText(view: MyEditText, highlightText: String) { val content = view.text.toString() - var indexOf = content.indexOf(textToHighlight, 0, true) + var indexOf = content.indexOf(highlightText, 0, true) val wordToSpan = SpannableString(view.text) var offset = 0 while (offset < content.length && indexOf != -1) { - indexOf = content.indexOf(textToHighlight, offset, true) + indexOf = content.indexOf(highlightText, offset, true) if (indexOf == -1) { break } else { - wordToSpan.setSpan(BackgroundColorSpan(ColorUtils.setAlphaComponent(config.primaryColor, 90)), indexOf, indexOf + textToHighlight.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) + val spanBgColor = BackgroundColorSpan(ColorUtils.setAlphaComponent(config.primaryColor, 90)) + val spanFlag = Spannable.SPAN_EXCLUSIVE_EXCLUSIVE + wordToSpan.setSpan(spanBgColor, indexOf, indexOf + highlightText.length, spanFlag) view.setText(wordToSpan, TextView.BufferType.SPANNABLE) } @@ -245,10 +247,11 @@ class MainActivity : SimpleActivity() { } updateTextColors(view_pager) + val contrastColor = config.primaryColor.getContrastColor() search_root.setBackgroundColor(config.primaryColor) - search_previous.applyColorFilter(config.primaryColor.getContrastColor()) - search_next.applyColorFilter(config.primaryColor.getContrastColor()) - search_clear.applyColorFilter(config.primaryColor.getContrastColor()) + search_previous.applyColorFilter(contrastColor) + search_next.applyColorFilter(contrastColor) + search_clear.applyColorFilter(contrastColor) } override fun onPause() { @@ -356,6 +359,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) { 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 34ce5be1..3ce92869 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 @@ -22,8 +22,9 @@ fun String.parseChecklistItems(): ArrayList? { @RequiresApi(Build.VERSION_CODES.N) fun String.toHtml() = - if (isNougatPlus()) + if (isNougatPlus()) { Html.fromHtml(this, Html.FROM_HTML_MODE_LEGACY) - else + } 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 5d588e03..716c4bc7 100644 --- a/app/src/main/res/layout/search_item.xml +++ b/app/src/main/res/layout/search_item.xml @@ -64,5 +64,5 @@ android:layout_height="1dp" android:layout_gravity="bottom" android:alpha="0.1" - android:background="#fff" /> + android:background="@color/md_grey_white" /> From 1d9775fac6b4637f8d4844913f97fc7bf6690fa7 Mon Sep 17 00:00:00 2001 From: Pavol Franek <> Date: Wed, 25 Mar 2020 20:01:08 +0100 Subject: [PATCH 5/6] fixed review issues 2 --- .../notes/pro/activities/MainActivity.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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 fc2e62d5..d70b9259 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 @@ -14,6 +14,7 @@ import android.view.ActionMode import android.view.Gravity import android.view.Menu import android.view.MenuItem +import android.view.inputmethod.EditorInfo import android.widget.TextView import androidx.core.graphics.ColorUtils import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog @@ -134,7 +135,6 @@ class MainActivity : SimpleActivity() { } search_clear.setOnClickListener { - search_query.text?.clear() searchHide() } @@ -144,11 +144,18 @@ class MainActivity : SimpleActivity() { searchClearSpans(noteView.text) } - search_query.text?.clear() searchHide() - currentTextFragment?.setTextWatcher() } + + search_query.setOnEditorActionListener(TextView.OnEditorActionListener { _, actionId, _ -> + if (actionId == EditorInfo.IME_ACTION_SEARCH) { + search_next.performClick() + return@OnEditorActionListener true + } + + false + }) } private val currentTextFragment: TextFragment? get() = mAdapter?.textFragment(view_pager.currentItem) @@ -202,7 +209,7 @@ class MainActivity : SimpleActivity() { if (indexOf == -1) { break } else { - val spanBgColor = BackgroundColorSpan(ColorUtils.setAlphaComponent(config.primaryColor, 90)) + val spanBgColor = BackgroundColorSpan(ColorUtils.setAlphaComponent(config.primaryColor, 128)) val spanFlag = Spannable.SPAN_EXCLUSIVE_EXCLUSIVE wordToSpan.setSpan(spanBgColor, indexOf, indexOf + highlightText.length, spanFlag) view.setText(wordToSpan, TextView.BufferType.SPANNABLE) @@ -228,6 +235,7 @@ class MainActivity : SimpleActivity() { } private fun searchHide() { + search_query.text?.clear() searchIsActive = false search_root.beGone() } @@ -348,6 +356,8 @@ class MainActivity : SimpleActivity() { } super.onBackPressed() } + } else if (searchIsActive) { + searchHide() } else { super.onBackPressed() } From 7d7fa44037046c4c58049a310da5e66fecbcaded Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Wed, 25 Mar 2020 20:33:57 +0100 Subject: [PATCH 6/6] make sure the search items are centered vertically --- app/src/main/res/layout/search_item.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/search_item.xml b/app/src/main/res/layout/search_item.xml index 716c4bc7..1f12d556 100644 --- a/app/src/main/res/layout/search_item.xml +++ b/app/src/main/res/layout/search_item.xml @@ -13,6 +13,7 @@