加载社团详情信息

master
pan 3 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. 266
      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. 23
      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. 27
      foreground/src/main/java/com/gyf/csams/uikit/BaseView.kt
  15. 21
      lib/src/main/java/com/gyf/lib/uikit/Profile.kt
  16. 15
      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. 24
      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.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
@ -69,7 +68,7 @@ class LoginActivity : ComponentActivity() {
if (finishLogin == true) {
startActivity(
Intent(
LocalContext.current,
this@LoginActivity,
MainActivity::class.java
)
)

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

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

@ -15,9 +15,8 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
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.lifecycle.viewmodel.compose.viewModel
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),
verticalArrangement = Arrangement.SpaceEvenly
) {
val context = LocalContext.current
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))
LazyRow(modifier = Modifier.weight(0.6F)) {
@ -130,7 +111,7 @@ class ManagementOfficerActivity : ComponentActivity() {
modifier = Modifier.clickable(onClick = {
if (it.value.duty.isOfficer()) expanded =
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.os.Build
import android.os.Bundle
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.lifecycle.MutableLiveData
import coil.ImageLoader
import coil.ImageLoaderFactory
import coil.imageLoader
import coil.memory.MemoryCache
import coil.request.ImageRequest
import coil.util.CoilUtils
import com.baidu.location.BDAbstractLocationListener
import com.baidu.location.BDLocation
import com.baidu.location.LocationClient
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.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.DiskLogAdapter
@ -29,27 +22,8 @@ import okhttp3.OkHttpClient
class MainApplication : Application(), ImageLoaderFactory {
private val backgroundImage = mutableMapOf<BackgroundImage, MemoryCache.Key?>()
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 {
return ImageLoader.Builder(applicationContext)
.crossfade(true)
@ -61,27 +35,6 @@ class MainApplication : Application(), ImageLoaderFactory {
.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() {
super.onCreate()
//初始化日志
@ -94,8 +47,6 @@ class MainApplication : Application(), ImageLoaderFactory {
Logger.i("${BuildConfig.foreground_app_name}启动")
SDKInitializer.initialize(this)
//预加载背景图
preloadImage()
/**
* 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.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.input.ImeAction
@ -69,7 +68,7 @@ class AccountActivity : ComponentActivity() {
if (finishLogin == true) {
startActivity(
Intent(
LocalContext.current,
this@AccountActivity,
MainActivity::class.java
)
)
@ -255,7 +254,6 @@ class AccountActivity : ComponentActivity() {
*/
@Composable
private fun PasswordDialog(accountViewModel: AccountViewModel = viewModel(), message: String) {
val context = LocalContext.current
val button: @Composable () -> Unit = {
Row(
horizontalArrangement = Arrangement.Center, modifier = Modifier
@ -270,7 +268,7 @@ class AccountActivity : ComponentActivity() {
}
OutlinedButton(
onClick = {
context.startActivity(Intent(context, AccountActivity::class.java))
startActivity(Intent(this@AccountActivity, AccountActivity::class.java))
},
colors = ButtonDefaults.outlinedButtonColors(
contentColor = MaterialTheme.colors.onBackground

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

@ -5,14 +5,12 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.gson.reflect.TypeToken
import com.gyf.csams.uikit.AssociationMenu
import com.gyf.csams.uikit.TopMenuInterface
import com.gyf.lib.model.ScrollViewModel
import com.gyf.lib.uikit.StringForm
import com.gyf.lib.util.HistoryActVo
import com.gyf.lib.util.MemberVo
import com.gyf.lib.util.NOT_IMPL_TIP
import com.gyf.lib.util.OngoingActVo
import com.gyf.lib.util.*
import com.orhanobut.logger.Logger
import kotlinx.coroutines.launch
@ -28,6 +26,20 @@ class AssociationViewModel : ViewModel(), TopMenuInterface<AssociationMenu> {
private val _expanded = MutableLiveData(false)
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.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
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
@ -33,7 +33,6 @@ import com.gyf.csams.uikit.*
import com.gyf.lib.uikit.*
import com.gyf.lib.util.HistoryActVo
import com.gyf.lib.util.MemberVo
import com.gyf.lib.util.randomChinese
import com.orhanobut.logger.Logger
@ -42,137 +41,150 @@ import com.orhanobut.logger.Logger
*
*/
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?) {
super.onCreate(savedInstanceState)
setContent {
NavBody { nav, scaffoldState ->
val context = LocalContext.current as AssociationActivity
val model: AssociationViewModel = viewModel()
val currentMenuName: AssociationMenu by model.currentMenu.observeAsState(
AssociationMenu.startMenu
)
val intent = Intent(context, ExamActivity::class.java)
val intent = Intent(this, ExamActivity::class.java)
val expanded by model.expanded.observeAsState(false)
Column {
Logger.i("expanded=$expanded")
TextTopAppBar(nav = nav,
currentMenuName = currentMenuName.menuName,
menuNames = AssociationMenu.values(),
iconMenu = { model.switchType() }) {
Row {
DropdownMenu(
expanded = expanded,
onDismissRequest = { /*TODO*/ },
properties = PopupProperties()
) {
DropdownMenuItem(onClick = {
startActivity(Intent(context, ApplyActActivity::class.java))
model.close()
}) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = getString(R.string.apply_act_menu))
Icon(
painter = painterResource(id = R.drawable.ic_add_fill),
contentDescription = null
)
}
TextTopAppBar(nav = nav,
currentMenuName = currentMenuName.menuName,
menuNames = AssociationMenu.values(),
iconMenu = { model.switchType() }) {
Row {
DropdownMenu(
expanded = expanded,
onDismissRequest = { },
properties = PopupProperties()
) {
DropdownMenuItem(onClick = {
startActivity(
Intent(
this@AssociationActivity,
ApplyActActivity::class.java
)
)
model.close()
}) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = getString(R.string.apply_act_menu))
Icon(
painter = painterResource(id = R.drawable.ic_add_fill),
contentDescription = null
)
}
DropdownMenuItem(onClick = {
intent.apply {
putExtra(
ExamActivityType::name.name,
ExamActivityType.SET_EXAM
)
}
startActivity(intent)
model.close()
}) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = getString(R.string.set_exam_menu))
Icon(
painter = painterResource(id = R.drawable.ic_editor),
contentDescription = null
)
}
}
DropdownMenuItem(onClick = {
intent.apply {
putExtra(
ExamActivityType::name.name,
ExamActivityType.SET_EXAM
)
}
DropdownMenuItem(onClick = {
startActivity(
Intent(
context,
ReNameActivity::class.java
)
startActivity(intent)
model.close()
}) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = getString(R.string.set_exam_menu))
Icon(
painter = painterResource(id = R.drawable.ic_editor),
contentDescription = null
)
model.close()
}) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = getString(R.string.rename_menu))
Icon(
painter = painterResource(id = R.drawable.ic_exchange_rate),
contentDescription = null
)
}
}
DropdownMenuItem(onClick = {
intent.apply {
putExtra(
ExamActivityType::name.name,
ExamActivityType.JOIN_Association
)
}
startActivity(intent)
model.close()
}) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = getString(R.string.join_association))
Icon(
painter = painterResource(id = R.drawable.ic_add_account),
contentDescription = null
)
}
}
DropdownMenuItem(onClick = {
startActivity(
Intent(
this@AssociationActivity,
ReNameActivity::class.java
)
)
model.close()
}) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = getString(R.string.rename_menu))
Icon(
painter = painterResource(id = R.drawable.ic_exchange_rate),
contentDescription = null
)
}
DropdownMenuItem(onClick = {
model.close()
}) {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(
painter = painterResource(id = R.drawable.ic_arrow_up),
contentDescription = null,
modifier = Modifier
.height(30.dp)
.fillMaxWidth()
)
}
}
DropdownMenuItem(onClick = {
intent.apply {
putExtra(
ExamActivityType::name.name,
ExamActivityType.JOIN_Association
)
}
startActivity(intent)
model.close()
}) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = getString(R.string.join_association))
Icon(
painter = painterResource(id = R.drawable.ic_add_account),
contentDescription = null
)
}
}
DropdownMenuItem(onClick = {
model.close()
}) {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(
painter = painterResource(id = R.drawable.ic_arrow_up),
contentDescription = null,
modifier = Modifier
.height(30.dp)
.fillMaxWidth()
)
}
}
}
}
}
NavHost(
navController = nav,
startDestination = AssociationMenu.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.ActivityList.name) {
model.clickMenu(AssociationMenu.ActivityList)
AssociationList()
ShowSnackbar(scaffoldState = scaffoldState)
}
NavHost(
navController = nav,
startDestination = AssociationMenu.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.ActivityList.name) {
model.clickMenu(AssociationMenu.ActivityList)
AssociationList()
ShowSnackbar(scaffoldState = scaffoldState)
}
}
}
}
}
}
@ -297,7 +309,10 @@ class AssociationActivity : ComponentActivity() {
*
*/
@Composable
private fun Main() {
private fun Main(model: AssociationViewModel = viewModel()) {
LaunchedEffect(associationId) {
model.load(associationId)
}
MainColumnFrame(background = {
Background(image = BackgroundImage.AssociationMain, alpha = 0.7F)
}) {
@ -308,12 +323,15 @@ class AssociationActivity : ComponentActivity() {
.fillMaxWidth()
.weight(nameW)
)
DescCard(
modifier = Modifier
.weight(cardW)
.fillMaxWidth(),
content = randomChinese(500)
)
val associationVo by model.associationVo.observeAsState()
associationVo?.associationVo?.desc?.let {
DescCard(
modifier = Modifier
.weight(cardW)
.fillMaxWidth(),
content = it
)
}
Commander(
modifier = Modifier.weight(cardW)
)
@ -327,7 +345,8 @@ class AssociationActivity : ComponentActivity() {
* @param modifier
*/
@Composable
private fun Name(modifier: Modifier) {
private fun Name(modifier: Modifier, model: AssociationViewModel = viewModel()) {
val associationVo by model.associationVo.observeAsState()
Box(modifier = modifier) {
Image(
painter = painterResource(id = R.drawable.association_name_border),
@ -343,7 +362,7 @@ class AssociationActivity : ComponentActivity() {
.weight(1F / 3),
horizontalArrangement = Arrangement.Center
) {
Text(text = "社团名字")
associationVo?.associationVo?.name?.let { Text(text = it) }
}
Spacer(modifier = Modifier.weight(0.3F / 3))
}
@ -356,7 +375,7 @@ class AssociationActivity : ComponentActivity() {
* @param modifier
*/
@Composable
private fun Commander(modifier: Modifier) {
private fun Commander(modifier: Modifier, model: AssociationViewModel = viewModel()) {
Box(modifier = modifier, contentAlignment = Alignment.Center) {
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
@ -365,7 +384,11 @@ class AssociationActivity : ComponentActivity() {
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,
model: OngoingActViewModel = viewModel()
) {
val context = LocalContext.current
val act by model.act.observeAsState()
// TODO 解决Build Warnning
Logger.i("$act")
Row(modifier = modifier.clickable(onClick = {
context.startActivity(Intent(context, ActivityDetailActivity::class.java))
startActivity(Intent(this, ActivityDetailActivity::class.java))
}), horizontalArrangement = Arrangement.Center) {
val weight = 0.5F
val spaceWeight = (1 - 0.5F) / 2
@ -480,9 +502,8 @@ class AssociationActivity : ComponentActivity() {
*/
@Composable
private fun HistoryActivity(modifier: Modifier, historyActVo: HistoryActVo) {
val context = LocalContext.current
Box(modifier = modifier.clickable(onClick = {
context.startActivity(Intent(context, ActivityDetailActivity::class.java))
startActivity(Intent(this, ActivityDetailActivity::class.java))
}), contentAlignment = Alignment.Center) {
Image(
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.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@ -71,9 +70,8 @@ class ExamActivity : ComponentActivity() {
*/
@Composable
private fun Title(modifier: Modifier = Modifier) {
val context = LocalContext.current as ExamActivity
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 {
Divider(color = MaterialTheme.colors.background)
Spacer(modifier = Modifier.height(30.dp))
val context = LocalContext.current as ExamActivity
when (context.activityType) {
when (activityType) {
ExamActivityType.SET_EXAM -> {
BottomButton(
modifier = Modifier.fillMaxWidth(),
@ -250,17 +247,16 @@ class ExamActivity : ComponentActivity() {
isAdd: Boolean = false
) {
Row(modifier = modifier) {
val context = LocalContext.current as ExamActivity
Question(
exam = openQuestionsVo, modifier =
if (context.activityType == ExamActivityType.SET_EXAM)
if (activityType == ExamActivityType.SET_EXAM)
Modifier
.weight(0.8F)
.fillMaxHeight()
else
Modifier
)
if (context.activityType == ExamActivityType.SET_EXAM) {
if (activityType == ExamActivityType.SET_EXAM) {
ActionButton(
modifier = Modifier
.weight(0.2F)
@ -286,9 +282,8 @@ class ExamActivity : ComponentActivity() {
questionWeight: Float
) {
Row(modifier = modifier) {
val context = LocalContext.current as ExamActivity
Column(
modifier = if (context.activityType == ExamActivityType.SET_EXAM)
modifier = if (activityType == ExamActivityType.SET_EXAM)
Modifier
.weight(0.8F)
.fillMaxHeight()
@ -334,7 +329,7 @@ class ExamActivity : ComponentActivity() {
}
}
if (context.activityType == ExamActivityType.SET_EXAM) {
if (activityType == ExamActivityType.SET_EXAM) {
ActionButton(
modifier = Modifier
.weight(0.2F)

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

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

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

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

@ -6,12 +6,11 @@ import androidx.compose.foundation.layout.*
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import com.google.accompanist.coil.rememberCoilPainter
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(
modifier = modifier,
) {
@ -47,10 +40,12 @@ fun Profile(
.border(width = 1.dp, color = MaterialTheme.colors.onBackground),
horizontalArrangement = Arrangement.SpaceBetween
) {
headImg.let {
personInfoVo.headImg.let {
if (it != null) {
val headImg = rememberCoilPainter(request = Api.buildUrl(it))
Image(
bitmap = it,
painter = headImg,
contentDescription = null,
modifier = Modifier
.weight(0.4F)
@ -63,7 +58,7 @@ fun Profile(
.fillMaxHeight(),
contentAlignment = Alignment.Center
) {
Text(text = "头像加载失败")
Text(text = "没有头像")
}
}
}

@ -78,7 +78,8 @@ enum class AssociationApi(val path: String) : UrlPath {
List("/list"),
Check("/check"),
Audit("/audit"),
Read("/read");
Read("/read"),
Load("/load");
override fun build(): String {
return "/api/association${this.path}"
@ -99,11 +100,13 @@ enum class NotificationApi(val path: String) : UrlPath {
* 构建服务端请求接口地址
*
*/
class Api {
companion object {
fun buildUrl(urlPath: UrlPath): String {
return "${BuildConfig.SERVER_ADDRESS}${urlPath.build()}"
}
object Api {
fun buildUrl(urlPath: UrlPath): String {
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
object ContextUtil {
fun hideKeyBoard(activity: Activity?) {
Logger.i("隐藏软键盘")
activity?.apply {

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

@ -288,6 +288,18 @@ data class AssociationMemberVo(
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(
override val id: Int,
@ -315,6 +327,11 @@ data class SearchAssociationVo(
override val clientType: ClientType = ClientType.Foreground
) : 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)
@ -474,4 +491,9 @@ data class RenameVo(
val oldName: String,
val newName: String,
val reason: String
)
)
abstract class ClientBaseVo {
val token: Token = TokenManager.getToken()
abstract val clientType: ClientType
}
Loading…
Cancel
Save