[android] add refresh on swipe in webconsole

Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
R4SAS 2021-01-13 21:06:12 +03:00
parent 29176dd9bf
commit 2bc0850b0f
4 changed files with 47 additions and 6 deletions

View File

@ -18,6 +18,10 @@
android:requestLegacyExternalStorage="true"
android:theme="@android:style/Theme.Holo.Light.DarkActionBar"
android:usesCleartextTraffic="true">
<meta-data
android:name="android.webkit.WebView.MetricsOptOut"
android:value="true"/>
<activity android:name=".WebConsoleActivity"></activity>
<receiver android:name=".NetworkStateChangeReceiver">

View File

@ -21,6 +21,7 @@ repositories {
dependencies {
implementation 'androidx.core:core:1.0.2'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
}
android {

View File

@ -1,14 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/layout_prompt"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".WebConsoleActivity">
<WebView
android:id="@+id/webview1"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
android:layout_height="fill_parent"
android:id="@+id/swipe">
<WebView
android:id="@+id/webview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>

View File

@ -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;
}