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

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.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.gyf.csams.NOT_IMPL_TIP import com.gyf.csams.NOT_IMPL_TIP
import com.gyf.csams.uikit.ActivityDetailMenu import com.gyf.csams.uikit.*
import com.gyf.csams.uikit.ScrollList
import com.gyf.csams.uikit.StringForm
import com.gyf.csams.uikit.TopMenuInterface
import com.gyf.csams.util.randomChinese import com.gyf.csams.util.randomChinese
import com.gyf.csams.util.randomDateTime import com.gyf.csams.util.randomDateTime
import com.gyf.csams.util.randomNum 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 override val initSize: Int = 10
val title="发送评论" val title="发送评论"
val newContent = StringForm(formDesc = "评论内容",textLength = 80) override val newContent = StringForm(formDesc = "评论内容",textLength = 80)
private val _openDialog=MutableLiveData<Boolean>() override val _openDialog=MutableLiveData<Boolean>()
val openDialog:LiveData<Boolean> = _openDialog override val openDialog:LiveData<Boolean> = _openDialog
init { init {
load() load()
} }
/**
* 打开评论弹窗 override fun openDialog(){
*
*/
fun openDialog(){
_openDialog.value=true _openDialog.value=true
} }
fun closeDialog(){ override fun closeDialog(){
_openDialog.value=false _openDialog.value=false
} }
@ -249,7 +243,7 @@ class BBSViewModel:ScrollList<BBSVo>(){
* *
* @param callback * @param callback
*/ */
fun send(callback: (message: String) -> Unit){ override fun send(callback: (message: String) -> Unit){
callback(NOT_IMPL_TIP) callback(NOT_IMPL_TIP)
} }

@ -363,10 +363,6 @@ class ActivityDetailActivity : ComponentActivity() {
private fun BBS(model: BBSViewModel = viewModel(), scaffoldModel: ScaffoldModel = viewModel()) { private fun BBS(model: BBSViewModel = viewModel(), scaffoldModel: ScaffoldModel = viewModel()) {
MainFrame(background = { Background(image = BackgroundImage.ActivityBBS, alpha = 0.7F) }) { MainFrame(background = { Background(image = BackgroundImage.ActivityBBS, alpha = 0.7F) }) {
// val drawerState = rememberBottomDrawerState(BottomDrawerValue.Closed)
val openDialog=model.openDialog.observeAsState()
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -390,42 +386,7 @@ class ActivityDetailActivity : ComponentActivity() {
} }
} }
if(openDialog.value ==true) { SendComment(model = model)
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)
)
}
}
})
}
Box( Box(
modifier = Modifier modifier = Modifier

@ -7,6 +7,7 @@ import androidx.lifecycle.viewModelScope
import com.gyf.csams.NOT_IMPL_TIP import com.gyf.csams.NOT_IMPL_TIP
import com.gyf.csams.R import com.gyf.csams.R
import com.gyf.csams.uikit.ScrollList import com.gyf.csams.uikit.ScrollList
import com.gyf.csams.uikit.SendInterface
import com.gyf.csams.uikit.StringForm import com.gyf.csams.uikit.StringForm
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
import kotlinx.coroutines.Job 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 发送留言 * TODO 发送留言
* *
* @param callback
*/ */
fun sendMessage(callback: (value: String) -> Unit){ override fun send(callback: (message: String) -> Unit) {
callback(NOT_IMPL_TIP) callback(NOT_IMPL_TIP)
} }

@ -312,13 +312,15 @@ class MainActivity : ComponentActivity() {
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
IconButton(onClick = { mainViewModel.openDialog() }) {
IconButton(onClick = { mainViewModel.sendMessage { scaffoldModel.update(message=it) } }) {
Icon( Icon(
painter = painterResource(id = R.drawable.ic_comments), painter = painterResource(id = R.drawable.ic_comments),
contentDescription = null, contentDescription = null,
) )
} }
SendComment(model = mainViewModel)
Row( Row(
horizontalArrangement = Arrangement.Center, horizontalArrangement = Arrangement.Center,
modifier = Modifier 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, contentScale = ContentScale.FillBounds,
modifier = Modifier.fillMaxSize() 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)) Spacer(modifier = Modifier.weight(0.15F))
Text( Text(
modifier = Modifier.weight(0.65F), modifier = Modifier.weight(0.65F),

Loading…
Cancel
Save