@@ -16,21 +16,27 @@ import android.provider.MediaStore
16
16
import android.widget.Toast
17
17
import androidx.activity.compose.LocalActivity
18
18
import androidx.compose.foundation.Image
19
+ import androidx.compose.foundation.border
19
20
import androidx.compose.foundation.layout.Column
20
21
import androidx.compose.foundation.layout.Row
21
22
import androidx.compose.foundation.layout.Spacer
22
23
import androidx.compose.foundation.layout.height
24
+ import androidx.compose.foundation.layout.padding
23
25
import androidx.compose.foundation.layout.width
24
26
import androidx.compose.foundation.rememberScrollState
27
+ import androidx.compose.foundation.shape.RoundedCornerShape
25
28
import androidx.compose.foundation.verticalScroll
26
29
import androidx.compose.material3.AlertDialog
27
30
import androidx.compose.material3.Button
28
31
import androidx.compose.material3.MaterialTheme
29
32
import androidx.compose.material3.OutlinedButton
30
33
import androidx.compose.material3.Text
31
34
import androidx.compose.runtime.Composable
35
+ import androidx.compose.runtime.LaunchedEffect
32
36
import androidx.compose.runtime.MutableState
33
37
import androidx.compose.runtime.getValue
38
+ import androidx.compose.runtime.mutableStateListOf
39
+ import androidx.compose.runtime.remember
34
40
import androidx.compose.runtime.rememberCoroutineScope
35
41
import androidx.compose.runtime.setValue
36
42
import androidx.compose.ui.Modifier
@@ -46,12 +52,14 @@ import androidx.compose.ui.unit.dp
46
52
import androidx.compose.ui.unit.sp
47
53
import androidx.core.content.ContextCompat
48
54
import androidx.core.graphics.drawable.toBitmap
55
+ import com.alibaba.fastjson2.JSONObject
49
56
import com.google.accompanist.permissions.ExperimentalPermissionsApi
50
57
import com.google.accompanist.permissions.isGranted
51
58
import com.google.accompanist.permissions.rememberPermissionState
52
59
import kotlinx.coroutines.Dispatchers
53
60
import kotlinx.coroutines.launch
54
61
import kotlinx.coroutines.withContext
62
+ import okhttp3.Request
55
63
import org.aquamarine5.brainspark.chaoxingsignfaker.R
56
64
import org.aquamarine5.brainspark.chaoxingsignfaker.UMengHelper
57
65
import org.aquamarine5.brainspark.chaoxingsignfaker.api.ChaoxingHttpClient
@@ -65,19 +73,29 @@ private const val SPONSOR_IMAGE_FILENAME_BASE = "ChaoxingSignFaker_sponsor"
65
73
@Composable
66
74
fun SponsorAlertDialog (showDialog : MutableState <Boolean >) {
67
75
val context = LocalActivity .current!! .applicationContext
68
- val sponsorList = listOf (
69
- listOf (" Xcellent" ," 18.80" ),
70
- listOf (" 催什么崔" , " 8.88" ),
71
- listOf (" 不愿透露姓名的耿先生" , " 8.88" ),
72
- listOf (" 不愿透露姓名的景先生" , " 7.66" ),
73
- listOf (" G*." , " 6.66" ),
74
- listOf (" R*e" ," 6.66" ),
75
- listOf (" 不愿透露姓名的高先生" , " 6.66" ),
76
- listOf (" 云端哥特" , " 6.60" ),
77
- listOf (" *." , " 6.00" ),
78
- listOf (" 死后世界战线" , " 5.88" ),
79
- listOf (" 不愿透露姓名的张先生" , " 2.88" ),
80
- )
76
+ val sponsorList = remember { mutableStateListOf<List <String >>() }
77
+ LaunchedEffect (Unit ) {
78
+ withContext(Dispatchers .IO ){
79
+ ChaoxingHttpClient .instance?.okHttpClient?.newCall(
80
+ Request .Builder ()
81
+ .get()
82
+ .url(" http://cdn.aquamarine5.fun/chaoxingsignfaker_sponsor.json" )
83
+ .build()
84
+ )?.execute().use {
85
+ val json = JSONObject .parseObject(it?.body?.string())
86
+ val list = json.getJSONArray(" sponsorList" )
87
+ if (list.isNotEmpty()) {
88
+ sponsorList.clear()
89
+ for (i in 0 until list.size) {
90
+ val item = list.getJSONArray(i)
91
+ if (item.size == 2 ) {
92
+ sponsorList.add(listOf (item.getString(0 ), item.getString(1 )))
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+ }
81
99
val coroutineScope = rememberCoroutineScope()
82
100
val permissionCheck =
83
101
if (Build .VERSION .SDK_INT < Build .VERSION_CODES .R ) rememberPermissionState(
@@ -221,7 +239,7 @@ fun SponsorAlertDialog(showDialog: MutableState<Boolean>) {
221
239
)
222
240
Spacer (modifier = Modifier .height(4 .dp))
223
241
Text (buildAnnotatedString {
224
- sponsorList.forEach {
242
+ sponsorList.forEachIndexed { index, it ->
225
243
withStyle(SpanStyle (fontWeight = FontWeight .Bold )) {
226
244
append(it[0 ])
227
245
}
@@ -236,9 +254,11 @@ fun SponsorAlertDialog(showDialog: MutableState<Boolean>) {
236
254
append(it[1 ])
237
255
}
238
256
append(" 元" )
257
+ if (index!= sponsorList.size- 1 )
239
258
append(" \n " )
240
259
}
241
- })
260
+ },modifier= Modifier .border(1 .dp, MaterialTheme .colorScheme.primary,
261
+ RoundedCornerShape (4 .dp)).padding(8 .dp))
242
262
}
243
263
})
244
264
}
0 commit comments