Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 6c691268 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #6289 from thundernest/fix_search_view_in_message_list

Fix search view in message list
parents df50ff50 60e33e52
Loading
Loading
Loading
Loading
+40 −4
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@ import android.view.animation.AnimationUtils
import android.widget.ProgressBar
import android.widget.ProgressBar
import android.widget.Toast
import android.widget.Toast
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.ActionBar
import androidx.appcompat.view.ActionMode
import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.Toolbar
import androidx.appcompat.widget.Toolbar
import androidx.drawerlayout.widget.DrawerLayout
import androidx.drawerlayout.widget.DrawerLayout
@@ -100,6 +101,9 @@ open class MessageList :


    private lateinit var actionBar: ActionBar
    private lateinit var actionBar: ActionBar
    private lateinit var searchView: SearchView
    private lateinit var searchView: SearchView
    private var initialSearchViewQuery: String? = null
    private var initialSearchViewIconified: Boolean = true

    private var drawer: K9Drawer? = null
    private var drawer: K9Drawer? = null
    private var openFolderTransaction: FragmentTransaction? = null
    private var openFolderTransaction: FragmentTransaction? = null
    private var progressBar: ProgressBar? = null
    private var progressBar: ProgressBar? = null
@@ -573,6 +577,8 @@ open class MessageList :
        outState.putSerializable(STATE_DISPLAY_MODE, displayMode)
        outState.putSerializable(STATE_DISPLAY_MODE, displayMode)
        outState.putBoolean(STATE_MESSAGE_VIEW_ONLY, messageViewOnly)
        outState.putBoolean(STATE_MESSAGE_VIEW_ONLY, messageViewOnly)
        outState.putBoolean(STATE_MESSAGE_LIST_WAS_DISPLAYED, messageListWasDisplayed)
        outState.putBoolean(STATE_MESSAGE_LIST_WAS_DISPLAYED, messageListWasDisplayed)
        outState.putBoolean(STATE_SEARCH_VIEW_ICONIFIED, searchView.isIconified)
        outState.putString(STATE_SEARCH_VIEW_QUERY, searchView.query?.toString())
    }
    }


    public override fun onRestoreInstanceState(savedInstanceState: Bundle) {
    public override fun onRestoreInstanceState(savedInstanceState: Bundle) {
@@ -580,6 +586,8 @@ open class MessageList :


        messageViewOnly = savedInstanceState.getBoolean(STATE_MESSAGE_VIEW_ONLY)
        messageViewOnly = savedInstanceState.getBoolean(STATE_MESSAGE_VIEW_ONLY)
        messageListWasDisplayed = savedInstanceState.getBoolean(STATE_MESSAGE_LIST_WAS_DISPLAYED)
        messageListWasDisplayed = savedInstanceState.getBoolean(STATE_MESSAGE_LIST_WAS_DISPLAYED)
        initialSearchViewIconified = savedInstanceState.getBoolean(STATE_SEARCH_VIEW_ICONIFIED)
        initialSearchViewQuery = savedInstanceState.getString(STATE_SEARCH_VIEW_QUERY)
    }
    }


    private fun initializeActionBar() {
    private fun initializeActionBar() {
@@ -708,7 +716,7 @@ open class MessageList :
                showMessageList()
                showMessageList()
            }
            }
        } else if (this::searchView.isInitialized && !searchView.isIconified) {
        } else if (this::searchView.isInitialized && !searchView.isIconified) {
            searchView.isIconified = true
            collapseSearchView()
        } else {
        } else {
            if (isDrawerEnabled && account != null && supportFragmentManager.backStackEntryCount == 0) {
            if (isDrawerEnabled && account != null && supportFragmentManager.backStackEntryCount == 0) {
                if (K9.isShowUnifiedInbox) {
                if (K9.isShowUnifiedInbox) {
@@ -918,6 +926,7 @@ open class MessageList :
                    if (drawer!!.isOpen) {
                    if (drawer!!.isOpen) {
                        drawer!!.close()
                        drawer!!.close()
                    } else {
                    } else {
                        collapseSearchView()
                        drawer!!.open()
                        drawer!!.open()
                    }
                    }
                } else {
                } else {
@@ -935,16 +944,28 @@ open class MessageList :
    override fun onCreateOptionsMenu(menu: Menu): Boolean {
    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        menuInflater.inflate(R.menu.message_list_option, menu)
        menuInflater.inflate(R.menu.message_list_option, menu)


        // setup search view
        val searchItem = menu.findItem(R.id.search)
        val searchItem = menu.findItem(R.id.search)
        initializeSearchMenuItem(searchItem)

        return true
    }

    private fun initializeSearchMenuItem(searchItem: MenuItem) {
        // Reuse existing SearchView if available
        if (::searchView.isInitialized) {
            searchItem.actionView = searchView
            return
        }

        searchView = searchItem.actionView as SearchView
        searchView = searchItem.actionView as SearchView
        searchView.maxWidth = Int.MAX_VALUE
        searchView.maxWidth = Int.MAX_VALUE
        searchView.queryHint = resources.getString(R.string.search_action)
        searchView.queryHint = resources.getString(R.string.search_action)
        val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
        val searchManager = getSystemService(SEARCH_SERVICE) as SearchManager
        searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName))
        searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName))
        searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
        searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
            override fun onQueryTextSubmit(query: String): Boolean {
            override fun onQueryTextSubmit(query: String): Boolean {
                messageListFragment?.onSearchRequested(query)
                messageListFragment?.onSearchRequested(query)
                collapseSearchView()
                return true
                return true
            }
            }


@@ -953,7 +974,13 @@ open class MessageList :
            }
            }
        })
        })


        return true
        searchView.isIconified = initialSearchViewIconified
        searchView.setQuery(initialSearchViewQuery, false)
    }

    private fun collapseSearchView() {
        searchView.setQuery(null, false)
        searchView.isIconified = true
    }
    }


    fun setActionBarTitle(title: String, subtitle: String? = null) {
    fun setActionBarTitle(title: String, subtitle: String? = null) {
@@ -1000,6 +1027,8 @@ open class MessageList :
                showMessageView()
                showMessageView()
            }
            }
        }
        }

        collapseSearchView()
    }
    }


    override fun onForward(messageReference: MessageReference, decryptionResultForReply: Parcelable?) {
    override fun onForward(messageReference: MessageReference, decryptionResultForReply: Parcelable?) {
@@ -1082,6 +1111,11 @@ open class MessageList :
        return true
        return true
    }
    }


    override fun startSupportActionMode(callback: ActionMode.Callback): ActionMode? {
        collapseSearchView()
        return super.startSupportActionMode(callback)
    }

    override fun showThread(account: Account, threadRootId: Long) {
    override fun showThread(account: Account, threadRootId: Long) {
        showMessageViewPlaceHolder()
        showMessageViewPlaceHolder()


@@ -1391,6 +1425,8 @@ open class MessageList :
        private const val STATE_DISPLAY_MODE = "displayMode"
        private const val STATE_DISPLAY_MODE = "displayMode"
        private const val STATE_MESSAGE_VIEW_ONLY = "messageViewOnly"
        private const val STATE_MESSAGE_VIEW_ONLY = "messageViewOnly"
        private const val STATE_MESSAGE_LIST_WAS_DISPLAYED = "messageListWasDisplayed"
        private const val STATE_MESSAGE_LIST_WAS_DISPLAYED = "messageListWasDisplayed"
        private const val STATE_SEARCH_VIEW_ICONIFIED = "searchViewIconified"
        private const val STATE_SEARCH_VIEW_QUERY = "searchViewQuery"


        private const val FIRST_FRAGMENT_TRANSACTION = "first"
        private const val FIRST_FRAGMENT_TRANSACTION = "first"
        private const val FRAGMENT_TAG_MESSAGE_VIEW_CONTAINER = "MessageViewContainerFragment"
        private const val FRAGMENT_TAG_MESSAGE_VIEW_CONTAINER = "MessageViewContainerFragment"
+2 −3
Original line number Original line Diff line number Diff line
@@ -17,7 +17,6 @@ import android.widget.AdapterView.OnItemLongClickListener
import android.widget.ListView
import android.widget.ListView
import android.widget.TextView
import android.widget.TextView
import android.widget.Toast
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode
import androidx.appcompat.view.ActionMode
import androidx.core.os.bundleOf
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.Fragment
@@ -1534,8 +1533,7 @@ class MessageListFragment :
    }
    }


    private fun startAndPrepareActionMode() {
    private fun startAndPrepareActionMode() {
        val activity = requireActivity() as AppCompatActivity
        actionMode = fragmentListener.startSupportActionMode(actionModeCallback)
        actionMode = activity.startSupportActionMode(actionModeCallback)
        actionMode?.invalidate()
        actionMode?.invalidate()
    }
    }


@@ -2003,6 +2001,7 @@ class MessageListFragment :
        fun setMessageListTitle(title: String, subtitle: String?)
        fun setMessageListTitle(title: String, subtitle: String?)
        fun onCompose(account: Account?)
        fun onCompose(account: Account?)
        fun startSearch(query: String, account: Account?, folderId: Long?): Boolean
        fun startSearch(query: String, account: Account?, folderId: Long?): Boolean
        fun startSupportActionMode(callback: ActionMode.Callback): ActionMode?
        fun goBack()
        fun goBack()
        fun onFolderNotFoundError()
        fun onFolderNotFoundError()