From 85b44d999abdac19df96ce6615f9a7760406a5ec Mon Sep 17 00:00:00 2001 From: AKIRA TAKEDA Date: Thu, 17 Mar 2022 10:16:39 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E3=83=89=E3=82=AD=E3=83=A5=E3=83=A1?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=83=93=E3=83=A5=E3=83=BC=E3=82=A2=E3=81=AE?= =?UTF-8?q?=E6=9B=B8=E9=A1=9E=E6=93=8D=E4=BD=9C=E3=81=AB=E3=81=A6=E4=B8=8A?= =?UTF-8?q?=E3=81=AB=E3=82=B9=E3=82=AF=E3=83=AD=E3=83=BC=E3=83=AB=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=81=AA=E3=81=84=E3=83=90=E3=82=B0=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/ui/documentweb/DocumentWebClient.kt | 2 ++ .../ui/documentweb/DocumentWebFragment.kt | 18 ++++++++++---- .../ui/documentweb/DocumentWebPresenter.kt | 5 ++++ .../ui/documentweb/DocumentWebViewModel.kt | 3 +++ .../view/ui/documentweb/SwipeControl.kt | 24 +++++++++++++++++++ 5 files changed, 48 insertions(+), 4 deletions(-) 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 bca95418..7996980f 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 d86da916..f6f7aecc 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 @@ -143,10 +143,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) } @@ -350,6 +356,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 daaf6faa..d86b5641 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 a1942d5d..75cef402 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 f110884f..234fff5e 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 -- GitLab From b060384dabdbd3ae0d16b8d43e2473122d19a093 Mon Sep 17 00:00:00 2001 From: AKIRA TAKEDA Date: Thu, 17 Mar 2022 11:39:47 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#42=E3=80=8C=E3=82=BF=E3=83=96=E9=81=B8?= =?UTF-8?q?=E6=8A=9E=E6=99=82=E3=80=81=E5=88=9D=E6=9C=9FURL=E3=82=92?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B=20=E3=80=8D=E3=81=AE?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C=E6=BC=8F=E3=82=8C=E5=8F=8A=E3=81=B3=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C=E3=81=AB=E3=82=88=E3=82=8A=E5=8B=95=E3=81=8D=E3=81=8C?= =?UTF-8?q?=E5=A4=89=E3=82=8F=E3=81=A3=E3=81=9F=E3=81=93=E3=81=A8=E3=81=AB?= =?UTF-8?q?=E3=82=B9=E3=83=AF=E3=82=A4=E3=83=97=E6=9B=B4=E6=96=B0=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=82=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agileworks/view/ui/documentweb/DocumentWebFragment.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 f6f7aecc..fc1e58fa 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を表示する必要があるか設定する(タブ変更時) @@ -270,7 +269,7 @@ class DocumentWebFragment : Fragment(), DocumentWebPresenter { applyCookieManager(connectUrl, true) } else { // タブ移動あり、一度タブ選択(=webView生成)されているタブを表示している状態でオンライン復帰 - applyCookieManager(lastUrl, false) + applyCookieManager(lastUrl, true) } } else { // タブ移動がない状態でオフラインからオンライン復帰時にここの処理が実施される -- GitLab