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 bca95418e51e9d8d6907304c12bf65681f567c53..7996980f3fc8ccc2d6383f1ab7f2a7315e5ab110 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 @@ -82,6 +82,8 @@ class DocumentWebViewClient(private val webShare: DocumentWebShare): WebViewClie */ // ネットワーク切断時Viewを表示する必要があるか設定する(URL変更時) url?.let { webShare.presenter.updateDisconnectViewDisplayState(it) } + // 書類部分のスクロール量を初期化する + webShare.presenter.initDocumentScrollAmount() } companion object { private val FORM_URL_PATTERN = Regex("/xpoint/form\\.do\\b") 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 d86da91619117eee77e8fd8169db475a0d770126..fc1e58fa33d6daecdf53a33fc0e0a83d5e477111 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 @@ -76,9 +76,8 @@ class DocumentWebFragment : Fragment(), DocumentWebPresenter { surveillanceNetwork.surveillanceNetwork { networkConnect -> if (networkConnect) { reloadAfterConnect() - } else { - swipeControl.updateSwipeRefreshState(false) } + swipeControl.updateSwipeRefreshState(networkConnect) } // ネットワーク切断時Viewを表示する必要があるか設定する(タブ変更時) @@ -143,10 +142,16 @@ class DocumentWebFragment : Fragment(), DocumentWebPresenter { } val gestureDetector = GestureDetectorCompat(requireContext(), listener) it.setOnTouchListener { _, event -> - if (event.action == MotionEvent.ACTION_DOWN) { - listener.resetScroll() - } else if (event.action == MotionEvent.ACTION_UP) { - swipeControl.updateSwipeRefreshState(it.scrollY == 0) + when (event.action) { + MotionEvent.ACTION_DOWN -> { + listener.resetScroll() + } + MotionEvent.ACTION_UP -> { + swipeControl.updateSwipeRefreshState(it.scrollY == 0) + } + MotionEvent.ACTION_MOVE -> { + swipeControl.updateDocumentScrollAmount() + } } gestureDetector.onTouchEvent(event) } @@ -264,7 +269,7 @@ class DocumentWebFragment : Fragment(), DocumentWebPresenter { applyCookieManager(connectUrl, true) } else { // タブ移動あり、一度タブ選択(=webView生成)されているタブを表示している状態でオンライン復帰 - applyCookieManager(lastUrl, false) + applyCookieManager(lastUrl, true) } } else { // タブ移動がない状態でオフラインからオンライン復帰時にここの処理が実施される @@ -350,6 +355,10 @@ class DocumentWebFragment : Fragment(), DocumentWebPresenter { } } + override fun initDocumentScrollAmount() { + viewDataBinding.viewModel?.documentScrollAmount?.value = 0.0 + } + // ツールバー部分のタイトルを更新する関数 override fun updateTitle(url: String) { try { 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 daaf6faa95ad6bd82475c76b05f96e99217f7450..d86b5641fbf9fc83607b8611066ba94ae7a3bcbe 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 @@ -42,4 +42,9 @@ interface DocumentWebPresenter { * ネットワーク切断時View表示フラグ更新 */ fun updateDisconnectViewDisplayState(url: String) + + /** + * 書類部分のスクロール量を初期化する + */ + fun initDocumentScrollAmount() } diff --git a/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebViewModel.kt b/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebViewModel.kt index a1942d5d427a83283d815716af36b9c283e6a6a8..75cef402b7c1975e0db8b4c124eae6756f42d12d 100644 --- a/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebViewModel.kt +++ b/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/DocumentWebViewModel.kt @@ -15,4 +15,7 @@ class DocumentWebViewModel : BaseViewModel(){ // ネットワーク切断時View表示/非表示フラグ val layoutDisconnectViewVisibility = MutableLiveData() + + // 書類部分のスクロール量 + val documentScrollAmount = MutableLiveData().apply { value = 0.0 } } \ No newline at end of file diff --git a/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/SwipeControl.kt b/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/SwipeControl.kt index f110884fc4a686c8fa0f54d4ede36ab35ef6c5b5..234fff5e517f9918d92c16b21df8a525903627f9 100644 --- a/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/SwipeControl.kt +++ b/app/src/main/java/jp/atled/agileworks/view/ui/documentweb/SwipeControl.kt @@ -6,6 +6,9 @@ import jp.atled.agileworks.databinding.FragmentWebviewDetailBinding class SwipeControl(var swipeRefreshLayout : SwipeRefreshLayout, var viewDataBinding : FragmentWebviewDetailBinding, var webview: WebView?) { + // 書類部分を取得するJavaScript + private val baseScript = "document.getElementById('doc-view-mobile-emmbedded-frame').contentDocument.getElementById('snapper-iframe')" + fun swipeControl() { swipeRefreshLayout.apply { setOnRefreshListener { @@ -32,4 +35,25 @@ class SwipeControl(var swipeRefreshLayout : SwipeRefreshLayout, var viewDataBind } } } + + fun updateDocumentScrollAmount() { + viewDataBinding.viewModel?.isDisconnectViewDisplay?.value?.let { isDisconnectViewDisplay -> + swipeRefreshLayout.let { swipeLayout -> + if (isDisconnectViewDisplay) { + // JavaScriptを実行し、書類部分のスクロール量を取得する + webview?.evaluateJavascript("$baseScript.contentWindow.pageYOffset") { result -> + if (result == "null") { + // 値が取得できない場合、後の変換で落ちるので以降の処理を行わない + return@evaluateJavascript + } + // 現在viewModelに保持しているスクロール量を変数に保存し、新たな値をviewModelに設定する + val oldScrollAmount = viewDataBinding.viewModel?.documentScrollAmount?.value + viewDataBinding.viewModel?.documentScrollAmount?.value = result.toDouble() + // 変数に保存した値と新たに設定した値を比較する + swipeLayout.isEnabled = oldScrollAmount == viewDataBinding.viewModel?.documentScrollAmount?.value + } + } + } + } + } } \ No newline at end of file