封装交流区发送评论逻辑,和留言区共用。

master
pan 4 years ago
parent 74c4bfd352
commit cf254306cf
  1. 24
      app/src/main/java/com/gyf/csams/activity/model/ActivityDetailViewModel.kt
  2. 41
      app/src/main/java/com/gyf/csams/activity/ui/ActivityDetailActivity.kt
  3. 20
      app/src/main/java/com/gyf/csams/main/model/MainViewModel.kt
  4. 6
      app/src/main/java/com/gyf/csams/main/ui/MainActivity.kt
  5. 85
      app/src/main/java/com/gyf/csams/uikit/BaseView.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<BBSVo>(){
class BBSViewModel:ScrollList<BBSVo>(), 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<Boolean>()
val openDialog:LiveData<Boolean> = _openDialog
override val _openDialog=MutableLiveData<Boolean>()
override val openDialog:LiveData<Boolean> = _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<BBSVo>(){
*
* @param callback
*/
fun send(callback: (message: String) -> Unit){
override fun send(callback: (message: String) -> Unit){
callback(NOT_IMPL_TIP)
}

@ -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

@ -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<Boolean> = MutableLiveData()
override val openDialog: LiveData<Boolean> = _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)
}

@ -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

@ -183,6 +183,87 @@ enum class ActivityDetailMenu(override val menuName:String):TopBarMenu{
}
}
interface SendInterface{
/**
* 弹窗状态
*/
val _openDialog:MutableLiveData<Boolean>
val openDialog:LiveData<Boolean>
/**
* 编辑内容
*/
val newContent:StringForm
/**
* 打开弹窗
*
*/
fun openDialog()
/**
* 关闭弹窗
*
*/
fun closeDialog()
/**
* 发送评论
*
* @param callback
*/
fun send(callback: (message: String) -> Unit)
}
/**
* 发送评论
*
* @param T
* @param model
* @param scaffoldModel
*/
@Composable
fun <T:SendInterface> 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),

Loading…
Cancel
Save