加载社团详情信息

master
pan 4 years ago
parent a3e4308037
commit 779c6c989f
  1. 3
      background/src/main/java/com/gyf/csams/account/ui/LoginActivity.kt
  2. 2
      background/src/main/java/com/gyf/csams/main/ui/AuditAssociationActivity.kt
  3. 21
      background/src/main/java/com/gyf/csams/main/ui/DepartmentActivity.kt
  4. 25
      background/src/main/java/com/gyf/csams/main/ui/ManagementOfficerActivity.kt
  5. 49
      foreground/src/main/java/com/gyf/csams/MainApplication.kt
  6. 6
      foreground/src/main/java/com/gyf/csams/account/ui/AccountActivity.kt
  7. 4
      foreground/src/main/java/com/gyf/csams/activity/ui/ApplyActActivity.kt
  8. 20
      foreground/src/main/java/com/gyf/csams/association/model/AssociationViewModel.kt
  9. 58
      foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt
  10. 17
      foreground/src/main/java/com/gyf/csams/association/ui/ExamActivity.kt
  11. 19
      foreground/src/main/java/com/gyf/csams/association/ui/RegAssociationActivity.kt
  12. 38
      foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt
  13. 6
      foreground/src/main/java/com/gyf/csams/message/ui/MessageActivity.kt
  14. 15
      foreground/src/main/java/com/gyf/csams/uikit/BaseView.kt
  15. 21
      lib/src/main/java/com/gyf/lib/uikit/Profile.kt
  16. 9
      lib/src/main/java/com/gyf/lib/util/Api.kt
  17. 1
      lib/src/main/java/com/gyf/lib/util/ContextUtil.kt
  18. 5
      lib/src/main/java/com/gyf/lib/util/TokenUtil.kt
  19. 22
      lib/src/main/java/com/gyf/lib/util/Vo.kt

