parent
d64411fa51
commit
a68a79ddb5
@ -0,0 +1,96 @@ |
||||
package com.gyf.csams.main.model |
||||
|
||||
import androidx.lifecycle.viewModelScope |
||||
import com.gyf.lib.ScrollList |
||||
import com.gyf.lib.util.randomChinese |
||||
import kotlinx.coroutines.launch |
||||
|
||||
/** |
||||
* 社团级别 |
||||
* |
||||
*/ |
||||
enum class AssociationLevel { |
||||
A, |
||||
B, |
||||
C, |
||||
D |
||||
} |
||||
|
||||
/** |
||||
* 所属院系 |
||||
* |
||||
*/ |
||||
enum class AssociationFaculty(val desc: String, val range: IntRange) { |
||||
ForeignLanguageDept("外语系", 0..0), |
||||
CivilEngineeringDept("土木工程", 1..10), |
||||
SEM("经理管理学院", 11..20), |
||||
MechanicalEngineeringDept("机械工程", 21..30), |
||||
TransportationDept("交通运输", 31..40), |
||||
ArchitectureAndArts("建筑与艺术", 41..50), |
||||
ElectricalDept("电气", 51..60), |
||||
MaterialsDept("材料", 61..70), |
||||
MessageDept("信息", 71..80), |
||||
MathematicsDept("数理", 81..90), |
||||
GraduateStudent("研究生", 91..99) |
||||
} |
||||
|
||||
/** |
||||
* 社团 |
||||
* |
||||
* @property name 社团名称 |
||||
*/ |
||||
data class AssociationVo( |
||||
val associationId: Long, val name: String, val commander: String, |
||||
val faculty: AssociationFaculty, val level: AssociationLevel, val desc: String |
||||
) |
||||
|
||||
/** |
||||
* 数据状态管理 |
||||
* |
||||
*/ |
||||
class AssociationManagementViewModel : ScrollList<AssociationVo>() { |
||||
override val initSize: Int = 10 |
||||
|
||||
init { |
||||
load() |
||||
} |
||||
|
||||
override fun load() { |
||||
viewModelScope.launch { |
||||
_data.value?.apply { |
||||
repeat(initSize) { |
||||
add( |
||||
AssociationVo( |
||||
associationId = (0..65535L).random(), |
||||
name = randomChinese(5), |
||||
commander = randomChinese(3), |
||||
faculty = AssociationFaculty.values().random(), |
||||
level = AssociationLevel.values().random(), |
||||
desc = randomChinese(20) |
||||
) |
||||
) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun loadMore(callback: (message: String) -> Unit) { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
/** |
||||
* TODO 更新社团级别 |
||||
* |
||||
* @param level |
||||
*/ |
||||
fun update(associationVo: AssociationVo, level: AssociationLevel) { |
||||
_data.value?.apply { |
||||
val i = indexOf(associationVo) |
||||
set(i, associationVo.copy(level = level)) |
||||
val new = mutableListOf<AssociationVo>() |
||||
new.addAll(this) |
||||
clear() |
||||
_data.postValue(new) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.gyf.csams.main.model |
||||
|
||||
import android.app.Activity |
||||
import androidx.lifecycle.ViewModel |
||||
import com.gyf.csams.main.ui.AssociationManagementActivity |
||||
|
||||
enum class MenuType(val desc: String, val clazz: Map<String, Class<out Activity>>) { |
||||
//老师 |
||||
//总部长 |
||||
Association("社团管理", mapOf("社团信息管理" to AssociationManagementActivity::class.java)) |
||||
} |
||||
|
||||
class MenuViewModel : ViewModel() { |
||||
|
||||
} |
@ -0,0 +1,124 @@ |
||||
package com.gyf.csams.main.ui |
||||
|
||||
import android.os.Bundle |
||||
import androidx.activity.ComponentActivity |
||||
import androidx.activity.compose.setContent |
||||
import androidx.compose.foundation.layout.* |
||||
import androidx.compose.foundation.lazy.LazyColumn |
||||
import androidx.compose.foundation.lazy.rememberLazyListState |
||||
import androidx.compose.material.* |
||||
import androidx.compose.runtime.getValue |
||||
import androidx.compose.runtime.livedata.observeAsState |
||||
import androidx.compose.runtime.mutableStateOf |
||||
import androidx.compose.runtime.remember |
||||
import androidx.compose.runtime.setValue |
||||
import androidx.compose.ui.Alignment |
||||
import androidx.compose.ui.Modifier |
||||
import androidx.compose.ui.unit.dp |
||||
import androidx.lifecycle.viewmodel.compose.viewModel |
||||
import com.gyf.csams.main.model.AssociationLevel |
||||
import com.gyf.csams.main.model.AssociationManagementViewModel |
||||
import com.gyf.lib.uikit.BodyS |
||||
import com.gyf.lib.uikit.MainBoxFrame |
||||
import com.gyf.lib.uikit.ScaffoldModel |
||||
|
||||
/** |
||||
* 社团管理 |
||||
* |
||||
*/ |
||||
class AssociationManagementActivity : ComponentActivity() { |
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
|
||||
setContent { |
||||
BodyS { |
||||
MainBoxFrame(background = { /*TODO*/ }) { |
||||
val model: AssociationManagementViewModel = viewModel() |
||||
val data by model.data.observeAsState() |
||||
val listState = rememberLazyListState() |
||||
val scaffoldModel: ScaffoldModel = viewModel() |
||||
LazyColumn(modifier = Modifier.fillMaxSize(), state = listState) { |
||||
data?.forEach { |
||||
it.apply { |
||||
item { |
||||
var expanded by remember { |
||||
mutableStateOf(false) |
||||
} |
||||
Card(backgroundColor = MaterialTheme.colors.background) { |
||||
Column( |
||||
modifier = Modifier.padding(10.dp), |
||||
verticalArrangement = Arrangement.SpaceBetween |
||||
) { |
||||
Row( |
||||
modifier = Modifier.fillMaxWidth(), |
||||
horizontalArrangement = Arrangement.SpaceBetween |
||||
) { |
||||
Text( |
||||
text = "$associationId", |
||||
style = MaterialTheme.typography.h6 |
||||
) |
||||
Text( |
||||
text = name, |
||||
style = MaterialTheme.typography.h4 |
||||
) |
||||
Spacer(modifier = Modifier) |
||||
} |
||||
Spacer(modifier = Modifier.height(5.dp)) |
||||
Row( |
||||
modifier = Modifier.fillMaxWidth(), |
||||
horizontalArrangement = Arrangement.SpaceBetween, |
||||
verticalAlignment = Alignment.CenterVertically |
||||
) { |
||||
Text( |
||||
text = commander, |
||||
style = MaterialTheme.typography.h5 |
||||
) |
||||
Text( |
||||
text = faculty.desc, |
||||
style = MaterialTheme.typography.h5 |
||||
) |
||||
|
||||
OutlinedButton(onClick = { |
||||
expanded = true |
||||
}) { |
||||
Text( |
||||
text = level.name, |
||||
style = MaterialTheme.typography.h5 |
||||
) |
||||
DropdownMenu( |
||||
expanded = expanded, |
||||
onDismissRequest = { /*TODO*/ }) { |
||||
AssociationLevel.values().forEach { |
||||
DropdownMenuItem(onClick = { |
||||
model.update( |
||||
associationVo = this@apply, |
||||
level = it |
||||
) |
||||
expanded = false |
||||
}) { |
||||
Text(text = it.name) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
Spacer(modifier = Modifier.height(5.dp)) |
||||
Card( |
||||
modifier = Modifier |
||||
.fillMaxWidth() |
||||
.height(50.dp) |
||||
) { |
||||
Text(text = desc) |
||||
} |
||||
} |
||||
} |
||||
Spacer(modifier = Modifier.height(10.dp)) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@ |
||||
package com.gyf.csams.main.ui |
||||
|
||||
import android.app.Activity |
||||
import android.content.Intent |
||||
import android.os.Bundle |
||||
import androidx.activity.ComponentActivity |
||||
import androidx.activity.compose.setContent |
||||
import androidx.compose.foundation.border |
||||
import androidx.compose.foundation.clickable |
||||
import androidx.compose.foundation.layout.* |
||||
import androidx.compose.material.Card |
||||
import androidx.compose.material.MaterialTheme |
||||
import androidx.compose.material.Text |
||||
import androidx.compose.runtime.Composable |
||||
import androidx.compose.ui.Alignment |
||||
import androidx.compose.ui.Modifier |
||||
import androidx.compose.ui.unit.dp |
||||
import com.gyf.csams.main.model.MenuType |
||||
import com.gyf.lib.uikit.BodyS |
||||
import com.gyf.lib.uikit.MainBoxFrame |
||||
|
||||
/** |
||||
* 菜单 |
||||
* |
||||
*/ |
||||
class MenuActivity : ComponentActivity() { |
||||
|
||||
lateinit var menuType: MenuType |
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
|
||||
menuType = intent?.getSerializableExtra(MenuType::name.name) as MenuType |
||||
|
||||
setContent { |
||||
BodyS { |
||||
MainBoxFrame(background = { /*TODO*/ }, contentAlignment = Alignment.Center) { |
||||
Column( |
||||
modifier = Modifier |
||||
.fillMaxSize() |
||||
.border(width = 1.dp, color = MaterialTheme.colors.onBackground) |
||||
.padding(10.dp), verticalArrangement = Arrangement.SpaceAround |
||||
) { |
||||
menuType.clazz.entries.chunked(2).forEach { |
||||
Row( |
||||
modifier = Modifier.fillMaxWidth(), |
||||
horizontalArrangement = Arrangement.SpaceEvenly |
||||
) { |
||||
MenuItem(menuName = it[0].key, clazz = it[0].value) |
||||
if (it.size == 2) { |
||||
MenuItem(menuName = it[1].key, clazz = it[1].value) |
||||
} else { |
||||
Spacer(modifier = Modifier.size(100.dp)) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Composable |
||||
private fun MenuItem(menuName: String, clazz: Class<out Activity>) { |
||||
Card( |
||||
modifier = Modifier |
||||
.size(100.dp) |
||||
.clickable(onClick = { |
||||
startActivity(Intent(this, clazz)) |
||||
}), |
||||
backgroundColor = MaterialTheme.colors.background |
||||
) { |
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { |
||||
Text(text = menuName) |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,18 @@ |
||||
package com.gyf.lib |
||||
|
||||
import androidx.lifecycle.LiveData |
||||
import androidx.lifecycle.MutableLiveData |
||||
import androidx.lifecycle.ViewModel |
||||
|
||||
abstract class ScrollList<T> : ViewModel() { |
||||
protected val _data = MutableLiveData<MutableList<T>>(mutableListOf()) |
||||
val data: LiveData<MutableList<T>> = _data |
||||
|
||||
abstract val initSize: Int |
||||
|
||||
//加载列表 |
||||
abstract fun load() |
||||
|
||||
//加载更多数据 |
||||
abstract fun loadMore(callback: (message: String) -> Unit) |
||||
} |
Loading…
Reference in new issue