diff --git a/app/build.gradle b/app/build.gradle index 85894412..d77d9798 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.6.0' + implementation 'com.simplemobiletools:commons:4.6.2' implementation files('../libs/RootTools.jar') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d6722f50..8f9c9838 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -52,6 +52,15 @@ + + + + + + + diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/ReadTextActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/ReadTextActivity.kt index 6b3724bd..1819d222 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/ReadTextActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/ReadTextActivity.kt @@ -1,7 +1,11 @@ package com.simplemobiletools.filemanager.activities +import android.app.SearchManager +import android.content.Context import android.net.Uri import android.os.Bundle +import android.support.v4.view.MenuItemCompat +import android.support.v7.widget.SearchView import android.view.Menu import android.view.MenuItem import com.simplemobiletools.commons.extensions.* @@ -17,6 +21,10 @@ import java.io.File class ReadTextActivity : SimpleActivity() { private var filePath = "" + private var originalText = "" + private var isSearchOpen = false + + private var searchMenuItem: MenuItem? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -35,6 +43,7 @@ class ReadTextActivity : SimpleActivity() { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_editor, menu) + setupSearch(menu) return true } @@ -47,6 +56,43 @@ class ReadTextActivity : SimpleActivity() { return true } + private fun setupSearch(menu: Menu) { + val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager + searchMenuItem = menu.findItem(R.id.search) + (searchMenuItem!!.actionView as SearchView).apply { + setSearchableInfo(searchManager.getSearchableInfo(componentName)) + isSubmitButtonEnabled = false + setOnQueryTextListener(object : android.support.v7.widget.SearchView.OnQueryTextListener { + override fun onQueryTextSubmit(query: String) = false + + override fun onQueryTextChange(newText: String): Boolean { + if (isSearchOpen) { + searchQueryChanged(newText) + } + return true + } + }) + } + + MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener { + override fun onMenuItemActionExpand(item: MenuItem?): Boolean { + isSearchOpen = true + searchQueryChanged("") + return true + } + + override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { + isSearchOpen = false + return true + } + }) + } + + private fun searchQueryChanged(text: String) { + val textToHighlight = if (text.length < 2) "" else text + read_text_view.setText(originalText.highlightTextPart(textToHighlight, getAdjustedPrimaryColor(), true)) + } + private fun saveText() { if (filePath.isEmpty()) { filePath = getRealPathFromURI(intent.data) ?: "" @@ -78,7 +124,7 @@ class ReadTextActivity : SimpleActivity() { return } - val text = if (uri.scheme == "file") { + originalText = if (uri.scheme == "file") { filePath = uri.path val file = File(filePath) if (file.exists()) { @@ -97,6 +143,6 @@ class ReadTextActivity : SimpleActivity() { } } - read_text_view.setText(text) + read_text_view.setText(originalText) } } diff --git a/app/src/main/res/layout/activity_read_text.xml b/app/src/main/res/layout/activity_read_text.xml index e04cdf36..8f53bdde 100644 --- a/app/src/main/res/layout/activity_read_text.xml +++ b/app/src/main/res/layout/activity_read_text.xml @@ -11,6 +11,7 @@ android:layout_height="wrap_content" android:background="@null" android:padding="@dimen/medium_margin" + android:inputType="textMultiLine|textNoSuggestions" android:textCursorDrawable="@null" android:textSize="@dimen/smaller_text_size"/> diff --git a/app/src/main/res/menu/menu_editor.xml b/app/src/main/res/menu/menu_editor.xml index 825b62e0..0ad7933b 100644 --- a/app/src/main/res/menu/menu_editor.xml +++ b/app/src/main/res/menu/menu_editor.xml @@ -1,6 +1,12 @@ +