AppOpenerのログ出力の追加

This commit is contained in:
tateisu 2020-12-07 22:06:25 +09:00
parent 17f11fd196
commit 76ae05d006
2 changed files with 95 additions and 95 deletions

View File

@ -11,7 +11,7 @@ fun getNotestockStatuses(root: JsonObject): JsonArray? =
root["statuses"].cast() root["statuses"].cast()
// notestock の検索結果からmax_dtを抽出します。 // notestock の検索結果からmax_dtを抽出します。
// 次ページがない場合はnullを返します。 // データがない場合はnullを返します。
fun getNotestockMaxDt(root: JsonObject)= fun getNotestockMaxDt(root: JsonObject)=
root.jsonArray("statuses") root.jsonArray("statuses")
?.mapNotNull{ it.cast<JsonObject>()?.string("published")} ?.mapNotNull{ it.cast<JsonObject>()?.string("published")}

View File

@ -40,8 +40,8 @@ private val log = LogCategory("AppOpener")
// returns true if activity is opened. // returns true if activity is opened.
// returns false if fallback required // returns false if fallback required
private fun Activity.startActivityExcludeMyApp( private fun Activity.startActivityExcludeMyApp(
intent: Intent, intent: Intent,
startAnimationBundle: Bundle? = null startAnimationBundle: Bundle? = null
): Boolean { ): Boolean {
try { try {
// このアプリのパッケージ名 // このアプリのパッケージ名
@ -56,13 +56,13 @@ private fun Activity.startActivityExcludeMyApp(
// resolveActivity がこのアプリ以外のActivityを返すなら、それがベストなんだろう // resolveActivity がこのアプリ以外のActivityを返すなら、それがベストなんだろう
// ただしAndroid M以降はMATCH_DEFAULT_ONLYだと「常時」が設定されてないとnullを返す // ただしAndroid M以降はMATCH_DEFAULT_ONLYだと「常時」が設定されてないとnullを返す
val ri = packageManager!!.resolveActivity( val ri = packageManager!!.resolveActivity(
intent, intent,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PackageManager.MATCH_ALL PackageManager.MATCH_ALL
} else { } else {
PackageManager.MATCH_DEFAULT_ONLY PackageManager.MATCH_DEFAULT_ONLY
} }
)?.takeIf(filter) )?.takeIf(filter)
return when { return when {
@ -74,11 +74,11 @@ private fun Activity.startActivityExcludeMyApp(
} }
else -> DlgAppPicker( else -> DlgAppPicker(
this, this,
intent, intent,
autoSelect = true, autoSelect = true,
filter = filter filter = filter
) { ) {
try { try {
intent.component = it.cn() intent.component = it.cn()
log.d("startActivityExcludeMyApp(2) $intent") log.d("startActivityExcludeMyApp(2) $intent")
@ -130,22 +130,23 @@ fun Activity.openCustomTab(url: String?) {
.setShowTitle(true) .setShowTitle(true)
.build() .build()
.let { .let {
log.w("startCustomTabIntent ComponentName=$cn")
startActivityExcludeMyApp( startActivityExcludeMyApp(
it.intent.also { intent -> it.intent.also { intent ->
if (cn != null) intent.component = cn if (cn != null) intent.component = cn
intent.data = url.toUri() intent.data = url.toUri()
}, },
it.startAnimationBundle it.startAnimationBundle
) )
} }
if (url.startsWith("http") && Pref.bpPriorChrome(pref)) { if (url.startsWith("http") && Pref.bpPriorChrome(pref)) {
try { try {
// 初回はChrome指定で試す // 初回はChrome指定で試す
val cn = ComponentName( val cn = ComponentName(
"com.android.chrome", "com.android.chrome",
"com.google.android.apps.chrome.Main" "com.google.android.apps.chrome.Main"
) )
if (startCustomTabIntent(cn)) return if (startCustomTabIntent(cn)) return
} catch (ex2: Throwable) { } catch (ex2: Throwable) {
log.e(ex2, "openCustomTab: missing chrome. retry to other application.") log.e(ex2, "openCustomTab: missing chrome. retry to other application.")
@ -154,7 +155,6 @@ fun Activity.openCustomTab(url: String?) {
// Chromeがないようなのでcomponent指定なしでリトライ // Chromeがないようなのでcomponent指定なしでリトライ
if (startCustomTabIntent(null)) return if (startCustomTabIntent(null)) return
showToast(true, "the browser app is not installed.") showToast(true, "the browser app is not installed.")
} catch (ex: Throwable) { } catch (ex: Throwable) {
@ -168,14 +168,14 @@ fun Activity.openCustomTab(ta: TootAttachment) =
openCustomTab(ta.getLargeUrl(pref())) openCustomTab(ta.getLargeUrl(pref()))
fun openCustomTab( fun openCustomTab(
activity: ActMain, activity: ActMain,
pos: Int, pos: Int,
url: String, url: String,
accessInfo: SavedAccount? = null, accessInfo: SavedAccount? = null,
tagList: ArrayList<String>? = null, tagList: ArrayList<String>? = null,
allowIntercept: Boolean = true, allowIntercept: Boolean = true,
whoRef: TootAccountRef? = null, whoRef: TootAccountRef? = null,
linkInfo: LinkInfo? = null linkInfo: LinkInfo? = null
) { ) {
try { try {
log.d("openCustomTab: $url") log.d("openCustomTab: $url")
@ -192,14 +192,14 @@ fun openCustomTab(
val tagInfo = url.findHashtagFromUrl() val tagInfo = url.findHashtagFromUrl()
if (tagInfo != null) { if (tagInfo != null) {
Action_HashTag.dialog( Action_HashTag.dialog(
activity, activity,
pos, pos,
url, url,
Host.parse(tagInfo.second), Host.parse(tagInfo.second),
tagInfo.first, tagInfo.first,
tagList, tagList,
whoAcct whoAcct
) )
return return
} }
@ -210,20 +210,20 @@ fun openCustomTab(
!accessInfo.matchHost(statusInfo.host) !accessInfo.matchHost(statusInfo.host)
) { ) {
Action_Toot.conversationOtherInstance( Action_Toot.conversationOtherInstance(
activity, activity,
pos, pos,
statusInfo.url, statusInfo.url,
statusInfo.statusId, statusInfo.statusId,
statusInfo.host, statusInfo.host,
statusInfo.statusId statusInfo.statusId
) )
} else { } else {
Action_Toot.conversationLocal( Action_Toot.conversationLocal(
activity, activity,
pos, pos,
accessInfo, accessInfo,
statusInfo.statusId statusInfo.statusId
) )
} }
return return
} }
@ -235,22 +235,22 @@ fun openCustomTab(
if (fullAcct != null) { if (fullAcct != null) {
if (fullAcct.host != null) { if (fullAcct.host != null) {
when (fullAcct.host.ascii) { when (fullAcct.host.ascii) {
"github.com", "github.com",
"twitter.com" -> "twitter.com" ->
activity.openCustomTab(mention.url) activity.openCustomTab(mention.url)
"gmail.com" -> "gmail.com" ->
activity.openBrowser("mailto:${fullAcct.pretty}") activity.openBrowser("mailto:${fullAcct.pretty}")
else -> else ->
Action_User.profile( Action_User.profile(
activity, activity,
pos, pos,
accessInfo, // FIXME nullが必要なケースがあったっけなかったっけ… accessInfo, // FIXME nullが必要なケースがあったっけなかったっけ…
mention.url, mention.url,
fullAcct.host, fullAcct.host,
fullAcct.username, fullAcct.username,
original_url = url original_url = url
) )
} }
return return
} }
@ -269,35 +269,35 @@ fun openCustomTab(
if (instance != null) { if (instance != null) {
val instanceHost = Host.parse(instance) val instanceHost = Host.parse(instance)
when (instanceHost.ascii) { when (instanceHost.ascii) {
"github.com", "twitter.com" -> { "github.com", "twitter.com" -> {
activity.openCustomTab("https://$instance/$user") activity.openCustomTab("https://$instance/$user")
} }
"gmail.com" -> { "gmail.com" -> {
activity.openBrowser("mailto:$user@$instance") activity.openBrowser("mailto:$user@$instance")
} }
else -> { else -> {
Action_User.profile( Action_User.profile(
activity, activity,
pos, pos,
null, // Misskeyだと疑似アカが必要なんだっけ… null, // Misskeyだと疑似アカが必要なんだっけ…
"https://$instance/@$user", "https://$instance/@$user",
instanceHost, instanceHost,
user, user,
original_url = url original_url = url
) )
} }
} }
} else { } else {
Action_User.profile( Action_User.profile(
activity, activity,
pos, pos,
accessInfo, accessInfo,
url, url,
Host.parse(host), Host.parse(host),
user user
) )
} }
return return
} }
@ -308,13 +308,13 @@ fun openCustomTab(
val user = m.groupEx(2)!!.decodePercent() val user = m.groupEx(2)!!.decodePercent()
Action_User.profile( Action_User.profile(
activity, activity,
pos, pos,
accessInfo, accessInfo,
url, url,
Host.parse(host), Host.parse(host),
user user
) )
return return
} }
@ -323,7 +323,7 @@ fun openCustomTab(
activity.openCustomTab(url) activity.openCustomTab(url)
} catch (ex: Throwable) { } catch (ex: Throwable) {
// warning.trace( ex ); log.trace(ex)
log.e(ex, "openCustomTab failed. $url") log.e(ex, "openCustomTab failed. $url")
} }
} }