Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1db8ef9
commit d15a825
Showing
6 changed files
with
203 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
app/src/main/kotlin/dev/aaa1115910/bv/component/Disclaimer.kt
This file was deleted.
Oops, something went wrong.
129 changes: 129 additions & 0 deletions
129
app/src/main/kotlin/dev/aaa1115910/bv/screen/RegionBlockScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package dev.aaa1115910.bv.screen | ||
|
||
import android.app.Activity | ||
import android.graphics.BitmapFactory | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.DisposableEffect | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.ImageBitmapConfig | ||
import androidx.compose.ui.graphics.asImageBitmap | ||
import androidx.compose.ui.graphics.toArgb | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import dev.aaa1115910.bv.R | ||
import dev.aaa1115910.bv.ui.theme.BVTheme | ||
import io.github.g0dkar.qrcode.QRCode | ||
import io.github.g0dkar.qrcode.render.Colors | ||
import okhttp3.internal.toHexString | ||
import java.io.ByteArrayInputStream | ||
import java.io.ByteArrayOutputStream | ||
import kotlin.system.exitProcess | ||
|
||
@Composable | ||
fun RegionBlockScreen( | ||
modifier: Modifier = Modifier | ||
) { | ||
val context = LocalContext.current | ||
var qrImage by remember { mutableStateOf(ImageBitmap(1, 1, ImageBitmapConfig.Argb8888)) } | ||
val primaryColorHex = | ||
"#" + MaterialTheme.colorScheme.primary.toArgb().toHexString().substring(2) | ||
|
||
LaunchedEffect(Unit) { | ||
println(primaryColorHex) | ||
val output = ByteArrayOutputStream() | ||
QRCode("扫码也没有用的!") | ||
.render(darkColor = Colors.css(primaryColorHex)) | ||
.writeImage(output) | ||
val input = ByteArrayInputStream(output.toByteArray()) | ||
qrImage = BitmapFactory.decodeStream(input).asImageBitmap() | ||
} | ||
|
||
DisposableEffect(key1 = Unit) { | ||
onDispose { | ||
(context as Activity).finish() | ||
exitProcess(0) | ||
} | ||
} | ||
|
||
Surface( | ||
modifier = modifier, | ||
color = MaterialTheme.colorScheme.primary | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(84.dp), | ||
contentAlignment = Alignment.CenterStart | ||
) { | ||
Column( | ||
verticalArrangement = Arrangement.spacedBy(24.dp) | ||
) { | ||
Text( | ||
text = stringResource(R.string.region_block_character_painting), | ||
fontSize = 100.sp | ||
) | ||
Column { | ||
Text( | ||
text = stringResource(R.string.region_block_title), | ||
style = MaterialTheme.typography.titleLarge | ||
) | ||
Text( | ||
text = stringResource(R.string.region_block_subtitle), | ||
style = MaterialTheme.typography.titleLarge | ||
) | ||
} | ||
Row( | ||
horizontalArrangement = Arrangement.spacedBy(12.dp) | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.size(80.dp) | ||
.background(Color.White), | ||
contentAlignment = Alignment.Center | ||
) { | ||
Image( | ||
modifier = Modifier.size(64.dp), | ||
bitmap = qrImage, | ||
contentDescription = null | ||
) | ||
} | ||
Column { | ||
Text(text = stringResource(R.string.region_block_solution_title)) | ||
Text(text = stringResource(R.string.region_block_solution_text)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview(device = "id:tv_1080p") | ||
@Composable | ||
private fun RegionBlockScreenPreview() { | ||
BVTheme { | ||
RegionBlockScreen() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dev.aaa1115910.bv.util | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.engine.okhttp.OkHttp | ||
import io.ktor.client.request.get | ||
import io.ktor.client.statement.bodyAsText | ||
import mu.KotlinLogging | ||
|
||
object NetworkUtil { | ||
private lateinit var client: HttpClient | ||
private const val LOC_CHECK_URL = "https://www.cloudflare.com/cdn-cgi/trace" | ||
private val logger = KotlinLogging.logger { } | ||
var networkCheckResult: Map<String, String> = emptyMap() | ||
|
||
init { | ||
createClient() | ||
} | ||
|
||
private fun createClient() { | ||
client = HttpClient(OkHttp) | ||
} | ||
|
||
suspend fun isMainlandChina(): Boolean { | ||
return runCatching { | ||
val result = client.get(LOC_CHECK_URL).bodyAsText() | ||
logger.info { "Network result:\n$result" } | ||
|
||
networkCheckResult = result | ||
.lines() | ||
.filter { it!="" } | ||
.associate { | ||
val splits = it.split("=") | ||
splits[0] to splits[1] | ||
} | ||
|
||
require(networkCheckResult["loc"] != "CN") { "BV doesn't support use in mainland China" } | ||
|
||
false | ||
}.getOrDefault(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters