Skip to content

Commit 70834cf

Browse files
committed
o8
1 parent 9dcb522 commit 70834cf

16 files changed

+880
-839
lines changed

app/src/main/java/org/aquamarine5/brainspark/chaoxingsignfaker/ChaoxingPredictableException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ package org.aquamarine5.brainspark.chaoxingsignfaker
88

99
open class ChaoxingPredictableException(
1010
override val message: String?,
11-
val throwable: Throwable? = null
11+
throwable: Throwable? = null
1212
) : Throwable(message, throwable)

app/src/main/java/org/aquamarine5/brainspark/chaoxingsignfaker/ImportOtherUserActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ class ImportOtherUserActivity : ComponentActivity() {
9999
}.onSuccess {
100100
isSuccess = true
101101
isLoading = false
102-
UMengHelper.onAccountOtherUserAddEvent(applicationContext,it)
102+
UMengHelper.onAccountOtherUserAddEvent(
103+
applicationContext,
104+
it
105+
)
103106
}.onFailure { failure ->
104107
errorTips =
105108
failure.message ?: failure.localizedMessage

app/src/main/java/org/aquamarine5/brainspark/chaoxingsignfaker/MainActivity.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ class MainActivity : ComponentActivity() {
318318
LocationClient.setAgreePrivacy(true)
319319
SDKInitializer.setAgreePrivacy(applicationContext, true)
320320
}
321+
ChaoxingHttpClient.deviceCode =
322+
datastore.deviceCode ?: ChaoxingHttpClient.generateDeviceCode(
323+
applicationContext
324+
)
321325
destination =
322326
when {
323327
!datastore.agreeTerms -> WelcomeDestination
@@ -338,10 +342,7 @@ class MainActivity : ComponentActivity() {
338342
}
339343
}
340344
}
341-
ChaoxingHttpClient.deviceCode =
342-
datastore.deviceCode ?: ChaoxingHttpClient.generateDeviceCode(
343-
applicationContext
344-
)
345+
345346
}
346347
}
347348
if (destination == null) {
@@ -463,7 +464,6 @@ class MainActivity : ComponentActivity() {
463464
}
464465
}
465466
}
466-
467467
}
468468
}
469469
}

app/src/main/java/org/aquamarine5/brainspark/chaoxingsignfaker/api/ChaoxingOtherUserHelper.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,18 @@ object ChaoxingOtherUserHelper {
5656
)
5757
}
5858

59-
suspend fun getSharedUrl(context: Context,insertSharedEntity: ChaoxingOtherUserSharedEntity?=null):String=
60-
withContext(Dispatchers.IO){
59+
suspend fun getSharedUrl(
60+
context: Context,
61+
insertSharedEntity: ChaoxingOtherUserSharedEntity? = null
62+
): String =
63+
withContext(Dispatchers.IO) {
6164
val sharedEntity =
6265
insertSharedEntity ?: getSharedUserEntity(context.chaoxingDataStore.data.first())
63-
"http://cdn.aquamarine5.fun/?phone=${sharedEntity.phoneNumber}&pwd=${sharedEntity.encryptedPassword}&name=${Uri.encode(sharedEntity.userName)}"
66+
"http://cdn.aquamarine5.fun/?phone=${sharedEntity.phoneNumber}&pwd=${sharedEntity.encryptedPassword}&name=${
67+
Uri.encode(
68+
sharedEntity.userName
69+
)
70+
}"
6471
}
6572

