Skip to content

Commit

Permalink
汐洛链滴社区客户端 #57
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed May 24, 2024
1 parent a4897c4 commit c15fc1f
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 71 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/org/b3log/siyuan/S.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@file:Suppress("CompositionLocalNaming", "CompositionLocalNaming")
package org.b3log.siyuan

import android.net.Uri
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -81,4 +82,13 @@ object S {
val Card_bgColor_green1 = compositionLocalOf { Color(0x9F237A58) }
val Card_bgColor_gold1 = compositionLocalOf { Color(0x88997758) }
}

data class UriMatchPattern(val scheme: String, val host: String)

fun isUriMatched(uri: Uri?, pattern: UriMatchPattern): Boolean {
return uri?.scheme == pattern.scheme && uri.host == pattern.host
}
val case_ld246_1 = UriMatchPattern("https", "ssl.ptlogin2.qq.com") // 目前必须将默认打开方式浏览器设置为汐洛,否则QQ回调进不来
val case_ld246_2 = UriMatchPattern("https", "ld246.com")
val case_github_1 = UriMatchPattern("https", "github.com")
}
24 changes: 17 additions & 7 deletions app/src/main/java/org/b3log/siyuan/Us.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.net.URLDecoder
import java.net.URLEncoder
import java.security.MessageDigest
import java.text.DecimalFormat
import javax.crypto.Cipher
Expand All @@ -65,13 +66,22 @@ import kotlin.math.sqrt


object Us {
fun dropAndDecodeUrl(url: String, drop: String): String {
// 正则表达式匹配 "https://ld246.com/forward?goto=" 并去除
val regex = drop.toRegex()
val withoutPrefix = regex.replace(url, "")

// URL 解码
return URLDecoder.decode(withoutPrefix, "UTF-8")
fun replaceScheme_deepDecode(url: String, old: String, new: String): String {
// 解码URL
var decodedUrl = URLDecoder.decode(url, "UTF-8")
// 替换scheme
decodedUrl = decodedUrl.replace(old, new)
var previousUrl: String
do {
previousUrl = decodedUrl
// 再次解码URL
decodedUrl = URLDecoder.decode(decodedUrl, "UTF-8")
} while (decodedUrl != previousUrl)

return decodedUrl
}
fun replaceEncodeScheme(url: String, old: String, new: String): String {
return url.replace(URLEncoder.encode(old), URLEncoder.encode(new))
}
fun parseAndDecodeUrl(url: String, regex: Regex): String {
val decodedUrls = regex.findAll(url).map { matchResult ->
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/org/b3log/siyuan/compose/HTML.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import android.util.Log
import android.view.MotionEvent
import android.view.View
import android.widget.TextView
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
Expand All @@ -42,7 +43,7 @@ fun HtmlText(html: String, modifier: Modifier = Modifier) {
@Composable
fun SelectableHtmlText(html: String, modifier: Modifier = Modifier) {
AndroidView(
modifier = modifier,
modifier = modifier.fillMaxWidth(),
factory = { context ->
TextView(context).apply {
// 允许长按复制文本,需放在前面
Expand All @@ -56,7 +57,7 @@ fun SelectableHtmlText(html: String, modifier: Modifier = Modifier) {
},
update = { textView ->
val _Html = Us.parseAndDecodeUrl(html, """['"]https://ld246.com/forward\?goto=([^'"]*)['"]""".toRegex())
Log.i("HTML", _Html)
// Log.i("HTML", _Html)
textView.text = HtmlCompat.fromHtml(_Html, HtmlCompat.FROM_HTML_MODE_COMPACT, null, MyTagHandler())
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fun TopRightMenu(
expanded = expanded,
onDismissRequest = onDismiss
) {
if (uri != null) {
if (uri != null && !listOf("http","https","siyuan").contains(uri.scheme)) {
DropdownMenuItem(
text = { Text("复制") },
leadingIcon = { Icon(Icons.TwoTone.ContentCopy, contentDescription = null) },
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/org/b3log/siyuan/ld246/DC.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.b3log.siyuan.ld246

data class ld246_Response_NoData(
val msg: String,
val random: String,
val code: Int,
)
data class ld246_Response(
val msg: String,
val random: String,
val code: Int,
val data: ld246_Response_Data,
// 其他可能存在的字段可以省略
)
data class ld246_Response_Data(
val notifications: List<ld246_Response_Data_Notification>, // 理想的字段,其实不存在
Expand All @@ -16,7 +20,6 @@ data class ld246_Response_Data(
val followingNotifications: List<ld246_Response_Data_Notification>, // 关注
val pagination: Pagination,
val unreadNotificationCount: UnreadNotificationCount,
// 其他可能存在的字段可以省略
)
data class ld246_Response_Data_Notification(
val dataId: String,
Expand All @@ -26,17 +29,14 @@ data class ld246_Response_Data_Notification(
val hasRead: Boolean,
val title: String,
val content: String,
// 其他可能存在的字段可以省略
)

data class Pagination(
val paginationPageCount: Int,
val paginationPageNums: List<Int>
// 其他可能存在的字段可以省略
)

data class UnreadNotificationCount(
val unreadReviewNotificationCnt: Int,
val unreadNotificationCnt: Int,
// 其他可能存在的字段可以省略
)
Loading

0 comments on commit c15fc1f

Please sign in to comment.