Skip to content

Commit 348c058

Browse files
committed
修复移动端未屏蔽中国用户
1 parent c0a6090 commit 348c058

File tree

4 files changed

+145
-4
lines changed

4 files changed

+145
-4
lines changed

app/mobile/src/main/kotlin/dev/aaa1115910/bv/mobile/activities/MainActivity.kt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,49 @@ package dev.aaa1115910.bv.mobile.activities
33
import android.os.Bundle
44
import androidx.activity.ComponentActivity
55
import androidx.activity.compose.setContent
6+
import androidx.compose.runtime.LaunchedEffect
7+
import androidx.compose.runtime.getValue
8+
import androidx.compose.runtime.mutableStateOf
9+
import androidx.compose.runtime.remember
10+
import androidx.compose.runtime.rememberCoroutineScope
11+
import androidx.compose.runtime.setValue
612
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
713
import dev.aaa1115910.bv.mobile.screen.MobileMainScreen
14+
import dev.aaa1115910.bv.mobile.screen.RegionBlockScreen
815
import dev.aaa1115910.bv.mobile.theme.BVMobileTheme
16+
import dev.aaa1115910.bv.util.NetworkUtil
17+
import kotlinx.coroutines.Dispatchers
18+
import kotlinx.coroutines.launch
919

1020
class MainActivity : ComponentActivity() {
1121
override fun onCreate(savedInstanceState: Bundle?) {
12-
installSplashScreen()
22+
var keepSplashScreen = true
23+
installSplashScreen().apply {
24+
setKeepOnScreenCondition { keepSplashScreen }
25+
}
1326
super.onCreate(savedInstanceState)
27+
1428
setContent {
29+
val scope = rememberCoroutineScope()
30+
var isCheckingNetwork by remember { mutableStateOf(true) }
31+
var isMainlandChina by remember { mutableStateOf(false) }
32+
33+
LaunchedEffect(Unit) {
34+
scope.launch(Dispatchers.IO) {
35+
isMainlandChina = NetworkUtil.isMainlandChina()
36+
isCheckingNetwork = false
37+
keepSplashScreen = false
38+
}
39+
}
40+
1541
BVMobileTheme {
16-
MobileMainScreen()
42+
if (isCheckingNetwork) {
43+
// 避免提前加载内容
44+
} else if (isMainlandChina) {
45+
RegionBlockScreen()
46+
} else {
47+
MobileMainScreen()
48+
}
1749
}
1850
}
1951
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package dev.aaa1115910.bv.mobile.screen
2+
3+
import android.app.Activity
4+
import android.content.res.Configuration
5+
import androidx.compose.foundation.layout.Arrangement
6+
import androidx.compose.foundation.layout.Box
7+
import androidx.compose.foundation.layout.Column
8+
import androidx.compose.foundation.layout.fillMaxSize
9+
import androidx.compose.foundation.layout.fillMaxWidth
10+
import androidx.compose.foundation.layout.padding
11+
import androidx.compose.foundation.layout.size
12+
import androidx.compose.foundation.layout.widthIn
13+
import androidx.compose.material.icons.Icons
14+
import androidx.compose.material.icons.filled.WarningAmber
15+
import androidx.compose.material3.FilledTonalButton
16+
import androidx.compose.material3.Icon
17+
import androidx.compose.material3.MaterialTheme
18+
import androidx.compose.material3.Scaffold
19+
import androidx.compose.material3.Text
20+
import androidx.compose.runtime.Composable
21+
import androidx.compose.ui.Alignment
22+
import androidx.compose.ui.Modifier
23+
import androidx.compose.ui.platform.LocalContext
24+
import androidx.compose.ui.res.stringResource
25+
import androidx.compose.ui.text.style.TextAlign
26+
import androidx.compose.ui.tooling.preview.Preview
27+
import androidx.compose.ui.unit.dp
28+
import dev.aaa1115910.bv.R
29+
import dev.aaa1115910.bv.mobile.theme.BVMobileTheme
30+
import kotlin.system.exitProcess
31+
32+
@Composable
33+
fun RegionBlockScreen(modifier: Modifier = Modifier) {
34+
val context = LocalContext.current
35+
36+
val exitApp: () -> Unit = {
37+
(context as Activity).finish()
38+
exitProcess(0)
39+
}
40+
41+
RegionBlockContent(
42+
modifier = modifier,
43+
onExit = exitApp
44+
)
45+
}
46+
47+
@Composable
48+
private fun RegionBlockContent(
49+
modifier: Modifier = Modifier,
50+
onExit: () -> Unit
51+
) {
52+
Scaffold(
53+
modifier = modifier
54+
) { innerPadding ->
55+
Box(
56+
modifier = Modifier
57+
.padding(innerPadding)
58+
.fillMaxSize()
59+
) {
60+
Column(
61+
modifier = Modifier
62+
.padding(horizontal = 24.dp)
63+
.align(Alignment.Center),
64+
horizontalAlignment = Alignment.CenterHorizontally,
65+
verticalArrangement = Arrangement.spacedBy(24.dp)
66+
) {
67+
Icon(
68+
modifier = Modifier.size(32.dp),
69+
imageVector = Icons.Default.WarningAmber,
70+
contentDescription = null,
71+
tint = MaterialTheme.colorScheme.error
72+
)
73+
Text(
74+
text = stringResource(R.string.region_block_title),
75+
style = MaterialTheme.typography.titleLarge,
76+
textAlign = TextAlign.Center
77+
)
78+
Text(
79+
text = stringResource(R.string.region_block_subtitle_mobile),
80+
style = MaterialTheme.typography.bodySmall,
81+
textAlign = TextAlign.Center
82+
)
83+
}
84+
FilledTonalButton(
85+
modifier = Modifier
86+
.align(Alignment.BottomCenter)
87+
.padding(horizontal = 24.dp, vertical = 12.dp)
88+
.widthIn(max = 320.dp)
89+
.fillMaxWidth(),
90+
onClick = onExit
91+
) {
92+
Text(text = stringResource(R.string.region_block_exit_button))
93+
}
94+
}
95+
}
96+
}
97+
98+
@Preview
99+
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
100+
@Composable
101+
private fun RegionBlockScreenPreview() {
102+
BVMobileTheme {
103+
RegionBlockContent(
104+
onExit = {}
105+
)
106+
}
107+
}

app/shared/src/main/res/values/strings.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@
139139
<string name="proxy_server_edit_dialog_warning">请谨慎使用代理服务器,因为您的登录凭证将会发送至代理服务器,使用代理服务器所带来的一切后果均由用户自行承担</string>
140140

141141
<string name="region_block_character_painting">:(</string>
142+
<string name="region_block_exit_button">退出应用</string>
142143
<string name="region_block_qr_content">扫码也没有用的!</string>
143144
<string name="region_block_solution_text">不要在中国大陆地区使用该应用</string>
144145
<string name="region_block_solution_title">该问题的解决方法就是:</string>
145-
<string name="region_block_subtitle">Bug Video 无法在中国大陆地区使用,您可以按任意键退出应用</string>
146+
<string name="region_block_subtitle_mobile">Bug Video 无法在中国大陆地区使用</string>
147+
<string name="region_block_subtitle_tv">Bug Video 无法在中国大陆地区使用,您可以按任意键退出应用</string>
146148
<string name="region_block_title">不支持的使用地区</string>
147149

148150
<string name="remote_control_panel_demo_tip_back">退出</string>

app/tv/src/main/kotlin/dev/aaa1115910/bv/tv/screens/RegionBlockScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fun RegionBlockScreen(
119119
style = MaterialTheme.typography.titleLarge
120120
)
121121
Text(
122-
text = stringResource(R.string.region_block_subtitle),
122+
text = stringResource(R.string.region_block_subtitle_tv),
123123
style = MaterialTheme.typography.titleLarge
124124
)
125125
}

0 commit comments

Comments
 (0)