Fix JSON parsing error related to mod fields. Handle back navigation in LoginActivity and WebViewActivity.

This commit is contained in:
Docile-Alligator
2025-07-29 22:20:28 -04:00
parent 7647079dfd
commit 1beb4272e1
4 changed files with 35 additions and 26 deletions

View File

@ -19,6 +19,7 @@ import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.core.graphics.Insets;
import androidx.core.view.OnApplyWindowInsetsListener;
@ -300,6 +301,18 @@ public class LoginActivity extends BaseActivity {
.setCancelable(false)
.show();
}
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
if (binding.webviewLoginActivity.canGoBack()) {
binding.webviewLoginActivity.goBack();
} else {
setEnabled(false);
triggerBackPress();
}
}
});
}
@Override

View File

@ -13,7 +13,6 @@ import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.InflateException;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -21,6 +20,7 @@ import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.core.graphics.Insets;
import androidx.core.view.OnApplyWindowInsetsListener;
@ -125,6 +125,18 @@ public class WebViewActivity extends BaseActivity {
}
};
binding.webViewWebViewActivity.setWebViewClient(client);
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
if (binding.webViewWebViewActivity.canGoBack()) {
binding.webViewWebViewActivity.goBack();
} else {
setEnabled(false);
triggerBackPress();
}
}
});
}
@Override
@ -200,22 +212,6 @@ public class WebViewActivity extends BaseActivity {
return false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (binding.webViewWebViewActivity.canGoBack()) {
binding.webViewWebViewActivity.goBack();
} else {
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);

View File

@ -313,11 +313,11 @@ public class ParseComment {
boolean sendReplies = singleCommentData.getBoolean(JSONUtils.SEND_REPLIES_KEY);
boolean locked = singleCommentData.getBoolean(JSONUtils.LOCKED_KEY);
boolean canModComment = singleCommentData.getBoolean(JSONUtils.CAN_MOD_POST_KEY);
boolean approved = singleCommentData.getBoolean(JSONUtils.APPROVED_KEY);
long approvedAtUTC = singleCommentData.isNull(JSONUtils.APPROVED_AT_UTC_KEY) ? 0: singleCommentData.getLong(JSONUtils.APPROVED_AT_UTC_KEY) * 1000;
String approvedBy = singleCommentData.getString(JSONUtils.APPROVED_BY_KEY);
boolean removed = singleCommentData.getBoolean(JSONUtils.REMOVED_KEY);
boolean spam = singleCommentData.getBoolean(JSONUtils.SPAM_KEY);
boolean approved = singleCommentData.has(JSONUtils.APPROVED_KEY) && singleCommentData.getBoolean(JSONUtils.APPROVED_KEY);
long approvedAtUTC = singleCommentData.has(JSONUtils.APPROVED_AT_UTC_KEY) ? (singleCommentData.isNull(JSONUtils.APPROVED_AT_UTC_KEY) ? 0 : singleCommentData.getLong(JSONUtils.APPROVED_AT_UTC_KEY) * 1000) : 0;
String approvedBy = singleCommentData.has(JSONUtils.APPROVED_BY_KEY) ? singleCommentData.getString(JSONUtils.APPROVED_BY_KEY) : null;
boolean removed = singleCommentData.has(JSONUtils.REMOVED_KEY) && singleCommentData.getBoolean(JSONUtils.REMOVED_KEY);
boolean spam = singleCommentData.has(JSONUtils.SPAM_KEY) && singleCommentData.getBoolean(JSONUtils.SPAM_KEY);
if (singleCommentData.has(JSONUtils.DEPTH_KEY)) {
depth = singleCommentData.getInt(JSONUtils.DEPTH_KEY);

View File

@ -184,10 +184,10 @@ public class ParsePost {
boolean deleted = !data.isNull(JSONUtils.REMOVED_BY_CATEGORY_KEY) && data.getString(JSONUtils.REMOVED_BY_CATEGORY_KEY).equals("deleted");
boolean removed = !data.isNull(JSONUtils.REMOVED_BY_CATEGORY_KEY) && data.getString(JSONUtils.REMOVED_BY_CATEGORY_KEY).equals("moderator");
boolean canModPost = data.getBoolean(JSONUtils.CAN_MOD_POST_KEY);
boolean approved = data.getBoolean(JSONUtils.APPROVED_KEY);
long approvedAtUTC = data.isNull(JSONUtils.APPROVED_AT_UTC_KEY) ? 0: data.getLong(JSONUtils.APPROVED_AT_UTC_KEY) * 1000;
String approvedBy = data.getString(JSONUtils.APPROVED_BY_KEY);
boolean spam = data.getBoolean(JSONUtils.SPAM_KEY);
boolean approved = data.has(JSONUtils.APPROVED_KEY) && data.getBoolean(JSONUtils.APPROVED_KEY);
long approvedAtUTC = data.has(JSONUtils.APPROVED_AT_UTC_KEY) ? (data.isNull(JSONUtils.APPROVED_AT_UTC_KEY) ? 0 : data.getLong(JSONUtils.APPROVED_AT_UTC_KEY) * 1000) : 0;
String approvedBy = data.has(JSONUtils.APPROVED_BY_KEY) ? data.getString(JSONUtils.APPROVED_BY_KEY) : null;
boolean spam = data.has(JSONUtils.SPAM_KEY) && data.getBoolean(JSONUtils.SPAM_KEY);
StringBuilder postFlairHTMLBuilder = new StringBuilder();
String flair = "";