完善活动详情,和服务端接口联调

master
pan 3 years ago
parent f093f47c37
commit 5ec8924532
  1. 2
      background/src/main/java/com/gyf/csams/InitActivity.kt
  2. 2
      background/src/main/java/com/gyf/csams/main/model/AssociationManagementViewModel.kt
  3. 3
      background/src/main/java/com/gyf/csams/main/model/AuditActViewModel.kt
  4. 3
      background/src/main/java/com/gyf/csams/main/model/AuditAssociationViewModel.kt
  5. 5
      background/src/main/java/com/gyf/csams/main/model/BaseAuditViewModel.kt
  6. 10
      background/src/main/java/com/gyf/csams/main/model/MenuViewModel.kt
  7. 11
      background/src/main/java/com/gyf/csams/main/ui/MainActivity.kt
  8. 2
      background/src/test/java/com/gyf/csams/ExampleUnitTest.kt
  9. 3
      foreground/src/main/java/com/gyf/csams/InitActivity.kt
  10. 5
      foreground/src/main/java/com/gyf/csams/account/model/AccountViewModel.kt
  11. 145
      foreground/src/main/java/com/gyf/csams/activity/model/ActivityDetailViewModel.kt
  12. 5
      foreground/src/main/java/com/gyf/csams/activity/model/ApplyActViewModel.kt
  13. 238
      foreground/src/main/java/com/gyf/csams/activity/ui/ActivityDetailActivity.kt
  14. 23
      foreground/src/main/java/com/gyf/csams/association/model/AssociationViewModel.kt
  15. 3
      foreground/src/main/java/com/gyf/csams/association/model/RegAssociationViewModel.kt
  16. 15
      foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt
  17. 8
      foreground/src/main/java/com/gyf/csams/main/model/MainViewModel.kt
  18. 2
      foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt
  19. 15
      foreground/src/main/java/com/gyf/csams/uikit/BaseView.kt
  20. 1
      foreground/src/main/java/com/gyf/csams/uikit/ViewModel.kt
  21. 3
      foreground/src/main/java/com/gyf/csams/util/HttpCallback.kt
  22. 4
      foreground/src/main/res/values-en/strings.xml
  23. 4
      foreground/src/main/res/values-zh/strings.xml
  24. 4
      foreground/src/main/res/values/strings.xml
  25. 2
      foreground/src/test/java/com/gyf/csams/ExampleUnitTest.kt
  26. 1
      lib/src/main/java/com/gyf/lib/model/AbstractLoginViewModel.kt
  27. 1
      lib/src/main/java/com/gyf/lib/model/InitViewModel.kt
  28. 1
      lib/src/main/java/com/gyf/lib/model/SysMessageViewModel.kt
  29. 1
      lib/src/main/java/com/gyf/lib/service/MessageService.kt
  30. 20
      lib/src/main/java/com/gyf/lib/util/Api.kt
  31. 4
      lib/src/main/java/com/gyf/lib/util/BottomButton.kt
  32. 21
      lib/src/main/java/com/gyf/lib/util/HttpUtil.kt

