link event listener

This commit is contained in:
Ryan Zhao 2021-06-29 14:00:47 +10:00
parent c294262ff3
commit 628477f2fd
3 changed files with 34 additions and 5 deletions

View File

@ -13,6 +13,8 @@ import android.util.TypedValue
import android.view.* import android.view.*
import android.widget.RelativeLayout import android.widget.RelativeLayout
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders import androidx.lifecycle.ViewModelProviders
import androidx.loader.app.LoaderManager import androidx.loader.app.LoaderManager
import androidx.loader.content.Loader import androidx.loader.content.Loader
@ -47,6 +49,8 @@ import org.thoughtcrime.securesms.conversation.v2.input_bar.mentions.MentionCand
import org.thoughtcrime.securesms.conversation.v2.menus.ConversationActionModeCallback import org.thoughtcrime.securesms.conversation.v2.menus.ConversationActionModeCallback
import org.thoughtcrime.securesms.conversation.v2.menus.ConversationMenuHelper import org.thoughtcrime.securesms.conversation.v2.menus.ConversationMenuHelper
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageView import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageView
import org.thoughtcrime.securesms.conversation.v2.search.SearchBottomBar
import org.thoughtcrime.securesms.conversation.v2.search.SearchViewModel
import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.DraftDatabase import org.thoughtcrime.securesms.database.DraftDatabase
import org.thoughtcrime.securesms.database.DraftDatabase.Drafts import org.thoughtcrime.securesms.database.DraftDatabase.Drafts
@ -70,8 +74,9 @@ import kotlin.math.*
// price we pay is a bit of back and forth between the input bar and the conversation activity. // price we pay is a bit of back and forth between the input bar and the conversation activity.
class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDelegate, class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDelegate,
InputBarRecordingViewDelegate, AttachmentManager.AttachmentListener { InputBarRecordingViewDelegate, AttachmentManager.AttachmentListener, SearchBottomBar.EventListener {
private val screenWidth = Resources.getSystem().displayMetrics.widthPixels private val screenWidth = Resources.getSystem().displayMetrics.widthPixels
private var searchViewModel: SearchViewModel? = null
private var linkPreviewViewModel: LinkPreviewViewModel? = null private var linkPreviewViewModel: LinkPreviewViewModel? = null
private var threadID: Long = -1 private var threadID: Long = -1
private var actionMode: ActionMode? = null private var actionMode: ActionMode? = null
@ -151,6 +156,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
getLatestOpenGroupInfoIfNeeded() getLatestOpenGroupInfoIfNeeded()
setUpBlockedBanner() setUpBlockedBanner()
setUpLinkPreviewObserver() setUpLinkPreviewObserver()
searchBottomBar.setEventListener(this)
setUpSearchResultObserver()
scrollToFirstUnreadMessageIfNeeded() scrollToFirstUnreadMessageIfNeeded()
markAllAsRead() markAllAsRead()
} }
@ -751,9 +758,34 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
// endregion // endregion
// region Search // region Search
private fun setUpSearchResultObserver() {
val searchViewModel = ViewModelProvider(this).get(SearchViewModel::class.java)
this.searchViewModel = searchViewModel
searchViewModel.searchResults.observe(this, Observer { result: SearchViewModel.SearchResult? ->
if (result == null) return@Observer
if (result.getResults().isNotEmpty()) {
conversationRecyclerView.scrollToPosition(result.position)
val messageResult = result.getResults()[result.position]
// fragment.jumpToMessage(messageResult.messageRecipient.address, messageResult.receivedTimestampMs, Runnable { searchViewModel.onMissingResult() })
}
this.searchBottomBar.setData(result.position, result.getResults().size)
})
}
fun getSearchViewModel(): SearchViewModel? {
return this.searchViewModel
}
fun onSearchQueryUpdated(query: String?) { fun onSearchQueryUpdated(query: String?) {
adapter.onSearchQueryUpdated(query) adapter.onSearchQueryUpdated(query)
} }
override fun onSearchMoveUpPressed() {
this.searchViewModel?.onMoveUp()
}
override fun onSearchMoveDownPressed() {
this.searchViewModel?.onMoveDown()
}
// endregion // endregion
} }

View File

@ -18,7 +18,6 @@ import kotlinx.android.synthetic.main.session_logo_action_bar_content.*
import network.loki.messenger.R import network.loki.messenger.R
import org.session.libsession.utilities.ExpirationUtil import org.session.libsession.utilities.ExpirationUtil
import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.components.ConversationSearchBottomBar
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2 import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2
import org.thoughtcrime.securesms.conversation.v2.search.SearchViewModel import org.thoughtcrime.securesms.conversation.v2.search.SearchViewModel
import org.thoughtcrime.securesms.loki.utilities.getColorWithID import org.thoughtcrime.securesms.loki.utilities.getColorWithID
@ -73,7 +72,7 @@ object ConversationMenuHelper {
// Search // Search
val searchViewItem = menu.findItem(R.id.menu_search) val searchViewItem = menu.findItem(R.id.menu_search)
val searchView = searchViewItem.actionView as SearchView val searchView = searchViewItem.actionView as SearchView
val searchViewModel:SearchViewModel = ViewModelProvider(context as ConversationActivityV2).get(SearchViewModel::class.java) val searchViewModel = (context as ConversationActivityV2).getSearchViewModel()!!
val queryListener = object : OnQueryTextListener { val queryListener = object : OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean { override fun onQueryTextSubmit(query: String): Boolean {
searchViewModel.onQueryUpdated(query, threadId) searchViewModel.onQueryUpdated(query, threadId)

View File

@ -5,8 +5,6 @@ import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.RelativeLayout
import androidx.constraintlayout.widget.ConstraintLayout
import kotlinx.android.synthetic.main.view_search_bottom_bar.view.* import kotlinx.android.synthetic.main.view_search_bottom_bar.view.*
import network.loki.messenger.R import network.loki.messenger.R