mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Migrate custom emoji prefs to repo pattern (#2767)
This commit is contained in:
parent
a46065865f
commit
e29003c79d
3 changed files with 53 additions and 18 deletions
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.geeksville.mesh.ui.common
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.geeksville.mesh.android.prefs.CustomEmojiPrefs
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class EmojiPickerViewModel @Inject constructor(private val customEmojiPrefs: CustomEmojiPrefs) : ViewModel() {
|
||||
|
||||
var customEmojiFrequency: String?
|
||||
get() = customEmojiPrefs.customEmojiFrequency
|
||||
set(value) {
|
||||
customEmojiPrefs.customEmojiFrequency = value
|
||||
}
|
||||
}
|
||||
|
|
@ -28,17 +28,29 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.emoji2.emojipicker.RecentEmojiProviderAdapter
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.geeksville.mesh.ui.common.EmojiPickerViewModel
|
||||
import com.geeksville.mesh.util.CustomRecentEmojiProvider
|
||||
|
||||
@Composable
|
||||
fun EmojiPicker(onDismiss: () -> Unit = {}, onConfirm: (String) -> Unit) {
|
||||
fun EmojiPicker(
|
||||
viewModel: EmojiPickerViewModel = hiltViewModel(),
|
||||
onDismiss: () -> Unit = {},
|
||||
onConfirm: (String) -> Unit,
|
||||
) {
|
||||
Column(verticalArrangement = Arrangement.Bottom) {
|
||||
BackHandler { onDismiss() }
|
||||
AndroidView(
|
||||
factory = { context ->
|
||||
androidx.emoji2.emojipicker.EmojiPickerView(context).apply {
|
||||
clipToOutline = true
|
||||
setRecentEmojiProvider(RecentEmojiProviderAdapter(CustomRecentEmojiProvider(context)))
|
||||
setRecentEmojiProvider(
|
||||
RecentEmojiProviderAdapter(
|
||||
CustomRecentEmojiProvider(viewModel.customEmojiFrequency) { updatedValue ->
|
||||
viewModel.customEmojiFrequency = updatedValue
|
||||
},
|
||||
),
|
||||
)
|
||||
setOnEmojiPickedListener { emoji ->
|
||||
onDismiss()
|
||||
onConfirm(emoji.emoji)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue