Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Commit

Permalink
fix: 适配新的查重API
Browse files Browse the repository at this point in the history
  • Loading branch information
re-ovo committed Jul 29, 2021
1 parent 3df76e9 commit 7ce81a2
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 44 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ android {

dependencies {
implementation ("androidx.core:core-ktx:1.6.0")
implementation ("androidx.appcompat:appcompat:1.3.0")
implementation ("androidx.appcompat:appcompat:1.3.1")
implementation ("com.google.android.material:material:1.4.0")

// Compose Lib
implementation ("androidx.compose.ui:ui:$composeVersion")
implementation ("androidx.compose.material:material:$composeVersion")
implementation ("androidx.compose.ui:ui-tooling:$composeVersion")
implementation ("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1")
implementation ("androidx.activity:activity-compose:1.3.0-rc02")
implementation ("androidx.activity:activity-compose:1.3.0")
implementation ("androidx.compose.runtime:runtime-livedata:$composeVersion")

// Dialog
Expand All @@ -69,7 +69,7 @@ dependencies {

// Paging3
implementation ("androidx.paging:paging-runtime-ktx:$pagingVersion")
implementation ("androidx.paging:paging-compose:1.0.0-alpha11")
implementation ("androidx.paging:paging-compose:1.0.0-alpha12")

// 图标扩展
implementation ("androidx.compose.material:material-icons-extended:$composeVersion")
Expand Down Expand Up @@ -101,7 +101,7 @@ dependencies {

// 约束布局
implementation ("androidx.constraintlayout:constraintlayout:2.0.4")
implementation ("androidx.constraintlayout:constraintlayout-compose:1.0.0-alpha08")
implementation ("androidx.constraintlayout:constraintlayout-compose:1.0.0-beta01")


testImplementation ("junit:junit:4.+")
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:roundIcon="@mipmap/ic_launcher_rounded"
android:allowBackup="true"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.ZhiWang">
<activity
android:name=".MainActivity"
Expand Down
43 changes: 41 additions & 2 deletions app/src/main/java/me/rerere/zhiwang/api/zhiwang/Response.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.rerere.zhiwang.api.zhiwang


import com.google.gson.annotations.SerializedName

data class Response(
Expand All @@ -16,8 +17,46 @@ data class Response(
@SerializedName("rate")
val rate: Double,
@SerializedName("related")
var related: List<List<Any>>,
val related: List<Related>,
@SerializedName("start_time")
val startTime: Int
)
) {
data class Related(
@SerializedName("rate")
val rate: Double,
@SerializedName("reply")
val reply: Reply,
@SerializedName("reply_url")
val replyUrl: String
) {
data class Reply(
@SerializedName("content")
val content: String,
@SerializedName("ctime")
val ctime: Int,
@SerializedName("dynamic_id")
val dynamicId: String,
@SerializedName("like_num")
val likeNum: Int,
@SerializedName("m_name")
val mName: String,
@SerializedName("mid")
val mid: Int,
@SerializedName("oid")
val oid: String,
@SerializedName("origin_rpid")
val originRpid: String,
@SerializedName("rpid")
val rpid: String,
@SerializedName("similar_count")
val similarCount: Int,
@SerializedName("similar_like_sum")
val similarLikeSum: Int,
@SerializedName("type_id")
val typeId: Int,

var avatar: String = ""
)
}
}
}
11 changes: 4 additions & 7 deletions app/src/main/java/me/rerere/zhiwang/repo/ZuowenRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@ class ZuowenRepo(
autoRetry {
zhiWangService.query(content)
}?.apply {
// 重新排序
this.data.related = this.data.related.sortedBy {
((it[1] as Map<*,*>)["ctime"] as Double).toLong()
}
println(this)

// 获取用户信息
this.data.related.forEach {
try {
val userInfo = it[1] as MutableMap<Any, Any>
val bilibiliUser = bilibiliUtil.getUserInfo((userInfo["mid"] as Double).toInt())
val mid = it.reply.mid
val bilibiliUser = bilibiliUtil.getUserInfo(mid)
bilibiliUser?.let { user ->
userInfo["avatar"] = user.data.face.replace("http:", "https:")
it.reply.avatar = user.data.face.replace("http:", "https:")
println("头像: ${user.data.face}")
}
}catch (e: Exception){
Expand Down
30 changes: 14 additions & 16 deletions app/src/main/java/me/rerere/zhiwang/ui/public/XiaoZuoWen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,31 @@ import androidx.constraintlayout.compose.ConstraintLayout
import coil.compose.ImagePainter
import coil.compose.rememberImagePainter
import com.google.accompanist.placeholder.material.placeholder
import me.rerere.zhiwang.api.zhiwang.Response
import me.rerere.zhiwang.ui.theme.PINK
import me.rerere.zhiwang.util.android.setClipboardText
import me.rerere.zhiwang.util.format.formatToString
import java.sql.Timestamp
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*

@Composable
fun XiaoZuoWen(data: List<Any>) {
fun XiaoZuoWen(data: Response.Data.Related) {
val context = LocalContext.current
val userInfo = data[1] as Map<*, *>
Card(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
.pointerInput(Unit) {
detectTapGestures(
onLongPress = {
context.setClipboardText(userInfo["content"] as String)
context.setClipboardText(data.reply.content)
Toast
.makeText(context, "已复制该作文到剪贴板", Toast.LENGTH_SHORT)
.show()
},
onTap = {
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse((data[2] as String).trim())
Uri.parse(data.replyUrl.trim())
)
context.startActivity(intent)
}
Expand All @@ -67,7 +65,7 @@ fun XiaoZuoWen(data: List<Any>) {
.padding(vertical = 4.dp)
) {
val (avatar, name, likes) = createRefs()
val painter = rememberImagePainter(userInfo["avatar"] as? String)
val painter = rememberImagePainter(data.reply.avatar as? String)
Box(modifier = Modifier
.constrainAs(avatar) {
start.linkTo(parent.start, 8.dp)
Expand All @@ -89,7 +87,7 @@ fun XiaoZuoWen(data: List<Any>) {
start.linkTo(avatar.end, 8.dp)
centerVerticallyTo(avatar)
},
text = userInfo["m_name"] as String,
text = data.reply.mName,
fontWeight = FontWeight.Bold,
color = PINK
)
Expand All @@ -104,32 +102,32 @@ fun XiaoZuoWen(data: List<Any>) {
contentDescription = null
)
Spacer(modifier = Modifier.width(3.dp))
Text(text = (userInfo["like_num"] as Double).toInt().toString())
Text(text = (data.reply.likeNum.toString()))
}
}
// 作文内容
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.high) {
Text(text = userInfo["content"] as String)
Text(text = data.reply.content)
}
// 作文信息
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.disabled) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Text(text = "重复度: ${((data[0] as Double) * 100).formatToString()}%")
Text(text = "重复度: ${(data.rate * 100f).toInt().coerceAtMost(100)}%")
Spacer(modifier = Modifier.width(8.dp))
Text(text = "日期: ${getDateTime((userInfo["ctime"] as Double).toLong())}")
Text(text = "日期: ${getDateTime((data.reply.ctime.toLong() * 1000L))}")
}
}
}
}
}

private fun getDateTime(time: Long): String? {
private val timeFormat = SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.CHINA)
fun getDateTime(time: Long): String? {
return try {
val timestamp = Timestamp(time)
return DateFormat.getDateInstance(2, Locale.CHINA).format(Date(timestamp.time * 1000L))
return timeFormat.format(Date(time))
} catch (e: Exception) {
e.toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ import com.google.accompanist.placeholder.PlaceholderHighlight
import com.google.accompanist.placeholder.material.placeholder
import com.google.accompanist.placeholder.material.shimmer
import me.rerere.zhiwang.ui.public.XiaoZuoWen
import me.rerere.zhiwang.ui.public.getDateTime
import me.rerere.zhiwang.ui.screen.index.IndexScreenVideoModel
import me.rerere.zhiwang.util.android.getClipboardContent
import me.rerere.zhiwang.util.format.formatToString
import me.rerere.zhiwang.util.format.format
import me.rerere.zhiwang.util.noRippleClickable
import java.text.DateFormat
import java.util.*

@ExperimentalAnimationApi
@Composable
Expand Down Expand Up @@ -194,7 +193,7 @@ fun Content(indexScreenVideoModel: IndexScreenVideoModel, scaffoldState: Scaffol
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "总文字复制比: ${(it.data.rate * 100).formatToString()}%",
text = "总文字复制比: ${(it.data.rate * 100).format()}%",
fontWeight = FontWeight.Bold,
fontSize = 23.sp,
modifier = Modifier.padding(4.dp),
Expand All @@ -215,15 +214,14 @@ fun Content(indexScreenVideoModel: IndexScreenVideoModel, scaffoldState: Scaffol
clipboardManager.setPrimaryClip(
ClipData.newPlainText(
null, """
查重结果:
* 查重时间: ${
DateFormat.getDateInstance(0, Locale.CHINA).format(
Date()
)
}
* 文字复制率: ${(it.data.rate * 100).formatToString()}%
* 首次出现于: ${if (it.data.related.isNotEmpty()) it.data.related[0][2] else ""}
数据来源于枝网,仅供参考
枝网文本复制检测报告(APP版)
查重时间: ${getDateTime(System.currentTimeMillis())}
总文字复制比: ${(it.data.rate * 100).format()}%
相似小作文: ${it.data.related[0].replyUrl}
作者: ${it.data.related[0].reply.mName}
发表时间: ${getDateTime(it.data.related[0].reply.ctime.toLong() * 1000L)}
查重结果仅作参考,请注意辨别是否为原创
""".trimIndent()
)
)
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// JetPack Compose 版本
const val composeVersion = "1.0.0-rc02"
const val composeVersion = "1.0.0"

// Hilt 版本
const val hiltVersion = "2.37"
Expand All @@ -9,4 +9,4 @@ const val pagingVersion = "3.0.0"

// accompanist 版本
// https://github.com/google/accompanist
const val accVersion = "0.14.0"
const val accVersion = "0.15.0"

0 comments on commit 7ce81a2

Please sign in to comment.