Convert HomeParser to use a bytebuffer
This commit is contained in:
1 parent
b7c8afe7d2
commit
b0f0686821
3 files changed
+9
-9
No files matched your search
@@ -199,7 +199,7 @@ object EhEngine {
|
||||
.apply { funds = funds ?: ehRequest(EhUrl.URL_FUNDS).executeAndParsingWith(HomeParser::parseFunds) }
|
||||
|
||||
suspend fun getImageLimits() = parZip(
|
||||
{ ehRequest(EhUrl.URL_HOME).executeAndParsingWith(HomeParser::parse) },
|
||||
{ fetchCompat(EhUrl.URL_HOME, parser = HomeParser::parse) },
|
||||
{ ehRequest(EhUrl.URL_FUNDS).executeAndParsingWith(HomeParser::parseFunds) },
|
||||
{ limits, funds -> HomeParser.Result(limits, funds) },
|
||||
)
|
||||
|
||||
@@ -4,12 +4,13 @@ import android.os.Parcelable
|
||||
import com.hippo.ehviewer.client.exception.InsufficientFundsException
|
||||
import com.hippo.ehviewer.client.exception.ParseException
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
object HomeParser {
|
||||
private val PATTERN_FUNDS = Regex("Available: ([\\d,]+) Credits.*Available: ([\\d,]+) kGP", RegexOption.DOT_MATCHES_ALL)
|
||||
private const val INSUFFICIENT_FUNDS = "Insufficient funds."
|
||||
|
||||
fun parse(body: String) = parseLimit(body)
|
||||
fun parse(body: ByteBuffer) = parseLimit(body)
|
||||
|
||||
fun parseResetLimits(body: String) {
|
||||
if (body.contains(INSUFFICIENT_FUNDS)) {
|
||||
@@ -34,4 +35,4 @@ object HomeParser {
|
||||
@Parcelize
|
||||
data class Limits(val current: Int, val maximum: Int, val resetCost: Int) : Parcelable
|
||||
|
||||
private external fun parseLimit(body: String): Limits
|
||||
private external fun parseLimit(body: ByteBuffer, limit: Int = body.limit()): Limits
|
||||
@@ -1,12 +1,11 @@
|
||||
use catch_panic::catch_panic;
|
||||
use get_vdom_first_element_by_class_name;
|
||||
use jni_fn::jni_fn;
|
||||
use jnix::jni::objects::{JClass, JString};
|
||||
use jnix::jni::sys::jobject;
|
||||
use jnix::jni::objects::{JByteBuffer, JClass};
|
||||
use jnix::jni::sys::{jint, jobject};
|
||||
use jnix::jni::JNIEnv;
|
||||
use jnix::{IntoJava, JnixEnv};
|
||||
use jnix_macros::IntoJava;
|
||||
use parse_jni_string;
|
||||
use {get_vdom_first_element_by_class_name, parse_bytebuffer};
|
||||
|
||||
#[derive(Default, IntoJava)]
|
||||
#[allow(non_snake_case)]
|
||||
@@ -21,9 +20,9 @@ pub struct Limits {
|
||||
#[catch_panic(default = "std::ptr::null_mut()")]
|
||||
#[allow(non_snake_case)]
|
||||
#[jni_fn("com.hippo.ehviewer.client.parser.HomeParserKt")]
|
||||
pub fn parseLimit(env: JNIEnv, _class: JClass, input: JString) -> jobject {
|
||||
pub fn parseLimit(env: JNIEnv, _class: JClass, input: JByteBuffer, limit: jint) -> jobject {
|
||||
let mut env = JnixEnv { env };
|
||||
parse_jni_string(&mut env, &input, |dom, parser, _env| {
|
||||
parse_bytebuffer(&mut env, input, limit, |dom, parser, _env| {
|
||||
let iter = get_vdom_first_element_by_class_name(dom, "homebox")?
|
||||
.as_tag()?
|
||||
.query_selector(parser, "strong")?;
|
||||
|
||||
Reference in new issue
Block a user