mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Tweak sizes and padding of various keyboard elements.
This commit is contained in:
committed by
Greyson Parrelli
parent
55c69cd50a
commit
916006e664
@@ -85,7 +85,7 @@ class EmojiKeyboardPageFragment : Fragment(R.layout.keyboard_pager_emoji_page_fr
|
||||
}
|
||||
|
||||
viewModel.pages.observe(viewLifecycleOwner) { pages ->
|
||||
emojiPageView.setList(pages)
|
||||
emojiPageView.setList(pages) { (emojiPageView.layoutManager as? LinearLayoutManager)?.scrollToPositionWithOffset(1, 0) }
|
||||
}
|
||||
|
||||
viewModel.selectedKey.observe(viewLifecycleOwner) { updateCategoryTab(it) }
|
||||
|
||||
@@ -56,7 +56,7 @@ class EmojiSearchFragment : Fragment(R.layout.emoji_search_fragment), EmojiPageV
|
||||
searchBar.callbacks = SearchCallbacks()
|
||||
|
||||
viewModel.emojiList.observe(viewLifecycleOwner) { results ->
|
||||
emojiPageView.setList(results.emojiList)
|
||||
emojiPageView.setList(results.emojiList, null)
|
||||
|
||||
if (results.emojiList.isNotEmpty() || results.isRecents) {
|
||||
emojiPageView.visibility = View.VISIBLE
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.thoughtcrime.securesms.keyboard.sticker
|
||||
|
||||
import android.graphics.Rect
|
||||
import android.view.View
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.thoughtcrime.securesms.util.InsetItemDecoration
|
||||
import org.thoughtcrime.securesms.util.ViewUtil
|
||||
|
||||
private val horizontalInset: Int = ViewUtil.dpToPx(8)
|
||||
private val verticalInset: Int = ViewUtil.dpToPx(8)
|
||||
|
||||
/**
|
||||
* Set insets for sticker items in a [RecyclerView]. For use in [InsetItemDecoration].
|
||||
*/
|
||||
class StickerInsetSetter : InsetItemDecoration.SetInset() {
|
||||
override fun setInset(outRect: Rect, view: View, parent: RecyclerView) {
|
||||
val isHeader = view.javaClass == AppCompatTextView::class.java
|
||||
|
||||
outRect.left = horizontalInset
|
||||
outRect.right = horizontalInset
|
||||
outRect.top = verticalInset
|
||||
outRect.bottom = if (isHeader) 0 else verticalInset
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,14 @@ 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
|
||||
import org.thoughtcrime.securesms.util.InsetItemDecoration
|
||||
import org.thoughtcrime.securesms.util.MappingModel
|
||||
import org.thoughtcrime.securesms.util.MappingModelList
|
||||
import org.thoughtcrime.securesms.util.Throttler
|
||||
import org.whispersystems.libsignal.util.Pair
|
||||
import java.util.Optional
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
|
||||
class StickerKeyboardPageFragment :
|
||||
LoggingFragment(R.layout.keyboard_pager_sticker_page_fragment),
|
||||
@@ -48,6 +51,7 @@ class StickerKeyboardPageFragment :
|
||||
private val packIdSelectionOnScroll: UpdatePackSelectionOnScroll = UpdatePackSelectionOnScroll()
|
||||
private val observerThrottler: Throttler = Throttler(500)
|
||||
private val stickerThrottler: Throttler = Throttler(100)
|
||||
private var firstLoad: Boolean = true
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
@@ -72,6 +76,7 @@ class StickerKeyboardPageFragment :
|
||||
stickerList.adapter = stickerListAdapter
|
||||
stickerList.addOnItemTouchListener(listTouchListener)
|
||||
stickerList.addOnScrollListener(packIdSelectionOnScroll)
|
||||
stickerList.addItemDecoration(InsetItemDecoration(StickerInsetSetter()))
|
||||
|
||||
stickerPacksRecycler = view.findViewById(R.id.sticker_packs_recycler)
|
||||
|
||||
@@ -106,13 +111,22 @@ class StickerKeyboardPageFragment :
|
||||
viewModel = ViewModelProviders.of(requireActivity(), StickerKeyboardPageViewModel.Factory(requireContext()))
|
||||
.get(StickerKeyboardPageViewModel::class.java)
|
||||
|
||||
viewModel.stickers.observe(viewLifecycleOwner, stickerListAdapter::submitList)
|
||||
viewModel.stickers.observe(viewLifecycleOwner, this::updateStickerList)
|
||||
viewModel.packs.observe(viewLifecycleOwner, stickerPacksAdapter::submitList)
|
||||
viewModel.getSelectedPack().observe(viewLifecycleOwner, this::updateCategoryTab)
|
||||
|
||||
viewModel.refreshStickers()
|
||||
}
|
||||
|
||||
private fun updateStickerList(stickers: MappingModelList) {
|
||||
if (firstLoad) {
|
||||
stickerListAdapter.submitList(stickers) { layoutManager.scrollToPositionWithOffset(1, 0) }
|
||||
firstLoad = false
|
||||
} else {
|
||||
stickerListAdapter.submitList(stickers)
|
||||
}
|
||||
}
|
||||
|
||||
private fun onTabSelected(stickerPack: KeyboardStickerPackListAdapter.StickerPack) {
|
||||
scrollTo(stickerPack.packRecord.packId)
|
||||
viewModel.selectPack(stickerPack.packRecord.packId)
|
||||
@@ -188,9 +202,8 @@ class StickerKeyboardPageFragment :
|
||||
}
|
||||
|
||||
private fun calculateColumnCount(@Px screenWidth: Int): Int {
|
||||
val modifier = resources.getDimensionPixelOffset(R.dimen.sticker_page_item_padding).toFloat()
|
||||
val divisor = resources.getDimensionPixelOffset(R.dimen.sticker_page_item_divisor).toFloat()
|
||||
return ((screenWidth - modifier) / divisor).toInt()
|
||||
val divisor = resources.getDimensionPixelOffset(R.dimen.sticker_page_item_width).toFloat() + resources.getDimensionPixelOffset(R.dimen.sticker_page_item_padding).toFloat()
|
||||
return max(1, (screenWidth / divisor).toInt())
|
||||
}
|
||||
|
||||
private inner class UpdatePackSelectionOnScroll : RecyclerView.OnScrollListener() {
|
||||
|
||||
@@ -16,7 +16,9 @@ import org.thoughtcrime.securesms.keyboard.findListener
|
||||
import org.thoughtcrime.securesms.mms.GlideApp
|
||||
import org.thoughtcrime.securesms.stickers.StickerEventListener
|
||||
import org.thoughtcrime.securesms.util.DeviceProperties
|
||||
import org.thoughtcrime.securesms.util.InsetItemDecoration
|
||||
import org.thoughtcrime.securesms.util.ViewUtil
|
||||
import kotlin.math.max
|
||||
|
||||
/**
|
||||
* Search dialog for finding stickers.
|
||||
@@ -50,6 +52,7 @@ class StickerSearchDialogFragment : DialogFragment(), KeyboardStickerListAdapter
|
||||
|
||||
list.layoutManager = layoutManager
|
||||
list.adapter = adapter
|
||||
list.addItemDecoration(InsetItemDecoration(StickerInsetSetter()))
|
||||
|
||||
val viewModel: StickerSearchViewModel = ViewModelProviders.of(this, StickerSearchViewModel.Factory(requireContext())).get(StickerSearchViewModel::class.java)
|
||||
|
||||
@@ -80,9 +83,8 @@ class StickerSearchDialogFragment : DialogFragment(), KeyboardStickerListAdapter
|
||||
}
|
||||
|
||||
private fun calculateColumnCount(@Px screenWidth: Int): Int {
|
||||
val modifier = resources.getDimensionPixelOffset(R.dimen.sticker_page_item_padding).toFloat()
|
||||
val divisor = resources.getDimensionPixelOffset(R.dimen.sticker_page_item_divisor).toFloat()
|
||||
return ((screenWidth - modifier) / divisor).toInt()
|
||||
val divisor = resources.getDimensionPixelOffset(R.dimen.sticker_page_item_width).toFloat() + resources.getDimensionPixelOffset(R.dimen.sticker_page_item_padding).toFloat()
|
||||
return max(1, (screenWidth / divisor).toInt())
|
||||
}
|
||||
|
||||
override fun onStickerClicked(sticker: KeyboardStickerListAdapter.Sticker) {
|
||||
|
||||
Reference in New Issue
Block a user