From 8347da397cfababa2bb9af44f22c51ce5f2b5e8c Mon Sep 17 00:00:00 2001 From: tateisu Date: Thu, 1 Aug 2019 03:30:56 +0900 Subject: [PATCH] fix #106, read visible_in_picker in custom emoji entity. --- app/build.gradle | 2 +- .../subwaytooter/api/entity/CustomEmoji.kt | 14 +++--- .../subwaytooter/dialog/EmojiPicker.kt | 44 +++++++++---------- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c78783dc..8b5720e3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { compileSdkVersion target_sdk_version - // exoplayer 2.9.0 以降は Java 8 compiler support を要求する + // exoPlayer 2.9.0 以降は Java 8 compiler support を要求する // https://github.com/google/ExoPlayer/blob/release-v2/RELEASENOTES.md // Invoke-customs are only supported starting with Android O (--min-api 26) // Default interface methods are only supported starting with Android N (--min-api 24) diff --git a/app/src/main/java/jp/juggler/subwaytooter/api/entity/CustomEmoji.kt b/app/src/main/java/jp/juggler/subwaytooter/api/entity/CustomEmoji.kt index a29299fc..9e19afba 100644 --- a/app/src/main/java/jp/juggler/subwaytooter/api/entity/CustomEmoji.kt +++ b/app/src/main/java/jp/juggler/subwaytooter/api/entity/CustomEmoji.kt @@ -11,11 +11,12 @@ class CustomEmoji( val url : String, // 画像URL val static_url : String?, // アニメーションなしの画像URL val aliases : ArrayList? = null, - val alias:String? =null + val alias : String? = null, + val visible_in_picker : Boolean = true ) : Mappable { - fun makeAlias(alias : String) = CustomEmoji ( - shortcode= this.shortcode, + fun makeAlias(alias : String) = CustomEmoji( + shortcode = this.shortcode, url = this.url, static_url = this.static_url, alias = alias @@ -29,7 +30,8 @@ class CustomEmoji( CustomEmoji( shortcode = src.notEmptyOrThrow("shortcode"), url = src.notEmptyOrThrow("url"), - static_url = src.parseString("static_url") + static_url = src.parseString("static_url"), + visible_in_picker = src.optBoolean("visible_in_picker", true) ) } val decodeMisskey : (JSONObject) -> CustomEmoji = { src -> @@ -47,7 +49,7 @@ class CustomEmoji( var dst = null as ArrayList? if(src != null) { val size = src.length() - if( size > 0){ + if(size > 0) { dst = ArrayList(size) for(i in 0 until size) { val str = src.parseString(i) ?: continue @@ -57,7 +59,7 @@ class CustomEmoji( } } } - return if(dst?.isNotEmpty() == true ) dst else null + return if(dst?.isNotEmpty() == true) dst else null } } diff --git a/app/src/main/java/jp/juggler/subwaytooter/dialog/EmojiPicker.kt b/app/src/main/java/jp/juggler/subwaytooter/dialog/EmojiPicker.kt index dd456d55..18bafedb 100644 --- a/app/src/main/java/jp/juggler/subwaytooter/dialog/EmojiPicker.kt +++ b/app/src/main/java/jp/juggler/subwaytooter/dialog/EmojiPicker.kt @@ -3,14 +3,13 @@ package jp.juggler.subwaytooter.dialog import android.annotation.SuppressLint import android.app.Activity import android.app.Dialog -import androidx.viewpager.widget.PagerAdapter -import androidx.viewpager.widget.ViewPager import android.util.SparseArray import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.WindowManager import android.widget.* +import androidx.viewpager.widget.ViewPager import com.astuetz.PagerSlidingTabStrip import jp.juggler.emoji.EmojiMap201709 import jp.juggler.subwaytooter.App1 @@ -31,7 +30,7 @@ class EmojiPicker( @Suppress("CanBeParameter") private val isMisskey : Boolean, private val onEmojiPicked : (name : String, instance : String?, bInstanceHasCustomEmoji : Boolean) -> Unit // onEmojiPickedのinstance引数は通常の絵文字ならnull、カスタム絵文字なら非null、 -) : View.OnClickListener, androidx.viewpager.widget.ViewPager.OnPageChangeListener { +) : View.OnClickListener, ViewPager.OnPageChangeListener { companion object { @@ -216,6 +215,7 @@ class EmojiPicker( bInstanceHasCustomEmoji = true custom_list.clear() for(emoji in list) { + if(! emoji.visible_in_picker) continue custom_list.add(EmojiItem(emoji.shortcode, instance)) emoji_url_map[emoji.shortcode] = emoji.url } @@ -302,30 +302,26 @@ class EmojiPicker( title_id : Int ) { - val title : String - val emoji_list : ArrayList + val title : String = activity.getString(title_id) - init { - this.title = activity.getString(title_id) - val c = EmojiMap201709.sCategoryMap.get(category_id) - if(c != null) { - this.emoji_list = ArrayList() - for(name in c.emoji_list) { - this.emoji_list.add(EmojiItem(name, null)) + val emoji_list = when(category_id) { + + CATEGORY_CUSTOM -> custom_list + + CATEGORY_RECENT -> + ArrayList().apply { + for(item in recent_list) { + if(item.instance != null && item.instance != instance) continue + add(item) + } } - } else if(category_id == CATEGORY_RECENT) { - this.emoji_list = ArrayList() - for(item in recent_list) { - if(item.instance != null && item.instance != instance) continue - this.emoji_list.add(item) + + else -> ArrayList().apply { + EmojiMap201709.sCategoryMap.get(category_id)?.emoji_list?.forEach { name -> + add(EmojiItem(name, null)) } - } else if(category_id == CATEGORY_CUSTOM) { - this.emoji_list = custom_list - } else { - this.emoji_list = ArrayList() } } - } inner class EmojiPickerPageViewHolder(activity : Activity, root : View) : BaseAdapter(), @@ -452,10 +448,10 @@ class EmojiPicker( val pref = App1.pref // Recentをロード(他インスタンスの絵文字を含む) - val list = try { + val list : ArrayList = try { Pref.spEmojiPickerRecent(pref).toJsonArray().toObjectList() } catch(ignored : Throwable) { - ArrayList() + ArrayList() } // 選択された絵文字と同じ項目を除去