From 779c6c989fd46fd781e0defeb730706fce9c3b39 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Tue, 1 Jun 2021 17:41:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E7=A4=BE=E5=9B=A2=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gyf/csams/account/ui/LoginActivity.kt | 3 +- .../csams/main/ui/AuditAssociationActivity.kt | 2 +- .../gyf/csams/main/ui/DepartmentActivity.kt | 21 +- .../main/ui/ManagementOfficerActivity.kt | 25 +- .../java/com/gyf/csams/MainApplication.kt | 49 ---- .../gyf/csams/account/ui/AccountActivity.kt | 6 +- .../gyf/csams/activity/ui/ApplyActActivity.kt | 4 +- .../association/model/AssociationViewModel.kt | 20 +- .../association/ui/AssociationActivity.kt | 266 ++++++++++-------- .../gyf/csams/association/ui/ExamActivity.kt | 17 +- .../association/ui/RegAssociationActivity.kt | 23 +- .../com/gyf/csams/main/ui/MainActivity.kt | 38 ++- .../gyf/csams/message/ui/MessageActivity.kt | 6 +- .../main/java/com/gyf/csams/uikit/BaseView.kt | 27 +- .../main/java/com/gyf/lib/uikit/Profile.kt | 21 +- lib/src/main/java/com/gyf/lib/util/Api.kt | 15 +- .../main/java/com/gyf/lib/util/ContextUtil.kt | 1 - .../main/java/com/gyf/lib/util/TokenUtil.kt | 5 - lib/src/main/java/com/gyf/lib/util/Vo.kt | 24 +- 19 files changed, 259 insertions(+), 314 deletions(-) diff --git a/background/src/main/java/com/gyf/csams/account/ui/LoginActivity.kt b/background/src/main/java/com/gyf/csams/account/ui/LoginActivity.kt index 30d3d5f..6765112 100644 --- a/background/src/main/java/com/gyf/csams/account/ui/LoginActivity.kt +++ b/background/src/main/java/com/gyf/csams/account/ui/LoginActivity.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 ) ) diff --git a/background/src/main/java/com/gyf/csams/main/ui/AuditAssociationActivity.kt b/background/src/main/java/com/gyf/csams/main/ui/AuditAssociationActivity.kt index 20ddfa1..ea566db 100644 --- a/background/src/main/java/com/gyf/csams/main/ui/AuditAssociationActivity.kt +++ b/background/src/main/java/com/gyf/csams/main/ui/AuditAssociationActivity.kt @@ -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) } diff --git a/background/src/main/java/com/gyf/csams/main/ui/DepartmentActivity.kt b/background/src/main/java/com/gyf/csams/main/ui/DepartmentActivity.kt index d02daaf..f53a498 100644 --- a/background/src/main/java/com/gyf/csams/main/ui/DepartmentActivity.kt +++ b/background/src/main/java/com/gyf/csams/main/ui/DepartmentActivity.kt @@ -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( diff --git a/background/src/main/java/com/gyf/csams/main/ui/ManagementOfficerActivity.kt b/background/src/main/java/com/gyf/csams/main/ui/ManagementOfficerActivity.kt index 0da4b4b..9d4ab5f 100644 --- a/background/src/main/java/com/gyf/csams/main/ui/ManagementOfficerActivity.kt +++ b/background/src/main/java/com/gyf/csams/main/ui/ManagementOfficerActivity.kt @@ -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)) }) ) diff --git a/foreground/src/main/java/com/gyf/csams/MainApplication.kt b/foreground/src/main/java/com/gyf/csams/MainApplication.kt index 42556ef..1d9bb26 100644 --- a/foreground/src/main/java/com/gyf/csams/MainApplication.kt +++ b/foreground/src/main/java/com/gyf/csams/MainApplication.kt @@ -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() - 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 diff --git a/foreground/src/main/java/com/gyf/csams/account/ui/AccountActivity.kt b/foreground/src/main/java/com/gyf/csams/account/ui/AccountActivity.kt index 56d3be5..d7a917c 100644 --- a/foreground/src/main/java/com/gyf/csams/account/ui/AccountActivity.kt +++ b/foreground/src/main/java/com/gyf/csams/account/ui/AccountActivity.kt @@ -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 diff --git a/foreground/src/main/java/com/gyf/csams/activity/ui/ApplyActActivity.kt b/foreground/src/main/java/com/gyf/csams/activity/ui/ApplyActActivity.kt index 1c464b8..21bb1e2 100644 --- a/foreground/src/main/java/com/gyf/csams/activity/ui/ApplyActActivity.kt +++ b/foreground/src/main/java/com/gyf/csams/activity/ui/ApplyActActivity.kt @@ -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()) } diff --git a/foreground/src/main/java/com/gyf/csams/association/model/AssociationViewModel.kt b/foreground/src/main/java/com/gyf/csams/association/model/AssociationViewModel.kt index 58cbad0..35b9aa1 100644 --- a/foreground/src/main/java/com/gyf/csams/association/model/AssociationViewModel.kt +++ b/foreground/src/main/java/com/gyf/csams/association/model/AssociationViewModel.kt @@ -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 { private val _expanded = MutableLiveData(false) val expanded: LiveData = _expanded + private val _associationVo = MutableLiveData() + val associationVo: LiveData = _associationVo + + fun load(id: Int) { + viewModelScope.launch { + HttpClient.post( + Api.buildUrl(AssociationApi.Load), + HttpCallback(action = "获取社团信息", onSuccess = { + it.body?.let { _associationVo.postValue(it) } + }, typeToken = object : TypeToken>() {}.type), + jsonParam = ShowAssociationVo(id = id) + ) + } + } /** * 切换下拉菜单状态 diff --git a/foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt b/foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt index 429f03b..7195fd2 100644 --- a/foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt +++ b/foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt @@ -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() { + diff --git a/foreground/src/main/java/com/gyf/csams/association/ui/ExamActivity.kt b/foreground/src/main/java/com/gyf/csams/association/ui/ExamActivity.kt index e384a64..fc60b1a 100644 --- a/foreground/src/main/java/com/gyf/csams/association/ui/ExamActivity.kt +++ b/foreground/src/main/java/com/gyf/csams/association/ui/ExamActivity.kt @@ -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) diff --git a/foreground/src/main/java/com/gyf/csams/association/ui/RegAssociationActivity.kt b/foreground/src/main/java/com/gyf/csams/association/ui/RegAssociationActivity.kt index d2f1529..f82c7f1 100644 --- a/foreground/src/main/java/com/gyf/csams/association/ui/RegAssociationActivity.kt +++ b/foreground/src/main/java/com/gyf/csams/association/ui/RegAssociationActivity.kt @@ -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( diff --git a/foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt b/foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt index 7df1617..ad4f221 100644 --- a/foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt +++ b/foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt @@ -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 diff --git a/foreground/src/main/java/com/gyf/csams/message/ui/MessageActivity.kt b/foreground/src/main/java/com/gyf/csams/message/ui/MessageActivity.kt index c237553..5d4f776 100644 --- a/foreground/src/main/java/com/gyf/csams/message/ui/MessageActivity.kt +++ b/foreground/src/main/java/com/gyf/csams/message/ui/MessageActivity.kt @@ -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 ) ) diff --git a/foreground/src/main/java/com/gyf/csams/uikit/BaseView.kt b/foreground/src/main/java/com/gyf/csams/uikit/BaseView.kt index 4b22214..362cf38 100644 --- a/foreground/src/main/java/com/gyf/csams/uikit/BaseView.kt +++ b/foreground/src/main/java/com/gyf/csams/uikit/BaseView.kt @@ -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() + ) } diff --git a/lib/src/main/java/com/gyf/lib/uikit/Profile.kt b/lib/src/main/java/com/gyf/lib/uikit/Profile.kt index fadc00e..84231d3 100644 --- a/lib/src/main/java/com/gyf/lib/uikit/Profile.kt +++ b/lib/src/main/java/com/gyf/lib/uikit/Profile.kt @@ -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 = "没有头像") } } } diff --git a/lib/src/main/java/com/gyf/lib/util/Api.kt b/lib/src/main/java/com/gyf/lib/util/Api.kt index 6ed85a3..dbb2c62 100644 --- a/lib/src/main/java/com/gyf/lib/util/Api.kt +++ b/lib/src/main/java/com/gyf/lib/util/Api.kt @@ -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}" } } diff --git a/lib/src/main/java/com/gyf/lib/util/ContextUtil.kt b/lib/src/main/java/com/gyf/lib/util/ContextUtil.kt index 238c19d..6c30a85 100644 --- a/lib/src/main/java/com/gyf/lib/util/ContextUtil.kt +++ b/lib/src/main/java/com/gyf/lib/util/ContextUtil.kt @@ -6,7 +6,6 @@ import android.view.inputmethod.InputMethodManager import com.orhanobut.logger.Logger object ContextUtil { - fun hideKeyBoard(activity: Activity?) { Logger.i("隐藏软键盘") activity?.apply { diff --git a/lib/src/main/java/com/gyf/lib/util/TokenUtil.kt b/lib/src/main/java/com/gyf/lib/util/TokenUtil.kt index 08f2431..d03bd63 100644 --- a/lib/src/main/java/com/gyf/lib/util/TokenUtil.kt +++ b/lib/src/main/java/com/gyf/lib/util/TokenUtil.kt @@ -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() diff --git a/lib/src/main/java/com/gyf/lib/util/Vo.kt b/lib/src/main/java/com/gyf/lib/util/Vo.kt index 4a61966..25cfce6 100644 --- a/lib/src/main/java/com/gyf/lib/util/Vo.kt +++ b/lib/src/main/java/com/gyf/lib/util/Vo.kt @@ -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? = 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 -) \ No newline at end of file +) + +abstract class ClientBaseVo { + val token: Token = TokenManager.getToken() + abstract val clientType: ClientType +} \ No newline at end of file