parent
014d4ae16c
commit
743486211b
@ -0,0 +1,84 @@ |
||||
package com.gyf.csams.association.model |
||||
|
||||
import androidx.lifecycle.LiveData |
||||
import androidx.lifecycle.MutableLiveData |
||||
import androidx.lifecycle.ViewModel |
||||
import androidx.lifecycle.viewModelScope |
||||
import com.gyf.csams.uikit.AssociationMenu |
||||
import com.gyf.csams.uikit.StringForm |
||||
import com.orhanobut.logger.Logger |
||||
import kotlinx.coroutines.launch |
||||
|
||||
class AssociationViewModel:ViewModel() { |
||||
private val _currentMenu=MutableLiveData<AssociationMenu>() |
||||
val currentMenu:LiveData<AssociationMenu> = _currentMenu |
||||
|
||||
fun clickMenu(menu:AssociationMenu){ |
||||
_currentMenu.value=menu |
||||
} |
||||
} |
||||
|
||||
data class MemberVo(val name:String) |
||||
|
||||
/** |
||||
* 社团会员 |
||||
* |
||||
*/ |
||||
class MemberViewModel:ViewModel(){ |
||||
val name=StringForm(formDesc = "姓名关键字",5) |
||||
|
||||
val search="搜索" |
||||
|
||||
private val _memberList=MutableLiveData<MutableList<MemberVo>>(mutableListOf()) |
||||
|
||||
val memberList=_memberList |
||||
|
||||
init { |
||||
initMemberList() |
||||
} |
||||
|
||||
/** |
||||
* 初始化成员 |
||||
* |
||||
*/ |
||||
private fun initMemberList(){ |
||||
viewModelScope.launch { |
||||
_memberList.value?.apply { |
||||
repeat(10) { |
||||
add(MemberVo(name = "成员${it+1}")) |
||||
} |
||||
} |
||||
Logger.i("初始化社团成员size=${_memberList.value?.size}") |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 加载更多成员 |
||||
* |
||||
*/ |
||||
fun loadMore(){ |
||||
viewModelScope.launch { |
||||
_memberList.value?.let { |
||||
val t= mutableListOf<MemberVo>() |
||||
t.addAll(it) |
||||
t.apply { |
||||
repeat(10){ |
||||
add(MemberVo(name = "成员${t.size+1}")) |
||||
} |
||||
} |
||||
_memberList.postValue(t) |
||||
Logger.i("加载更多社团成员,size=${t.size}") |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* TODO 社团成员搜索 |
||||
* |
||||
* @param callback |
||||
*/ |
||||
fun search(callback: (value: String) -> Unit){ |
||||
Logger.i("搜索条件[成员姓名:${name.formValue.value}]") |
||||
callback("功能尚未实现,敬请期待") |
||||
} |
||||
} |
@ -0,0 +1,263 @@ |
||||
package com.gyf.csams.association.ui |
||||
|
||||
import android.os.Bundle |
||||
import androidx.activity.ComponentActivity |
||||
import androidx.activity.compose.setContent |
||||
import androidx.compose.foundation.Image |
||||
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.Composable |
||||
import androidx.compose.runtime.getValue |
||||
import androidx.compose.runtime.livedata.observeAsState |
||||
import androidx.compose.ui.Alignment |
||||
import androidx.compose.ui.Modifier |
||||
import androidx.compose.ui.layout.ContentScale |
||||
import androidx.compose.ui.platform.LocalContext |
||||
import androidx.compose.ui.res.painterResource |
||||
import androidx.compose.ui.tooling.preview.Preview |
||||
import androidx.compose.ui.unit.dp |
||||
import androidx.lifecycle.viewmodel.compose.viewModel |
||||
import androidx.navigation.compose.NavHost |
||||
import androidx.navigation.compose.composable |
||||
import com.gyf.csams.R |
||||
import com.gyf.csams.association.model.AssociationViewModel |
||||
import com.gyf.csams.association.model.MemberViewModel |
||||
import com.gyf.csams.association.model.MemberVo |
||||
import com.gyf.csams.uikit.* |
||||
import com.gyf.csams.uikit.theme.CSAMSTheme |
||||
|
||||
/** |
||||
* 社团界面 |
||||
* |
||||
*/ |
||||
class AssociationActivity: ComponentActivity() { |
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
setContent { |
||||
CSAMSTheme { |
||||
Body { |
||||
nav, scaffoldState -> |
||||
val context= LocalContext.current as AssociationActivity |
||||
val model:AssociationViewModel= viewModel() |
||||
val startMenu=AssociationMenu.main |
||||
val menu:AssociationMenu by model.currentMenu.observeAsState(startMenu) |
||||
|
||||
Column { |
||||
AssociationAppBar(menu = menu,nav = nav,back = { context.onBackPressed() }){ |
||||
|
||||
} |
||||
NavHost(navController = nav, startDestination = startMenu.name) { |
||||
composable(AssociationMenu.member.name){ |
||||
model.clickMenu(AssociationMenu.member) |
||||
Member() |
||||
ShowSnackbar(scaffoldState = scaffoldState) |
||||
} |
||||
composable(AssociationMenu.main.name){ |
||||
model.clickMenu(AssociationMenu.main) |
||||
Main() |
||||
ShowSnackbar(scaffoldState = scaffoldState) |
||||
} |
||||
composable(AssociationMenu.list.name){ |
||||
model.clickMenu(AssociationMenu.list) |
||||
AssociationList() |
||||
ShowSnackbar(scaffoldState = scaffoldState) |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 社团成员 |
||||
* |
||||
*/ |
||||
@Composable |
||||
private fun Member(){ |
||||
MainFrame(background = { Background(image = BackgroundImage.association_main) }) { |
||||
val searchWeight=0.2F |
||||
Search(modifier = Modifier |
||||
.fillMaxWidth() |
||||
.weight(searchWeight)) |
||||
MemberList(modifier = Modifier |
||||
.fillMaxWidth() |
||||
.weight(1 - searchWeight)) |
||||
|
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 检索成员 |
||||
* |
||||
*/ |
||||
@Composable |
||||
private fun Search(modifier:Modifier=Modifier, model: MemberViewModel= viewModel(), scaffoldModel: ScaffoldModel= viewModel()){ |
||||
Column(modifier = modifier.fillMaxSize()) { |
||||
Spacer(modifier = Modifier.weight(0.5F)) |
||||
Row(modifier = Modifier |
||||
.fillMaxWidth() |
||||
.weight(0.5F),verticalAlignment = Alignment.CenterVertically) { |
||||
|
||||
val textFieldWeight=0.4F |
||||
val buttonWeight=0.2F |
||||
val spaceWeight=(1-textFieldWeight-buttonWeight)/3 |
||||
Spacer(modifier = Modifier.weight((spaceWeight))) |
||||
BaseTextField(modifier = Modifier.weight(textFieldWeight),form = model.name,singeLine = true) |
||||
Spacer(modifier = Modifier.weight(spaceWeight)) |
||||
OutlinedButton(onClick = { model.search { scaffoldModel.update(it) } },modifier = Modifier.weight(buttonWeight)) { |
||||
Text(text = model.search) |
||||
} |
||||
Spacer(modifier = Modifier.weight(spaceWeight)) |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 成员列表 |
||||
* |
||||
*/ |
||||
@Composable |
||||
private fun MemberList(modifier: Modifier=Modifier,viewModel: MemberViewModel=viewModel()){ |
||||
val list:MutableList<MemberVo>? by viewModel.memberList.observeAsState() |
||||
val listState= rememberLazyListState() |
||||
LazyColumn(state = listState,modifier = modifier) { |
||||
list?.forEach { |
||||
item { |
||||
Column { |
||||
Spacer(modifier = Modifier.height(10.dp)) |
||||
Row{ |
||||
val weight = 1F / 3 |
||||
Spacer(modifier = Modifier.weight(weight)) |
||||
Card( |
||||
modifier = Modifier.weight(weight), |
||||
backgroundColor = MaterialTheme.colors.background |
||||
) { |
||||
Text(text = it.name) |
||||
} |
||||
Spacer(modifier = Modifier.weight(weight)) |
||||
} |
||||
Spacer(modifier = Modifier.height(10.dp)) |
||||
Divider(color = MaterialTheme.colors.background) |
||||
} |
||||
} |
||||
} |
||||
item { |
||||
Row(horizontalArrangement = Arrangement.Center,modifier = Modifier.fillMaxWidth()) { |
||||
IconButton(onClick = { viewModel.loadMore() }) { |
||||
Icon(painter = painterResource(id = R.drawable.ic_arrow_down), contentDescription = null) |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 社团主页 |
||||
* |
||||
*/ |
||||
@Composable |
||||
private fun Main(){ |
||||
MainFrame(background = { |
||||
Background(image = BackgroundImage.association_main,alpha = 0.7F) |
||||
}) { |
||||
val nameW=0.1F |
||||
val cardW=0.66F*0.4F |
||||
Name(modifier = Modifier |
||||
.fillMaxWidth() |
||||
.weight(nameW)) |
||||
DescCard( |
||||
modifier = Modifier |
||||
.weight(cardW) |
||||
.fillMaxWidth() |
||||
) |
||||
Commander( |
||||
modifier = Modifier.weight(cardW) |
||||
) |
||||
Showcase(modifier = Modifier.weight(1F-nameW-cardW-cardW)) |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 社团名字 |
||||
* |
||||
* @param modifier |
||||
*/ |
||||
@Composable |
||||
private fun Name(modifier: Modifier){ |
||||
Box(modifier = modifier) { |
||||
Image( |
||||
painter = painterResource(id = R.drawable.association_name_border), |
||||
contentDescription = null, |
||||
contentScale = ContentScale.FillBounds, |
||||
modifier=Modifier.fillMaxSize() |
||||
) |
||||
Column{ |
||||
Spacer(modifier = Modifier.weight(1.7F / 3)) |
||||
Row(modifier = Modifier |
||||
.fillMaxWidth() |
||||
.weight(1F / 3), |
||||
horizontalArrangement = Arrangement.Center) { |
||||
Text(text = "社团名字") |
||||
} |
||||
Spacer(modifier = Modifier.weight(0.3F / 3)) |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 团长名字 |
||||
* |
||||
* @param modifier |
||||
*/ |
||||
@Composable |
||||
private fun Commander(modifier: Modifier){ |
||||
Box(modifier=modifier,contentAlignment = Alignment.Center){ |
||||
Row(modifier = Modifier.fillMaxWidth(),horizontalArrangement = Arrangement.Center) { |
||||
|
||||
Image(painter = painterResource(id = R.drawable.association_persion_name_border), |
||||
contentDescription = null |
||||
) |
||||
} |
||||
Text(text = "团长") |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 风采展示区 |
||||
* |
||||
* @param modifier |
||||
*/ |
||||
@Composable |
||||
private fun Showcase(modifier: Modifier){ |
||||
Box(modifier = modifier,contentAlignment = Alignment.Center) { |
||||
Image(painter = painterResource(id = R.drawable.showcase_border), |
||||
contentDescription = null, |
||||
modifier=Modifier.fillMaxSize()) |
||||
Image(painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = null) |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 活动列表 |
||||
* |
||||
*/ |
||||
@Composable |
||||
private fun AssociationList(){ |
||||
MainFrame(background = { Background(image = BackgroundImage.association_main,alpha = 07F) }) { |
||||
Text(text = "活动列表") |
||||
} |
||||
} |
||||
|
||||
@Preview |
||||
@Composable |
||||
fun NamePreview(){ |
||||
Divider(color = MaterialTheme.colors.background) |
||||
} |
||||
|
||||
|
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="200dp" |
||||
android:height="200dp" |
||||
android:viewportWidth="1024" |
||||
android:viewportHeight="1024"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M500.8,604.78L267.31,371.39l-45.23,45.27 278.74,278.61L779.31,416.66l-45.25,-45.25z"/> |
||||
</vector> |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="200dp" |
||||
android:height="200dp" |
||||
android:viewportWidth="1024" |
||||
android:viewportHeight="1024"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M641.28,278.61l-45.23,-45.23 -278.63,278.76 278.61,278.49 45.25,-45.27 -233.37,-233.24z"/> |
||||
</vector> |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="211.71875dp" |
||||
android:height="200dp" |
||||
android:viewportWidth="1084" |
||||
android:viewportHeight="1024"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M825.22,90.35c-18.07,-36.14 -60.24,-60.24 -102.4,-60.24s-84.33,24.09 -102.4,60.24H0v120.47h620.42c18.07,36.14 60.24,60.24 102.4,60.24s84.33,-24.09 102.4,-60.24H1084.24v-120.47h-259.01zM542.12,391.53c-42.16,0 -78.31,24.09 -102.4,54.21H0v120.47h433.69c18.07,36.14 60.24,66.26 108.42,66.26s84.33,-24.09 108.42,-66.26H1084.24v-120.47h-439.72c-24.09,-30.12 -60.24,-54.21 -102.4,-54.21zM783.06,752.94c-42.16,0 -72.28,18.07 -96.38,48.19H0v120.47h674.64c18.07,42.16 60.24,72.28 108.42,72.28s90.35,-30.12 108.42,-72.28H1084.24v-120.47h-204.8c-24.09,-30.12 -54.21,-48.19 -96.38,-48.19z"/> |
||||
</vector> |
Loading…
Reference in new issue