@ -14,7 +14,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -69,7 +68,7 @@ class LoginActivity : ComponentActivity() {
if (finishLogin == true) { if (finishLogin == true) {
startActivity( startActivity(
Intent( Intent(
LocalContext.current, this@LoginActivity,
MainActivity::class.java MainActivity::class.java
) )
) )

@ -287,7 +287,7 @@ class AuditAssociationActivity : ComponentActivity() {
) { ) {
//TODO 图片全屏显示 //TODO 图片全屏显示
val painter = val painter =
rememberCoilPainter("${com.gyf.lib.BuildConfig.SERVER_ADDRESS}/${vo.logo}") rememberCoilPainter(Api.buildUrl(vo.logo))
Image(painter = painter, contentDescription = null) Image(painter = painter, contentDescription = null)
} }

@ -12,7 +12,6 @@ import androidx.compose.material.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.gyf.csams.R import com.gyf.csams.R
@ -34,7 +33,6 @@ class DepartmentActivity : ComponentActivity() {
val weight = 0.1F val weight = 0.1F
val departWeight = 0.2F val departWeight = 0.2F
val space = 0.05F val space = 0.05F
val context = LocalContext.current
var dialogContent: Int? by remember { var dialogContent: Int? by remember {
mutableStateOf(null) mutableStateOf(null)
} }
@ -48,7 +46,7 @@ class DepartmentActivity : ComponentActivity() {
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center horizontalArrangement = Arrangement.Center
) { ) {
Text(text = context.getString(R.string.department_desc)) Text(text = stringResource(id = R.string.department_desc))
} }
Spacer(modifier = Modifier.height(10.dp)) Spacer(modifier = Modifier.height(10.dp))
@ -59,19 +57,13 @@ class DepartmentActivity : ComponentActivity() {
) { ) {
when (it) { when (it) {
R.string.secretariat -> Text( R.string.secretariat -> Text(
text = context.getString( text = stringResource(id = R.string.secretariat_desc)
R.string.secretariat_desc
)
) )
R.string.propaganda_department -> Text( R.string.propaganda_department -> Text(
text = context.getString( text = stringResource(id = R.string.propaganda_desc)
R.string.propaganda_desc
)
) )
R.string.public_relations_department -> Text( R.string.public_relations_department -> Text(
text = context.getString( text = stringResource(id = R.string.public_relations_department_desc)
R.string.public_relations_department_desc
)
) )
} }
} }
@ -96,7 +88,7 @@ class DepartmentActivity : ComponentActivity() {
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center horizontalArrangement = Arrangement.Center
) { ) {
Text(text = context.getString(R.string.department_management)) Text(text = stringResource(id = R.string.department_management))
} }
@ -124,7 +116,6 @@ class DepartmentActivity : ComponentActivity() {
@StringRes id: Int, @StringRes id: Int,
onClick: () -> Unit onClick: () -> Unit
) { ) {
val context = LocalContext.current
Row( Row(
modifier = modifier modifier = modifier
.fillMaxWidth() .fillMaxWidth()
@ -141,7 +132,7 @@ class DepartmentActivity : ComponentActivity() {
.clickable(onClick = onClick), .clickable(onClick = onClick),
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
) { ) {
Text(text = context.getString(id)) Text(text = stringResource(id = id))
} }
Spacer(modifier = Modifier.weight(0.1F)) Spacer(modifier = Modifier.weight(0.1F))
Column( Column(

@ -15,9 +15,8 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import com.gyf.csams.R import com.gyf.csams.R
@ -69,23 +68,6 @@ class ManagementOfficerActivity : ComponentActivity() {
} }
} }
@Composable
private fun BoxItem(content: @Composable () -> Unit) {
Box(
Modifier
.width(150.dp)
.height(40.dp)
.border(
width = 1.dp,
color = MaterialTheme.colors.onBackground
)
.padding(vertical = 10.dp),
contentAlignment = Alignment.Center
) {
content()
}
}
/** /**
* *
* 表格 * 表格
@ -105,10 +87,9 @@ class ManagementOfficerActivity : ComponentActivity() {
.border(width = 1.dp, color = MaterialTheme.colors.onBackground), .border(width = 1.dp, color = MaterialTheme.colors.onBackground),
verticalArrangement = Arrangement.SpaceEvenly verticalArrangement = Arrangement.SpaceEvenly
) { ) {
val context = LocalContext.current
Spacer(modifier = Modifier.weight(0.05F)) Spacer(modifier = Modifier.weight(0.05F))
Text(text = context.getString(id), modifier = Modifier.weight(0.1F)) Text(text = stringResource(id = id), modifier = Modifier.weight(0.1F))
Spacer(modifier = Modifier.weight(0.05F)) Spacer(modifier = Modifier.weight(0.05F))
LazyRow(modifier = Modifier.weight(0.6F)) { LazyRow(modifier = Modifier.weight(0.6F)) {
@ -130,7 +111,7 @@ class ManagementOfficerActivity : ComponentActivity() {
modifier = Modifier.clickable(onClick = { modifier = Modifier.clickable(onClick = {
if (it.value.duty.isOfficer()) expanded = if (it.value.duty.isOfficer()) expanded =
true else scaffoldModel true else scaffoldModel
.update(message = context.getString(R.string.update_duty_error)) .update(message = getString(R.string.update_duty_error))
}) })
) )

@ -5,21 +5,14 @@ import android.app.Application
import android.app.NotificationManager import android.app.NotificationManager
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import coil.ImageLoader import coil.ImageLoader
import coil.ImageLoaderFactory import coil.ImageLoaderFactory
import coil.imageLoader
import coil.memory.MemoryCache
import coil.request.ImageRequest
import coil.util.CoilUtils import coil.util.CoilUtils
import com.baidu.location.BDAbstractLocationListener import com.baidu.location.BDAbstractLocationListener
import com.baidu.location.BDLocation import com.baidu.location.BDLocation
import com.baidu.location.LocationClient import com.baidu.location.LocationClient
import com.baidu.mapapi.SDKInitializer import com.baidu.mapapi.SDKInitializer
import com.gyf.csams.uikit.BackgroundImage
import com.gyf.lib.util.ImageUtil
import com.gyf.lib.util.NotificationUtil import com.gyf.lib.util.NotificationUtil
import com.orhanobut.logger.AndroidLogAdapter import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.DiskLogAdapter import com.orhanobut.logger.DiskLogAdapter
@ -29,27 +22,8 @@ import okhttp3.OkHttpClient
class MainApplication : Application(), ImageLoaderFactory { class MainApplication : Application(), ImageLoaderFactory {
private val backgroundImage = mutableMapOf<BackgroundImage, MemoryCache.Key?>()
lateinit var mLocationClient: LocationClient lateinit var mLocationClient: LocationClient
/**
* 获取背景图
*
* @param image
* @return
*/
suspend fun getImage(image: BackgroundImage): ImageBitmap? {
val key = backgroundImage[image]
if (key != null) {
return applicationContext.imageLoader.memoryCache[key]?.asImageBitmap()
?: ImageUtil.getImage(applicationContext, image.id)
} else {
throw IllegalArgumentException("无法从${key}获取背景图!")
}
}
override fun newImageLoader(): ImageLoader { override fun newImageLoader(): ImageLoader {
return ImageLoader.Builder(applicationContext) return ImageLoader.Builder(applicationContext)
.crossfade(true) .crossfade(true)
@ -61,27 +35,6 @@ class MainApplication : Application(), ImageLoaderFactory {
.build() .build()
} }
/**
* 预加载背景图
*
*/
private fun preloadImage() {
BackgroundImage.values().forEach {
Logger.i("预加载背景图:${it.name}")
val request = ImageRequest.Builder(applicationContext)
.data(it.id)
// Optional, but setting a ViewSizeResolver will conserve memory by limiting the size the image should be preloaded into memory at.
.size(800, 600)
.listener { _, metadata ->
Logger.i("metadata.memoryCacheKey=${metadata.memoryCacheKey}")
backgroundImage[it] = metadata.memoryCacheKey
}
.build()
applicationContext.imageLoader.enqueue(request = request)
}
}
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
//初始化日志 //初始化日志
@ -94,8 +47,6 @@ class MainApplication : Application(), ImageLoaderFactory {
Logger.i("${BuildConfig.foreground_app_name}启动") Logger.i("${BuildConfig.foreground_app_name}启动")
SDKInitializer.initialize(this) SDKInitializer.initialize(this)
//预加载背景图
preloadImage()
/** /**
* https://developer.android.com/training/notify-user/build-notification?hl=zh-cn#java * https://developer.android.com/training/notify-user/build-notification?hl=zh-cn#java

@ -12,7 +12,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.ImeAction
@ -69,7 +68,7 @@ class AccountActivity : ComponentActivity() {
if (finishLogin == true) { if (finishLogin == true) {
startActivity( startActivity(
Intent( Intent(
LocalContext.current, this@AccountActivity,
MainActivity::class.java MainActivity::class.java
) )
) )
@ -255,7 +254,6 @@ class AccountActivity : ComponentActivity() {
*/ */
@Composable @Composable
private fun PasswordDialog(accountViewModel: AccountViewModel = viewModel(), message: String) { private fun PasswordDialog(accountViewModel: AccountViewModel = viewModel(), message: String) {
val context = LocalContext.current
val button: @Composable () -> Unit = { val button: @Composable () -> Unit = {
Row( Row(
horizontalArrangement = Arrangement.Center, modifier = Modifier horizontalArrangement = Arrangement.Center, modifier = Modifier
@ -270,7 +268,7 @@ class AccountActivity : ComponentActivity() {
} }
OutlinedButton( OutlinedButton(
onClick = { onClick = {
context.startActivity(Intent(context, AccountActivity::class.java)) startActivity(Intent(this@AccountActivity, AccountActivity::class.java))
}, },
colors = ButtonDefaults.outlinedButtonColors( colors = ButtonDefaults.outlinedButtonColors(
contentColor = MaterialTheme.colors.onBackground contentColor = MaterialTheme.colors.onBackground

@ -20,7 +20,6 @@ import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@ -380,7 +379,6 @@ class ApplyActActivity : AppCompatActivity() {
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
model: ApplyActViewModel = viewModel() model: ApplyActViewModel = viewModel()
) { ) {
val context = LocalContext.current as ApplyActActivity
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
BaseTextField( BaseTextField(
modifier = modifier, modifier = modifier,
@ -393,7 +391,7 @@ class ApplyActActivity : AppCompatActivity() {
.datePicker() .datePicker()
.setSelection(Date().time) .setSelection(Date().time)
.build() .build()
picker.show(context.supportFragmentManager, picker.toString()) picker.show(supportFragmentManager, picker.toString())
picker.addOnPositiveButtonClickListener { picker.addOnPositiveButtonClickListener {
model.activityTime.onChange(Date(it).format()) model.activityTime.onChange(Date(it).format())
} }

@ -5,14 +5,12 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.google.gson.reflect.TypeToken
import com.gyf.csams.uikit.AssociationMenu import com.gyf.csams.uikit.AssociationMenu
import com.gyf.csams.uikit.TopMenuInterface import com.gyf.csams.uikit.TopMenuInterface
import com.gyf.lib.model.ScrollViewModel import com.gyf.lib.model.ScrollViewModel
import com.gyf.lib.uikit.StringForm import com.gyf.lib.uikit.StringForm
import com.gyf.lib.util.HistoryActVo import com.gyf.lib.util.*
import com.gyf.lib.util.MemberVo
import com.gyf.lib.util.NOT_IMPL_TIP
import com.gyf.lib.util.OngoingActVo
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -28,6 +26,20 @@ class AssociationViewModel : ViewModel(), TopMenuInterface<AssociationMenu> {
private val _expanded = MutableLiveData(false) private val _expanded = MutableLiveData(false)
val expanded: LiveData<Boolean> = _expanded val expanded: LiveData<Boolean> = _expanded
private val _associationVo = MutableLiveData<AssociationMainVo>()
val associationVo: LiveData<AssociationMainVo> = _associationVo
fun load(id: Int) {
viewModelScope.launch {
HttpClient.post(
Api.buildUrl(AssociationApi.Load),
HttpCallback<AssociationMainVo>(action = "获取社团信息", onSuccess = {
it.body?.let { _associationVo.postValue(it) }
}, typeToken = object : TypeToken<ApiResponse<AssociationMainVo>>() {}.type),
jsonParam = ShowAssociationVo(id = id)
)
}
}
/** /**
* 切换下拉菜单状态 * 切换下拉菜单状态

@ -12,12 +12,12 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -33,7 +33,6 @@ import com.gyf.csams.uikit.*
import com.gyf.lib.uikit.* import com.gyf.lib.uikit.*
import com.gyf.lib.util.HistoryActVo import com.gyf.lib.util.HistoryActVo
import com.gyf.lib.util.MemberVo import com.gyf.lib.util.MemberVo
import com.gyf.lib.util.randomChinese
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
@ -42,21 +41,29 @@ import com.orhanobut.logger.Logger
* *
*/ */
class AssociationActivity : ComponentActivity() { class AssociationActivity : ComponentActivity() {
val associationId: Int
get() {
val id = intent.getIntExtra(
AssociationActivity::javaClass.name,
0
)
return if (id == 0) throw IllegalArgumentException("社团id:${id}不合法,初始化失败") else id
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContent { setContent {
NavBody { nav, scaffoldState -> NavBody { nav, scaffoldState ->
val context = LocalContext.current as AssociationActivity
val model: AssociationViewModel = viewModel() val model: AssociationViewModel = viewModel()
val currentMenuName: AssociationMenu by model.currentMenu.observeAsState( val currentMenuName: AssociationMenu by model.currentMenu.observeAsState(
AssociationMenu.startMenu AssociationMenu.startMenu
) )
val intent = Intent(context, ExamActivity::class.java) val intent = Intent(this, ExamActivity::class.java)
val expanded by model.expanded.observeAsState(false) val expanded by model.expanded.observeAsState(false)
Column { Column {
Logger.i("expanded=$expanded")
TextTopAppBar(nav = nav, TextTopAppBar(nav = nav,
currentMenuName = currentMenuName.menuName, currentMenuName = currentMenuName.menuName,
menuNames = AssociationMenu.values(), menuNames = AssociationMenu.values(),
@ -64,11 +71,16 @@ class AssociationActivity : ComponentActivity() {
Row { Row {
DropdownMenu( DropdownMenu(
expanded = expanded, expanded = expanded,
onDismissRequest = { /*TODO*/ }, onDismissRequest = { },
properties = PopupProperties() properties = PopupProperties()
) { ) {
DropdownMenuItem(onClick = { DropdownMenuItem(onClick = {
startActivity(Intent(context, ApplyActActivity::class.java)) startActivity(
Intent(
this@AssociationActivity,
ApplyActActivity::class.java
)
)
model.close() model.close()
}) { }) {
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
@ -100,7 +112,7 @@ class AssociationActivity : ComponentActivity() {
DropdownMenuItem(onClick = { DropdownMenuItem(onClick = {
startActivity( startActivity(
Intent( Intent(
context, this@AssociationActivity,
ReNameActivity::class.java ReNameActivity::class.java
) )
) )
@ -297,7 +309,10 @@ class AssociationActivity : ComponentActivity() {
* *
*/ */
@Composable @Composable
private fun Main() { private fun Main(model: AssociationViewModel = viewModel()) {
LaunchedEffect(associationId) {
model.load(associationId)
}
MainColumnFrame(background = { MainColumnFrame(background = {
Background(image = BackgroundImage.AssociationMain, alpha = 0.7F) Background(image = BackgroundImage.AssociationMain, alpha = 0.7F)
}) { }) {
@ -308,12 +323,15 @@ class AssociationActivity : ComponentActivity() {
.fillMaxWidth() .fillMaxWidth()
.weight(nameW) .weight(nameW)
) )
val associationVo by model.associationVo.observeAsState()
associationVo?.associationVo?.desc?.let {
DescCard( DescCard(
modifier = Modifier modifier = Modifier
.weight(cardW) .weight(cardW)
.fillMaxWidth(), .fillMaxWidth(),
content = randomChinese(500) content = it
) )
}
Commander( Commander(
modifier = Modifier.weight(cardW) modifier = Modifier.weight(cardW)
) )
@ -327,7 +345,8 @@ class AssociationActivity : ComponentActivity() {
* @param modifier * @param modifier
*/ */
@Composable @Composable
private fun Name(modifier: Modifier) { private fun Name(modifier: Modifier, model: AssociationViewModel = viewModel()) {
val associationVo by model.associationVo.observeAsState()
Box(modifier = modifier) { Box(modifier = modifier) {
Image( Image(
painter = painterResource(id = R.drawable.association_name_border), painter = painterResource(id = R.drawable.association_name_border),
@ -343,7 +362,7 @@ class AssociationActivity : ComponentActivity() {
.weight(1F / 3), .weight(1F / 3),
horizontalArrangement = Arrangement.Center horizontalArrangement = Arrangement.Center
) { ) {
Text(text = "社团名字") associationVo?.associationVo?.name?.let { Text(text = it) }
} }
Spacer(modifier = Modifier.weight(0.3F / 3)) Spacer(modifier = Modifier.weight(0.3F / 3))
} }
@ -356,7 +375,7 @@ class AssociationActivity : ComponentActivity() {
* @param modifier * @param modifier
*/ */
@Composable @Composable
private fun Commander(modifier: Modifier) { private fun Commander(modifier: Modifier, model: AssociationViewModel = viewModel()) {
Box(modifier = modifier, contentAlignment = Alignment.Center) { Box(modifier = modifier, contentAlignment = Alignment.Center) {
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) { Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
@ -365,7 +384,11 @@ class AssociationActivity : ComponentActivity() {
contentDescription = null contentDescription = null
) )
} }
Text(text = "团长") val info by model.associationVo.observeAsState()
info?.head?.let {
Text(text = it.name)
}
} }
} }
@ -425,12 +448,11 @@ class AssociationActivity : ComponentActivity() {
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
model: OngoingActViewModel = viewModel() model: OngoingActViewModel = viewModel()
) { ) {
val context = LocalContext.current
val act by model.act.observeAsState() val act by model.act.observeAsState()
// TODO 解决Build Warnning // TODO 解决Build Warnning
Logger.i("$act") Logger.i("$act")
Row(modifier = modifier.clickable(onClick = { Row(modifier = modifier.clickable(onClick = {
context.startActivity(Intent(context, ActivityDetailActivity::class.java)) startActivity(Intent(this, ActivityDetailActivity::class.java))
}), horizontalArrangement = Arrangement.Center) { }), horizontalArrangement = Arrangement.Center) {
val weight = 0.5F val weight = 0.5F
val spaceWeight = (1 - 0.5F) / 2 val spaceWeight = (1 - 0.5F) / 2
@ -480,9 +502,8 @@ class AssociationActivity : ComponentActivity() {
*/ */
@Composable @Composable
private fun HistoryActivity(modifier: Modifier, historyActVo: HistoryActVo) { private fun HistoryActivity(modifier: Modifier, historyActVo: HistoryActVo) {
val context = LocalContext.current
Box(modifier = modifier.clickable(onClick = { Box(modifier = modifier.clickable(onClick = {
context.startActivity(Intent(context, ActivityDetailActivity::class.java)) startActivity(Intent(this, ActivityDetailActivity::class.java))
}), contentAlignment = Alignment.Center) { }), contentAlignment = Alignment.Center) {
Image( Image(
painter = painterResource(id = R.drawable.history_activity_border), painter = painterResource(id = R.drawable.history_activity_border),
@ -508,3 +529,4 @@ class AssociationActivity : ComponentActivity() {

@ -13,7 +13,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -71,9 +70,8 @@ class ExamActivity : ComponentActivity() {
*/ */
@Composable @Composable
private fun Title(modifier: Modifier = Modifier) { private fun Title(modifier: Modifier = Modifier) {
val context = LocalContext.current as ExamActivity
Row(horizontalArrangement = Arrangement.Center, modifier = modifier.fillMaxWidth()) { Row(horizontalArrangement = Arrangement.Center, modifier = modifier.fillMaxWidth()) {
Text(text = context.activityType.menuName, style = MaterialTheme.typography.h4) Text(text = activityType.menuName, style = MaterialTheme.typography.h4)
} }
} }
@ -133,9 +131,8 @@ class ExamActivity : ComponentActivity() {
Column { Column {
Divider(color = MaterialTheme.colors.background) Divider(color = MaterialTheme.colors.background)
Spacer(modifier = Modifier.height(30.dp)) Spacer(modifier = Modifier.height(30.dp))
val context = LocalContext.current as ExamActivity
when (context.activityType) { when (activityType) {
ExamActivityType.SET_EXAM -> { ExamActivityType.SET_EXAM -> {
BottomButton( BottomButton(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
@ -250,17 +247,16 @@ class ExamActivity : ComponentActivity() {
isAdd: Boolean = false isAdd: Boolean = false
) { ) {
Row(modifier = modifier) { Row(modifier = modifier) {
val context = LocalContext.current as ExamActivity
Question( Question(
exam = openQuestionsVo, modifier = exam = openQuestionsVo, modifier =
if (context.activityType == ExamActivityType.SET_EXAM) if (activityType == ExamActivityType.SET_EXAM)
Modifier Modifier
.weight(0.8F) .weight(0.8F)
.fillMaxHeight() .fillMaxHeight()
else else
Modifier Modifier
) )
if (context.activityType == ExamActivityType.SET_EXAM) { if (activityType == ExamActivityType.SET_EXAM) {
ActionButton( ActionButton(
modifier = Modifier modifier = Modifier
.weight(0.2F) .weight(0.2F)
@ -286,9 +282,8 @@ class ExamActivity : ComponentActivity() {
questionWeight: Float questionWeight: Float
) { ) {
Row(modifier = modifier) { Row(modifier = modifier) {
val context = LocalContext.current as ExamActivity
Column( Column(
modifier = if (context.activityType == ExamActivityType.SET_EXAM) modifier = if (activityType == ExamActivityType.SET_EXAM)
Modifier Modifier
.weight(0.8F) .weight(0.8F)
.fillMaxHeight() .fillMaxHeight()
@ -334,7 +329,7 @@ class ExamActivity : ComponentActivity() {
} }
} }
if (context.activityType == ExamActivityType.SET_EXAM) { if (activityType == ExamActivityType.SET_EXAM) {
ActionButton( ActionButton(
modifier = Modifier modifier = Modifier
.weight(0.2F) .weight(0.2F)

@ -18,11 +18,11 @@ import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.OutlinedButton import androidx.compose.material.OutlinedButton
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.* import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle import androidx.compose.ui.text.withStyle
@ -30,6 +30,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.coil.rememberCoilPainter
import com.gyf.csams.R import com.gyf.csams.R
import com.gyf.csams.association.model.RegAssociationViewModel import com.gyf.csams.association.model.RegAssociationViewModel
import com.gyf.csams.uikit.Background import com.gyf.csams.uikit.Background
@ -37,7 +38,6 @@ import com.gyf.csams.uikit.BackgroundImage
import com.gyf.lib.uikit.* import com.gyf.lib.uikit.*
import com.gyf.lib.util.BottomButton import com.gyf.lib.util.BottomButton
import com.gyf.lib.util.CheckStatus import com.gyf.lib.util.CheckStatus
import com.gyf.lib.util.ImageUtil
import com.gyf.lib.util.format import com.gyf.lib.util.format
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
import java.util.* import java.util.*
@ -178,7 +178,6 @@ class RegAssociationActivity : ComponentActivity() {
//model.loadPicture(context) //model.loadPicture(context)
resultLauncher.launch(photoIntent) resultLauncher.launch(photoIntent)
} }
// val context= LocalContext.current
val launcher = rememberLauncherForActivityResult( val launcher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission() ActivityResultContracts.RequestPermission()
) { isGranted: Boolean -> ) { isGranted: Boolean ->
@ -224,18 +223,10 @@ class RegAssociationActivity : ComponentActivity() {
uri.let { it -> uri.let { it ->
if (it != null) { if (it != null) {
Row { Row {
var logo: ImageBitmap? by remember { val logo = rememberCoilPainter(request = uri)
mutableStateOf(null)
}
LaunchedEffect(it) {
logo = ImageUtil.getImage(this@RegAssociationActivity, uri)
}
logo?.let {
Image( Image(
bitmap = it, contentDescription = null painter = logo, contentDescription = null
) )
}
val checkInfo by model.checkInfo.observeAsState() val checkInfo by model.checkInfo.observeAsState()
if (checkInfo == null || checkInfo?.checkStatus == CheckStatus.Finish) { if (checkInfo == null || checkInfo?.checkStatus == CheckStatus.Finish) {
Column( Column(

@ -15,7 +15,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -23,6 +22,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import com.google.accompanist.coil.rememberCoilPainter
import com.gyf.csams.R import com.gyf.csams.R
import com.gyf.csams.account.model.AccountViewModel import com.gyf.csams.account.model.AccountViewModel
import com.gyf.csams.activity.ui.ActivityDetailActivity import com.gyf.csams.activity.ui.ActivityDetailActivity
@ -203,7 +203,6 @@ class MainActivity : BaseActivity() {
*/ */
@Composable @Composable
private fun RegisterAssociation() { private fun RegisterAssociation() {
val context = LocalContext.current
Row( Row(
horizontalArrangement = Arrangement.End, horizontalArrangement = Arrangement.End,
modifier = Modifier modifier = Modifier
@ -211,7 +210,7 @@ class MainActivity : BaseActivity() {
.padding(10.dp) .padding(10.dp)
) { ) {
IconButton(onClick = { IconButton(onClick = {
context.startActivity(Intent(context, RegAssociationActivity::class.java)) startActivity(Intent(this@MainActivity, RegAssociationActivity::class.java))
}) { }) {
Icon( Icon(
painter = painterResource(id = R.drawable.ic_add_fill), painter = painterResource(id = R.drawable.ic_add_fill),
@ -240,12 +239,12 @@ class MainActivity : BaseActivity() {
Row { Row {
Spacer(modifier = Modifier.weight(0.1F)) Spacer(modifier = Modifier.weight(0.1F))
Box(modifier = Modifier.weight(0.35F)) { Box(modifier = Modifier.weight(0.35F)) {
Association(associationListVo = it[0]) Association(associationVo = it[0])
} }
Spacer(modifier = Modifier.weight(0.05F)) Spacer(modifier = Modifier.weight(0.05F))
if (it.size == 2) { if (it.size == 2) {
Box(modifier = Modifier.weight(0.35F)) { Box(modifier = Modifier.weight(0.35F)) {
Association(associationListVo = it[1]) Association(associationVo = it[1])
} }
} else { } else {
Box( Box(
@ -270,26 +269,28 @@ class MainActivity : BaseActivity() {
} }
} }
/**
* 社团卡片
*
* @param associationVo
*/
@Composable @Composable
private fun Association(associationListVo: AssociationVo) { private fun Association(associationVo: AssociationVo) {
val context = LocalContext.current
Card(modifier = Modifier.clickable(onClick = { Card(modifier = Modifier.clickable(onClick = {
context.startActivity( val intent = Intent(this, AssociationActivity::class.java)
Intent( intent.putExtra(AssociationActivity::javaClass.name, associationVo.id)
context, startActivity(intent)
AssociationActivity::class.java
)
)
})) { })) {
val backgroundImage = rememberCoilPainter(request = R.drawable.association_list_border)
Image( Image(
painter = painterResource(id = R.drawable.association_list_border), painter = backgroundImage,
contentDescription = null contentDescription = null
) )
Row( Row(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center horizontalArrangement = Arrangement.Center
) { ) {
Text(text = associationListVo.name) Text(text = associationVo.name)
} }
} }
@ -351,7 +352,6 @@ class MainActivity : BaseActivity() {
*/ */
@Composable @Composable
private fun Notification(notificationViewModel: NotificationViewModel = viewModel()) { private fun Notification(notificationViewModel: NotificationViewModel = viewModel()) {
val context = LocalContext.current
val count by notificationViewModel.count.observeAsState(null) val count by notificationViewModel.count.observeAsState(null)
count?.let { count?.let {
Row( Row(
@ -361,7 +361,7 @@ class MainActivity : BaseActivity() {
.padding(10.dp) .padding(10.dp)
) { ) {
IconButton(onClick = { IconButton(onClick = {
context.startActivity(Intent(context, MessageActivity::class.java)) startActivity(Intent(this@MainActivity, MessageActivity::class.java))
}) { }) {
Icon( Icon(
painter = painterResource(id = if (it > 0) R.drawable.ic_notice else R.drawable.ic_notification), painter = painterResource(id = if (it > 0) R.drawable.ic_notice else R.drawable.ic_notification),
@ -449,8 +449,6 @@ class MainActivity : BaseActivity() {
viewModel: ImageViewModel = viewModel() viewModel: ImageViewModel = viewModel()
) { ) {
val context = LocalContext.current as MainActivity
val error by viewModel.error.observeAsState() val error by viewModel.error.observeAsState()
error?.let { error?.let {
scaffoldModel.update(message = it) scaffoldModel.update(message = it)
@ -458,7 +456,7 @@ class MainActivity : BaseActivity() {
} }
Carousel(imageBitmap = viewModel.image) { Carousel(imageBitmap = viewModel.image) {
Column(modifier = Modifier.clickable(onClick = { Column(modifier = Modifier.clickable(onClick = {
context.startActivity(Intent(context, ActivityDetailActivity::class.java)) startActivity(Intent(this, ActivityDetailActivity::class.java))
})) { })) {
Poster( Poster(
modifier = Modifier modifier = Modifier

@ -12,7 +12,6 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
@ -36,7 +35,6 @@ class MessageActivity : ComponentActivity() {
setContent { setContent {
Body { Body {
val model: MessageViewModel = viewModel() val model: MessageViewModel = viewModel()
val context = LocalContext.current
MainColumnFrame(background = { MainColumnFrame(background = {
Background( Background(
image = BackgroundImage.ActivityMessage, image = BackgroundImage.ActivityMessage,
@ -52,9 +50,9 @@ class MessageActivity : ComponentActivity() {
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.clickable(onClick = { modifier = Modifier.clickable(onClick = {
context.startActivity( startActivity(
Intent( Intent(
context, this@MessageActivity,
SysMessageActivity::class.java SysMessageActivity::class.java
) )
) )

@ -31,6 +31,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import com.google.accompanist.coil.rememberCoilPainter
import com.gyf.csams.MainApplication import com.gyf.csams.MainApplication
import com.gyf.csams.R import com.gyf.csams.R
import com.gyf.csams.main.model.MarqueeViewModel import com.gyf.csams.main.model.MarqueeViewModel
@ -432,21 +433,17 @@ enum class BackgroundImage(@DrawableRes val id: Int) {
@Composable @Composable
fun Background(image: BackgroundImage, alpha: Float = DefaultAlpha) { fun Background(image: BackgroundImage, alpha: Float = DefaultAlpha) {
val app = LocalContext.current.applicationContext as MainApplication val app = LocalContext.current.applicationContext as MainApplication
var i: ImageBitmap? by remember {
mutableStateOf(null) // val img=app.getImage(image = image)
} val backgroundImage = rememberCoilPainter(request = image.id)
LaunchedEffect(image) {
i = app.getImage(image = image)
}
i?.let {
Image( Image(
bitmap = it, painter = backgroundImage,
contentDescription = null, contentDescription = null,
contentScale = ContentScale.FillBounds, contentScale = ContentScale.FillBounds,
alpha = alpha, alpha = alpha,
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
) )
}
} }

@ -6,12 +6,11 @@ import androidx.compose.foundation.layout.*
import androidx.compose.material.Card import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.* import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.google.accompanist.coil.rememberCoilPainter
import com.gyf.lib.util.* import com.gyf.lib.util.*
@ -30,13 +29,7 @@ fun Profile(
) )
} }
) { ) {
var headImg: ImageBitmap? by remember {
mutableStateOf(null)
}
val context = LocalContext.current
LaunchedEffect(personInfoVo.headImg) {
headImg = ImageUtil.getImage(context = context, personInfoVo.headImg)
}
Column( Column(
modifier = modifier, modifier = modifier,
) { ) {
@ -47,10 +40,12 @@ fun Profile(
.border(width = 1.dp, color = MaterialTheme.colors.onBackground), .border(width = 1.dp, color = MaterialTheme.colors.onBackground),
horizontalArrangement = Arrangement.SpaceBetween horizontalArrangement = Arrangement.SpaceBetween
) { ) {
headImg.let {
personInfoVo.headImg.let {
if (it != null) { if (it != null) {
val headImg = rememberCoilPainter(request = Api.buildUrl(it))
Image( Image(
bitmap = it, painter = headImg,
contentDescription = null, contentDescription = null,
modifier = Modifier modifier = Modifier
.weight(0.4F) .weight(0.4F)
@ -63,7 +58,7 @@ fun Profile(
.fillMaxHeight(), .fillMaxHeight(),
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
) { ) {
Text(text = "头像加载失败") Text(text = "没有头像")
} }
} }
} }

@ -78,7 +78,8 @@ enum class AssociationApi(val path: String) : UrlPath {
List("/list"), List("/list"),
Check("/check"), Check("/check"),
Audit("/audit"), Audit("/audit"),
Read("/read"); Read("/read"),
Load("/load");
override fun build(): String { override fun build(): String {
return "/api/association${this.path}" return "/api/association${this.path}"
@ -99,11 +100,13 @@ enum class NotificationApi(val path: String) : UrlPath {
* 构建服务端请求接口地址 * 构建服务端请求接口地址
* *
*/ */
class Api { object Api {
companion object {
fun buildUrl(urlPath: UrlPath): String { fun buildUrl(urlPath: UrlPath): String {
return "${BuildConfig.SERVER_ADDRESS}${urlPath.build()}" return "${BuildConfig.SERVER_ADDRESS}${urlPath.build()}"
} }
fun buildUrl(path: String): String {
return "${BuildConfig.SERVER_ADDRESS}${if (path.startsWith("/")) "" else "/"}${path}"
} }
} }

@ -6,7 +6,6 @@ import android.view.inputmethod.InputMethodManager
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
object ContextUtil { object ContextUtil {
fun hideKeyBoard(activity: Activity?) { fun hideKeyBoard(activity: Activity?) {
Logger.i("隐藏软键盘") Logger.i("隐藏软键盘")
activity?.apply { activity?.apply {

@ -16,11 +16,6 @@ data class Token(
@ColumnInfo val createTime: Long @ColumnInfo val createTime: Long
) )
abstract class ClientBaseVo {
val token: Token = TokenManager.getToken()
abstract val clientType: ClientType
}
data class OnlyToken( data class OnlyToken(
override val clientType: ClientType override val clientType: ClientType
) : ClientBaseVo() ) : ClientBaseVo()

@ -288,6 +288,18 @@ data class AssociationMemberVo(
val isHead: Boolean val isHead: Boolean
) )
/**
* 活动照片
*
* @property path
*/
data class AssociationActPhotoVo(val path: String)
data class AssociationMainVo(
val associationVo: AssociationVo, val head: UserInfoVo,
val photos: List<AssociationActPhotoVo>? = null
)
//用户社团 //用户社团
data class AssociationCheckVo( data class AssociationCheckVo(
override val id: Int, override val id: Int,
@ -315,6 +327,11 @@ data class SearchAssociationVo(
override val clientType: ClientType = ClientType.Foreground override val clientType: ClientType = ClientType.Foreground
) : ClientBaseVo() ) : ClientBaseVo()
data class ShowAssociationVo(
val id: Int,
override val clientType: ClientType = ClientType.Foreground
) : ClientBaseVo()
data class BBSVo(val studentId: String, val name: String, val createTime: Date, val content: String) data class BBSVo(val studentId: String, val name: String, val createTime: Date, val content: String)
@ -475,3 +492,8 @@ data class RenameVo(
val newName: String, val newName: String,
val reason: String val reason: String
) )
abstract class ClientBaseVo {
val token: Token = TokenManager.getToken()
abstract val clientType: ClientType
}
Loading…
Cancel
Save