diff --git a/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebClient.kt b/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebClient.kt index f60f87294a93003504e805332313834c32aa81d4..7556676927d3dfb712ea787bebe7e1ab717d4b8d 100644 --- a/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebClient.kt +++ b/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebClient.kt @@ -95,4 +95,13 @@ class DocumentWebChromeClient(private val webShare: DocumentWebShare) : WebChrom false } } + // webViewからのアラートを取得、表示 + override fun onJsAlert(view: WebView?, url: String?, message: String?, result: JsResult?): Boolean { + if (message != null && view != null) { + webShare.presenter.showDialog(message, view) + } + result?.confirm() + // webViewでは表示せずアプリ標準の方で表示する + return true + } } \ No newline at end of file diff --git a/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebFragment.kt b/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebFragment.kt index b651560200ce422f16f0e6e1da87daafa3a933aa..66dac2ba756066a6bd2df5efd37da50b3fe0ed46 100644 --- a/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebFragment.kt +++ b/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebFragment.kt @@ -1,6 +1,7 @@ package jp.atled.agileworks.view.ui.documentweb import android.annotation.SuppressLint +import android.app.AlertDialog import android.content.Context import android.content.Intent import android.net.ConnectivityManager @@ -40,6 +41,8 @@ class DocumentWebFragment : Fragment(), DocumentWebPresenter { private var lastUrl: String? = null private var connectUrl: String? = null private var getUrl: String? = null + // webViewからのアラート表示用変数 + private var dialog: AlertDialog? = null // スワイプのジェスチャー。折に触れて状態設定をする必要があるのでメンバーとして持つ。 // 必要とされるタイミング次第で null のままのことがある恐れがあるので lateinit にはしていない。 @@ -139,6 +142,14 @@ class DocumentWebFragment : Fragment(), DocumentWebPresenter { // バックグラウンドかの情報 viewDataBinding?.viewModel?.setAppBackGroundStatus(true) } + // 画面を閉じた際にアラートが表示されていたら閉じる + override fun onDestroy() { + super.onDestroy() + dialog?.dismiss() + if (dialog != null) { + dialog = null + } + } @SuppressLint("ClickableViewAccessibility") private fun setClickListeners() { @@ -425,6 +436,19 @@ class DocumentWebFragment : Fragment(), DocumentWebPresenter { else -> {} } } + // webviewのアラートを表示、WebPresenterで宣言 + override fun showDialog(message: String, view: WebView) { + if (message != null && view != null) { + val builder = AlertDialog.Builder(view.getContext()) + builder.setTitle(R.string.login_alert_title) + .setMessage(message) + .setPositiveButton(R.string.login_alert_button_label) { _, _ -> } + .setCancelable(false) + // onDestroyでdismissするために変数へ保存 + dialog = builder.create() + dialog?.show() + } + } companion object { private const val TAG = "DocumentWebFragmentHandler" diff --git a/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebPresenter.kt b/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebPresenter.kt index 71468c2d4f8df2d3d973c5dfcc43329a7b1c8d39..8ce8d0ee7b4f58ab003cbae2a09e112de1146403 100644 --- a/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebPresenter.kt +++ b/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebPresenter.kt @@ -1,5 +1,7 @@ package jp.atled.agileworks.view.ui.documentweb +import android.webkit.WebView + /** * 書類ビューにて見た目を反映させるインターフェース。 * 書類ビュー関連の各クラスはこれを通して表示の変更をリクエストする。 @@ -42,4 +44,9 @@ interface DocumentWebPresenter { * ネットワーク切断時View表示フラグ更新 */ fun updateDisconnectViewDisplayState(url: String) + + /** + * webViewからのアラートをダイアログ表示 + */ + fun showDialog(message: String, view: WebView) }