Fix bug with back button
This commit is contained in:
parent
989299cf31
commit
75a4874225
@ -9,8 +9,8 @@ android {
|
||||
applicationId "nl.privacydragon.bookwyrm"
|
||||
minSdk 23
|
||||
targetSdk 31
|
||||
versionCode 4
|
||||
versionName "1.2.1"
|
||||
versionCode 5
|
||||
versionName "1.2.2"
|
||||
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
Binary file not shown.
@ -11,8 +11,8 @@
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 4,
|
||||
"versionName": "1.2.1",
|
||||
"versionCode": 5,
|
||||
"versionName": "1.2.2",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
|
@ -8,6 +8,7 @@ import android.net.Uri;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Base64;
|
||||
import android.view.KeyEvent;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
@ -31,6 +32,7 @@ import javax.crypto.spec.GCMParameterSpec;
|
||||
|
||||
public class HandlerActivity extends AppCompatActivity {
|
||||
|
||||
WebView myWebView;
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -41,7 +43,7 @@ public class HandlerActivity extends AppCompatActivity {
|
||||
String appLinkAction = appLinkIntent.getAction();
|
||||
Uri appLinkData = appLinkIntent.getData();
|
||||
// End of auto-generated stuff
|
||||
WebView myWebView = (WebView) findViewById(R.id.webview);
|
||||
myWebView = (WebView) findViewById(R.id.webview);
|
||||
myWebView.getSettings().setJavaScriptEnabled(true);
|
||||
//The user credentials are stored in the shared preferences, so first they have to be read from there.
|
||||
String defaultValue = "none";
|
||||
@ -149,6 +151,17 @@ public class HandlerActivity extends AppCompatActivity {
|
||||
//Here, load the login page of the server. That actually does all that is needed.
|
||||
myWebView.loadUrl(toGoServer);
|
||||
}
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
// Check if the key event was the Back button and if there's history
|
||||
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
|
||||
myWebView.goBack();
|
||||
return true;
|
||||
}
|
||||
// If it wasn't the Back key or there's no web page history, bubble up to the default
|
||||
// system behavior (probably exit the activity)
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
//Here is code to make sure that links of the bookwyrm server are handled withing the webview client, instead of having it open in the default browser.
|
||||
//Yes, I used the web for this too.
|
||||
private class MyWebViewClient extends WebViewClient {
|
||||
|
@ -7,6 +7,7 @@ import android.content.SharedPreferences;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Base64;
|
||||
import android.view.KeyEvent;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
@ -29,13 +30,13 @@ import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.spec.GCMParameterSpec;
|
||||
|
||||
public class StartActivity extends AppCompatActivity {
|
||||
|
||||
WebView myWebView;
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_start);
|
||||
WebView myWebView = (WebView) findViewById(R.id.webview);
|
||||
myWebView = (WebView) findViewById(R.id.webview);
|
||||
myWebView.getSettings().setJavaScriptEnabled(true);
|
||||
//The user credentials are stored in the shared preferences, so first they have to be read from there.
|
||||
String defaultValue = "none";
|
||||
@ -118,6 +119,17 @@ public class StartActivity extends AppCompatActivity {
|
||||
//Here, load the login page of the server. That actually does all that is needed.
|
||||
myWebView.loadUrl("https://" + server + "/login");
|
||||
}
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
// Check if the key event was the Back button and if there's history
|
||||
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
|
||||
myWebView.goBack();
|
||||
return true;
|
||||
}
|
||||
// If it wasn't the Back key or there's no web page history, bubble up to the default
|
||||
// system behavior (probably exit the activity)
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
//Here is code to make sure that links of the bookwyrm server are handled withing the webview client, instead of having it open in the default browser.
|
||||
//Yes, I used the web for this too.
|
||||
private class MyWebViewClient extends WebViewClient {
|
||||
|
Loading…
x
Reference in New Issue
Block a user