fix #123, ChromebookでIMEのアクションボタンの動作がおかしい

This commit is contained in:
tateisu 2020-01-05 17:24:52 +09:00
parent bab1efb92b
commit 206098676c
4 changed files with 95 additions and 79 deletions

View File

@ -24,6 +24,7 @@ import android.text.method.LinkMovementMethod
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.view.inputmethod.EditorInfo
import android.widget.*
import jp.juggler.subwaytooter.Styler.defaultColorIcon
import jp.juggler.subwaytooter.api.*
@ -1160,6 +1161,11 @@ class ActPost : AppCompatActivity(),
cbContentWarning = findViewById(R.id.cbContentWarning)
etContentWarning = findViewById(R.id.etContentWarning)
etContent = findViewById(R.id.etContent)
// https://github.com/tateisu/SubwayTooter/issues/123
// 早い段階で指定する必要がある
etContent.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
etContent.imeOptions = EditorInfo.IME_ACTION_NONE
cbQuoteRenote = findViewById(R.id.cbQuoteRenote)
@ -1280,7 +1286,6 @@ class ActPost : AppCompatActivity(),
etContent.contentMineTypeArray =
acceptable_mime_types.toArray(arrayOfNulls<String>(acceptable_mime_types.size))
etContent.commitContentListener = commitContentListener
}
private var lastInstanceTask : TootTaskRunner? = null

View File

