Merge pull request #5423 from arissystem-labs/issue-5384

Search view replaced and its UI and logic refactored in MessageList
This commit is contained in:
cketti 2021-08-12 17:38:37 +02:00 committed by GitHub
commit 0e28b3ac45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 15 deletions

View file

@ -17,6 +17,7 @@ import android.view.animation.AnimationUtils
import android.widget.ProgressBar
import android.widget.Toast
import androidx.appcompat.app.ActionBar
import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.Toolbar
import androidx.drawerlayout.widget.DrawerLayout
import androidx.drawerlayout.widget.DrawerLayout.DrawerListener
@ -96,6 +97,7 @@ open class MessageList :
private val permissionUiHelper: PermissionUiHelper = K9PermissionUiHelper(this)
private lateinit var actionBar: ActionBar
private lateinit var searchView: SearchView
private var drawer: K9Drawer? = null
private var openFolderTransaction: FragmentTransaction? = null
private var menu: Menu? = null
@ -668,6 +670,8 @@ open class MessageList :
drawer!!.close()
} else if (displayMode == DisplayMode.MESSAGE_VIEW && messageListWasDisplayed) {
showMessageList()
} else if (this::searchView.isInitialized && !searchView.isIconified) {
searchView.isIconified = true
} else {
if (isDrawerEnabled && account != null && supportFragmentManager.backStackEntryCount == 0) {
if (K9.isShowUnifiedInbox) {
@ -858,10 +862,6 @@ open class MessageList :
return super.onKeyUp(keyCode, event)
}
override fun onSearchRequested(): Boolean {
return messageListFragment!!.onSearchRequested()
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
val id = item.itemId
if (id == android.R.id.home) {
@ -909,9 +909,6 @@ open class MessageList :
} else if (id == R.id.select_all) {
messageListFragment!!.selectAll()
return true
} else if (id == R.id.search) {
messageListFragment!!.onSearchRequested()
return true
} else if (id == R.id.search_remote) {
messageListFragment!!.onRemoteSearch()
return true
@ -1007,6 +1004,25 @@ open class MessageList :
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.message_list_option, menu)
this.menu = menu
// setup search view
val searchItem = menu.findItem(R.id.search)
searchView = searchItem.actionView as SearchView
searchView.maxWidth = Int.MAX_VALUE
searchView.queryHint = resources.getString(R.string.search_action)
val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName))
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
messageListFragment?.onSearchRequested(query)
return true
}
override fun onQueryTextChange(s: String): Boolean {
return false
}
})
return true
}
@ -1278,19 +1294,24 @@ open class MessageList :
}
}
override fun startSearch(account: Account?, folderId: Long?): Boolean {
override fun startSearch(query: String, account: Account?, folderId: Long?): Boolean {
// If this search was started from a MessageList of a single folder, pass along that folder info
// so that we can enable remote search.
if (account != null && folderId != null) {
val appData = Bundle().apply {
val appData = if (account != null && folderId != null) {
Bundle().apply {
putString(EXTRA_SEARCH_ACCOUNT, account.uuid)
putLong(EXTRA_SEARCH_FOLDER, folderId)
}
startSearch(null, false, appData, false)
} else {
// TODO Handle the case where we're searching from within a search result.
startSearch(null, false, null, false)
null
}
val searchIntent = Intent(this, Search::class.java).apply {
action = Intent.ACTION_SEARCH
putExtra(SearchManager.QUERY, query)
putExtra(SearchManager.APP_DATA, appData)
}
startActivity(searchIntent)
return true
}

View file

@ -1413,9 +1413,9 @@ class MessageListFragment :
val isRemoteSearchAllowed: Boolean
get() = isManualSearch && !isRemoteSearch && isSingleFolderMode && account?.isAllowRemoteSearch == true
fun onSearchRequested(): Boolean {
fun onSearchRequested(query: String): Boolean {
val folderId = currentFolder?.databaseId
return fragmentListener.startSearch(account, folderId)
return fragmentListener.startSearch(query, account, folderId)
}
fun setMessageList(messageListInfo: MessageListInfo) {
@ -1897,7 +1897,7 @@ class MessageListFragment :
fun openMessage(messageReference: MessageReference)
fun setMessageListTitle(title: String, subtitle: String?)
fun onCompose(account: Account?)
fun startSearch(account: Account?, folderId: Long?): Boolean
fun startSearch(query: String, account: Account?, folderId: Long?): Boolean
fun remoteSearchStarted()
fun goBack()
fun updateMenu()

View file

@ -16,6 +16,7 @@
android:id="@+id/search"
android:icon="?attr/iconActionSearch"
app:showAsAction="always"
app:actionViewClass="androidx.appcompat.widget.SearchView"
android:title="@string/search_action"/>
<!-- MessageList -->