Fix bug with back button
This commit is contained in:
parent
989299cf31
commit
75a4874225
@ -9,8 +9,8 @@ android {
|
|||||||
applicationId "nl.privacydragon.bookwyrm"
|
applicationId "nl.privacydragon.bookwyrm"
|
||||||
minSdk 23
|
minSdk 23
|
||||||
targetSdk 31
|
targetSdk 31
|
||||||
versionCode 4
|
versionCode 5
|
||||||
versionName "1.2.1"
|
versionName "1.2.2"
|
||||||
|
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -11,8 +11,8 @@
|
|||||||
"type": "SINGLE",
|
"type": "SINGLE",
|
||||||
"filters": [],
|
"filters": [],
|
||||||
"attributes": [],
|
"attributes": [],
|
||||||
"versionCode": 4,
|
"versionCode": 5,
|
||||||
"versionName": "1.2.1",
|
"versionName": "1.2.2",
|
||||||
"outputFile": "app-release.apk"
|
"outputFile": "app-release.apk"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -8,6 +8,7 @@ import android.net.Uri;
|
|||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.webkit.WebResourceRequest;
|
import android.webkit.WebResourceRequest;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
@ -31,6 +32,7 @@ import javax.crypto.spec.GCMParameterSpec;
|
|||||||
|
|
||||||
public class HandlerActivity extends AppCompatActivity {
|
public class HandlerActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
WebView myWebView;
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -41,7 +43,7 @@ public class HandlerActivity extends AppCompatActivity {
|
|||||||
String appLinkAction = appLinkIntent.getAction();
|
String appLinkAction = appLinkIntent.getAction();
|
||||||
Uri appLinkData = appLinkIntent.getData();
|
Uri appLinkData = appLinkIntent.getData();
|
||||||
// End of auto-generated stuff
|
// End of auto-generated stuff
|
||||||
WebView myWebView = (WebView) findViewById(R.id.webview);
|
myWebView = (WebView) findViewById(R.id.webview);
|
||||||
myWebView.getSettings().setJavaScriptEnabled(true);
|
myWebView.getSettings().setJavaScriptEnabled(true);
|
||||||
//The user credentials are stored in the shared preferences, so first they have to be read from there.
|
//The user credentials are stored in the shared preferences, so first they have to be read from there.
|
||||||
String defaultValue = "none";
|
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.
|
//Here, load the login page of the server. That actually does all that is needed.
|
||||||
myWebView.loadUrl(toGoServer);
|
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.
|
//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.
|
//Yes, I used the web for this too.
|
||||||
private class MyWebViewClient extends WebViewClient {
|
private class MyWebViewClient extends WebViewClient {
|
||||||
|
@ -7,6 +7,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.webkit.WebResourceRequest;
|
import android.webkit.WebResourceRequest;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
@ -29,13 +30,13 @@ import javax.crypto.NoSuchPaddingException;
|
|||||||
import javax.crypto.spec.GCMParameterSpec;
|
import javax.crypto.spec.GCMParameterSpec;
|
||||||
|
|
||||||
public class StartActivity extends AppCompatActivity {
|
public class StartActivity extends AppCompatActivity {
|
||||||
|
WebView myWebView;
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_start);
|
setContentView(R.layout.activity_start);
|
||||||
WebView myWebView = (WebView) findViewById(R.id.webview);
|
myWebView = (WebView) findViewById(R.id.webview);
|
||||||
myWebView.getSettings().setJavaScriptEnabled(true);
|
myWebView.getSettings().setJavaScriptEnabled(true);
|
||||||
//The user credentials are stored in the shared preferences, so first they have to be read from there.
|
//The user credentials are stored in the shared preferences, so first they have to be read from there.
|
||||||
String defaultValue = "none";
|
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.
|
//Here, load the login page of the server. That actually does all that is needed.
|
||||||
myWebView.loadUrl("https://" + server + "/login");
|
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.
|
//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.
|
//Yes, I used the web for this too.
|
||||||
private class MyWebViewClient extends WebViewClient {
|
private class MyWebViewClient extends WebViewClient {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user