@ -4,10 +4,10 @@ import android.app.Activity
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.csams.account.ui.LoginActivity import com.gyf.csams.account.ui.LoginActivity
import com.gyf.csams.main.ui.MainActivity import com.gyf.csams.main.ui.MainActivity
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.ManagerVo import com.gyf.csams.module.ManagerVo
import com.gyf.lib.uikit.AbstractInitActivity import com.gyf.lib.uikit.AbstractInitActivity
import com.gyf.lib.util.AccountApi import com.gyf.lib.util.AccountApi
import com.gyf.lib.util.ApiResponse
import java.lang.reflect.Type import java.lang.reflect.Type
class InitActivity : AbstractInitActivity<ManagerVo>() { class InitActivity : AbstractInitActivity<ManagerVo>() {

@ -20,7 +20,7 @@ class AssociationManagementViewModel(application: Application) : ScrollViewModel
} }
fun load() { fun load() {
TODO() TODO("数据状态管理")
} }
fun loadMore(callback: (message: String) -> Unit) { fun loadMore(callback: (message: String) -> Unit) {

@ -2,10 +2,9 @@ package com.gyf.csams.main.model
import android.app.Application import android.app.Application
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.AuditActVo import com.gyf.csams.module.AuditActVo
import com.gyf.lib.util.ActivityApi import com.gyf.lib.util.ActivityApi
import com.gyf.lib.util.ApiResponse
import com.gyf.lib.util.UrlPath import com.gyf.lib.util.UrlPath
import java.lang.reflect.Type import java.lang.reflect.Type

@ -2,10 +2,9 @@ package com.gyf.csams.main.model
import android.app.Application import android.app.Application
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.AuditAssociationVo import com.gyf.csams.module.AuditAssociationVo
import com.gyf.lib.util.ApiResponse
import com.gyf.lib.util.AssociationApi import com.gyf.lib.util.AssociationApi
import com.gyf.lib.util.UrlPath import com.gyf.lib.util.UrlPath
import java.lang.reflect.Type import java.lang.reflect.Type

@ -3,10 +3,7 @@ package com.gyf.csams.main.model
import android.app.Application import android.app.Application
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.csams.module.AcceptVo import com.gyf.csams.module.*
import com.gyf.csams.module.AuditVo
import com.gyf.csams.module.CheckVo
import com.gyf.csams.module.ClientType
import com.gyf.lib.model.ScrollViewModel import com.gyf.lib.model.ScrollViewModel
import com.gyf.lib.util.* import com.gyf.lib.util.*
import kotlinx.coroutines.launch import kotlinx.coroutines.launch

@ -2,13 +2,15 @@ package com.gyf.csams.main.model
import android.app.Activity import android.app.Activity
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import com.gyf.csams.main.ui.* import com.gyf.csams.main.ui.AuditActActivity
import com.gyf.csams.main.ui.AuditAssociationActivity
import com.gyf.csams.main.ui.RenameActivity
enum class MenuType(val desc: String, val clazz: Map<String, Class<out Activity>>) { enum class MenuType(val desc: String, val clazz: Map<String, Class<out Activity>>) {
Association( Association(
"社团管理", "社团管理",
mapOf( mapOf(
"社团信息管理" to AssociationManagementActivity::class.java, // TODO "社团信息管理" to AssociationManagementActivity::class.java,
"审核社团换名" to RenameActivity::class.java, "审核社团换名" to RenameActivity::class.java,
"审核社团注册" to AuditAssociationActivity::class.java "审核社团注册" to AuditAssociationActivity::class.java
), ),
@ -16,8 +18,8 @@ enum class MenuType(val desc: String, val clazz: Map<String, Class<out Activity>
Act( Act(
"活动管理", mapOf( "活动管理", mapOf(
"审核社团活动" to AuditActActivity::class.java, "审核社团活动" to AuditActActivity::class.java,
"审核质量报告单" to CheckQualityReportActivity::class.java, // TODO "审核质量报告单" to CheckQualityReportActivity::class.java,
"查看社团活动" to ManagerActActivity::class.java // "查看社团活动" to ManagerActActivity::class.java
) )
) )
} }

@ -59,11 +59,12 @@ class MainActivity : BaseActivity() {
Text(text = "我的通知") Text(text = "我的通知")
} }
OutlinedButton(onClick = { // TODO 部门管理
startActivity(Intent(this@MainActivity, DepartmentActivity::class.java)) // OutlinedButton(onClick = {
}, modifier = Modifier.fillMaxWidth()) { // startActivity(Intent(this@MainActivity, DepartmentActivity::class.java))
Text(text = stringResource(id = R.string.department_management)) // }, modifier = Modifier.fillMaxWidth()) {
} // Text(text = stringResource(id = R.string.department_management))
// }
OutlinedButton(onClick = { OutlinedButton(onClick = {
startActivity( startActivity(
Intent( Intent(

@ -1,7 +1,7 @@
package com.gyf.csams package com.gyf.csams
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.lib.util.ApiResponse import com.gyf.csams.module.ApiResponse
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.Test

@ -4,11 +4,10 @@ import android.app.Activity
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.csams.account.ui.AccountActivity import com.gyf.csams.account.ui.AccountActivity
import com.gyf.csams.main.ui.MainActivity import com.gyf.csams.main.ui.MainActivity
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.UserVo import com.gyf.csams.module.UserVo
import com.gyf.lib.uikit.AbstractInitActivity import com.gyf.lib.uikit.AbstractInitActivity
import com.gyf.lib.util.AccountApi import com.gyf.lib.util.AccountApi
import com.gyf.lib.util.ApiResponse
import java.lang.reflect.Type import java.lang.reflect.Type
class InitActivity : AbstractInitActivity<UserVo>() { class InitActivity : AbstractInitActivity<UserVo>() {

@ -11,10 +11,7 @@ import com.google.gson.reflect.TypeToken
import com.gyf.csams.R import com.gyf.csams.R
import com.gyf.csams.account.ui.AccountActivity import com.gyf.csams.account.ui.AccountActivity
import com.gyf.csams.account.ui.AccountRoute import com.gyf.csams.account.ui.AccountRoute
import com.gyf.csams.module.ClientType import com.gyf.csams.module.*
import com.gyf.csams.module.UserLoginVo
import com.gyf.csams.module.UserRegVo
import com.gyf.csams.module.UserVo
import com.gyf.lib.model.AbstractLoginViewModel import com.gyf.lib.model.AbstractLoginViewModel
import com.gyf.lib.uikit.FormStatus import com.gyf.lib.uikit.FormStatus
import com.gyf.lib.uikit.ValidStringForm import com.gyf.lib.uikit.ValidStringForm

@ -1,19 +1,22 @@
package com.gyf.csams.activity.model package com.gyf.csams.activity.model
import android.app.Application import android.app.Application
import android.net.Uri
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import com.gyf.csams.module.ActivityDetailVo import androidx.lifecycle.viewModelScope
import com.gyf.csams.module.ActivityPhotoVo import com.google.gson.reflect.TypeToken
import com.gyf.csams.module.BBSVo import com.gyf.csams.MainApplication
import com.gyf.csams.module.UserInfoVo import com.gyf.csams.module.*
import com.gyf.csams.uikit.AbstractComment import com.gyf.csams.uikit.AbstractComment
import com.gyf.csams.uikit.ActivityDetailMenu import com.gyf.csams.uikit.ActivityDetailMenu
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.ValidStringForm import com.gyf.lib.uikit.ValidStringForm
import com.gyf.lib.util.NOT_IMPL_TIP import com.gyf.lib.util.*
import kotlinx.coroutines.launch
import java.io.File
/** /**
* 活动详情菜单通用状态 * 活动详情菜单通用状态
@ -36,9 +39,6 @@ class ActivityInfoViewModel : ViewModel() {
val like = "点赞" val like = "点赞"
val collect = "收藏" val collect = "收藏"
init {
loadInfo()
}
/** /**
* TODO 点赞 * TODO 点赞
@ -58,8 +58,24 @@ class ActivityInfoViewModel : ViewModel() {
callback(NOT_IMPL_TIP) callback(NOT_IMPL_TIP)
} }
private fun loadInfo() { /**
TODO() * 加载活动详情
*
* @param activityId
*/
fun load(activityId: Int) {
viewModelScope.launch {
HttpClient.post(url = Api.buildUrl(ActivityApi.Show),
callback = HttpCallback<ActivityDetailVo>(action = "加载活动详情",
onSuccess = { it ->
it.body?.let {
_activityDetailVo.postValue(it)
}
}, typeToken = object : TypeToken<ApiResponse<ActivityDetailVo>>() {}.type
),
jsonParam = ShowActivityVo(activityId = activityId, token = TokenManager.getToken())
)
}
} }
} }
@ -71,32 +87,61 @@ class ActivityInfoViewModel : ViewModel() {
*/ */
class ActivityPhotoViewModel(application: Application) : class ActivityPhotoViewModel(application: Application) :
ScrollViewModel<ActivityPhotoVo>(application) { ScrollViewModel<ActivityPhotoVo>(application) {
override val initSize: Int = 10
init {
load()
}
fun upload(callback: (message: String) -> Unit) { val name = ValidStringForm("照片名", textLength = 10)
callback(NOT_IMPL_TIP)
}
/** /**
* 上传照片
* *
* * @param uri
*/ */
fun load() { fun upload(activityId: Int, uri: Uri, callback: (message: String) -> Unit) {
TODO("加载相册") val resolver = getApplication<MainApplication>().contentResolver
resolver.openInputStream(uri)?.readBytes()?.apply {
name.clean()
viewModelScope.launch {
val context = getApplication<MainApplication>()
runCatching {
val cacheFile = File(context.cacheDir, "${System.currentTimeMillis()}")
cacheFile.writeBytes(this@apply)
HttpClient.uploadFile(url = Api.buildUrl(ActivityApi.UploadPhoto),
callback = HttpCallback<Boolean>(action = "上传照片",
onSuccess = {
callback("上传成功")
}, typeToken = object : TypeToken<ApiResponse<Boolean>>() {}.type
),
params = mapOf(
"activityId" to "$activityId",
"name" to (name.formValue.value
?: throw IllegalArgumentException("照片名字为空"))
),
fileList = arrayOf(cacheFile)
)
}
}
}
} }
/** /**
* 加载相册
* *
*
* @param callback
*/ */
fun loadMore(callback: (message: String) -> Unit) { fun load(activityId: Int) {
TODO("加载更多相册") viewModelScope.launch {
HttpClient.post(
url = Api.buildUrl(ActivityApi.Photo),
callback = HttpCallback<MutableList<ActivityPhotoVo>>(
action = "加载相册",
onSuccess = {
_data.postValue(it.body)
},
typeToken = object :
TypeToken<ApiResponse<MutableList<ActivityPhotoVo>>>() {}.type
),
jsonParam = SearchActivityPhotoVo(activityId = activityId)
)
}
} }
} }
@ -104,25 +149,36 @@ class ActivityPhotoViewModel(application: Application) :
class ActivityMemberViewModel(application: Application) : class ActivityMemberViewModel(application: Application) :
ScrollViewModel<UserInfoVo>(application) { ScrollViewModel<UserInfoVo>(application) {
/**
*
*
*/
fun load() {
TODO("加载活动成员")
}
} }
class BBSCommentModel : AbstractComment() { class BBSCommentModel : AbstractComment() {
override val newContent = ValidStringForm(formDesc = "评论内容", textLength = 80) override val newContent = ValidStringForm(formDesc = "评论内容", textLength = 80)
var activityId: Int? = null
/** /**
* TODO 发送评论 * 发送评论
*
* @param callback * @param callback
*/ */
override fun send(callback: (message: String) -> Unit) { override fun send(callback: (message: String) -> Unit) {
callback(NOT_IMPL_TIP) viewModelScope.launch {
HttpClient.post(url = Api.buildUrl(ActivityApi.SendComment),
callback = HttpCallback<Boolean>(action = "发送评论",
onSuccess = {
callback(it.message)
}, typeToken = object : TypeToken<ApiResponse<Boolean>>() {}.type
),
jsonParam =
SendBBSVo(
content = newContent.formValue.value
?: throw IllegalArgumentException("评论内容为空"),
token = TokenManager.getToken(),
activityId = activityId ?: throw IllegalArgumentException("活动id没有初始化")
)
)
}
} }
} }
@ -131,14 +187,21 @@ class BBSCommentModel : AbstractComment() {
* *
*/ */
class BBSViewModel(application: Application) : ScrollViewModel<BBSVo>(application) { class BBSViewModel(application: Application) : ScrollViewModel<BBSVo>(application) {
override val initSize: Int = 10
val title = "发送评论"
/** /**
* * 加载评论
*/ */
fun load() { fun load(activityId: Int) {
TODO("加载评论") viewModelScope.launch {
HttpClient.post(url = Api.buildUrl(ActivityApi.Comment),
callback = HttpCallback<MutableList<BBSVo>>(action = "加载评论",
onSuccess = {
_data.postValue(it.body)
}, typeToken = object : TypeToken<ApiResponse<MutableList<BBSVo>>>() {}.type
),
jsonParam = SearchCommentVo(activityId = activityId)
)
}
} }
} }

@ -25,7 +25,6 @@ import com.gyf.csams.R
import com.gyf.csams.module.* import com.gyf.csams.module.*
import com.gyf.lib.uikit.* import com.gyf.lib.uikit.*
import com.gyf.lib.util.* import com.gyf.lib.util.*
import com.gyf.lib.util.ApiResponse
import com.gyf.lib.util.DateTimeUtil.DATE_FORMAT import com.gyf.lib.util.DateTimeUtil.DATE_FORMAT
import com.gyf.lib.util.DateTimeUtil.TIME_FORMAT import com.gyf.lib.util.DateTimeUtil.TIME_FORMAT
import com.gyf.lib.util.DateTimeUtil.dateFormat import com.gyf.lib.util.DateTimeUtil.dateFormat
@ -613,9 +612,9 @@ class ApplyActViewModel(application: Application) : AndroidViewModel(application
activityTime = "$activityDate $activityTime".toDate().time, activityTime = "$activityDate $activityTime".toDate().time,
activityAddress = activityAddress, activityAddress = activityAddress,
activityDesc = activityDesc, activityDesc = activityDesc,
activitySize = activitySize.toInt() activitySize = activitySize.toInt(),
activityId = _checkInfo.value?.body?.activityId
), ),
activityId = _checkInfo.value?.body?.activityId,
token = TokenManager.getToken() token = TokenManager.getToken()
) )
) )

@ -1,8 +1,13 @@
package com.gyf.csams.activity.ui package com.gyf.csams.activity.ui
import android.content.Intent
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.provider.MediaStore
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.Canvas import androidx.compose.foundation.Canvas
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.border import androidx.compose.foundation.border
@ -10,38 +15,63 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn 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.*
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.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
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.google.accompanist.imageloading.ImageLoadState
import com.google.accompanist.insets.ExperimentalAnimatedInsets
import com.google.accompanist.insets.navigationBarsWithImePadding
import com.gyf.csams.R import com.gyf.csams.R
import com.gyf.csams.activity.model.* import com.gyf.csams.activity.model.*
import com.gyf.csams.association.ui.AssociationActivity
import com.gyf.csams.module.ActivityPhotoVo import com.gyf.csams.module.ActivityPhotoVo
import com.gyf.csams.module.BBSVo import com.gyf.csams.module.BBSVo
import com.gyf.csams.module.UserInfoVo import com.gyf.csams.module.UserInfoVo
import com.gyf.csams.uikit.* import com.gyf.csams.uikit.*
import com.gyf.lib.uikit.MainColumnFrame import com.gyf.lib.uikit.*
import com.gyf.lib.uikit.NavBody import com.gyf.lib.util.Api
import com.gyf.lib.uikit.ScaffoldModel import com.gyf.lib.util.BottomButton
import com.gyf.lib.uikit.ShowSnackbar
import com.gyf.lib.util.DateTimeUtil.datetimeFormat import com.gyf.lib.util.DateTimeUtil.datetimeFormat
import com.gyf.lib.util.TokenManager
import com.orhanobut.logger.Logger
import java.util.* import java.util.*
val PHOTO_HEIGHT = 200.dp
/** /**
* 活动详情 * 活动详情
* *
*/ */
class ActivityDetailActivity : ComponentActivity() { class ActivityDetailActivity : ComponentActivity() {
private val associationId: Int
get() {
val id = intent.getIntExtra(
AssociationActivity::class.java.name,
0
)
return if (id == 0) throw IllegalArgumentException("社团id:${id}不合法,初始化失败") else id
}
private val activityId: Int
get() {
val id = intent.getIntExtra(
ActivityDetailActivity::class.java.name,
0
)
return if (id == 0) throw IllegalArgumentException("活动id:${id}不合法,初始化失败") else id
}
@ExperimentalAnimatedInsets
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -66,15 +96,15 @@ class ActivityDetailActivity : ComponentActivity() {
model.clickMenu(ActivityDetailMenu.Info) model.clickMenu(ActivityDetailMenu.Info)
} }
composable(ActivityDetailMenu.Photo.name) { composable(ActivityDetailMenu.Photo.name) {
Photo() Photo(nav = nav)
ShowSnackbar(scaffoldState = scaffoldState) ShowSnackbar(scaffoldState = scaffoldState)
model.clickMenu(ActivityDetailMenu.Photo) model.clickMenu(ActivityDetailMenu.Photo)
} }
composable(ActivityDetailMenu.Member.name) { // composable(ActivityDetailMenu.Member.name) {
Member() // Member()
ShowSnackbar(scaffoldState = scaffoldState) // ShowSnackbar(scaffoldState = scaffoldState)
model.clickMenu(ActivityDetailMenu.Member) // model.clickMenu(ActivityDetailMenu.Member)
} // }
composable(ActivityDetailMenu.BBS.name) { composable(ActivityDetailMenu.BBS.name) {
BBS() BBS()
ShowSnackbar(scaffoldState = scaffoldState) ShowSnackbar(scaffoldState = scaffoldState)
@ -87,32 +117,17 @@ class ActivityDetailActivity : ComponentActivity() {
} }
/** /**
* 底部按钮 * 活动信息
* *
* @param modifier
*/ */
@Composable @Composable
private fun BottomButton( private fun Info(
modifier: Modifier = Modifier,
model: ActivityInfoViewModel = viewModel(), model: ActivityInfoViewModel = viewModel(),
scaffoldModel: ScaffoldModel = viewModel() scaffoldModel: ScaffoldModel = viewModel()
) { ) {
Row(modifier = modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceEvenly) { LaunchedEffect(activityId) {
OutlinedButton(onClick = { model.like { scaffoldModel.update(message = it) } }) { model.load(activityId = activityId)
Text(text = model.like)
}
OutlinedButton(onClick = { model.collect { scaffoldModel.update(message = it) } }) {
Text(text = model.collect)
}
} }
}
/**
* 活动信息
*
*/
@Composable
private fun Info() {
MainColumnFrame(background = { MainColumnFrame(background = {
Background( Background(
image = BackgroundImage.ActivityInfo, image = BackgroundImage.ActivityInfo,
@ -122,7 +137,17 @@ class ActivityDetailActivity : ComponentActivity() {
RectList(modifier = Modifier.weight(0.4F)) RectList(modifier = Modifier.weight(0.4F))
ActivityDesc(modifier = Modifier.weight(0.4F)) ActivityDesc(modifier = Modifier.weight(0.4F))
Spacer(modifier = Modifier.weight(0.05F)) Spacer(modifier = Modifier.weight(0.05F))
BottomButton() BottomButton(
modifier = Modifier.fillMaxWidth(),
confirmDesc = R.string.like_btn,
backDesc = R.string.collect_btn,
onConfirm = {
model.like { scaffoldModel.update(message = it) }
},
onBack = {
model.collect { scaffoldModel.update(message = it) }
})
Spacer(modifier = Modifier.weight(0.05F)) Spacer(modifier = Modifier.weight(0.05F))
} }
} }
@ -199,28 +224,106 @@ class ActivityDetailActivity : ComponentActivity() {
* 相册 * 相册
* *
*/ */
@ExperimentalAnimatedInsets
@Composable @Composable
private fun Photo( private fun Photo(
model: ActivityPhotoViewModel = viewModel(), model: ActivityPhotoViewModel = viewModel(),
scaffoldModel: ScaffoldModel = viewModel() scaffoldModel: ScaffoldModel = viewModel(),
nav: NavHostController
) { ) {
LaunchedEffect(activityId) {
model.load(activityId = activityId)
}
MainColumnFrame(background = { MainColumnFrame(background = {
Background( Background(
image = BackgroundImage.ActivityPhoto, image = BackgroundImage.ActivityPhoto,
alpha = 0.7F alpha = 0.7F
) )
}) { }) {
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
IconButton(onClick = { model.upload { scaffoldModel.update(message = it) } }) { if (TokenManager.getUserInfo()?.associationVo?.associationId == associationId && TokenManager.getUserInfo()?.isHead == true) {
Icon( var photoUri: Uri? by remember {
painter = painterResource(id = R.drawable.ic_upload), mutableStateOf(null)
contentDescription = null
)
} }
} Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
val resultLauncher =
rememberLauncherForActivityResult(contract = ActivityResultContracts.StartActivityForResult()) {
when (it.resultCode) {
RESULT_OK -> {
it.data?.data?.apply {
Logger.i("uri=$this")
photoUri = this
}
}
}
}
IconButton(onClick = {
resultLauncher.launch(
Intent(
Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI
)
)
}) {
Icon(
painter = painterResource(id = R.drawable.ic_upload),
contentDescription = null
)
}
}
photoUri?.let {
val status by model.name.statusForm.observeAsState()
AlertDialog(onDismissRequest = { /*TODO*/ }, title = {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
) {
Text(text = "上传照片")
}
}, text = {
val photo = rememberCoilPainter(request = it)
Column {
BaseTextField(
modifier = Modifier.navigationBarsWithImePadding(),
form = model.name
)
Image(
// modifier=Modifier.weight(0.5F),
painter = photo,
contentDescription = null,
contentScale = ContentScale.Inside
)
}
Spacer(modifier = Modifier.height(10.dp))
}, buttons = {
BottomButton(
modifier = Modifier.fillMaxWidth(),
confirmDesc = R.string.upload_btn,
backDesc = R.string.close_btn,
onConfirm = {
model.upload(activityId = activityId, uri = it) {
photoUri = null
scaffoldModel.update(it, actionLabel = "关闭提示") {
nav.navigate(ActivityDetailMenu.Photo.name)
}
}
},
onBack = {
photoUri = null
},
enabled = status == FormStatus.Valid
)
}
)
}
Spacer(modifier = Modifier.height(10.dp))
}
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
@ -242,10 +345,18 @@ class ActivityDetailActivity : ComponentActivity() {
horizontalArrangement = Arrangement.SpaceEvenly horizontalArrangement = Arrangement.SpaceEvenly
) { ) {
Spacer(modifier = Modifier.weight(0.05F)) Spacer(modifier = Modifier.weight(0.05F))
PhotoItem(vo = it[0], modifier = Modifier.weight(0.4F)) PhotoItem(
vo = it[0], modifier = Modifier
.weight(0.4F)
.height(PHOTO_HEIGHT)
)
Spacer(modifier = Modifier.weight(0.1F)) Spacer(modifier = Modifier.weight(0.1F))
if (it.size == 2) { if (it.size == 2) {
PhotoItem(vo = it[1], modifier = Modifier.weight(0.4F)) PhotoItem(
vo = it[1], modifier = Modifier
.weight(0.4F)
.height(PHOTO_HEIGHT)
)
} else { } else {
Spacer(modifier = Modifier.weight(0.4F)) Spacer(modifier = Modifier.weight(0.4F))
} }
@ -255,25 +366,35 @@ class ActivityDetailActivity : ComponentActivity() {
} }
} }
} }
// Logger.i("totalItemsCount=${listState.layoutInfo.totalItemsCount},firstVisibleItemIndex=${listState.firstVisibleItemIndex}")
if (listState.layoutInfo.totalItemsCount - listState.firstVisibleItemIndex == model.initSize / 2 - 1) {
model.loadMore { scaffoldModel.update(message = it) }
}
} }
} }
} }
} }
@Composable @Composable
private fun PhotoItem(modifier: Modifier = Modifier, vo: ActivityPhotoVo) { private fun PhotoItem(modifier: Modifier = Modifier, vo: ActivityPhotoVo) {
Box( Box(
modifier = modifier.border(width = 1.dp, color = MaterialTheme.colors.onBackground), modifier = modifier.border(width = 1.dp, color = MaterialTheme.colors.onBackground),
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
) { ) {
val photo = rememberCoilPainter(request = Api.buildUrl(vo.url))
Image( Image(
painter = painterResource(id = R.drawable.ic_launcher_foreground), painter = photo,
contentDescription = null, contentDescription = vo.name,
) )
when (photo.loadState) {
is ImageLoadState.Loading -> {
// Display a circular progress indicator whilst loading
CircularProgressIndicator(Modifier.align(Alignment.Center))
}
is ImageLoadState.Error -> {
// If you wish to display some content if the request fails
}
else -> {
}
}
} }
} }
@ -307,6 +428,7 @@ class ActivityDetailActivity : ComponentActivity() {
painter = painterResource(id = R.drawable.persion_name_border), painter = painterResource(id = R.drawable.persion_name_border),
contentDescription = null contentDescription = null
) )
Text(text = first().name) Text(text = first().name)
} }
} }
@ -377,9 +499,12 @@ class ActivityDetailActivity : ComponentActivity() {
@Composable @Composable
private fun BBS( private fun BBS(
model: BBSViewModel = viewModel(), model: BBSViewModel = viewModel(),
scaffoldModel: ScaffoldModel = viewModel(),
bbsCommentModel: BBSCommentModel = viewModel() bbsCommentModel: BBSCommentModel = viewModel()
) { ) {
LaunchedEffect(activityId) {
bbsCommentModel.activityId = this@ActivityDetailActivity.activityId
model.load(activityId)
}
MainColumnFrame(background = { MainColumnFrame(background = {
Background( Background(
image = BackgroundImage.ActivityBBS, image = BackgroundImage.ActivityBBS,
@ -402,7 +527,9 @@ class ActivityDetailActivity : ComponentActivity() {
} }
} }
SendComment(model = bbsCommentModel) SendComment(model = bbsCommentModel) {
model.load(activityId)
}
Box( Box(
modifier = Modifier modifier = Modifier
@ -421,9 +548,6 @@ class ActivityDetailActivity : ComponentActivity() {
} }
} }
} }
if (listState.layoutInfo.totalItemsCount - listState.firstVisibleItemIndex == model.initSize / 2 - 1) {
TODO("加载更多")
}
} }
} }
@ -445,8 +569,8 @@ class ActivityDetailActivity : ComponentActivity() {
modifier = Modifier.height(50.dp), modifier = Modifier.height(50.dp),
verticalArrangement = Arrangement.SpaceEvenly verticalArrangement = Arrangement.SpaceEvenly
) { ) {
Text(text = vo.name) Text(text = vo.user.name)
Text(text = vo.createTime.datetimeFormat()) Text(text = Date(vo.createTime).datetimeFormat())
} }
} }
Spacer(modifier = Modifier.weight(0.5F)) Spacer(modifier = Modifier.weight(0.5F))

