mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Remove dead keyboard code after refresh.
This commit is contained in:
committed by
Greyson Parrelli
parent
7419570f94
commit
c54c6018b2
@@ -11,7 +11,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiKeyboardProvider
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiEventListener
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageView
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageViewGridAdapter
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageViewGridAdapter.EmojiHeader
|
||||
@@ -22,14 +22,14 @@ import java.util.Optional
|
||||
|
||||
private val DELETE_KEY_EVENT: KeyEvent = KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)
|
||||
|
||||
class EmojiKeyboardPageFragment : Fragment(R.layout.keyboard_pager_emoji_page_fragment), EmojiKeyboardProvider.EmojiEventListener, EmojiPageViewGridAdapter.VariationSelectorListener {
|
||||
class EmojiKeyboardPageFragment : Fragment(R.layout.keyboard_pager_emoji_page_fragment), EmojiEventListener, EmojiPageViewGridAdapter.VariationSelectorListener {
|
||||
|
||||
private lateinit var viewModel: EmojiKeyboardPageViewModel
|
||||
private lateinit var emojiPageView: EmojiPageView
|
||||
private lateinit var searchView: View
|
||||
private lateinit var emojiCategoriesRecycler: RecyclerView
|
||||
private lateinit var backspaceView: View
|
||||
private lateinit var eventListener: EmojiKeyboardProvider.EmojiEventListener
|
||||
private lateinit var eventListener: EmojiEventListener
|
||||
private lateinit var callback: Callback
|
||||
private lateinit var categoriesAdapter: EmojiKeyboardPageCategoriesAdapter
|
||||
private lateinit var searchBar: KeyboardPageSearchView
|
||||
|
||||
@@ -2,15 +2,15 @@ package org.thoughtcrime.securesms.keyboard.emoji
|
||||
|
||||
import android.content.Context
|
||||
import org.signal.core.util.concurrent.SignalExecutors
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiKeyboardProvider
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageModel
|
||||
import org.thoughtcrime.securesms.components.emoji.RecentEmojiPageModel
|
||||
import org.thoughtcrime.securesms.emoji.EmojiSource.Companion.latest
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import java.util.function.Consumer
|
||||
|
||||
class EmojiKeyboardPageRepository(context: Context) {
|
||||
|
||||
private val recentEmojiPageModel: RecentEmojiPageModel = RecentEmojiPageModel(context, EmojiKeyboardProvider.RECENT_STORAGE_KEY)
|
||||
private val recentEmojiPageModel: RecentEmojiPageModel = RecentEmojiPageModel(context, TextSecurePreferences.RECENT_STORAGE_KEY)
|
||||
|
||||
fun getEmoji(consumer: Consumer<List<EmojiPageModel>>) {
|
||||
SignalExecutors.BOUNDED.execute {
|
||||
|
||||
@@ -6,7 +6,6 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiKeyboardProvider
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageModel
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageViewGridAdapter
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageViewGridAdapter.EmojiHeader
|
||||
@@ -19,6 +18,7 @@ import org.thoughtcrime.securesms.keyboard.emoji.EmojiKeyboardPageCategoryMappin
|
||||
import org.thoughtcrime.securesms.util.DefaultValueLiveData
|
||||
import org.thoughtcrime.securesms.util.MappingModel
|
||||
import org.thoughtcrime.securesms.util.MappingModelList
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil
|
||||
|
||||
class EmojiKeyboardPageViewModel(repository: EmojiKeyboardPageRepository) : ViewModel() {
|
||||
@@ -70,12 +70,12 @@ class EmojiKeyboardPageViewModel(repository: EmojiKeyboardPageRepository) : View
|
||||
}
|
||||
|
||||
fun addToRecents(emoji: String) {
|
||||
RecentEmojiPageModel(ApplicationDependencies.getApplication(), EmojiKeyboardProvider.RECENT_STORAGE_KEY).onCodePointSelected(emoji)
|
||||
RecentEmojiPageModel(ApplicationDependencies.getApplication(), TextSecurePreferences.RECENT_STORAGE_KEY).onCodePointSelected(emoji)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getStartingTab(): String {
|
||||
return if (RecentEmojiPageModel.hasRecents(ApplicationDependencies.getApplication(), EmojiKeyboardProvider.RECENT_STORAGE_KEY)) {
|
||||
return if (RecentEmojiPageModel.hasRecents(ApplicationDependencies.getApplication(), TextSecurePreferences.RECENT_STORAGE_KEY)) {
|
||||
RecentEmojiPageModel.KEY
|
||||
} else {
|
||||
EmojiCategory.PEOPLE.key
|
||||
|
||||
@@ -11,7 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiKeyboardProvider
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiEventListener
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageView
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageViewGridAdapter
|
||||
import org.thoughtcrime.securesms.keyboard.emoji.KeyboardPageSearchView
|
||||
@@ -36,7 +36,7 @@ class EmojiSearchFragment : Fragment(R.layout.emoji_search_fragment), EmojiPageV
|
||||
viewModel = ViewModelProviders.of(this, factory)[EmojiSearchViewModel::class.java]
|
||||
|
||||
val keyboardAwareLinearLayout: KeyboardAwareLinearLayout = view.findViewById(R.id.kb_aware_layout)
|
||||
val eventListener: EmojiKeyboardProvider.EmojiEventListener = requireNotNull(findListener())
|
||||
val eventListener: EmojiEventListener = requireNotNull(findListener())
|
||||
val searchBar: KeyboardPageSearchView = view.findViewById(R.id.emoji_search_view)
|
||||
val resultsContainer: FrameLayout = view.findViewById(R.id.emoji_search_results_container)
|
||||
val noResults: TextView = view.findViewById(R.id.emoji_search_empty)
|
||||
|
||||
@@ -4,12 +4,12 @@ import android.content.Context
|
||||
import android.net.Uri
|
||||
import org.signal.core.util.concurrent.SignalExecutors
|
||||
import org.thoughtcrime.securesms.components.emoji.Emoji
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiKeyboardProvider
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageModel
|
||||
import org.thoughtcrime.securesms.components.emoji.RecentEmojiPageModel
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.EmojiSearchDatabase
|
||||
import org.thoughtcrime.securesms.emoji.EmojiSource
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import java.util.function.Consumer
|
||||
|
||||
private const val MINIMUM_QUERY_THRESHOLD = 1
|
||||
@@ -21,7 +21,7 @@ class EmojiSearchRepository(private val context: Context) {
|
||||
|
||||
fun submitQuery(query: String, includeRecents: Boolean, limit: Int = EMOJI_SEARCH_LIMIT, consumer: Consumer<EmojiPageModel>) {
|
||||
if (query.length < MINIMUM_QUERY_THRESHOLD && includeRecents) {
|
||||
consumer.accept(RecentEmojiPageModel(context, EmojiKeyboardProvider.RECENT_STORAGE_KEY))
|
||||
consumer.accept(RecentEmojiPageModel(context, TextSecurePreferences.RECENT_STORAGE_KEY))
|
||||
} else {
|
||||
SignalExecutors.SERIAL.execute {
|
||||
val emoji: List<String> = emojiSearchDatabase.query(query, limit)
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.thoughtcrime.securesms.util.MappingAdapter
|
||||
import org.thoughtcrime.securesms.util.MappingModel
|
||||
import org.thoughtcrime.securesms.util.MappingViewHolder
|
||||
|
||||
class StickerPackListAdapter(private val glideRequests: GlideRequests, private val allowApngAnimation: Boolean, private val onTabSelected: (StickerPack) -> Unit) : MappingAdapter() {
|
||||
class KeyboardStickerPackListAdapter(private val glideRequests: GlideRequests, private val allowApngAnimation: Boolean, private val onTabSelected: (StickerPack) -> Unit) : MappingAdapter() {
|
||||
|
||||
init {
|
||||
registerFactory(StickerPack::class.java, LayoutFactory(::StickerPackViewHolder, R.layout.keyboard_pager_category_icon))
|
||||
@@ -17,7 +17,7 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.keyboard.emoji.KeyboardPageSearchView
|
||||
import org.thoughtcrime.securesms.keyboard.findListener
|
||||
import org.thoughtcrime.securesms.mms.GlideApp
|
||||
import org.thoughtcrime.securesms.stickers.StickerKeyboardProvider.StickerEventListener
|
||||
import org.thoughtcrime.securesms.stickers.StickerEventListener
|
||||
import org.thoughtcrime.securesms.stickers.StickerRolloverTouchListener
|
||||
import org.thoughtcrime.securesms.stickers.StickerRolloverTouchListener.RolloverStickerRetriever
|
||||
import org.thoughtcrime.securesms.util.DeviceProperties
|
||||
@@ -36,12 +36,12 @@ class StickerKeyboardPageFragment :
|
||||
View.OnLayoutChangeListener {
|
||||
|
||||
private lateinit var stickerList: RecyclerView
|
||||
private lateinit var keyboardStickerListAdapter: KeyboardStickerListAdapter
|
||||
private lateinit var stickerListAdapter: KeyboardStickerListAdapter
|
||||
private lateinit var layoutManager: GridLayoutManager
|
||||
private lateinit var listTouchListener: StickerRolloverTouchListener
|
||||
private lateinit var stickerPacksRecycler: RecyclerView
|
||||
private lateinit var appBarLayout: AppBarLayout
|
||||
private lateinit var stickerPacksAdapter: StickerPackListAdapter
|
||||
private lateinit var stickerPacksAdapter: KeyboardStickerPackListAdapter
|
||||
|
||||
private lateinit var viewModel: StickerKeyboardPageViewModel
|
||||
|
||||
@@ -53,11 +53,11 @@ class StickerKeyboardPageFragment :
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val glideRequests = GlideApp.with(this)
|
||||
keyboardStickerListAdapter = KeyboardStickerListAdapter(glideRequests, this, DeviceProperties.shouldAllowApngStickerAnimation(requireContext()))
|
||||
stickerListAdapter = KeyboardStickerListAdapter(glideRequests, this, DeviceProperties.shouldAllowApngStickerAnimation(requireContext()))
|
||||
layoutManager = GridLayoutManager(requireContext(), 2).apply {
|
||||
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
|
||||
override fun getSpanSize(position: Int): Int {
|
||||
val model: Optional<MappingModel<*>> = keyboardStickerListAdapter.getModel(position)
|
||||
val model: Optional<MappingModel<*>> = stickerListAdapter.getModel(position)
|
||||
if (model.isPresent && model.get() is KeyboardStickerListAdapter.StickerHeader) {
|
||||
return spanCount
|
||||
}
|
||||
@@ -69,13 +69,13 @@ class StickerKeyboardPageFragment :
|
||||
|
||||
stickerList = view.findViewById(R.id.sticker_keyboard_list)
|
||||
stickerList.layoutManager = layoutManager
|
||||
stickerList.adapter = keyboardStickerListAdapter
|
||||
stickerList.adapter = stickerListAdapter
|
||||
stickerList.addOnItemTouchListener(listTouchListener)
|
||||
stickerList.addOnScrollListener(packIdSelectionOnScroll)
|
||||
|
||||
stickerPacksRecycler = view.findViewById(R.id.sticker_packs_recycler)
|
||||
|
||||
stickerPacksAdapter = StickerPackListAdapter(glideRequests, DeviceProperties.shouldAllowApngStickerAnimation(requireContext()), this::onTabSelected)
|
||||
stickerPacksAdapter = KeyboardStickerPackListAdapter(glideRequests, DeviceProperties.shouldAllowApngStickerAnimation(requireContext()), this::onTabSelected)
|
||||
stickerPacksRecycler.adapter = stickerPacksAdapter
|
||||
|
||||
appBarLayout = view.findViewById(R.id.sticker_keyboard_search_appbar)
|
||||
@@ -106,21 +106,21 @@ class StickerKeyboardPageFragment :
|
||||
viewModel = ViewModelProviders.of(requireActivity(), StickerKeyboardPageViewModel.Factory(requireContext()))
|
||||
.get(StickerKeyboardPageViewModel::class.java)
|
||||
|
||||
viewModel.stickers.observe(viewLifecycleOwner, keyboardStickerListAdapter::submitList)
|
||||
viewModel.stickers.observe(viewLifecycleOwner, stickerListAdapter::submitList)
|
||||
viewModel.packs.observe(viewLifecycleOwner, stickerPacksAdapter::submitList)
|
||||
viewModel.getSelectedPack().observe(viewLifecycleOwner, this::updateCategoryTab)
|
||||
|
||||
viewModel.refreshStickers()
|
||||
}
|
||||
|
||||
private fun onTabSelected(stickerPack: StickerPackListAdapter.StickerPack) {
|
||||
private fun onTabSelected(stickerPack: KeyboardStickerPackListAdapter.StickerPack) {
|
||||
scrollTo(stickerPack.packRecord.packId)
|
||||
viewModel.selectPack(stickerPack.packRecord.packId)
|
||||
}
|
||||
|
||||
private fun updateCategoryTab(packId: String) {
|
||||
stickerPacksRecycler.post {
|
||||
val index: Int = stickerPacksAdapter.indexOfFirst(StickerPackListAdapter.StickerPack::class.java) { it.packRecord.packId == packId }
|
||||
val index: Int = stickerPacksAdapter.indexOfFirst(KeyboardStickerPackListAdapter.StickerPack::class.java) { it.packRecord.packId == packId }
|
||||
|
||||
if (index != -1) {
|
||||
stickerPacksRecycler.smoothScrollToPosition(index)
|
||||
@@ -129,7 +129,7 @@ class StickerKeyboardPageFragment :
|
||||
}
|
||||
|
||||
private fun scrollTo(packId: String) {
|
||||
val index = keyboardStickerListAdapter.indexOfFirst(KeyboardStickerListAdapter.StickerHeader::class.java) { it.packId == packId }
|
||||
val index = stickerListAdapter.indexOfFirst(KeyboardStickerListAdapter.StickerHeader::class.java) { it.packId == packId }
|
||||
if (index != -1) {
|
||||
appBarLayout.setExpanded(false, true)
|
||||
packIdSelectionOnScroll.startAutoScrolling()
|
||||
@@ -163,7 +163,7 @@ class StickerKeyboardPageFragment :
|
||||
|
||||
override fun getStickerDataFromView(view: View): Pair<Any, String>? {
|
||||
val position: Int = stickerList.getChildAdapterPosition(view)
|
||||
val model: Optional<MappingModel<*>> = keyboardStickerListAdapter.getModel(position)
|
||||
val model: Optional<MappingModel<*>> = stickerListAdapter.getModel(position)
|
||||
if (model.isPresent && model.get() is KeyboardStickerListAdapter.Sticker) {
|
||||
val sticker = model.get() as KeyboardStickerListAdapter.Sticker
|
||||
return Pair(sticker.uri, sticker.stickerRecord.emoji)
|
||||
@@ -216,7 +216,7 @@ class StickerKeyboardPageFragment :
|
||||
|
||||
val layoutManager = recyclerView.layoutManager as LinearLayoutManager
|
||||
val index = layoutManager.findFirstCompletelyVisibleItemPosition()
|
||||
val item: Optional<MappingModel<*>> = keyboardStickerListAdapter.getModel(index)
|
||||
val item: Optional<MappingModel<*>> = stickerListAdapter.getModel(index)
|
||||
if (item.isPresent && item.get() is KeyboardStickerListAdapter.HasPackId) {
|
||||
viewModel.selectPack((item.get() as KeyboardStickerListAdapter.HasPackId).packId)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.keyboard.sticker.StickerPackListAdapter.StickerPack
|
||||
import org.thoughtcrime.securesms.keyboard.sticker.KeyboardStickerPackListAdapter.StickerPack
|
||||
import org.thoughtcrime.securesms.util.MappingModelList
|
||||
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.thoughtcrime.securesms.keyboard.sticker
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Point
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -13,25 +11,23 @@ import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.database.model.StickerRecord
|
||||
import org.thoughtcrime.securesms.keyboard.emoji.KeyboardPageSearchView
|
||||
import org.thoughtcrime.securesms.keyboard.findListener
|
||||
import org.thoughtcrime.securesms.mms.GlideApp
|
||||
import org.thoughtcrime.securesms.stickers.StickerKeyboardPageAdapter
|
||||
import org.thoughtcrime.securesms.stickers.StickerKeyboardProvider
|
||||
import org.thoughtcrime.securesms.stickers.StickerEventListener
|
||||
import org.thoughtcrime.securesms.util.DeviceProperties
|
||||
import org.thoughtcrime.securesms.util.ViewUtil
|
||||
|
||||
/**
|
||||
* Search dialog for finding stickers.
|
||||
*/
|
||||
class StickerSearchDialogFragment : DialogFragment(), StickerKeyboardPageAdapter.EventListener {
|
||||
class StickerSearchDialogFragment : DialogFragment(), KeyboardStickerListAdapter.EventListener, View.OnLayoutChangeListener {
|
||||
|
||||
private lateinit var search: KeyboardPageSearchView
|
||||
private lateinit var list: RecyclerView
|
||||
private lateinit var noResults: View
|
||||
|
||||
private lateinit var adapter: StickerKeyboardPageAdapter
|
||||
private lateinit var adapter: KeyboardStickerListAdapter
|
||||
private lateinit var layoutManager: GridLayoutManager
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -49,19 +45,17 @@ class StickerSearchDialogFragment : DialogFragment(), StickerKeyboardPageAdapter
|
||||
list = view.findViewById(R.id.sticker_search_list)
|
||||
noResults = view.findViewById(R.id.sticker_search_no_results)
|
||||
|
||||
adapter = StickerKeyboardPageAdapter(GlideApp.with(this), this, DeviceProperties.shouldAllowApngStickerAnimation(requireContext()))
|
||||
adapter = KeyboardStickerListAdapter(GlideApp.with(this), this, DeviceProperties.shouldAllowApngStickerAnimation(requireContext()))
|
||||
layoutManager = GridLayoutManager(requireContext(), 2)
|
||||
|
||||
list.layoutManager = layoutManager
|
||||
list.adapter = adapter
|
||||
|
||||
onScreenWidthChanged(getScreenWidth())
|
||||
|
||||
val viewModel: StickerSearchViewModel = ViewModelProviders.of(this, StickerSearchViewModel.Factory(requireContext())).get(StickerSearchViewModel::class.java)
|
||||
|
||||
viewModel.searchResults.observe(viewLifecycleOwner) { stickerRecords ->
|
||||
adapter.setStickers(stickerRecords, calculateStickerSize(getScreenWidth()))
|
||||
noResults.visibility = if (stickerRecords.isEmpty()) View.VISIBLE else View.GONE
|
||||
viewModel.searchResults.observe(viewLifecycleOwner) { stickers ->
|
||||
adapter.submitList(stickers)
|
||||
noResults.visibility = if (stickers.isEmpty()) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
search.enableBackNavigation()
|
||||
@@ -77,22 +71,12 @@ class StickerSearchDialogFragment : DialogFragment(), StickerKeyboardPageAdapter
|
||||
}
|
||||
|
||||
search.requestFocus()
|
||||
|
||||
view.addOnLayoutChangeListener(this)
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
onScreenWidthChanged(getScreenWidth())
|
||||
}
|
||||
|
||||
private fun onScreenWidthChanged(@Px newWidth: Int) {
|
||||
layoutManager.spanCount = calculateColumnCount(newWidth)
|
||||
adapter.setStickerSize(calculateStickerSize(newWidth))
|
||||
}
|
||||
|
||||
private fun getScreenWidth(): Int {
|
||||
val size = Point()
|
||||
requireActivity().windowManager.defaultDisplay.getSize(size)
|
||||
return size.x
|
||||
override fun onLayoutChange(v: View?, left: Int, top: Int, right: Int, bottom: Int, oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int) {
|
||||
layoutManager.spanCount = calculateColumnCount(view?.width ?: 0)
|
||||
}
|
||||
|
||||
private fun calculateColumnCount(@Px screenWidth: Int): Int {
|
||||
@@ -101,23 +85,17 @@ class StickerSearchDialogFragment : DialogFragment(), StickerKeyboardPageAdapter
|
||||
return ((screenWidth - modifier) / divisor).toInt()
|
||||
}
|
||||
|
||||
private fun calculateStickerSize(@Px screenWidth: Int): Int {
|
||||
val multiplier = resources.getDimensionPixelOffset(R.dimen.sticker_page_item_multiplier).toFloat()
|
||||
val columnCount = calculateColumnCount(screenWidth)
|
||||
return ((screenWidth - (columnCount + 1) * multiplier) / columnCount).toInt()
|
||||
override fun onStickerClicked(sticker: KeyboardStickerListAdapter.Sticker) {
|
||||
ViewUtil.hideKeyboard(requireContext(), requireView())
|
||||
findListener<StickerEventListener>()?.onStickerSelected(sticker.stickerRecord)
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
|
||||
override fun onStickerLongClicked(sticker: KeyboardStickerListAdapter.Sticker) = Unit
|
||||
|
||||
companion object {
|
||||
fun show(fragmentManager: FragmentManager) {
|
||||
StickerSearchDialogFragment().show(fragmentManager, "TAG")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStickerClicked(sticker: StickerRecord) {
|
||||
ViewUtil.hideKeyboard(requireContext(), requireView())
|
||||
findListener<StickerKeyboardProvider.StickerEventListener>()?.onStickerSelected(sticker)
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
|
||||
override fun onStickerLongClicked(targetView: View) = Unit
|
||||
}
|
||||
|
||||
@@ -5,14 +5,16 @@ import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import org.thoughtcrime.securesms.database.model.StickerRecord
|
||||
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil
|
||||
|
||||
class StickerSearchViewModel(private val searchRepository: StickerSearchRepository) : ViewModel() {
|
||||
|
||||
private val searchQuery: MutableLiveData<String> = MutableLiveData("")
|
||||
|
||||
val searchResults: LiveData<List<StickerRecord>> = LiveDataUtil.mapAsync(searchQuery) { q -> searchRepository.search(q) }
|
||||
val searchResults: LiveData<List<KeyboardStickerListAdapter.Sticker>> = LiveDataUtil.mapAsync(searchQuery) { q ->
|
||||
searchRepository.search(q)
|
||||
.map { KeyboardStickerListAdapter.Sticker(it.packId, it) }
|
||||
}
|
||||
|
||||
fun query(query: String) {
|
||||
searchQuery.postValue(query)
|
||||
|
||||
Reference in New Issue
Block a user