6673
suspend fun generateQRCode(
@@ -69,7 +76,11 @@ object ChaoxingOtherUserHelper {
6976
): Bitmap = withContext(Dispatchers.Default) {
7077
val qrcodeSize = getQRCodeSize(context)
7178
val qrCode = QRCodeWriter().encode(
72-
getSharedUrl(context, insertSharedEntity), BarcodeFormat.QR_CODE, qrcodeSize, qrcodeSize, mapOf(
79+
getSharedUrl(context, insertSharedEntity),
80+
BarcodeFormat.QR_CODE,
81+
qrcodeSize,
82+
qrcodeSize,
83+
mapOf(
7384
EncodeHintType.CHARACTER_SET to "utf-8",
7485
EncodeHintType.MARGIN to 1,
7586
EncodeHintType.ERROR_CORRECTION to ErrorCorrectionLevel.M

app/src/main/java/org/aquamarine5/brainspark/chaoxingsignfaker/signer/ChaoxingSignHelper.kt renamed to app/src/main/java/org/aquamarine5/brainspark/chaoxingsignfaker/api/ChaoxingSignHelper.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Repository: https://github.com/aquamarine5/ChaoxingSignFaker
55
*/
66

7-
package org.aquamarine5.brainspark.chaoxingsignfaker.signer
7+
package org.aquamarine5.brainspark.chaoxingsignfaker.api
88

99
import android.content.Context
1010
import android.widget.Toast
@@ -39,6 +39,4 @@ object ChaoxingSignHelper {
3939
null
4040
}
4141
}
42-
43-
4442
}

app/src/main/java/org/aquamarine5/brainspark/chaoxingsignfaker/components/CourseSignActivityColumnCard.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import androidx.compose.ui.Modifier
2121
import androidx.compose.ui.graphics.Color
2222
import androidx.compose.ui.platform.LocalContext
2323
import androidx.compose.ui.unit.dp
24+
import org.aquamarine5.brainspark.chaoxingsignfaker.api.ChaoxingSignHelper
2425
import org.aquamarine5.brainspark.chaoxingsignfaker.entity.ChaoxingSignActivityEntity
25-
import org.aquamarine5.brainspark.chaoxingsignfaker.signer.ChaoxingSignHelper
2626

2727

2828
@Composable
@@ -52,7 +52,6 @@ inline fun CourseSignActivityColumnCard(
5252
Text(activity.nameOne)
5353
Text("结束时间:${activity.nameFour}")
5454
}
55-
5655
}
5756
Spacer(modifier = Modifier.height(16.dp))
5857
}

app/src/main/java/org/aquamarine5/brainspark/chaoxingsignfaker/components/OtherUserSelectorComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fun OtherUserSelectorComponent(
126126
}
127127
Spacer(modifier = Modifier.height(6.dp))
128128
Text(
129-
"选择要进行二维码签到的用户",
129+
"选择要进行签到的用户",
130130
modifier = Modifier.padding(start = 3.dp)
131131
)
132132
Column(

app/src/main/java/org/aquamarine5/brainspark/chaoxingsignfaker/entity/ChaoxingSignStatus.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ data class ChaoxingSignStatus(
5858

5959
@Composable
6060
fun ResultCard() {
61-
6261
when (isSuccess.value) {
6362
true -> {
6463
Icon(painterResource(R.drawable.ic_check), "签到成功")

app/src/main/java/org/aquamarine5/brainspark/chaoxingsignfaker/screen/LocationSignScreen.kt

Lines changed: 91 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package org.aquamarine5.brainspark.chaoxingsignfaker.screen
99
import android.widget.Toast
1010
import androidx.activity.compose.BackHandler
1111
import androidx.compose.animation.AnimatedVisibility
12+
import androidx.compose.animation.Crossfade
1213
import androidx.compose.animation.core.tween
1314
import androidx.compose.animation.fadeIn
1415
import androidx.compose.animation.fadeOut
@@ -86,107 +87,110 @@ fun LocationSignScreen(
8687
navToCourseDetailDestination()
8788
}
8889
}
89-
when (isAlreadySigned) {
90-
true -> {
91-
AlreadySignedNotice(onSignForOtherUser = {
92-
isAlreadySigned = false
93-
isSignForOther = true
94-
}, onDismiss = {
95-
isAlreadySigned = false
96-
}) { navToCourseDetailDestination() }
97-
}
98-
99-
false -> {
100-
var isGetLocation by remember { mutableStateOf(false) }
101-
val signStatus = remember { mutableListOf(ChaoxingSignStatus()) }
102-
var isSelfForSign by remember { mutableStateOf(false) }
103-
val otherUserSessionForSignList = remember { mutableListOf<ChaoxingOtherUserSession>() }
104-
105-
OtherUserSelectorComponent(
106-
navToOtherUser = { navToOtherUserDestination() },
107-
signStatus = signStatus,
108-
isCurrentAlreadySigned = isSignForOther,
109-
) { isSelf, otherUserSessionList, _ ->
110-
isSelfForSign = isSelf
111-
otherUserSessionForSignList.addAll(otherUserSessionList)
112-
isGetLocation = true
90+
Crossfade(isAlreadySigned) { v ->
91+
when (v) {
92+
true -> {
93+
AlreadySignedNotice(onSignForOtherUser = {
94+
isAlreadySigned = false
95+
isSignForOther = true
96+
}, onDismiss = {
97+
isAlreadySigned = false
98+
}) { navToCourseDetailDestination() }
11399
}
114100

115-
AnimatedVisibility(
116-
isGetLocation, enter =
117-
slideInHorizontally(
118-
initialOffsetX = { it },
119-
animationSpec = tween(300)
120-
) + fadeIn(
121-
animationSpec = tween(300)
122-
), exit =
123-
scaleOut(targetScale = 0.8f, animationSpec = tween(300)) + fadeOut(
124-
animationSpec = tween(300)
125-
), modifier = Modifier.zIndex(1f)
126-
) {
127-
BackHandler(isGetLocation) {
128-
isGetLocation = false
101+
false -> {
102+
var isGetLocation by remember { mutableStateOf(false) }
103+
val signStatus = remember { mutableListOf(ChaoxingSignStatus()) }
104+
var isSelfForSign by remember { mutableStateOf(false) }
105+
val otherUserSessionForSignList =
106+
remember { mutableListOf<ChaoxingOtherUserSession>() }
107+
108+
OtherUserSelectorComponent(
109+
navToOtherUser = { navToOtherUserDestination() },
110+
signStatus = signStatus,
111+
isCurrentAlreadySigned = isSignForOther,
112+
) { isSelf, otherUserSessionList, _ ->
113+
isSelfForSign = isSelf
114+
otherUserSessionForSignList.addAll(otherUserSessionList)
115+
isGetLocation = true
129116
}
130-
GetLocationComponent(signInfo, confirmButtonText = {
131-
Text("签到")
132-
}) { result ->
133-
isGetLocation = false
134-
coroutineScope.launch {
135-
if (isSelfForSign)
136-
runCatching {
137-
signStatus[0].loading()
138-
signer.sign(result)
139-
}.onSuccess {
140-
signStatus[0].success()
141-
UMengHelper.onSignLocationEvent(
142-
context,
143-
result,
144-
ChaoxingHttpClient.instance!!.userEntity.name
145-
)
146-
}.onFailure {
147-
signStatus[0].failed(it)
148-
Toast.makeText(context, it.message, Toast.LENGTH_SHORT).show()
149-
if ((it is ChaoxingPredictableException).not()) {
150-
Sentry.captureException(it)
117+
118+
AnimatedVisibility(
119+
isGetLocation, enter =
120+
slideInHorizontally(
121+
initialOffsetX = { it },
122+
animationSpec = tween(300)
123+
) + fadeIn(
124+
animationSpec = tween(300)
125+
), exit =
126+
scaleOut(targetScale = 0.8f, animationSpec = tween(300)) + fadeOut(
127+
animationSpec = tween(300)
128+
), modifier = Modifier.zIndex(1f)
129+
) {
130+
BackHandler(isGetLocation) {
131+
isGetLocation = false
132+
}
133+
GetLocationComponent(signInfo, confirmButtonText = {
134+
Text("签到")
135+
}) { result ->
136+
isGetLocation = false
137+
coroutineScope.launch {
138+
if (isSelfForSign)
139+
runCatching {
140+
signStatus[0].loading()
141+
signer.sign(result)
142+
}.onSuccess {
143+
signStatus[0].success()
144+
UMengHelper.onSignLocationEvent(
145+
context,
146+
result,
147+
ChaoxingHttpClient.instance!!.userEntity.name
148+
)
149+
}.onFailure {
150+
signStatus[0].failed(it)
151+
Toast.makeText(context, it.message, Toast.LENGTH_SHORT).show()
152+
if ((it is ChaoxingPredictableException).not()) {
153+
Sentry.captureException(it)
154+
}
151155
}
152-
}
153-
otherUserSessionForSignList.forEachIndexed { index, userSession ->
154-
runCatching {
155-
signStatus[index + 1].loading()
156-
delay(1500)
157-
ChaoxingHttpClient.loadFromOtherUserSession(userSession)
158-
.also { client ->
159-
ChaoxingLocationSigner(client, destination).apply {
160-
if (preSign()) {
161-
signStatus[index + 1].failed(ChaoxingSigner.AlreadySignedException())
162-
} else {
163-
sign(result)
156+
otherUserSessionForSignList.forEachIndexed { index, userSession ->
157+
runCatching {
158+
signStatus[index + 1].loading()
159+
delay(1500)
160+
ChaoxingHttpClient.loadFromOtherUserSession(userSession)
161+
.also { client ->
162+
ChaoxingLocationSigner(client, destination).apply {
163+
if (preSign()) {
164+
signStatus[index + 1].failed(ChaoxingSigner.AlreadySignedException())
165+
} else {
166+
sign(result)
167+
}
164168
}
165169
}
170+
}.onSuccess {
171+
signStatus[index + 1].success()
172+
UMengHelper.onSignLocationEvent(
173+
context,
174+
result,
175+
userSession.name,
176+
true
177+
)
178+
}.onFailure {
179+
it.printStackTrace()
180+
if ((it is ChaoxingPredictableException).not()) {
181+
Sentry.captureException(it)
166182
}
167-
}.onSuccess {
168-
signStatus[index + 1].success()
169-
UMengHelper.onSignLocationEvent(
170-
context,
171-
result,
172-
userSession.name,
173-
true
174-
)
175-
}.onFailure {
176-
it.printStackTrace()
177-
if ((it is ChaoxingPredictableException).not()) {
178-
Sentry.captureException(it)
183+
signStatus[index + 1].failed(it)
179184
}
180-
signStatus[index + 1].failed(it)
181185
}
182186
}
183187
}
184188
}
185189
}
186-
}
187190

188-
null -> {
189-
CenterCircularProgressIndicator()
191+
null -> {
192+
CenterCircularProgressIndicator()
193+
}
190194
}
191195
}
192196

app/src/main/java/org/aquamarine5/brainspark/chaoxingsignfaker/screen/OtherUserScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fun OtherUserScreen(naviBack: () -> Unit) {
147147
}, title = {
148148
Text("通过文本链接的形式分享自己的用户数据")
149149
}, icon = {
150-
Icon(painterResource(R.drawable.ic_link),null)
150+
Icon(painterResource(R.drawable.ic_link), null)
151151
}, text = {
152152
Column {
153153
Text("对方将链接从浏览器打开即可导入你的用户数据(对方需更新到1.5版本及以上),或将链接粘贴到以下输入框中:")
@@ -233,7 +233,7 @@ fun OtherUserScreen(naviBack: () -> Unit) {
233233
)
234234
}, "分享自己的链接给他人"))
235235
}
236-
},modifier=Modifier.fillMaxWidth()) {
236+
}, modifier = Modifier.fillMaxWidth()) {
237237
Row(
238238
horizontalArrangement = Arrangement.Center,
239239
verticalAlignment = Alignment.CenterVertically

0 commit comments

Comments
 (0)