Skip to content

Commit

Permalink
Update webview disconnect page bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
bplaat committed Aug 16, 2020
1 parent ddeb1b9 commit 2bdd3df
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/nl/plaatsoft/warquest3/Config.java.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class Config {
private Config() {}

// The WarQuest root url
public static final String WARQUEST_URL = "https://warquest.plaatsoft.nl/";
public static final String WARQUEST_URL = "https://warquest.plaatsoft.nl";

// The WarQuest API url (enter your own)
public static final String WARQUEST_API_KEY = "";
Expand Down
2 changes: 1 addition & 1 deletion src/nl/plaatsoft/warquest3/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void onClick(View view) {
// Create request url
String url = null;
try {
url = Config.WARQUEST_URL + "api/auth/login?key=" + Config.WARQUEST_API_KEY +
url = Config.WARQUEST_URL + "/api/auth/login?key=" + Config.WARQUEST_API_KEY +
"&username=" + URLEncoder.encode(usernameInput.getText().toString(), "UTF-8") +
"&password=" + URLEncoder.encode(passwordInput.getText().toString(), "UTF-8");
} catch (Exception exception) {
Expand Down
20 changes: 14 additions & 6 deletions src/nl/plaatsoft/warquest3/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,34 @@ public void onClick(View view) {
((Button)findViewById(R.id.main_disconnected_refresh_button)).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Refresh the webview
loadWebview(Config.WARQUEST_URL);
loadWebview(Config.WARQUEST_URL + "/");
}
});

// Webview update title handler
TextView headerTitle = (TextView)findViewById(R.id.main_header_title);
webview.setWebChromeClient(new WebChromeClient() {
public void onReceivedTitle(WebView view, String title) {
// Filter weird Android bug out
if (title.equals(Config.WARQUEST_URL)) {
return;
}

// Check if the disconnected page must bee soon
if (title.equals("about:blank")) {
webview.clearHistory();
headerTitle.setText("WarQuest");
webview.clearHistory();
webview.setVisibility(View.GONE);
disconnectedPage.setVisibility(View.VISIBLE);
}

// Else just load normal and set title
else {
headerTitle.setText(title);

// Check if the webview is hidden
if (disconnectedPage.getVisibility() == View.VISIBLE) {
webview.clearHistory();
webview.setVisibility(View.VISIBLE);
disconnectedPage.setVisibility(View.GONE);
}
Expand Down Expand Up @@ -138,7 +146,7 @@ public void onReceivedError(WebView view, WebResourceRequest webResourceRequest,
}

// Load the webview
loadWebview(Config.WARQUEST_URL);
loadWebview(Config.WARQUEST_URL + "/");
}
}

Expand Down Expand Up @@ -191,7 +199,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}

// Reload webview
loadWebview(Config.WARQUEST_URL);
loadWebview(Config.WARQUEST_URL + "/");
}

// When there is an error reading the accounts json create a new account
Expand Down Expand Up @@ -221,7 +229,7 @@ public void onBackPressed() {

// Create a new account and open the webview
private void createNewAccountAndOpen() {
FetchDataTask.fetchData(this, Config.WARQUEST_URL + "api/auth/register?key=" + Config.WARQUEST_API_KEY, false, false, new FetchDataTask.OnLoadListener() {
FetchDataTask.fetchData(this, Config.WARQUEST_URL + "/api/auth/register?key=" + Config.WARQUEST_API_KEY, false, false, new FetchDataTask.OnLoadListener() {
public void onLoad(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
Expand All @@ -240,7 +248,7 @@ public void onLoad(String response) {
settingsEditor.apply();

// Reload the webview
loadWebview(Config.WARQUEST_URL);
loadWebview(Config.WARQUEST_URL + "/");
return;
}
} catch (Exception exception) {
Expand Down
6 changes: 3 additions & 3 deletions src/nl/plaatsoft/warquest3/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon
// Create new account button
if (position == accountsAdapter.getCount() - 1) {
// Send register request
FetchDataTask.fetchData(SettingsActivity.this, Config.WARQUEST_URL + "api/auth/register?key=" + Config.WARQUEST_API_KEY, false, false, new FetchDataTask.OnLoadListener() {
FetchDataTask.fetchData(SettingsActivity.this, Config.WARQUEST_URL + "/api/auth/register?key=" + Config.WARQUEST_API_KEY, false, false, new FetchDataTask.OnLoadListener() {
public void onLoad(String response) {
try {
// Parse response
Expand Down Expand Up @@ -194,7 +194,7 @@ public void removeAccount(int position) {
// When no accounts are left create new own
if (jsonAccounts.length() == 0) {
// Send register request
FetchDataTask.fetchData(this, Config.WARQUEST_URL + "api/auth/register?key=" + Config.WARQUEST_API_KEY, false, false, new FetchDataTask.OnLoadListener() {
FetchDataTask.fetchData(this, Config.WARQUEST_URL + "/api/auth/register?key=" + Config.WARQUEST_API_KEY, false, false, new FetchDataTask.OnLoadListener() {
public void onLoad(String response) {
try {
// Parse response
Expand Down Expand Up @@ -295,7 +295,7 @@ private void updateAccountsData() {
}

// Create request url
String url = Config.WARQUEST_URL + "api/players?key=" + Config.WARQUEST_API_KEY;
String url = Config.WARQUEST_URL + "/api/players?key=" + Config.WARQUEST_API_KEY;
try {
for (int i = 0; i < jsonAccounts.length(); i++) {
Account account = Account.fromJson(jsonAccounts.getJSONObject(i));
Expand Down
Binary file modified warquest.apk
Binary file not shown.

0 comments on commit 2bdd3df

Please sign in to comment.