@ -13,7 +13,6 @@ 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.* import com.gyf.lib.util.*
import com.gyf.lib.util.ApiResponse
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -105,6 +104,24 @@ class OngoingActViewModel : ViewModel() {
* 历史活动 * 历史活动
* *
*/ */
class HistoryActViewModel(application: Application) : ScrollViewModel<HistoryActVo>(application) { class HistoryActViewModel(application: Application) : ScrollViewModel<ActivityVo>(application) {
override val initSize = 10
fun load(associationId: Int) {
viewModelScope.launch {
HttpClient.post(
url = Api.buildUrl(ActivityApi.Load),
callback = HttpCallback<MutableList<ActivityVo>>(
action = "查看社团活动",
onSuccess = {
_data.postValue(it.body)
},
typeToken = object : TypeToken<ApiResponse<MutableList<ActivityVo>>>() {}.type
),
jsonParam = SearchActivityVo(
associationId = associationId,
token = TokenManager.getToken()
)
)
}
}
} }

@ -12,6 +12,7 @@ import coil.imageLoader
import coil.request.ImageRequest import coil.request.ImageRequest
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.csams.MainApplication import com.gyf.csams.MainApplication
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.AssociationCheckVo import com.gyf.csams.module.AssociationCheckVo
import com.gyf.csams.module.AssociationRegVo import com.gyf.csams.module.AssociationRegVo
import com.gyf.csams.module.ClientType import com.gyf.csams.module.ClientType
@ -54,7 +55,7 @@ class RegAssociationViewModel(application: Application) : AndroidViewModel(appli
_picture.value = uri _picture.value = uri
} }
fun getInputSteam(): InputStream? { private fun getInputSteam(): InputStream? {
_picture.value?.let { _picture.value?.let {
val resolver = getApplication<MainApplication>().contentResolver val resolver = getApplication<MainApplication>().contentResolver
return resolver.openInputStream(it) return resolver.openInputStream(it)

@ -30,7 +30,7 @@ import com.gyf.csams.R
import com.gyf.csams.activity.ui.ActivityDetailActivity import com.gyf.csams.activity.ui.ActivityDetailActivity
import com.gyf.csams.activity.ui.ApplyActActivity import com.gyf.csams.activity.ui.ApplyActActivity
import com.gyf.csams.association.model.* import com.gyf.csams.association.model.*
import com.gyf.csams.module.HistoryActVo import com.gyf.csams.module.ActivityVo
import com.gyf.csams.uikit.* import com.gyf.csams.uikit.*
import com.gyf.lib.uikit.* import com.gyf.lib.uikit.*
import com.gyf.lib.util.TokenManager import com.gyf.lib.util.TokenManager
@ -488,6 +488,10 @@ class AssociationActivity : ComponentActivity() {
modifier: Modifier, modifier: Modifier,
model: HistoryActViewModel = viewModel() model: HistoryActViewModel = viewModel()
) { ) {
LaunchedEffect(associationId) {
model.load(associationId = associationId)
}
val listState = rememberLazyListState() val listState = rememberLazyListState()
val list by model.data.observeAsState() val list by model.data.observeAsState()
LazyColumn(state = listState, modifier = modifier) { LazyColumn(state = listState, modifier = modifier) {
@ -515,9 +519,12 @@ class AssociationActivity : ComponentActivity() {
* @param modifier * @param modifier
*/ */
@Composable @Composable
private fun HistoryActivity(modifier: Modifier, historyActVo: HistoryActVo) { private fun HistoryActivity(modifier: Modifier, historyActVo: ActivityVo) {
Box(modifier = modifier.clickable(onClick = { Box(modifier = modifier.clickable(onClick = {
startActivity(Intent(this, ActivityDetailActivity::class.java)) startActivity(Intent(this, ActivityDetailActivity::class.java).apply {
putExtra(ActivityDetailActivity::class.java.name, historyActVo.activityId)
putExtra(AssociationActivity::class.java.name, associationId)
})
}), contentAlignment = Alignment.Center) { }), contentAlignment = Alignment.Center) {
Image( Image(
painter = painterResource(id = R.drawable.history_activity_border), painter = painterResource(id = R.drawable.history_activity_border),
@ -529,7 +536,7 @@ class AssociationActivity : ComponentActivity() {
contentDescription = null, contentDescription = null,
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
) )
Text(text = historyActVo.name) Text(text = historyActVo.activityName)
} }
} }

@ -10,7 +10,6 @@ import com.gyf.lib.uikit.FormStatus
import com.gyf.lib.uikit.StringForm import com.gyf.lib.uikit.StringForm
import com.gyf.lib.uikit.ValidStringForm import com.gyf.lib.uikit.ValidStringForm
import com.gyf.lib.util.* import com.gyf.lib.util.*
import com.gyf.lib.util.ApiResponse
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@ -203,11 +202,4 @@ class CenterViewModel : ViewModel() {
val myLikeActivity = "我点赞的社团活动" val myLikeActivity = "我点赞的社团活动"
val myCollectActivity = "我收藏的社团活动" val myCollectActivity = "我收藏的社团活动"
private fun load() {
viewModelScope.launch {
TODO()
}
}
} }

@ -127,7 +127,7 @@ class MainActivity : BaseActivity() {
putExtra(AssociationActivity::javaClass.name, it) putExtra(AssociationActivity::javaClass.name, it)
}) })
} }
CenterMenuItem(text = model.myJoinActivity) // CenterMenuItem(text = model.myJoinActivity)
CenterMenuItem(text = model.myLikeActivity) CenterMenuItem(text = model.myLikeActivity)
CenterMenuItem(text = model.myCollectActivity) CenterMenuItem(text = model.myCollectActivity)
} }

@ -117,7 +117,9 @@ enum class AssociationMenu(override val menuName: String) : TopBarMenu {
enum class ActivityDetailMenu(override val menuName: String) : TopBarMenu { enum class ActivityDetailMenu(override val menuName: String) : TopBarMenu {
Info("活动信息"), Info("活动信息"),
Photo("相册"), Photo("相册"),
Member("活动成员"),
//TODO 活动成员
// Member("活动成员"),
BBS("交流区"); BBS("交流区");
companion object Menu : StartMenu<ActivityDetailMenu> { companion object Menu : StartMenu<ActivityDetailMenu> {
@ -175,7 +177,11 @@ abstract class AbstractComment : ViewModel() {
*/ */
@Composable @Composable
fun <T : AbstractComment> SendComment(model: T, scaffoldModel: ScaffoldModel = viewModel()) { fun <T : AbstractComment> SendComment(
model: T,
scaffoldModel: ScaffoldModel = viewModel(),
callback: () -> Unit = {}
) {
val openDialog by model.openDialog.observeAsState() val openDialog by model.openDialog.observeAsState()
val status by model.newContent.statusForm.observeAsState() val status by model.newContent.statusForm.observeAsState()
@ -191,7 +197,10 @@ fun <T : AbstractComment> SendComment(model: T, scaffoldModel: ScaffoldModel = v
OutlinedButton(onClick = { OutlinedButton(onClick = {
model.send { model.send {
model.closeDialog() model.closeDialog()
scaffoldModel.update(message = it) scaffoldModel.update(message = it, actionLabel = "知道了") {
}
callback()
} }
}, enabled = status == FormStatus.Valid) { }, enabled = status == FormStatus.Valid) {
Text(text = "发送") Text(text = "发送")

@ -8,6 +8,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.csams.R import com.gyf.csams.R
import com.gyf.csams.module.ApiResponse
import com.gyf.lib.util.* import com.gyf.lib.util.*
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
import kotlinx.coroutines.Job import kotlinx.coroutines.Job

@ -2,9 +2,8 @@ package com.gyf.csams.util
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.Exam import com.gyf.csams.module.Exam
import com.gyf.lib.util.ApiResponse
import com.gyf.lib.util.HttpCallback import com.gyf.lib.util.HttpCallback
import java.lang.reflect.Type import java.lang.reflect.Type

@ -16,4 +16,8 @@
<string name="welcome_start">同学您好\n</string> <string name="welcome_start">同学您好\n</string>
<string name="welcome_end">欢迎使用</string> <string name="welcome_end">欢迎使用</string>
<string name="reg_again_btn">再次申请</string> <string name="reg_again_btn">再次申请</string>
<string name="like_btn">点赞</string>
<string name="collect_btn">收藏</string>
<string name="upload_btn">上传</string>
<string name="close_btn">关闭</string>
</resources> </resources>

@ -16,4 +16,8 @@
<string name="welcome_start">同学您好\n</string> <string name="welcome_start">同学您好\n</string>
<string name="welcome_end">欢迎使用</string> <string name="welcome_end">欢迎使用</string>
<string name="reg_again_btn">再次申请</string> <string name="reg_again_btn">再次申请</string>
<string name="like_btn">点赞</string>
<string name="collect_btn">收藏</string>
<string name="upload_btn">上传</string>
<string name="close_btn">关闭</string>
</resources> </resources>

@ -16,4 +16,8 @@
<string name="welcome_start">同学您好\n</string> <string name="welcome_start">同学您好\n</string>
<string name="welcome_end">欢迎使用</string> <string name="welcome_end">欢迎使用</string>
<string name="reg_again_btn">再次申请</string> <string name="reg_again_btn">再次申请</string>
<string name="like_btn">点赞</string>
<string name="collect_btn">收藏</string>
<string name="upload_btn">上传</string>
<string name="close_btn">关闭</string>
</resources> </resources>

@ -2,8 +2,8 @@ package com.gyf.csams
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.csams.module.ApiResponse
import com.gyf.lib.uikit.StringForm import com.gyf.lib.uikit.StringForm
import com.gyf.lib.util.ApiResponse
import com.gyf.lib.util.randomChinese import com.gyf.lib.util.randomChinese
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.Test

@ -8,6 +8,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.ClientType import com.gyf.csams.module.ClientType
import com.gyf.csams.module.ManagerVo import com.gyf.csams.module.ManagerVo
import com.gyf.csams.module.UserVo import com.gyf.csams.module.UserVo

@ -6,6 +6,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.OwnInfoVo import com.gyf.csams.module.OwnInfoVo
import com.gyf.csams.module.Token import com.gyf.csams.module.Token
import com.gyf.lib.util.* import com.gyf.lib.util.*

@ -5,6 +5,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.ClientType import com.gyf.csams.module.ClientType
import com.gyf.csams.module.NotificationDto import com.gyf.csams.module.NotificationDto
import com.gyf.csams.module.NotificationVo import com.gyf.csams.module.NotificationVo

@ -6,6 +6,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.ClientType import com.gyf.csams.module.ClientType
import com.gyf.csams.module.NotificationDto import com.gyf.csams.module.NotificationDto
import com.gyf.csams.module.NotificationVo import com.gyf.csams.module.NotificationVo

@ -130,7 +130,25 @@ enum class ActivityApi(val path: String) : UrlPath {
Check("/check"), Check("/check"),
//审核进度 //审核进度
Read("/read"); Read("/read"),
//加载活动
Load("/load"),
//加载活动详情
Show("/show"),
//加载活动照片
Photo("/photo"),
//上传照片
UploadPhoto("${Photo.path}/upload"),
//查看评论
Comment("/comment"),
//发送评论
SendComment("${Comment.path}/send");
override fun build(): String { override fun build(): String {

@ -26,7 +26,7 @@ fun BottomButton(
onBack: (() -> Unit)? = null, onBack: (() -> Unit)? = null,
onConfirm: () -> Unit onConfirm: () -> Unit
) { ) {
val context = LocalContext.current as Activity val context = LocalContext.current as? Activity
Row(modifier = modifier, horizontalArrangement = Arrangement.Center) { Row(modifier = modifier, horizontalArrangement = Arrangement.Center) {
OutlinedButton( OutlinedButton(
onClick = onConfirm, onClick = onConfirm,
@ -39,7 +39,7 @@ fun BottomButton(
if (backDesc != null) { if (backDesc != null) {
Spacer(modifier = Modifier.width(10.dp)) Spacer(modifier = Modifier.width(10.dp))
OutlinedButton(onClick = { OutlinedButton(onClick = {
if (onBack == null) context.onBackPressed() else onBack() if (onBack == null) context?.onBackPressed() else onBack()
}, modifier = Modifier.background(color = MaterialTheme.colors.secondary)) { }, modifier = Modifier.background(color = MaterialTheme.colors.secondary)) {
Text(text = stringResource(id = backDesc)) Text(text = stringResource(id = backDesc))
} }

@ -1,6 +1,7 @@
package com.gyf.lib.util package com.gyf.lib.util
import com.google.gson.* import com.google.gson.*
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.Token import com.gyf.csams.module.Token
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
import okhttp3.* import okhttp3.*
@ -152,13 +153,21 @@ object HttpClient {
* @param url * @param url
* @param callback * @param callback
*/ */
fun uploadFile(url: String, callback: Callback, vararg fileList: File) { fun uploadFile(
url: String,
callback: Callback,
params: Map<String, String>? = null,
vararg fileList: File
) {
Logger.i("request url=$url") Logger.i("request url=$url")
val token = TokenManager.getToken() val token = TokenManager.getToken()
val body = MultipartBody.Builder() val body = MultipartBody.Builder()
.addFormDataPart("id", token.id.toString()) .addFormDataPart("id", token.id.toString())
.addFormDataPart("token", token.token) .addFormDataPart("token", token.token)
.addFormDataPart("createTime", token.createTime.toString()) .addFormDataPart("createTime", token.createTime.toString())
params?.forEach {
body.addFormDataPart(it.key, it.value)
}
fileList.withIndex().forEach { fileList.withIndex().forEach {
body.addFormDataPart( body.addFormDataPart(
"file${it.index}", "file${it.index}",
@ -175,16 +184,6 @@ object HttpClient {
} }
} }
/**
* 接口响应实体
*
* @param T
* @property code
* @property message
* @property body
*/
data class ApiResponse<T>(val code: Int, val message: String, val body: T? = null)
interface GsonBuilderInterface { interface GsonBuilderInterface {
val gson: Gson val gson: Gson

Loading…
Cancel
Save