(マストドン2.4.2以降)http,https以外のスキーマのリンクに対応した

This commit is contained in:
tateisu 2018-06-20 12:15:29 +09:00
parent 5fb7f1f0e6
commit 1a2a1b35ac
3 changed files with 24 additions and 7 deletions

View File

@ -12,8 +12,8 @@ android {
minSdkVersion 21
targetSdkVersion 27
versionCode 257
versionName "2.5.7"
versionCode 258
versionName "2.5.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// https://stackoverflow.com/questions/47791227/java-lang-illegalstateexception-dex-archives-setting-dex-extension-only-for

View File

@ -508,7 +508,7 @@ class App1 : Application() {
// Chrome Custom Tab を開く
fun openCustomTab(activity : Activity, url : String) {
try {
if(Pref.bpPriorChrome(pref)) {
if(url.startsWith("http") && Pref.bpPriorChrome(pref)) {
try {
// 初回はChrome指定で試す
val builder = CustomTabsIntent.Builder()
@ -539,7 +539,17 @@ class App1 : Application() {
customTabsIntent.launchUrl(activity, Uri.parse(url))
} catch(ex : Throwable) {
log.trace(ex)
showToast(activity, false, "can't open browser app")
val scheme = try{
Uri.parse(url).scheme
}catch(_:Throwable){
url
}
showToast(
activity,
true,
"can't open browser app for %s",scheme
)
}
}

View File

@ -387,6 +387,8 @@ object HTMLDecoder {
}
}
private val reNormalLink = Pattern.compile("\\A\\w+://")
private fun encodeUrl(
options : DecodeOptions,
display_url : String,
@ -398,7 +400,10 @@ object HTMLDecoder {
return display_url
}
if(! display_url.startsWith("http")) {
// 通常リンクは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 m = TootAccount.reAccountUrl.matcher(href)
@ -410,8 +415,6 @@ object HTMLDecoder {
return display_url
}
if(options.isMediaAttachment(href)) {
val sb = SpannableStringBuilder()
sb.append(href)
@ -429,6 +432,10 @@ object HTMLDecoder {
try {
val uri = Uri.parse(display_url)
val sb = StringBuilder()
if(! display_url.startsWith("http")){
sb.append(uri.scheme)
sb.append("://")
}
sb.append(uri.authority)
val a = uri.encodedPath
val q = uri.encodedQuery