アプリ設定に「リンクを開く際に (ChromeやFirefoxの) Custom Tabsを使わない」を追加
This commit is contained in:
parent
81a7bbb87e
commit
9085a6c93c
|
@ -5,6 +5,7 @@ import android.app.Activity
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.database.sqlite.SQLiteDatabase
|
import android.database.sqlite.SQLiteDatabase
|
||||||
import android.database.sqlite.SQLiteOpenHelper
|
import android.database.sqlite.SQLiteOpenHelper
|
||||||
|
@ -213,8 +214,8 @@ class App1 : Application() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun prepareOkHttp(
|
private fun prepareOkHttp(
|
||||||
timeoutSecondsConnect:Int,
|
timeoutSecondsConnect : Int,
|
||||||
timeoutSecondsRead:Int
|
timeoutSecondsRead : Int
|
||||||
) : OkHttpClient.Builder {
|
) : OkHttpClient.Builder {
|
||||||
val spec = ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
|
val spec = ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
|
||||||
.cipherSuites(*APPROVED_CIPHER_SUITES)
|
.cipherSuites(*APPROVED_CIPHER_SUITES)
|
||||||
|
@ -313,7 +314,6 @@ class App1 : Application() {
|
||||||
MediaShown.deleteOld(now)
|
MediaShown.deleteOld(now)
|
||||||
MediaShownMisskey.deleteOld(now)
|
MediaShownMisskey.deleteOld(now)
|
||||||
|
|
||||||
|
|
||||||
// if( USE_OLD_EMOJIONE ){
|
// if( USE_OLD_EMOJIONE ){
|
||||||
// if( typeface_emoji == null ){
|
// if( typeface_emoji == null ){
|
||||||
// typeface_emoji = TypefaceUtils.load( app_context.getAssets(), "emojione_android.ttf" );
|
// typeface_emoji = TypefaceUtils.load( app_context.getAssets(), "emojione_android.ttf" );
|
||||||
|
@ -329,25 +329,24 @@ class App1 : Application() {
|
||||||
|
|
||||||
run {
|
run {
|
||||||
// API用のHTTP設定はキャッシュを使わない
|
// API用のHTTP設定はキャッシュを使わない
|
||||||
var builder = prepareOkHttp(30,60)
|
var builder = prepareOkHttp(30, 60)
|
||||||
ok_http_client = builder.build()
|
ok_http_client = builder.build()
|
||||||
|
|
||||||
|
|
||||||
// ディスクキャッシュ
|
// ディスクキャッシュ
|
||||||
val cacheDir = File(app_context.cacheDir, "http2")
|
val cacheDir = File(app_context.cacheDir, "http2")
|
||||||
val cache = Cache(cacheDir, 30000000L)
|
val cache = Cache(cacheDir, 30000000L)
|
||||||
|
|
||||||
// カスタム絵文字用のHTTP設定はキャッシュを使う
|
// カスタム絵文字用のHTTP設定はキャッシュを使う
|
||||||
builder = prepareOkHttp(30,60)
|
builder = prepareOkHttp(30, 60)
|
||||||
builder.cache(cache)
|
builder.cache(cache)
|
||||||
|
|
||||||
ok_http_client2 = builder.build()
|
ok_http_client2 = builder.build()
|
||||||
|
|
||||||
// 内蔵メディアビューア用のHTTP設定は同じキャッシュを使うが、タイムアウトは別の値を指定する
|
// 内蔵メディアビューア用のHTTP設定は同じキャッシュを使うが、タイムアウトは別の値を指定する
|
||||||
var mediaReadTimeout = Pref.spMediaReadTimeout.toInt(pref)
|
var mediaReadTimeout = Pref.spMediaReadTimeout.toInt(pref)
|
||||||
if( mediaReadTimeout < 3 ) mediaReadTimeout = 3
|
if(mediaReadTimeout < 3) mediaReadTimeout = 3
|
||||||
|
|
||||||
builder = prepareOkHttp(mediaReadTimeout,mediaReadTimeout)
|
builder = prepareOkHttp(mediaReadTimeout, mediaReadTimeout)
|
||||||
builder.cache(cache)
|
builder.cache(cache)
|
||||||
ok_http_client_media_viewer = builder.build()
|
ok_http_client_media_viewer = builder.build()
|
||||||
}
|
}
|
||||||
|
@ -538,57 +537,59 @@ class App1 : Application() {
|
||||||
// Chrome Custom Tab を開く
|
// Chrome Custom Tab を開く
|
||||||
fun openCustomTab(activity : Activity, url : String) {
|
fun openCustomTab(activity : Activity, url : String) {
|
||||||
try {
|
try {
|
||||||
if(url.startsWith("http") && Pref.bpPriorChrome(pref)) {
|
if( Pref.bpDontUseCustomTabs(pref)){
|
||||||
try {
|
val intent = Intent(Intent.ACTION_VIEW,Uri.parse(url))
|
||||||
// 初回はChrome指定で試す
|
activity.startActivity(intent)
|
||||||
val builder = CustomTabsIntent.Builder()
|
|
||||||
builder.setToolbarColor(
|
}else{
|
||||||
Styler.getAttributeColor(
|
|
||||||
activity,
|
if(url.startsWith("http") && Pref.bpPriorChrome(pref)) {
|
||||||
R.attr.colorPrimary
|
try {
|
||||||
|
// 初回はChrome指定で試す
|
||||||
|
val customTabsIntent = CustomTabsIntent.Builder()
|
||||||
|
.setToolbarColor(
|
||||||
|
Styler.getAttributeColor(
|
||||||
|
activity,
|
||||||
|
R.attr.colorPrimary
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setShowTitle(true)
|
||||||
|
.build()
|
||||||
|
customTabsIntent.intent.component = ComponentName(
|
||||||
|
"com.android.chrome",
|
||||||
|
"com.google.android.apps.chrome.Main"
|
||||||
)
|
)
|
||||||
).setShowTitle(true)
|
customTabsIntent.launchUrl(activity, Uri.parse(url))
|
||||||
val customTabsIntent = builder.build()
|
return
|
||||||
customTabsIntent.intent.component = ComponentName(
|
} catch(ex2 : Throwable) {
|
||||||
"com.android.chrome",
|
log.e(ex2, "openChromeTab: missing chrome. retry to other application.")
|
||||||
"com.google.android.apps.chrome.Main"
|
}
|
||||||
)
|
|
||||||
customTabsIntent.launchUrl(activity, Uri.parse(url))
|
|
||||||
return
|
|
||||||
} catch(ex2 : Throwable) {
|
|
||||||
log.e(ex2, "openChromeTab: missing chrome. retry to other application.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Chromeがないようなのでcomponent指定なしでリトライ
|
||||||
|
CustomTabsIntent.Builder()
|
||||||
|
.setToolbarColor(Styler.getAttributeColor(activity, R.attr.colorPrimary))
|
||||||
|
.setShowTitle(true)
|
||||||
|
.build()
|
||||||
|
.launchUrl(activity, Uri.parse(url))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// chromeがないなら ResolverActivity でアプリを選択させる
|
|
||||||
val builder = CustomTabsIntent.Builder()
|
|
||||||
builder.setToolbarColor(Styler.getAttributeColor(activity, R.attr.colorPrimary))
|
|
||||||
.setShowTitle(true)
|
|
||||||
val customTabsIntent = builder.build()
|
|
||||||
customTabsIntent.launchUrl(activity, Uri.parse(url))
|
|
||||||
} catch(ex : Throwable) {
|
} catch(ex : Throwable) {
|
||||||
log.trace(ex)
|
log.trace(ex)
|
||||||
val scheme = try{
|
val scheme = try {
|
||||||
Uri.parse(url).scheme
|
Uri.parse(url).scheme
|
||||||
}catch(_:Throwable){
|
} catch(_ : Throwable) {
|
||||||
url
|
url
|
||||||
}
|
}
|
||||||
showToast(
|
showToast(activity,true,"can't open browser app for %s", scheme)
|
||||||
activity,
|
|
||||||
true,
|
|
||||||
"can't open browser app for %s",scheme
|
|
||||||
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openCustomTab(activity : Activity, ta : TootAttachment) {
|
fun openCustomTab(activity : Activity, ta : TootAttachment) {
|
||||||
val url = ta.getLargeUrl(pref)
|
val url = ta.getLargeUrl(pref) ?: return
|
||||||
if(url != null) {
|
openCustomTab(activity, url)
|
||||||
openCustomTab(activity, url)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,7 +245,11 @@ object Pref {
|
||||||
true,
|
true,
|
||||||
R.id.swPriorChrome
|
R.id.swPriorChrome
|
||||||
)
|
)
|
||||||
|
val bpDontUseCustomTabs = BooleanPref(
|
||||||
|
"DontUseCustomTabs",
|
||||||
|
false,
|
||||||
|
R.id.swDontUseCustomTabs
|
||||||
|
)
|
||||||
val bpPriorLocalURL = BooleanPref(
|
val bpPriorLocalURL = BooleanPref(
|
||||||
"prior_local_url",
|
"prior_local_url",
|
||||||
false,
|
false,
|
||||||
|
|
|
@ -266,6 +266,22 @@
|
||||||
|
|
||||||
<View style="@style/setting_divider"/>
|
<View style="@style/setting_divider"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/setting_row_label"
|
||||||
|
android:text="@string/dont_use_custom_tabs"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<LinearLayout style="@style/setting_row_form">
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/swDontUseCustomTabs"
|
||||||
|
style="@style/setting_horizontal_stretch"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View style="@style/setting_divider"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/setting_row_label"
|
style="@style/setting_row_label"
|
||||||
android:text="@string/allow_column_duplication"
|
android:text="@string/allow_column_duplication"
|
||||||
|
|
|
@ -759,5 +759,6 @@
|
||||||
<string name="zooming_of">×%3$.1f\n%1$d×%2$d</string>
|
<string name="zooming_of">×%3$.1f\n%1$d×%2$d</string>
|
||||||
<string name="link_color">リンクの色 (アプリ再起動が必要)</string>
|
<string name="link_color">リンクの色 (アプリ再起動が必要)</string>
|
||||||
<string name="missing_closeable_column">閉じれるカラムが表示範囲内にありません</string>
|
<string name="missing_closeable_column">閉じれるカラムが表示範囲内にありません</string>
|
||||||
|
<string name="dont_use_custom_tabs">リンクを開く際に (ChromeやFirefoxの) Custom Tabsを使わない</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -777,5 +777,6 @@
|
||||||
<string name="timeout_for_embed_media_viewer">Timeout for embed media viewer (unit:seconds, app restart(delete from app history) required)</string>
|
<string name="timeout_for_embed_media_viewer">Timeout for embed media viewer (unit:seconds, app restart(delete from app history) required)</string>
|
||||||
<string name="link_color">Link color (app restart required)</string>
|
<string name="link_color">Link color (app restart required)</string>
|
||||||
<string name="missing_closeable_column">missing closeable column in visible range.</string>
|
<string name="missing_closeable_column">missing closeable column in visible range.</string>
|
||||||
|
<string name="dont_use_custom_tabs">Don\'t use (Chrome/Firefox) Custom Tabs when open links</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue