Skip to content

Commit

Permalink
1.7.6 릴리즈
Browse files Browse the repository at this point in the history
1. Json 파서 성능 개선
2. createInstance 메소드에 Synchronized 어노테이션 추가
  • Loading branch information
JellyBrick committed Jul 21, 2020
1 parent c142cda commit df5ae16
Show file tree
Hide file tree
Showing 30 changed files with 176 additions and 121 deletions.
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: '1.3.61'
classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: '1.3.72'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.10.0"
Expand All @@ -21,7 +21,7 @@ apply plugin: 'org.jetbrains.dokka'

def libName = 'KotlinInside'
def libDevVersion = ''
def libVersion = "1.7.5$libDevVersion"
def libVersion = "1.7.6$libDevVersion"
def libDesc = 'Unofficial DCInside API written in Kotlin'

group = 'be.zvz'
Expand All @@ -39,19 +39,19 @@ compileJava {
}

dependencies {
implementation group: 'commons-codec', name: 'commons-codec', version: '1.13'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
implementation group: 'commons-codec', name: 'commons-codec', version: '1.14'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
implementation group: 'org.apache.commons', name: 'commons-text', version: '1.8'

//Jackson
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.1'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.10.1'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.11.1'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.11.1'

//FlexMark
implementation group: 'com.vladsch.flexmark', name: 'flexmark', version: '0.50.46'
implementation group: 'com.vladsch.flexmark', name: 'flexmark-ext-gfm-strikethrough', version: '0.50.46'
implementation group: 'com.vladsch.flexmark', name: 'flexmark-ext-tables', version: '0.50.46'
implementation group: 'com.vladsch.flexmark', name: 'flexmark-ext-gfm-tasklist', version: '0.50.46'
implementation group: 'com.vladsch.flexmark', name: 'flexmark', version: '0.62.2'
implementation group: 'com.vladsch.flexmark', name: 'flexmark-ext-gfm-strikethrough', version: '0.62.2'
implementation group: 'com.vladsch.flexmark', name: 'flexmark-ext-tables', version: '0.62.2'
implementation group: 'com.vladsch.flexmark', name: 'flexmark-ext-gfm-tasklist', version: '0.62.2'

// Use the Kotlin JDK standard library.
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk7'
Expand All @@ -60,7 +60,7 @@ dependencies {
// Use the Kotlin JUnit integration.
testImplementation group: 'org.jetbrains.kotlin', name: 'kotlin-test-junit5'

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.5.2'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.6.2'
}

tasks.test {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-bin.zip
63 changes: 63 additions & 0 deletions src/main/java/be/zvz/kotlininside/json/JsonBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,69 @@ public <T> T as(Class<T> klass) {
}
}

public boolean asBoolean() {
return asBoolean(false);
}

public boolean asBoolean(boolean defaultValue) {
if (node != null) {
if (node.isBoolean()) {
return node.booleanValue();
} else if (node.isTextual()) {
switch (node.textValue()) {
case "TRUE":
case "true":
return true;
case "FALSE":
case "false":
return false;
}
}
}

return defaultValue;
}

public long asLong() {
return asLong(0);
}

public long asLong(long defaultValue) {
if (node != null) {
if (node.isNumber()) {
return node.numberValue().longValue();
} else if (node.isTextual()) {
try {
return Long.parseLong(node.textValue());
} catch (NumberFormatException ignored) {
// Fall through to default value.
}
}
}

return defaultValue;
}

public int asInteger() {
return asInteger(0);
}

public int asInteger(int defaultValue) {
if (node != null) {
if (node.isNumber()) {
return node.numberValue().intValue();
} else if (node.isTextual()) {
try {
return Integer.parseInt(node.textValue());
} catch (NumberFormatException ignored) {
// Fall through to default value.
}
}
}

return defaultValue;
}

public <K, V> Map<K, V> toMap() {
try {
return mapper.convertValue(node, new TypeReference<Map<K, V>>() {
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/be/zvz/kotlininside/value/ApiUrl.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package be.zvz.kotlininside.value;

public final class ApiUrl {
public static final String PC_WEB = "https://gall.dcinside.com/";
public static final String MOBILE_WEB = "http://m.dcinside.com/";
public static final String APP_API = "https://app.dcinside.com/api/";
public static final String AUTH_API = "https://dcid.dcinside.com/join/";
public static final String MAIN_API = "http://json2.dcinside.com/";
public static final String UPLOAD = "https://upload.dcinside.com/";
public static final String REDIRECT = APP_API + "redirect.php";

public static final class Article {
public static final String LIST = APP_API + "gall_list_new.php";
public static final String READ = APP_API + "gall_view_new.php";
public static final String WRITE = "https://upload.dcinside.com/_app_write_api.php";
public static final String WRITE = UPLOAD + "_app_write_api.php";
public static final String DELETE = APP_API + "gall_del.php";
public static final String MODIFY = APP_API + "gall_modify.php";

public static final String UPVOTE = APP_API + "_recommend_up.php";
public static final String DOWNVOTE = APP_API + "_recommend_down.php";

public static final String REPORT = "http://m.dcinside.com/api/report.php";
public static final String REPORT = MOBILE_WEB + "api/report.php";

public static final String HIT_UPVOTE = APP_API + "hit_recommend";
}
Expand All @@ -33,7 +36,7 @@ public static final class DCCon {

public static final class Gallery {
public static final String MINOR_INFO = APP_API + "minor_info";
public static final String MINOR_MANAGEMENT = "https://gall.dcinside.com/mgallery/management/mobile";
public static final String MINOR_MANAGEMENT = PC_WEB + "mgallery/management/mobile";
public static final String MINOR_MANAGER_REQUEST = APP_API + "_manager_request.php";
public static final String MINOR_BLOCK_WEB = APP_API + "minor_avoid";
public static final String MINOR_BLOCK_ADD = APP_API + "minor_avoidadd";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/be/zvz/kotlininside/value/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
public final class Const {
public static final String DC_APP_SIGNATURE = "ReOo4u96nnv8Njd7707KpYiIVYQ3FlcKHDJE046Pg6s=";
public static final String DC_APP_PACKAGE = "com.dcinside.app";
public static final String DC_APP_VERSION_CODE = "30131";
public static final String DC_APP_VERSION_NAME = "3.5.2";
public static final String DC_APP_VERSION_CODE = "30308";
public static final String DC_APP_VERSION_NAME = "3.8.15";

public static final String DEFAULT_FCM_TOKEN;

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/be/zvz/kotlininside/KotlinInside.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class KotlinInside private constructor(
*/
@JvmStatic
@JvmOverloads
@Synchronized
fun createInstance(user: User, httpInterface: HttpInterface, sessionAutoRefresh: Boolean = false) {
if (!::instance.isInitialized) {
instance = KotlinInside(user, httpInterface, sessionAutoRefresh)
instance.init()
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class ArticleDelete @JvmOverloads constructor(
return DeleteResult(
result = false,
message = json.get("message").text(),
status = json.get("status").`as`(Int::class.java)
status = json.get("status").asInteger()
)
}
else -> {
val result = `as`(Boolean::class.java)
val result = asBoolean()

return when {
result -> DeleteResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ArticleHitUpvote(

val json = KotlinInside.getInstance().httpInterface.upload(ApiUrl.Article.HIT_UPVOTE, option)!!.index(0)

val result = json.get("result").`as`(Boolean::class.java)
val result = json.get("result").asBoolean()

return when {
result -> HitUpvoteResult(
Expand Down
46 changes: 18 additions & 28 deletions src/main/kotlin/be/zvz/kotlininside/api/article/ArticleList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,37 +146,27 @@ class ArticleList @JvmOverloads constructor(

return GallInfo(
title = gallInfo.get("gall_title").text(),
category = gallInfo.get("category").`as`(Int::class.java),
fileCount = gallInfo.get("file_cnt").`as`(Int::class.java),
fileSize = gallInfo.get("file_size").`as`(Int::class.java),
category = gallInfo.get("category").asInteger(),
fileCount = gallInfo.get("file_cnt").asInteger(),
fileSize = gallInfo.get("file_size").asInteger(),
captcha = gallInfo.safeGet("captcha").run {
when {
isNull -> null
else -> `as`(Boolean::class.java)
else -> asBoolean()
}
},
codeCount = gallInfo.safeGet("code_count").run {
when {
isNull -> null
else -> `as`(Int::class.java)
}
},
isMinor = gallInfo.safeGet("is_minor").run {
when {
isNull -> false
else -> `as`(Boolean::class.java)
}
},
isManager = gallInfo.safeGet("managerskill").run {
when {
isNull -> false
else -> `as`(Boolean::class.java)
else -> asInteger()
}
},
isMinor = gallInfo.safeGet("is_minor").asBoolean(),
isManager = gallInfo.safeGet("managerskill").asBoolean(),
notifyRecent = gallInfo.get("notify_recent").run {
when {
isNull -> null
else -> `as`(Int::class.java)
else -> asInteger()
}
},
relationGall = gallInfo.safeGet("relation_gall").run {
Expand All @@ -191,10 +181,10 @@ class ArticleList @JvmOverloads constructor(
!isNull -> values().forEach {
add(
HeadText(
identifier = it.get("no").`as`(Int::class.java),
identifier = it.get("no").asInteger(),
name = it.get("name").text(),
level = it.get("level").`as`(Int::class.java),
selected = it.get("selected").`as`(Boolean::class.java)
level = it.get("level").asInteger(),
selected = it.get("selected").asBoolean()
)
)
}
Expand All @@ -217,19 +207,19 @@ class ArticleList @JvmOverloads constructor(
for (gallList in json.index(0).get("gall_list").values()) {
add(
GallList(
identifier = gallList.get("no").`as`(Int::class.java),
views = gallList.get("hit").`as`(Int::class.java),
upvote = gallList.get("recommend").`as`(Int::class.java),
identifier = gallList.get("no").asInteger(),
views = gallList.get("hit").asInteger(),
upvote = gallList.get("recommend").asInteger(),
imageIcon = StringUtil.ynToBoolean(gallList.get("img_icon").text()),
upvoteIcon = StringUtil.ynToBoolean(gallList.get("recommend_icon").text()),
bestCheck = StringUtil.ynToBoolean(gallList.get("best_chk").text()),
level = gallList.get("level").`as`(Int::class.java),
totalComment = gallList.get("total_comment").`as`(Int::class.java),
totalVoice = gallList.get("total_voice").`as`(Int::class.java),
level = gallList.get("level").asInteger(),
totalComment = gallList.get("total_comment").asInteger(),
totalVoice = gallList.get("total_voice").asInteger(),
userId = gallList.get("user_id").text(),
voiceIcon = StringUtil.ynToBoolean(gallList.get("voice_icon").text()),
winnertaIcon = StringUtil.ynToBoolean(gallList.get("winnerta_icon").text()),
memberIcon = gallList.get("member_icon").`as`(Int::class.java),
memberIcon = gallList.get("member_icon").asInteger(),
ip = gallList.get("ip").text(),
gallerCon = gallList.safeGet("gallercon").run {
when {
Expand Down
14 changes: 7 additions & 7 deletions src/main/kotlin/be/zvz/kotlininside/api/article/ArticleModify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ class ArticleModify(
option
)!!.index(0)

val result = json.get("result").`as`(Boolean::class.java)
val result = json.get("result").asBoolean()

if (result) {
return ModifyResult(
result = result,
gallId = json.get("gall_id").text(),
articleId = json.get("gall_no").`as`(Int::class.java),
fileCount = json.get("file_cnt").`as`(Int::class.java),
fileSize = json.get("file_size").`as`(Int::class.java),
articleId = json.get("gall_no").asInteger(),
fileCount = json.get("file_cnt").asInteger(),
fileSize = json.get("file_size").asInteger(),
subject = json.get("subject").text(),
content = mutableListOf<Content>().apply {
json.get("memo").values().forEach {
Expand Down Expand Up @@ -127,10 +127,10 @@ class ArticleModify(
!jsonHeadText.isNull -> jsonHeadText.values().forEach {
add(
HeadText(
identifier = it.get("no").`as`(Int::class.java),
identifier = it.get("no").asInteger(),
name = it.get("name").text(),
level = it.get("level").`as`(Int::class.java),
selected = it.get("selected").`as`(Boolean::class.java)
level = it.get("level").asInteger(),
selected = it.get("selected").asBoolean()
)
)
}
Expand Down
Loading

0 comments on commit df5ae16

Please sign in to comment.