diff --git a/.idea/dictionaries/tateisu.xml b/.idea/dictionaries/tateisu.xml index b01c3a40..87c760aa 100644 --- a/.idea/dictionaries/tateisu.xml +++ b/.idea/dictionaries/tateisu.xml @@ -44,6 +44,7 @@ mailto mimumedon navi + nicodic nicoru noto nsfw diff --git a/app/src/main/java/jp/juggler/subwaytooter/util/HTMLDecoder.kt b/app/src/main/java/jp/juggler/subwaytooter/util/HTMLDecoder.kt index 122a6563..590c027d 100644 --- a/app/src/main/java/jp/juggler/subwaytooter/util/HTMLDecoder.kt +++ b/app/src/main/java/jp/juggler/subwaytooter/util/HTMLDecoder.kt @@ -1,6 +1,8 @@ package jp.juggler.subwaytooter.util +import android.net.Uri import android.text.Spannable +import android.text.SpannableString import android.text.SpannableStringBuilder import android.text.Spanned import jp.juggler.subwaytooter.App1 @@ -316,9 +318,7 @@ object HTMLDecoder { val start = sb.length - sb.append( - encodeUrl(options, sb_tmp.toString(), href) - ) + sb.append( encodeUrl(options, sb_tmp.toString(), href) ) val end = sb.length @@ -386,7 +386,8 @@ object HTMLDecoder { } } - private val reNormalLink = Pattern.compile("\\A\\w+://") + private val reNormalLink = Pattern.compile("""\A\w+://""") + private val reNicodic = Pattern.compile("""\Ahttps?://dic.nicovideo.jp/a/([^?#/]+)\z""") private fun encodeUrl( options : DecodeOptions, @@ -395,39 +396,51 @@ object HTMLDecoder { ) : CharSequence { val context = options.context - if(context == null || ! options.short) { + + if(context == null || ! options.short){ return display_url } + // 添付メディアのURLなら絵文字に変換する + if( options.isMediaAttachment(href)){ + return SpannableString(href).apply{ + setSpan( + EmojiImageSpan(context, R.drawable.emj_1f5bc_fe0f), + 0, + length, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE + ) + } + } + + // ニコニコ大百科のURLを変える + val m = reNicodic.matcher(href) + if( m.find() ){ + return SpannableString("${Uri.decode(m.group(1))}:nicodic:").apply{ + setSpan( + EmojiImageSpan(context, R.drawable.nicodic), + length -9, + length, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE + ) + } + } + // 通常リンクはhttp,httpsだけでなく幾つかのスキーマ名が含まれる // スキーマ名の直後には必ず :// が出現する // https://github.com/tootsuite/mastodon/pull/7810 - if(! reNormalLink.matcher(display_url).find()) { - if(display_url.startsWith("@") && href != null && Pref.bpMentionFullAcct(App1.pref)) { - // メンションをfull acct にする - val acct = TootAccount.getAcctFromUrl(href) - if(acct != null) return "@$acct" - } - // ハッシュタグやメンションはURLの短縮表示の対象外 - return display_url + if( reNormalLink.matcher(display_url).find() ){ + return shortenUrl(display_url) } - if(options.isMediaAttachment(href)) { - val sb = SpannableStringBuilder() - sb.append(href) - val start = 0 - val end = sb.length - sb.setSpan( - EmojiImageSpan(context, R.drawable.emj_1f5bc_fe0f), - start, - end, - Spanned.SPAN_EXCLUSIVE_EXCLUSIVE - ) - return sb + // メンションをfull acct にする + if( display_url.startsWith("@") && href != null && Pref.bpMentionFullAcct(App1.pref) ){ + val acct = TootAccount.getAcctFromUrl(href) + if(acct != null) return "@$acct" } - return shortenUrl(display_url) - + // ハッシュタグやメンションはURLの短縮表示の対象外 + return display_url } } diff --git a/resizeLauncherIcon.pl b/resizeLauncherIcon.pl index 946c56f8..65274929 100644 --- a/resizeLauncherIcon.pl +++ b/resizeLauncherIcon.pl @@ -155,7 +155,6 @@ my $res_dir = "app/src/main/res"; #resize_scales( "../extra-SubwayTooter/_ArtWork/local-visibility/ic_local_ltl_dark.png" ,$res_dir,"drawable","ic_local_ltl_dark",0,32); -resize_scales( "../extra-SubwayTooter/_ArtWork/media_bg_dark.png" ,$res_dir,"drawable","media_bg_dark",0,24); - - +# resize_scales( "../extra-SubwayTooter/_ArtWork/media_bg_dark.png" ,$res_dir,"drawable","media_bg_dark",0,24); +resize_scales( "../extra-SubwayTooter/_ArtWork/nicodic.png" ,$res_dir,"drawable","nicodic",32,60);