Skip to content

Commit

Permalink
fixes pages number calculation, fixes quotation parser, releases
Browse files Browse the repository at this point in the history
  • Loading branch information
yudanhezhongweijie committed Jul 3, 2022
1 parent 292f3f6 commit 2be7d46
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 36 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# ChangeLog 更新日志
- 1.6.01
- 1.6.05
- 更新域名至NMBXD
- 更新饼干读取逻辑
- 更新权限
- 支持读取值班室板块(需求饼干)
- 修复页数计算错误
- 修复串外引用,跳转

- 1.4.00
- 支持备胎
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ android {
applicationId "com.laotoua.dawnislandk"
minSdkVersion 23
targetSdkVersion 30
versionCode 58
versionName "v1.6.01"
versionCode 62
versionName "v1.6.05"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@

<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="nmbxd.com" />
<data android:host="www.nmbxd.com" />
<data android:host="www.nmbxd1.com" />
<!-- <data android:host="tnmb.org" />-->
<data android:pathPrefix="/t/" />
<data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ data class Post(
fun getImgUrl() = (img + ext)
fun getSimplifiedTitle(): String = if (title.isNotBlank() && title != "无标题") "标题:$title" else ""
fun getSimplifiedName(): String = if (name.isNotBlank() && name != "无名氏") "名称:$name" else ""

/**
* A page does not include the header post in comments
* w. cookie, a page of comments can have 20 reply w. ad, or 19 reply w/o ad
* w/o cookie, always have 20 reply w. ad
* Note: Using replyCount will always result into correct page number, however, some pages
* may have less than 19 replies(i.e. some replies are deleted)
* *** here DB only store nonAd data
* **********************************************
*/
fun getMaxPage() = if (replyCount.isBlank()) 1 else 1.coerceAtLeast(ceil(replyCount.toDouble() / 19).toInt())

// only compares by server fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,15 @@ sealed class APIDataResponse<T>(
// server returns non json string
Timber.e("Parse failed: $e")
Timber.d("Response is non JSON data...$resBody")
val resJson = JSONObject(StringEscapeUtils.unescapeJava(resBody.replace("\"", "")))
Error(StringEscapeUtils.unescapeJava(resJson.optString("error").toByteArray().decodeToString()))
val clean = resBody.replace("\"", "")
val error = try {
val resJson = JSONObject(StringEscapeUtils.unescapeJava(clean))
resJson.optString("error").toByteArray().decodeToString()
} catch (e2: Exception) {
Timber.e("Parse JSON catch failed: $e2")
clean
}
Error(StringEscapeUtils.unescapeJava(error))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.laotoua.dawnislandk.util.ReadableTime
import com.squareup.moshi.*
import org.json.JSONObject
import org.jsoup.Jsoup
import timber.log.Timber
import java.time.LocalDateTime


Expand Down Expand Up @@ -116,8 +117,9 @@ abstract class NMBJsonParser<T> {
val userid = if (uidText.startsWith("ID:")) uidText.substring(3) else uidText
val admin = if (uid.childNodeSize() > 1) "1" else "0"
val href = thread.getElementsByClass("h-threads-info-id").first().attr("href")
val endIndex = href.indexOf("?")
val parentId = if (endIndex < 0) href.substring(3) else href.substring(3, endIndex)
Timber.d("Extracting id from $href")
val parentId = href.substringAfterLast("/").substringBefore("?")
Timber.d("Extracted parentId $parentId")
val content = thread.getElementsByClass("h-threads-content").first().html()
return Comment(
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,10 @@ class CommentRepository @Inject constructor(
}

/**
* A page does not include the header post in comments
* w. cookie, a page of comments can have 20 reply w. ad, or 19 reply w/o ad
* w/o cookie, always have 20 reply w. ad
* *** here DB only store nonAd data
* **********************************************
* By default, a post is only stored in the post table, but not stored in the comment table.
* However when requesting references, all references are stored as comment in comment table.
* Therefore, the first page can have or not have the header post, if using local cache
*/
fun checkFullPage(id: String, page: Int): Boolean =
(commentsMap[id]?.get(page)?.value?.data?.filter { it.isNotAd() }?.size ?: 0) == 19

* */
fun getCommentsOnPage(id: String, page: Int, remoteDataOnly: Boolean, localDataOnly: Boolean): LiveData<DataResource<List<Comment>>> {
if (commentsMap[id] == null) {
commentsMap[id] = SparseArray()
Expand Down
30 changes: 15 additions & 15 deletions app/src/main/java/com/laotoua/dawnislandk/screens/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,24 @@ class MainActivity : DaggerAppCompatActivity() {
if (action == Intent.ACTION_VIEW && data != null) {
val path = data.path
if (path.isNullOrBlank()) return
val count = path.filter { it == '/' }.count()
val count = path.count { it == '/' }
val raw = data.toString().substringAfterLast("/")
if (raw.isNotBlank()) {
val id = if (raw.contains("?")) raw.substringBefore("?") else raw
Timber.d("Received intent data $data path ${data.path} schema ${data.scheme}")
if (data.scheme != DawnApp.currentDomain){
when (data.scheme) {
DawnConstants.NMBXDDomain -> {
goToNMBXD()
}
DawnConstants.TNMBDomain -> {
goToTNMB()
}
else -> {
Timber.e("Unsupported Intent Filter ${data.scheme}")
}
}
}
Timber.d("Received intent data $data path ${data.path} host ${data.host} schema ${data.scheme}")
// if (data.scheme != DawnApp.currentDomain){
// when (data.scheme) {
// DawnConstants.NMBXDDomain -> {
// goToNMBXD()
// }
// DawnConstants.TNMBDomain -> {
// goToTNMB()
// }
// else -> {
// Timber.e("Unsupported Intent Filter ${data.scheme}")
// }
// }
// }

if ((count == 1 && data.host == "t") || (count == 2 && path[1] == 't')) {
val navAction = MainNavDirections.actionGlobalCommentsFragment(id, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ class CommentsViewModel @Inject constructor(

fun getNextPage(incrementPage: Boolean = true, readingProgress: Int? = null, forceUpdate: Boolean = true) {
var nextPage = readingProgress ?: (commentList.lastOrNull()?.page ?: 1)
if (incrementPage && commentRepo.checkFullPage(currentPostId, nextPage)) nextPage += 1
if (incrementPage && maxPage > nextPage) nextPage += 1
listenToNewPage(nextPage, forceUpdate)
}

fun getPreviousPage(forceUpdate: Boolean = true) {
// Refresh when no data, usually error occurs
if (commentList.isNullOrEmpty()) {
if (commentList.isEmpty()) {
getNextPage()
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class QuotePopup(
}
LoadingStatus.ERROR -> {
dismiss()
Toast.makeText(context, it.message, Toast.LENGTH_LONG).show()
Toast.makeText(context, "无法获取引用。", Toast.LENGTH_LONG).show()
}
// do nothing when loading or no data
else -> {}
Expand Down Expand Up @@ -161,7 +161,7 @@ class QuotePopup(
}

findViewById<Button>(R.id.jumpToQuotedPost).run {
visibility = if (quote.parentId != currentPostId) View.VISIBLE else View.GONE
visibility = if (quote.parentId == quote.id && quote.parentId != currentPostId) View.VISIBLE else View.GONE
setOnClickListener {
if (isShow) {
mCaller?.jumpToNewPost(quote.parentId)
Expand Down

0 comments on commit 2be7d46

Please sign in to comment.