Skip to content

Commit

Permalink
add stream agreement setting
Browse files Browse the repository at this point in the history
  • Loading branch information
aderan committed Sep 11, 2024
1 parent 9bf706e commit 34c979e
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/io/agora/flat/data/model/StreamAgreement.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.agora.flat.data.model

data class StreamAgreement(val isAgree: Boolean)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.agora.flat.data.model

class StreamAgreementReq(val isAgree: Boolean)
15 changes: 15 additions & 0 deletions app/src/main/java/io/agora/flat/data/repository/MiscRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import io.agora.flat.data.AppKVCenter
import io.agora.flat.data.Result
import io.agora.flat.data.model.PureRoomReq
import io.agora.flat.data.model.PureToken
import io.agora.flat.data.model.RespNoData
import io.agora.flat.data.model.RtmCensorReq
import io.agora.flat.data.model.StreamAgreementReq
import io.agora.flat.data.toResult
import io.agora.flat.http.api.MiscService
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -45,4 +47,17 @@ class MiscRepository @Inject constructor(
}
}
}

suspend fun getStreamAgreement(): Boolean? {
return withContext(Dispatchers.IO) {
val result = miscService.getStreamAgreement().toResult()
return@withContext result.get()?.isAgree
}
}

suspend fun setStreamAgreement(isAgree: Boolean): Result<RespNoData> {
return withContext(Dispatchers.IO) {
return@withContext miscService.setStreamAgreement(StreamAgreementReq(isAgree)).toResult()
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/io/agora/flat/http/api/MiscService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,14 @@ interface MiscService {

@GET("v2/region/configs")
fun getRegionConfigs(): Call<BaseResp<RegionConfigs>>

@POST("v1/user/agreement/get")
fun getStreamAgreement(
@Body empty: BaseReq = BaseReq.EMPTY,
): Call<BaseResp<StreamAgreement>>

@POST("v1/user/agreement/set")
fun setStreamAgreement(
@Body req: StreamAgreementReq,
): Call<BaseResp<RespNoData>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DevSettingsActivity : BaseComposeActivity() {
onBack = { finish() },
onLogout = {},
onDownload = { Uri.EMPTY },
onAgreeStream = {},
)
}
}
Expand Down
36 changes: 32 additions & 4 deletions app/src/main/java/io/agora/flat/ui/activity/setting/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import io.agora.flat.ui.compose.FlatDivider
import io.agora.flat.ui.compose.FlatHighlightTextButton
import io.agora.flat.ui.compose.FlatTextBodyOne
import io.agora.flat.ui.compose.FlatTextCaption
import io.agora.flat.ui.compose.StreamCollectDialog
import io.agora.flat.ui.compose.UpdateDialog
import io.agora.flat.ui.theme.FlatTheme
import io.agora.flat.ui.viewmodel.SettingsUiState
Expand All @@ -59,6 +60,7 @@ fun SettingsScreen(navController: NavController, viewModel: SettingsViewModel =
SettingsScreen(
state = state,
onDownload = viewModel::downloadApp,
onAgreeStream = viewModel::setAgreeStream,
onBack = { navController.popBackStack() },
onLogout = {
viewModel.logout()
Expand All @@ -71,6 +73,7 @@ fun SettingsScreen(navController: NavController, viewModel: SettingsViewModel =
fun SettingsScreen(
state: SettingsUiState,
onDownload: suspend () -> Uri,
onAgreeStream: (Boolean) -> Unit,
onBack: () -> Unit,
onLogout: () -> Unit
) {
Expand All @@ -80,16 +83,17 @@ fun SettingsScreen(
onBackPressed = onBack
)
Box(Modifier.weight(1f)) {
SettingsList(state, onDownload)
SettingsList(state, onDownload, onAgreeStream)
}
BottomOperateArea(onLogout = onLogout)
}
}

@Composable
private fun SettingsList(state: SettingsUiState, onDownload: suspend () -> Uri) {
private fun SettingsList(state: SettingsUiState, onDownload: suspend () -> Uri, onAgreeStream: (Boolean) -> Unit) {
val context = LocalContext.current
var showUpdate by remember { mutableStateOf(false) }
var showCollect by remember { mutableStateOf(false) }

LazyColumn {
item {
Expand Down Expand Up @@ -117,7 +121,6 @@ private fun SettingsList(state: SettingsUiState, onDownload: suspend () -> Uri)
id = R.drawable.ic_settings_dark_light,
tip = stringResource(R.string.title_dark_mode),
onClick = { Navigator.launchDarkModeActivity(context) })

Spacer(Modifier.height(12.dp))
SettingLabel(stringResource(R.string.privacy))
SettingItem(
Expand All @@ -139,6 +142,15 @@ private fun SettingsList(state: SettingsUiState, onDownload: suspend () -> Uri)
id = R.drawable.ic_settings_info_third_party,
tip = stringResource(R.string.info_third_party),
onClick = { Navigator.launchWebViewActivity(context, Constants.URL.Libraries) })
if (state.isAgreeStream != null) {
SettingItem(
id = R.drawable.ic_settings_stream_analysis,
tip = stringResource(R.string.stream_data_analysis),
desc = if (state.isAgreeStream) stringResource(R.string.setting_on) else stringResource(R.string.setting_off),
onClick = { showCollect = true }
)
SettingItemDivider()
}

Spacer(Modifier.height(12.dp))
SettingLabel(stringResource(R.string.more))
Expand Down Expand Up @@ -187,6 +199,22 @@ private fun SettingsList(state: SettingsUiState, onDownload: suspend () -> Uri)
}
)
}

if (showCollect) {
StreamCollectDialog(
onOpen = {
onAgreeStream(true)
showCollect = false
},
onClose = {
onAgreeStream(false)
showCollect = false
},
onCancel = {
showCollect = false
}
)
}
}

@Composable
Expand Down Expand Up @@ -292,6 +320,6 @@ internal fun SettingItemDivider() {
fun UserSettingActivityPreview() {
val state = SettingsUiState()
FlatColumnPage {
SettingsScreen(state, { Uri.EMPTY }, {}, {})
SettingsScreen(state, { Uri.EMPTY }, {}, {}, {})
}
}
94 changes: 94 additions & 0 deletions app/src/main/java/io/agora/flat/ui/compose/StreamCollectDialog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package io.agora.flat.ui.compose

import androidx.compose.foundation.clickable
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.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import io.agora.flat.R
import io.agora.flat.ui.theme.FlatTheme

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun StreamCollectDialog(onOpen: () -> Unit, onClose: () -> Unit, onCancel: () -> Unit) {
val openDialog = remember { mutableStateOf(true) }

if (openDialog.value) {
FlatTheme {
Dialog(
onDismissRequest = {
onCancel()
openDialog.value = false
},
properties = DialogProperties(usePlatformDefaultWidth = false),
) {
Box(
modifier = Modifier
.fillMaxSize()
.clickable {
onCancel()
openDialog.value = false
},
contentAlignment = Alignment.BottomCenter,
) {
Surface(
modifier = Modifier.fillMaxWidth(),
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(6.dp)
) {
OperationItem(stringResource(R.string.setting_on)) {
onOpen()
openDialog.value = false
}
OperationItem(stringResource(R.string.setting_off)) {
onClose()
openDialog.value = false
}
OperationItem(stringResource(R.string.cancel)) {
onCancel()
openDialog.value = false
}
}
}
}
}
}
}
}

@Composable
fun OperationItem(text: String, onClick: () -> Unit) {
Row(
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 48.dp)
.clickable(onClick = onClick),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
FlatTextBodyOne(text)
}
}

@Composable
@Preview(locale = "zh")
fun StreamCollectDialogPreview() {
StreamCollectDialog({}, {}, {})
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.agora.flat.common.version.VersionCheckResult
import io.agora.flat.common.version.VersionChecker
import io.agora.flat.data.AppEnv
import io.agora.flat.data.AppKVCenter
import io.agora.flat.data.repository.MiscRepository
import io.agora.flat.data.repository.UserRepository
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -21,6 +22,7 @@ class SettingsViewModel @Inject constructor(
private val appKVCenter: AppKVCenter,
private val versionChecker: VersionChecker,
private val downloader: AndroidDownloader,
private val miscRepository: MiscRepository,
env: AppEnv
) : ViewModel() {
private val _state = MutableStateFlow(
Expand All @@ -34,6 +36,11 @@ class SettingsViewModel @Inject constructor(
viewModelScope.launch {
_state.value = _state.value.copy(versionCheckResult = versionChecker.forceCheck())
}

viewModelScope.launch {
val value = miscRepository.getStreamAgreement()
_state.value = _state.value.copy(isAgreeStream = value)
}
}

suspend fun downloadApp(): Uri {
Expand All @@ -46,12 +53,20 @@ class SettingsViewModel @Inject constructor(
_state.value = _state.value.copy(versionCheckResult = VersionCheckResult.Empty)
}

fun setAgreeStream(isAgree: Boolean) {
viewModelScope.launch {
miscRepository.setStreamAgreement(isAgree)
_state.value = _state.value.copy(isAgreeStream = isAgree)
}
}

fun logout() {
userRepository.logout()
}
}

data class SettingsUiState(
val infoUrl: String = "",
val versionCheckResult: VersionCheckResult = VersionCheckResult.Empty
val versionCheckResult: VersionCheckResult = VersionCheckResult.Empty,
val isAgreeStream: Boolean? = null
)
27 changes: 27 additions & 0 deletions app/src/main/res/drawable/ic_settings_stream_analysis.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#00000000"
android:pathData="M21,7.6V20.4C21,20.731 20.731,21 20.4,21H7.6C7.269,21 7,20.731 7,20.4V7.6C7,7.269 7.269,7 7.6,7H20.4C20.731,7 21,7.269 21,7.6Z"
android:strokeWidth="1.25"
android:strokeColor="#5D6066"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
<path
android:fillColor="#00000000"
android:pathData="M18,4H4.6C4.269,4 4,4.269 4,4.6V18"
android:strokeWidth="1.25"
android:strokeColor="#5D6066"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
<path
android:fillColor="#00000000"
android:pathData="M12.909,11.545C12.509,11.305 12,11.593 12,12.06V15.94C12,16.407 12.509,16.695 12.909,16.455L16.142,14.514C16.531,14.281 16.531,13.719 16.142,13.486L12.909,11.545Z"
android:strokeWidth="1.25"
android:strokeColor="#5D6066"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</vector>
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<string name="preferences">首选项</string>
<string name="privacy">隐私</string>
<string name="more">更多</string>
<string name="setting_on">开启</string>
<string name="setting_off">关闭</string>

<!-- time -->
<string name="relative_time_mm">%d分</string>
Expand Down Expand Up @@ -60,6 +62,7 @@
<string name="network_acceleration">网络加速</string>
<string name="account_security">账户安全</string>
<string name="delete_account">注销账户</string>
<string name="stream_data_analysis">音视频数据采集</string>

<string name="room_type_big_class">大班课</string>
<string name="room_type_small_class">小班课</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<string name="preferences">Preferences</string>
<string name="privacy">Privacy</string>
<string name="more">More</string>
<string name="setting_on">On</string>
<string name="setting_off">Off</string>

<string name="relative_time_mm">%d m</string>
<string name="relative_time_hh">%d h</string>
Expand Down Expand Up @@ -57,6 +59,7 @@
<string name="network_acceleration">Network Acceleration</string>
<string name="account_security">Account Security</string>
<string name="delete_account">Delete Account</string>
<string name="stream_data_analysis">Data Analysis</string>

<string name="room_type_big_class">Big Class</string>
<string name="room_type_small_class">Small Class</string>
Expand Down

0 comments on commit 34c979e

Please sign in to comment.