Tag: Singh

3-step guide to adding emojis — Jetpack Emoji Picker | by Nav Singh | Sep, 2023

class CustomRecentEmojiProvider(context: Context) : RecentEmojiAsyncProvider { private val sharedPreferences by lazy {context.getSharedPreferences(RECENT_EMOJI_LIST_PREF_NAME, Context.MODE_PRIVATE)} private val emoji2Frequency: MutableMap<String, Int> by lazy {sharedPreferences.getString(CUSTOM_EMOJI_FREQ_PREF_KEY, null)?.split(SPLIT_CHAR)?.associate { entry ->entry.split(VALUE_DELIMITER, limit = 2).let { value -> value[0] to value[1].toInt() }}?.toMutableMap() ?: mutableMapOf()} override fun getRecentEmojiListAsync(): ListenableFuture<List<String>> =Futures.immediateFuture(emoji2Frequency.toList().sortedByDescending { it.second }.map…

MenuProvider API— Android. In this article, we will learn how to… | by Nav Singh | Aug, 2023

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)// Add options menu to the toolbarrequireActivity().addMenuProvider(object : MenuProvider {override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {menuInflater.inflate(R.menu.main_menu, menu)}override fun onMenuItemSelected(menuItem: MenuItem): Boolean {return when (menuItem.itemId) {R.id.settings -> {true}else -> false}}}, viewLifecycleOwner)} Source link