Add support for time stickers in image editor.

This commit is contained in:
Clark
2023-03-30 11:26:56 -04:00
committed by Alex Hart
parent 08ebca501b
commit 28f27915c5
29 changed files with 1254 additions and 23 deletions

View File

@@ -62,7 +62,7 @@ class KeyboardStickerListAdapter(
}
}
data class StickerHeader(override val packId: String, private val title: String?, private val titleResource: Int?) : MappingModel<StickerHeader>, HasPackId {
data class StickerHeader(override val packId: String, private val title: String?, private val titleResource: Int?) : MappingModel<StickerHeader>, HasPackId, Header {
fun getTitle(context: Context): String {
return title ?: context.resources.getString(titleResource ?: R.string.StickerManagementAdapter_untitled)
}
@@ -85,6 +85,7 @@ class KeyboardStickerListAdapter(
}
}
interface Header
interface HasPackId {
val packId: String
}

View File

@@ -31,7 +31,7 @@ import java.util.Optional
import kotlin.math.abs
import kotlin.math.max
class StickerKeyboardPageFragment :
open class StickerKeyboardPageFragment :
LoggingFragment(R.layout.keyboard_pager_sticker_page_fragment),
KeyboardStickerListAdapter.EventListener,
StickerRolloverTouchListener.RolloverEventListener,
@@ -39,9 +39,9 @@ class StickerKeyboardPageFragment :
DatabaseObserver.Observer,
View.OnLayoutChangeListener {
private lateinit var stickerList: RecyclerView
private lateinit var stickerListAdapter: KeyboardStickerListAdapter
private lateinit var layoutManager: GridLayoutManager
protected lateinit var stickerList: RecyclerView
protected lateinit var stickerListAdapter: KeyboardStickerListAdapter
protected lateinit var layoutManager: GridLayoutManager
private lateinit var listTouchListener: StickerRolloverTouchListener
private lateinit var stickerPacksRecycler: RecyclerView
private lateinit var appBarLayout: AppBarLayout
@@ -63,7 +63,7 @@ class StickerKeyboardPageFragment :
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
val model: Optional<MappingModel<*>> = stickerListAdapter.getModel(position)
if (model.isPresent && model.get() is KeyboardStickerListAdapter.StickerHeader) {
if (model.isPresent && model.get() is KeyboardStickerListAdapter.Header) {
return spanCount
}
return 1
@@ -124,15 +124,19 @@ class StickerKeyboardPageFragment :
viewModel.refreshStickers()
}
private fun updateStickerList(stickers: MappingModelList) {
open fun updateStickerList(stickers: MappingModelList) {
if (firstLoad) {
stickerListAdapter.submitList(stickers) { layoutManager.scrollToPositionWithOffset(1, 0) }
stickerListAdapter.submitList(stickers, this::scrollOnLoad)
firstLoad = false
} else {
stickerListAdapter.submitList(stickers)
}
}
open fun scrollOnLoad() {
layoutManager.scrollToPositionWithOffset(1, 0)
}
private fun onTabSelected(stickerPack: KeyboardStickerPackListAdapter.StickerPack) {
scrollTo(stickerPack.packRecord.packId)
viewModel.selectPack(stickerPack.packRecord.packId)