adding more search related functionality
This commit is contained in:
parent
7048b7bcb5
commit
131b1a44c3
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.SearchActivity"
|
android:name=".activities.SearchActivity"
|
||||||
android:label="@string/search"
|
android:label=""
|
||||||
android:parentActivityName=".activities.MainActivity"
|
android:parentActivityName=".activities.MainActivity"
|
||||||
android:resizeableActivity="true">
|
android:resizeableActivity="true">
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,11 @@ import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.core.view.MenuItemCompat
|
import androidx.core.view.MenuItemCompat
|
||||||
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
import com.simplemobiletools.smsmessenger.extensions.messagesDB
|
import com.simplemobiletools.smsmessenger.extensions.messagesDB
|
||||||
|
import kotlinx.android.synthetic.main.activity_search.*
|
||||||
|
|
||||||
class SearchActivity : SimpleActivity() {
|
class SearchActivity : SimpleActivity() {
|
||||||
private var mIsSearchOpen = false
|
private var mIsSearchOpen = false
|
||||||
|
@ -21,12 +23,12 @@ class SearchActivity : SimpleActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_search)
|
setContentView(R.layout.activity_search)
|
||||||
|
updateTextColors(search_holder)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.menu_search, menu)
|
menuInflater.inflate(R.menu.menu_search, menu)
|
||||||
setupSearch(menu)
|
setupSearch(menu)
|
||||||
updateMenuItemColors(menu)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +47,7 @@ class SearchActivity : SimpleActivity() {
|
||||||
if (mIsSearchOpen) {
|
if (mIsSearchOpen) {
|
||||||
mIsSearchOpen = false
|
mIsSearchOpen = false
|
||||||
mLastSearchedText = ""
|
mLastSearchedText = ""
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -69,8 +72,20 @@ class SearchActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun textChanged(text: String) {
|
private fun textChanged(text: String) {
|
||||||
ensureBackgroundThread {
|
search_placeholder_2.beGoneIf(text.length >= 2)
|
||||||
val messages = messagesDB.getMessagesWithText("%$text%")
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,46 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<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:id="@+id/search_holder"
|
||||||
android:layout_width="match_parent"
|
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>
|
||||||
|
|
Loading…
Reference in New Issue