diff --git a/app/src/main/java/com/gyf/csams/activity/model/ActivityDetailViewModel.kt b/app/src/main/java/com/gyf/csams/activity/model/ActivityDetailViewModel.kt index dac851b..633e613 100644 --- a/app/src/main/java/com/gyf/csams/activity/model/ActivityDetailViewModel.kt +++ b/app/src/main/java/com/gyf/csams/activity/model/ActivityDetailViewModel.kt @@ -5,10 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.gyf.csams.NOT_IMPL_TIP -import com.gyf.csams.uikit.ActivityDetailMenu -import com.gyf.csams.uikit.ScrollList -import com.gyf.csams.uikit.StringForm -import com.gyf.csams.uikit.TopMenuInterface +import com.gyf.csams.uikit.* import com.gyf.csams.util.randomChinese import com.gyf.csams.util.randomDateTime import com.gyf.csams.util.randomNum @@ -218,29 +215,26 @@ data class BBSVo(val studentId:String,val name:String,val createTime:Date,val co * 交流区数据状态管理 * */ -class BBSViewModel:ScrollList(){ +class BBSViewModel:ScrollList(), SendInterface { override val initSize: Int = 10 val title="发送评论" - val newContent = StringForm(formDesc = "评论内容",textLength = 80) + override val newContent = StringForm(formDesc = "评论内容",textLength = 80) - private val _openDialog=MutableLiveData() - val openDialog:LiveData = _openDialog + override val _openDialog=MutableLiveData() + override val openDialog:LiveData = _openDialog init { load() } - /** - * 打开评论弹窗 - * - */ - fun openDialog(){ + + override fun openDialog(){ _openDialog.value=true } - fun closeDialog(){ + override fun closeDialog(){ _openDialog.value=false } @@ -249,7 +243,7 @@ class BBSViewModel:ScrollList(){ * * @param callback */ - fun send(callback: (message: String) -> Unit){ + override fun send(callback: (message: String) -> Unit){ callback(NOT_IMPL_TIP) } diff --git a/app/src/main/java/com/gyf/csams/activity/ui/ActivityDetailActivity.kt b/app/src/main/java/com/gyf/csams/activity/ui/ActivityDetailActivity.kt index 86a0687..2f03c58 100644 --- a/app/src/main/java/com/gyf/csams/activity/ui/ActivityDetailActivity.kt +++ b/app/src/main/java/com/gyf/csams/activity/ui/ActivityDetailActivity.kt @@ -363,10 +363,6 @@ class ActivityDetailActivity : ComponentActivity() { private fun BBS(model: BBSViewModel = viewModel(), scaffoldModel: ScaffoldModel = viewModel()) { MainFrame(background = { Background(image = BackgroundImage.ActivityBBS, alpha = 0.7F) }) { -// val drawerState = rememberBottomDrawerState(BottomDrawerValue.Closed) - val openDialog=model.openDialog.observeAsState() - - Row( modifier = Modifier .fillMaxWidth() @@ -390,42 +386,7 @@ class ActivityDetailActivity : ComponentActivity() { } } - if(openDialog.value ==true) { - AlertDialog(onDismissRequest = { /*TODO*/ }, - buttons = { - Row( - modifier = Modifier - .padding(10.dp) - .fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceEvenly - ) { - OutlinedButton(onClick = { - model.send { scaffoldModel.update(message = it) } - }) { - - Text(text = "发送") - } - OutlinedButton(onClick = { - model.closeDialog() - }) { - Text(text = "关闭") - } - } - }, text = { - Column(modifier = Modifier.padding(10.dp)) { - Card( - backgroundColor = MaterialTheme.colors.background, - modifier = Modifier.padding(10.dp) - ) { - BaseTextField( - form = model.newContent, modifier = Modifier - .fillMaxWidth() - .height(200.dp) - ) - } - } - }) - } + SendComment(model = model) Box( modifier = Modifier diff --git a/app/src/main/java/com/gyf/csams/main/model/MainViewModel.kt b/app/src/main/java/com/gyf/csams/main/model/MainViewModel.kt index fbfbafd..70098b0 100644 --- a/app/src/main/java/com/gyf/csams/main/model/MainViewModel.kt +++ b/app/src/main/java/com/gyf/csams/main/model/MainViewModel.kt @@ -7,6 +7,7 @@ import androidx.lifecycle.viewModelScope import com.gyf.csams.NOT_IMPL_TIP import com.gyf.csams.R import com.gyf.csams.uikit.ScrollList +import com.gyf.csams.uikit.SendInterface import com.gyf.csams.uikit.StringForm import com.orhanobut.logger.Logger import kotlinx.coroutines.Job @@ -80,12 +81,27 @@ data class AssociationDto(val name:String) * 主页 * */ -class MainViewModel:ViewModel(){ +class MainViewModel:ViewModel(),SendInterface{ + + override val _openDialog: MutableLiveData = MutableLiveData() + override val openDialog: LiveData = _openDialog + + override val newContent: StringForm = StringForm(formDesc = "留言",textLength = 30) + + override fun openDialog() { + _openDialog.value=true + } + + override fun closeDialog() { + _openDialog.value=false + } + /** * TODO 发送留言 * + * @param callback */ - fun sendMessage(callback: (value: String) -> Unit){ + override fun send(callback: (message: String) -> Unit) { callback(NOT_IMPL_TIP) } diff --git a/app/src/main/java/com/gyf/csams/main/ui/MainActivity.kt b/app/src/main/java/com/gyf/csams/main/ui/MainActivity.kt index f2c43bf..054af15 100644 --- a/app/src/main/java/com/gyf/csams/main/ui/MainActivity.kt +++ b/app/src/main/java/com/gyf/csams/main/ui/MainActivity.kt @@ -312,13 +312,15 @@ class MainActivity : ComponentActivity() { verticalAlignment = Alignment.CenterVertically ) { - - IconButton(onClick = { mainViewModel.sendMessage { scaffoldModel.update(message=it) } }) { + IconButton(onClick = { mainViewModel.openDialog() }) { Icon( painter = painterResource(id = R.drawable.ic_comments), contentDescription = null, ) } + + SendComment(model = mainViewModel) + Row( horizontalArrangement = Arrangement.Center, modifier = Modifier diff --git a/app/src/main/java/com/gyf/csams/uikit/BaseView.kt b/app/src/main/java/com/gyf/csams/uikit/BaseView.kt index 7bbc403..0630f54 100644 --- a/app/src/main/java/com/gyf/csams/uikit/BaseView.kt +++ b/app/src/main/java/com/gyf/csams/uikit/BaseView.kt @@ -183,6 +183,87 @@ enum class ActivityDetailMenu(override val menuName:String):TopBarMenu{ } } + +interface SendInterface{ + /** + * 弹窗状态 + */ + val _openDialog:MutableLiveData + val openDialog:LiveData + + /** + * 编辑内容 + */ + val newContent:StringForm + + /** + * 打开弹窗 + * + */ + fun openDialog() + + /** + * 关闭弹窗 + * + */ + fun closeDialog() + + /** + * 发送评论 + * + * @param callback + */ + fun send(callback: (message: String) -> Unit) +} + +/** + * 发送评论 + * + * @param T + * @param model + * @param scaffoldModel + */ +@Composable +fun SendComment(model:T, scaffoldModel: ScaffoldModel= viewModel()){ + val openDialog by model.openDialog.observeAsState() + if(openDialog==true) { + AlertDialog(onDismissRequest = { /*TODO*/ }, + buttons = { + Row( + modifier = Modifier + .padding(10.dp) + .fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceEvenly + ) { + OutlinedButton(onClick = { + model.send { scaffoldModel.update(message = it) } + }) { + + Text(text = "发送") + } + OutlinedButton(onClick = { + model.closeDialog() + }) { + Text(text = "关闭") + } + } + }, text = { + Column(modifier = Modifier.padding(10.dp)) { + Card( + backgroundColor = MaterialTheme.colors.background, + modifier = Modifier.padding(10.dp) + ) { + BaseTextField( + form = model.newContent, modifier = Modifier + .fillMaxWidth() + .height(200.dp) + ) + } + } + }) + } +} + /** * 社团顶部菜单 * @@ -562,7 +643,9 @@ fun DescCard(modifier: Modifier,content:String) { contentScale = ContentScale.FillBounds, modifier = Modifier.fillMaxSize() ) - Column(modifier = Modifier.fillMaxSize().padding(horizontal = 10.dp)) { + Column(modifier = Modifier + .fillMaxSize() + .padding(horizontal = 10.dp)) { Spacer(modifier = Modifier.weight(0.15F)) Text( modifier = Modifier.weight(0.65F),