From 2bc0850b0fe363015401ecdadd422101ab7fab92 Mon Sep 17 00:00:00 2001 From: R4SAS Date: Wed, 13 Jan 2021 21:06:12 +0300 Subject: [PATCH] [android] add refresh on swipe in webconsole Signed-off-by: R4SAS --- android/AndroidManifest.xml | 4 +++ android/build.gradle | 1 + android/res/layout/activity_web_console.xml | 16 +++++++--- .../purplei2p/i2pd/WebConsoleActivity.java | 32 +++++++++++++++++-- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 8b011b8e..d0e8ecb6 100755 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -18,6 +18,10 @@ android:requestLegacyExternalStorage="true" android:theme="@android:style/Theme.Holo.Light.DarkActionBar" android:usesCleartextTraffic="true"> + + diff --git a/android/build.gradle b/android/build.gradle index dbe75759..0c208c91 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,6 +21,7 @@ repositories { dependencies { implementation 'androidx.core:core:1.0.2' + implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' } android { diff --git a/android/res/layout/activity_web_console.xml b/android/res/layout/activity_web_console.xml index 5724b387..60d22a0b 100644 --- a/android/res/layout/activity_web_console.xml +++ b/android/res/layout/activity_web_console.xml @@ -1,14 +1,22 @@ - - + android:layout_height="fill_parent" + android:id="@+id/swipe"> + + + + + diff --git a/android/src/org/purplei2p/i2pd/WebConsoleActivity.java b/android/src/org/purplei2p/i2pd/WebConsoleActivity.java index 0fcf37fe..5e20e8fa 100644 --- a/android/src/org/purplei2p/i2pd/WebConsoleActivity.java +++ b/android/src/org/purplei2p/i2pd/WebConsoleActivity.java @@ -2,14 +2,18 @@ package org.purplei2p.i2pd; import android.app.Activity; import android.os.Bundle; +import android.os.Handler; import android.view.MenuItem; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import java.util.Objects; public class WebConsoleActivity extends Activity { + private WebView webView; + private SwipeRefreshLayout swipeRefreshLayout; @Override protected void onCreate(Bundle savedInstanceState) { @@ -18,19 +22,43 @@ public class WebConsoleActivity extends Activity { Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true); - final WebView webView = findViewById(R.id.webview1); + webView = (WebView) findViewById(R.id.webview1); webView.setWebViewClient(new WebViewClient()); final WebSettings webSettings = webView.getSettings(); webSettings.setBuiltInZoomControls(true); webSettings.setJavaScriptEnabled(false); webView.loadUrl("http://127.0.0.1:7070"); // TODO: instead 7070 I2Pd....HttpPort + + swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe); + swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + swipeRefreshLayout.setRefreshing(true); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + swipeRefreshLayout.setRefreshing(false); + webView.reload(); + } + }, 1000); + } + }); + } + + @Override + public void onBackPressed() { + if (webView.canGoBack()) { + webView.goBack(); + } else { + super.onBackPressed(); + } } public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); - if (id==android.R.id.home) { + if (id == android.R.id.home) { finish(); return true; }