fix #134, add error message when browser app is not installed.

This commit is contained in:
tateisu 2020-02-24 13:00:58 +09:00
parent 0ae804a4dc
commit cfe9846ebb
2 changed files with 17 additions and 8 deletions

View File

@ -599,6 +599,7 @@ class App1 : Application() {
private fun startActivityExcludeMyApp( private fun startActivityExcludeMyApp(
activity : AppCompatActivity, activity : AppCompatActivity,
intent : Intent, intent : Intent,
emptyError:String,
startAnimationBundle : Bundle? = null startAnimationBundle : Bundle? = null
) { ) {
try { try {
@ -613,6 +614,7 @@ class App1 : Application() {
DlgAppPicker( DlgAppPicker(
activity, activity,
intent, intent,
emptyError,
autoSelect = true, autoSelect = true,
filter = {it.activityInfo.packageName != activity.packageName } filter = {it.activityInfo.packageName != activity.packageName }
) { ) {
@ -632,7 +634,7 @@ class App1 : Application() {
} }
fun openBrowser(activity : AppCompatActivity, uri : Uri?) { fun openBrowser(activity : AppCompatActivity, uri : Uri?) {
if(uri != null) startActivityExcludeMyApp(activity, Intent(Intent.ACTION_VIEW, uri)) if(uri != null) startActivityExcludeMyApp(activity, Intent(Intent.ACTION_VIEW, uri),"there is no app that can open $uri")
} }
fun openBrowser(activity : AppCompatActivity, url : String?) = fun openBrowser(activity : AppCompatActivity, url : String?) =
@ -681,13 +683,13 @@ class App1 : Application() {
) )
it.data = url.toUri() it.data = url.toUri()
}, },
"chrome(product line) is not installed.",
customTabsIntent.startAnimationBundle customTabsIntent.startAnimationBundle
) )
return return
} catch(ex2 : Throwable) { } catch(ex2 : Throwable) {
log.e(ex2, "openChromeTab: missing chrome. retry to other application.") log.e(ex2, "openChromeTab: missing chrome. retry to other application.")
} }
} }
// Chromeがないようなのでcomponent指定なしでリトライ // Chromeがないようなのでcomponent指定なしでリトライ
@ -701,6 +703,7 @@ class App1 : Application() {
customTabsIntent.intent.also { customTabsIntent.intent.also {
it.data = url.toUri() it.data = url.toUri()
}, },
"the app that supports custom tabs is not installed.",
customTabsIntent.startAnimationBundle customTabsIntent.startAnimationBundle
) )

View File

@ -20,6 +20,7 @@ import jp.juggler.util.*
class DlgAppPicker( class DlgAppPicker(
val activity : AppCompatActivity, val activity : AppCompatActivity,
val intent : Intent, val intent : Intent,
val emptyError: String ,
val autoSelect : Boolean = false, val autoSelect : Boolean = false,
val filter : (ResolveInfo) -> Boolean = { true }, val filter : (ResolveInfo) -> Boolean = { true },
val callback : (String) -> Unit val callback : (String) -> Unit
@ -98,12 +99,17 @@ class DlgAppPicker(
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
fun show() { fun show() {
dialog?.run { if( list.isEmpty()){
window?.setLayout( dialog?.dismissSafe()
WindowManager.LayoutParams.MATCH_PARENT, showToast(activity,true,emptyError)
WindowManager.LayoutParams.WRAP_CONTENT }else {
) dialog?.run {
this.show() window?.setLayout(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT
)
this.show()
}
} }
} }