@ -2334,7 +2334,6 @@ internal class ItemViewHolder(
topMargin = (0.5f + density * 3f).toInt()
}
}
// +ボタン
run {
@ -2396,100 +2395,111 @@ internal class ItemViewHolder(
// 通常の絵文字はUnicodeを使う
fun addEmojiReaction(name:String,unicode:String,count:Int){
val b = Button(activity)
val blp = FlexboxLayout.LayoutParams(
FlexboxLayout.LayoutParams.WRAP_CONTENT,
buttonHeight
)
b.minWidthCompat = buttonHeight
b.layoutParams = blp
blp.endMargin = marginBetween
b.background = ContextCompat.getDrawable(
activity,
R.drawable.btn_bg_transparent
)
b.setTextColor(content_color)
b.setPadding(paddingH, paddingV, paddingH, paddingV)
b.text = EmojiDecoder.decodeEmoji(options,"$unicode $count")
b.allCaps = false
b.tag = name
b.setOnClickListener { addReaction(status, it.tag as? String) }
val b = Button(activity).apply{
b.setOnLongClickListener {
Action_Toot.reactionFromAnotherAccount(
activity,
access_info,
status_showing,
it.tag as? String
layoutParams = FlexboxLayout.LayoutParams(
FlexboxLayout.LayoutParams.WRAP_CONTENT,
buttonHeight
).apply{
endMargin = marginBetween
}
text = EmojiDecoder.decodeEmoji(options,"$unicode $count")
allCaps = false
tag = name
minWidthCompat = buttonHeight
background = ContextCompat.getDrawable(
this@ItemViewHolder.activity,
R.drawable.btn_bg_transparent
)
true
setTextColor(content_color)
setPadding(paddingH, paddingV, paddingH, paddingV)
setOnClickListener {
addReaction(status, it.tag as? String)
}
setOnLongClickListener {
Action_Toot.reactionFromAnotherAccount(
this@ItemViewHolder.activity,
access_info,
status_showing,
it.tag as? String
)
true
}
}
box.addView(b)
lastButton = b
}
fun addCustomEmojiReaction(name:String,customCode:String,count:Int){
val b = Button(activity)
val blp = FlexboxLayout.LayoutParams(
FlexboxLayout.LayoutParams.WRAP_CONTENT,
buttonHeight
)
b.minWidthCompat = buttonHeight
b.layoutParams = blp
blp.endMargin = marginBetween
b.background = ContextCompat.getDrawable(
activity,
R.drawable.btn_bg_transparent
)
b.setTextColor(content_color)
b.setPadding(paddingH, paddingV, paddingH, paddingV)
val emojiUrl =App1.custom_emoji_lister.getMap(access_info.host, true)
?.get(customCode)
?.let {
if(Pref.bpDisableEmojiAnimation(activity.pref)) {
it.static_url
} else {
it.url
}
val b = Button(activity).apply{
layoutParams = FlexboxLayout.LayoutParams(
FlexboxLayout.LayoutParams.WRAP_CONTENT,
buttonHeight
).apply{
endMargin = marginBetween
}
val sb = SpannableStringBuilder("$name $count")
if(emojiUrl != null) {
sb.setSpan(
NetworkEmojiSpan(emojiUrl, scale = 1.5f),
0,
name.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
minWidthCompat = buttonHeight
background = ContextCompat.getDrawable(
this@ItemViewHolder.activity,
R.drawable.btn_bg_transparent
)
val invalidator = NetworkEmojiInvalidator(activity.handler, b)
invalidator.register(sb)
extra_invalidator_list.add(invalidator)
}
b.text = sb
b.allCaps = false
b.tag = name
b.setOnClickListener { addReaction(status, it.tag as? String) }
b.setOnLongClickListener {
Action_Toot.reactionFromAnotherAccount(
activity,
access_info,
status_showing,
it.tag as? String
)
true
setTextColor(content_color)
setPadding(paddingH, paddingV, paddingH, paddingV)
val emojiUrl =App1.custom_emoji_lister
.getMap(access_info.host, true)
?.get(customCode)
?.let {
if(Pref.bpDisableEmojiAnimation(this@ItemViewHolder.activity.pref)) {
it.static_url
} else {
it.url
}
}
val sb = SpannableStringBuilder("$name $count")
if(emojiUrl != null) {
sb.setSpan(
NetworkEmojiSpan(emojiUrl, scale = 1.5f),
0,
name.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
val invalidator = NetworkEmojiInvalidator(this@ItemViewHolder.activity.handler, this)
invalidator.register(sb)
extra_invalidator_list.add(invalidator)
}
text = sb
allCaps = false
tag = name
setOnClickListener {
addReaction(status, it.tag as? String)
}
setOnLongClickListener {
Action_Toot.reactionFromAnotherAccount(
this@ItemViewHolder.activity,
access_info,
status_showing,
it.tag as? String
)
true
}
}
box.addView(b)
lastButton = b
}
// 既定のリアクション
for(mr in MisskeyReaction.values()) {
val count = reactionsCount[mr.shortcode]
if(count == null || count <= 0) continue
addEmojiReaction(mr.shortcode,mr.emojiUtf16,count)
}
// カスタム絵文字リアクション
// カスタム絵文字またはUnicode絵文字のリアクション
val list = reactionsCount.keys
.filter { MisskeyReaction.shortcodeMap[it] == null }
.sorted()
@ -2508,7 +2518,7 @@ internal class ItemViewHolder(
lastButton
?.layoutParams
?.castOrNull<ViewGroup.MarginLayoutParams>()
?.cast<ViewGroup.MarginLayoutParams>()
?.endMargin = 0
}

View File

@ -365,7 +365,7 @@ class TootStatus(parser : TootParser, src : JSONObject) : TimelineItem() {
// しかしTLにRenoteが露出してるならそのIDを使う方が賢明であろう
// 外側ステータスが自分なら、内側ステータスのmyRenoteIdを設定する
if( reblog != null && (parser.linkHelper as? SavedAccount)?.isMe( account) ==true ){
if( reblog != null && parser.linkHelper.cast<SavedAccount>()?.isMe( account) ==true ){
reblog.myRenoteId = id
reblog.reblogged = true
}

View File

@ -5,9 +5,10 @@ import androidx.core.content.ContextCompat
// 型推論できる文脈だと型名を書かずにすむ
@Suppress("unused")
inline fun <reified T : Any> Any?.cast(): T = this as T
inline fun <reified T : Any> Any?.cast(): T? = this as? T
inline fun <reified T : Any> Any?.castOrNull(): T? = this as? T
@Suppress("unused")
inline fun <reified T : Any> Any.castNotNull(): T = this as T
// 型推論できる文脈だと型名を書かずにすむ
inline fun <reified T> systemService(context: Context): T? =