adding more search related functionality

This commit is contained in:
tibbi 2021-02-15 21:46:51 +01:00
parent 7048b7bcb5
commit 131b1a44c3
3 changed files with 61 additions and 5 deletions

View File

@ -40,7 +40,7 @@
<activity
android:name=".activities.SearchActivity"
android:label="@string/search"
android:label=""
android:parentActivityName=".activities.MainActivity"
android:resizeableActivity="true">

View File

@ -8,9 +8,11 @@ import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.extensions.messagesDB
import kotlinx.android.synthetic.main.activity_search.*
class SearchActivity : SimpleActivity() {
private var mIsSearchOpen = false
@ -21,12 +23,12 @@ class SearchActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_search)
updateTextColors(search_holder)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_search, menu)
setupSearch(menu)
updateMenuItemColors(menu)
return true
}
@ -45,6 +47,7 @@ class SearchActivity : SimpleActivity() {
if (mIsSearchOpen) {
mIsSearchOpen = false
mLastSearchedText = ""
finish()
}
return true
}
@ -69,8 +72,20 @@ class SearchActivity : SimpleActivity() {
}
private fun textChanged(text: String) {
ensureBackgroundThread {
val messages = messagesDB.getMessagesWithText("%$text%")
search_placeholder_2.beGoneIf(text.length >= 2)
if (text.length >= 2) {
ensureBackgroundThread {
val messages = messagesDB.getMessagesWithText("%$text%")
if (text == mLastSearchedText) {
runOnUiThread {
search_results_list.beVisibleIf(messages.isNotEmpty())
search_placeholder.beVisibleIf(messages.isEmpty())
}
}
}
} else {
search_placeholder.beVisible()
search_results_list.beGone()
}
}
}

View File

@ -1,5 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/search_holder"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/search_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/activity_margin"
android:alpha="0.8"
android:gravity="center"
android:paddingStart="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin"
android:text="@string/no_items_found"
android:textSize="@dimen/bigger_text_size"
android:textStyle="italic" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/search_placeholder_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/search_placeholder"
android:layout_centerHorizontal="true"
android:alpha="0.8"
android:gravity="center"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingEnd="@dimen/activity_margin"
android:paddingBottom="@dimen/medium_margin"
android:text="@string/type_2_characters"
android:textSize="@dimen/bigger_text_size"
android:textStyle="italic" />
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/search_results_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical"
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
</RelativeLayout>