活动点赞与收藏

Former-commit-id: 0655cd2c64fc5eb347a410194933059dd64e410b
master
pan 4 years ago
parent 4145e3fbef
commit 9b12cef29c
  1. 2
      background/src/main/java/com/gyf/csams/main/model/MenuViewModel.kt
  2. 8
      background/src/main/java/com/gyf/csams/uikit/CheckForm.kt
  3. 2
      build.gradle.kts
  4. 1
      foreground/debug/background-debug.aab.REMOVED.git-id
  5. 1
      foreground/debug/foreground-debug.aab.REMOVED.git-id
  6. 1
      foreground/libs/BaiduLBS_Android.jar.REMOVED.git-id
  7. 1
      foreground/release/background-release.aab.REMOVED.git-id
  8. 1
      foreground/release/foreground-release.aab.REMOVED.git-id
  9. 4
      foreground/src/main/AndroidManifest.xml
  10. 41
      foreground/src/main/java/com/gyf/csams/activity/model/ActivityDetailViewModel.kt
  11. 32
      foreground/src/main/java/com/gyf/csams/activity/model/TendencyViewModel.kt
  12. 57
      foreground/src/main/java/com/gyf/csams/activity/ui/ActivityDetailActivity.kt
  13. 58
      foreground/src/main/java/com/gyf/csams/activity/ui/TendencyActivity.kt
  14. 2
      foreground/src/main/java/com/gyf/csams/association/model/AssociationViewModel.kt
  15. 67
      foreground/src/main/java/com/gyf/csams/association/ui/AssociationActivity.kt
  16. 1
      foreground/src/main/java/com/gyf/csams/association/ui/RenameActivity.kt
  17. 25
      foreground/src/main/java/com/gyf/csams/main/ui/MainActivity.kt
  18. 72
      foreground/src/main/java/com/gyf/csams/uikit/Activies.kt
  19. 3
      foreground/src/main/java/com/gyf/csams/uikit/BaseView.kt
  20. 125
      foreground/src/main/java/com/gyf/csams/util/GsonUtil.kt
  21. 28
      foreground/src/main/java/com/gyf/csams/util/HttpCallback.kt
  22. 1
      foreground/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_map_v7_3_0.so.REMOVED.git-id
  23. 1
      foreground/src/main/jniLibs/arm64-v8a/libgnustl_shared.so.REMOVED.git-id
  24. 1
      foreground/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_map_v7_3_0.so.REMOVED.git-id
  25. 1
      foreground/src/main/jniLibs/armeabi/libBaiduMapSDK_map_v7_3_0.so.REMOVED.git-id
  26. 1
      foreground/src/main/jniLibs/x86/libBaiduMapSDK_map_v7_3_0.so.REMOVED.git-id
  27. 1
      foreground/src/main/jniLibs/x86/libgnustl_shared.so.REMOVED.git-id
  28. 1
      foreground/src/main/jniLibs/x86_64/libBaiduMapSDK_map_v7_3_0.so.REMOVED.git-id
  29. 1
      foreground/src/main/jniLibs/x86_64/libgnustl_shared.so.REMOVED.git-id
  30. 1
      foreground/src/main/res/drawable/mb_bg_fb_01.png.REMOVED.git-id
  31. 1
      foreground/src/main/res/drawable/mb_bg_fb_02.png.REMOVED.git-id
  32. 1
      foreground/src/main/res/drawable/mb_bg_fb_03.png.REMOVED.git-id
  33. 1
      foreground/src/main/res/drawable/mb_bg_fb_04.png.REMOVED.git-id
  34. 1
      foreground/src/main/res/drawable/mb_bg_fb_06.png.REMOVED.git-id
  35. 1
      foreground/src/main/res/drawable/mb_bg_fb_07.png.REMOVED.git-id
  36. 1
      foreground/src/main/res/drawable/mb_bg_fb_08.png.REMOVED.git-id
  37. 1
      foreground/src/main/res/drawable/mb_bg_fb_09.png.REMOVED.git-id
  38. 1
      foreground/src/main/res/drawable/mb_bg_fb_25.png.REMOVED.git-id
  39. 1
      foreground/src/main/res/drawable/mb_bg_fb_25_180.png.REMOVED.git-id
  40. 1
      foreground/src/main/res/drawable/mb_bg_fb_26.png.REMOVED.git-id
  41. 1
      foreground/src/main/res/drawable/mb_bg_fb_27.png.REMOVED.git-id
  42. 1
      foreground/src/main/res/drawable/mb_bg_fb_28.png.REMOVED.git-id
  43. 2
      foreground/src/main/res/values-en/strings.xml
  44. 2
      foreground/src/main/res/values-zh/strings.xml
  45. 2
      foreground/src/main/res/values/strings.xml
  46. 4
      lib/src/main/java/com/gyf/lib/model/SysMessageViewModel.kt
  47. 11
      lib/src/main/java/com/gyf/lib/util/Api.kt

@ -15,7 +15,7 @@ enum class MenuType(val desc: String, val clazz: Map<String, Class<out Activity>
Act(
"活动管理", mapOf(
"审核社团活动" to AuditActActivity::class.java,
"审核质量报告单" to CheckQualityReportActivity::class.java,
"审核活动报告" to CheckQualityReportActivity::class.java,
"查看社团活动" to ManagerActActivity::class.java
)
)

@ -93,9 +93,7 @@ inline fun <reified VO : AuditVo, reified M : BaseAuditViewModel<VO>> CheckForm(
result = result,
cause = cause.getValue()
) {
scaffoldModel.update(message = it, actionLabel = "刷新") {
model.load()
}
model.load()
}
}
}
@ -106,9 +104,7 @@ inline fun <reified VO : AuditVo, reified M : BaseAuditViewModel<VO>> CheckForm(
model.accept(
auditId = vo.audit.id
) {
scaffoldModel.update(message = it, actionLabel = "刷新") {
model.load()
}
model.load()
}
}
}

@ -16,7 +16,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.1.0-alpha01")
classpath("com.android.tools.build:gradle:7.1.0-alpha02")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}")
// NOTE: Do not place your application dependencies here; they belong

@ -0,0 +1 @@
336c59a7cdc6f9b18fecb981ae5b14f6b7366d90

@ -0,0 +1 @@
a30262664371040b970f72f5089d69a476fed40b

@ -0,0 +1 @@
a524dd25e1d96e659662021decd71ed8bfce7a78

@ -0,0 +1 @@
27a39082c3e76250c3bed8df065a0febcc36c901

@ -0,0 +1 @@
95c6b9f9e380ae08145d3219b820d65a3a7b268b

@ -89,7 +89,11 @@
<!--入团申请-->
<activity android:name=".association.ui.AuditJoinActivity" />
<!--用户倾向-->
<activity android:name=".activity.ui.TendencyActivity" />
<service android:name="com.gyf.lib.service.MessageService" />
</application>
</manifest>

@ -36,26 +36,41 @@ class ActivityInfoViewModel : ViewModel() {
private val _activityDetailVo = MutableLiveData<ActivityDetailVo>()
val activityDetailVo: LiveData<ActivityDetailVo> = _activityDetailVo
val like = "点赞"
val collect = "收藏"
val tendency = MutableLiveData<CheckTendencyResVo>()
/**
* TODO 点赞
*
* @param callback
*/
fun like(callback: (message: String) -> Unit) {
callback(NOT_IMPL_TIP)
fun checkTendency(activityId: Int) {
viewModelScope.launch {
HttpClient.post(url = Api.buildUrl(ActivityApi.CheckTendency),
callback = HttpCallback<CheckTendencyResVo>(action = "检查用户倾向",
onSuccess = {
it.body?.apply { tendency.postValue(this) }
}, typeToken = object : TypeToken<ApiResponse<CheckTendencyResVo>>() {}.type
),
jsonParam =
CheckTendencyVo(activityId = activityId, token = TokenManager.getToken())
)
}
}
/**
* TODO 收藏
* 记录用户倾向
*
* @param type
* @param activityId
* @param callback
*/
fun collect(callback: (message: String) -> Unit) {
callback(NOT_IMPL_TIP)
fun tendency(type: TendencyType, activityId: Int, callback: (flag: Boolean) -> Unit) {
viewModelScope.launch {
HttpClient.post(url = Api.buildUrl(ActivityApi.Tendency),
callback = HttpCallback<Boolean>(action = "记录用户倾向",
onSuccess = {
it.body?.let(callback)
}, typeToken = object : TypeToken<ApiResponse<Boolean>>() {}.type
),
jsonParam =
TendencyVo(activityId = activityId, type = type, token = TokenManager.getToken())
)
}
}
/**

@ -0,0 +1,32 @@
package com.gyf.csams.activity.model
import android.app.Application
import androidx.lifecycle.viewModelScope
import com.google.gson.reflect.TypeToken
import com.gyf.csams.module.ActivityVo
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.FindTendencyVo
import com.gyf.csams.module.TendencyType
import com.gyf.lib.model.ScrollViewModel
import com.gyf.lib.util.*
import kotlinx.coroutines.launch
class TendencyViewModel(application: Application) :
ScrollViewModel<ActivityVo>(application = application) {
fun load(type: TendencyType) {
viewModelScope.launch {
HttpClient.post(
url = Api.buildUrl(ActivityApi.FindTendency),
callback = HttpCallback<MutableList<ActivityVo>>(
action = "加载${type.desc}活动",
onSuccess = {
it.body?.apply { _data.postValue(this) }
},
typeToken = object : TypeToken<ApiResponse<MutableList<ActivityVo>>>() {}.type
),
jsonParam = FindTendencyVo(type = type, token = TokenManager.getToken())
)
}
}
}

@ -32,9 +32,9 @@ import com.google.accompanist.insets.ExperimentalAnimatedInsets
import com.google.accompanist.insets.navigationBarsWithImePadding
import com.gyf.csams.R
import com.gyf.csams.activity.model.*
import com.gyf.csams.association.ui.AssociationActivity
import com.gyf.csams.module.ActivityPhotoVo
import com.gyf.csams.module.BBSVo
import com.gyf.csams.module.TendencyType
import com.gyf.csams.module.UserInfoVo
import com.gyf.csams.uikit.*
import com.gyf.lib.uikit.*
@ -53,14 +53,6 @@ val PHOTO_HEIGHT = 200.dp
*/
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() {
@ -127,6 +119,7 @@ class ActivityDetailActivity : ComponentActivity() {
) {
LaunchedEffect(activityId) {
model.load(activityId = activityId)
model.checkTendency(activityId = activityId)
}
MainColumnFrame(background = {
Background(
@ -137,16 +130,34 @@ class ActivityDetailActivity : ComponentActivity() {
RectList(modifier = Modifier.weight(0.4F))
ActivityDesc(modifier = Modifier.weight(0.4F))
Spacer(modifier = Modifier.weight(0.05F))
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) }
})
val checkTendency by model.tendency.observeAsState()
checkTendency?.apply {
val confirmDesc = if (hasLike) R.string.cancel_like else R.string.like_btn
val backDesc = if (hasCollect) R.string.cancel_collect else R.string.collect_btn
BottomButton(
modifier = Modifier.fillMaxWidth(),
confirmDesc = confirmDesc,
backDesc = backDesc,
onConfirm = {
model.tendency(type = TendencyType.Like, activityId = activityId) {
scaffoldModel.update(
message = "${getString(confirmDesc)}${if (it) "成功" else "失败"}",
"确认"
)
model.checkTendency(activityId = activityId)
}
},
onBack = {
model.tendency(type = TendencyType.Collect, activityId = activityId) {
scaffoldModel.update(
message = "${getString(backDesc)}${if (it) "成功" else "失败"}",
"确认"
)
model.checkTendency(activityId = activityId)
}
})
}
Spacer(modifier = Modifier.weight(0.05F))
}
@ -228,6 +239,7 @@ class ActivityDetailActivity : ComponentActivity() {
@Composable
private fun Photo(
model: ActivityPhotoViewModel = viewModel(),
infoModel: ActivityInfoViewModel = viewModel(),
scaffoldModel: ScaffoldModel = viewModel(),
nav: NavHostController
) {
@ -241,8 +253,8 @@ class ActivityDetailActivity : ComponentActivity() {
alpha = 0.7F
)
}) {
if (TokenManager.getUserInfo()?.associationVo?.associationId == associationId && TokenManager.getUserInfo()?.isHead == true) {
val activityDetailVo by infoModel.activityDetailVo.observeAsState()
if (TokenManager.getUserInfo()?.associationVo?.associationId == activityDetailVo?.associationVo?.associationId && TokenManager.getUserInfo()?.isHead == true) {
var photoUri: Uri? by remember {
mutableStateOf(null)
}
@ -397,8 +409,7 @@ class ActivityDetailActivity : ComponentActivity() {
*/
@Composable
private fun Member(
model: ActivityMemberViewModel = viewModel(),
scaffoldModel: ScaffoldModel = viewModel()
model: ActivityMemberViewModel = viewModel()
) {
MainColumnFrame(background = {
Background(

@ -0,0 +1,58 @@
package com.gyf.csams.activity.ui
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.viewModel
import com.gyf.csams.activity.model.TendencyViewModel
import com.gyf.csams.module.TendencyType
import com.gyf.csams.uikit.Activities
import com.gyf.csams.uikit.Background
import com.gyf.csams.uikit.BackgroundImage
import com.gyf.lib.uikit.Body
import com.gyf.lib.uikit.MainColumnFrame
class TendencyActivity : ComponentActivity() {
private val type: TendencyType
get() {
return intent.getSerializableExtra(TendencyType::class.java.name) as TendencyType
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Body {
MainColumnFrame(background = {
Background(
image = BackgroundImage.AssociationMain,
alpha = 07F
)
}) {
val model: TendencyViewModel = viewModel()
LaunchedEffect(type) {
model.load(type = type)
}
val data by model.data.observeAsState()
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
) {
Text(text = "我的${type.desc}", style = MaterialTheme.typography.h4)
}
Activities(list = data, modifier = Modifier.fillMaxWidth())
}
}
}
}
}

@ -110,7 +110,7 @@ class MemberViewModel(application: Application) : ScrollViewModel<UserInfoVo>(ap
* 加载社团成员
*
*/
fun load(id: Int, callback: (message: String) -> Unit) {
fun load(id: Int) {
viewModelScope.launch {
HttpClient.post(
Api.buildUrl(AssociationApi.LoadMember), HttpCallback<MutableList<UserInfoVo>>(

@ -9,7 +9,6 @@ import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
@ -28,10 +27,8 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.gyf.csams.R
import com.gyf.csams.activity.ui.ActivityDetailActivity
import com.gyf.csams.activity.ui.ApplyActActivity
import com.gyf.csams.association.model.*
import com.gyf.csams.module.ActivityVo
import com.gyf.csams.uikit.*
import com.gyf.lib.uikit.*
import com.gyf.lib.util.TokenManager
@ -373,9 +370,7 @@ class AssociationActivity : ComponentActivity() {
Spacer(modifier = Modifier.weight(spaceWeight))
OutlinedButton(
onClick = {
model.load(associationId) {
}
model.load(associationId)
},
modifier = Modifier.weight(buttonWeight)
) {
@ -395,9 +390,7 @@ class AssociationActivity : ComponentActivity() {
modifier: Modifier = Modifier,
model: MemberViewModel = viewModel()
) {
model.load(associationId) {
}
model.load(associationId)
val data by model.data.observeAsState()
val listState = rememberLazyListState()
LazyColumn(
@ -532,12 +525,6 @@ class AssociationActivity : ComponentActivity() {
alpha = 07F
)
}) {
// val onGoWeight = 0.3F
// OngoingActivity(
// modifier = Modifier
// .weight(onGoWeight)
// .fillMaxWidth()
// )
HistoryActivityList(
modifier = Modifier
.fillMaxWidth()
@ -554,7 +541,7 @@ class AssociationActivity : ComponentActivity() {
private fun OngoingActivity(
modifier: Modifier = Modifier
) {
Row(horizontalArrangement = Arrangement.Center) {
Row(modifier = modifier, horizontalArrangement = Arrangement.Center) {
val weight = 0.5F
val spaceWeight = (1 - 0.5F) / 2
Spacer(modifier = Modifier.weight(spaceWeight))
@ -578,62 +565,17 @@ class AssociationActivity : ComponentActivity() {
model.load(associationId = associationId)
}
val listState = rememberLazyListState()
val list by model.data.observeAsState()
if (list?.size == 0) {
Row(modifier = Modifier.fillMaxWidth()) {
Text(text = "目前社团没有任何活动")
}
} else {
LazyColumn(state = listState, modifier = modifier) {
list?.chunked(2)?.forEach {
item {
Row(modifier = Modifier.fillMaxWidth()) {
HistoryActivity(modifier = Modifier.weight(0.4F), it[0])
Spacer(modifier = Modifier.weight(0.2F))
if (it.size == 2) HistoryActivity(
modifier = Modifier.weight(0.4F),
it[1]
)
else Box(modifier = Modifier.weight(0.4F))
}
Spacer(modifier = Modifier.height(10.dp))
Divider(color = MaterialTheme.colors.background)
}
}
}
Activities(list = list, modifier = modifier)
}
}
/**
* 历史活动
*
* @param modifier
*/
@Composable
private fun HistoryActivity(modifier: Modifier, historyActVo: ActivityVo) {
Box(modifier = modifier.clickable(onClick = {
startActivity(Intent(this, ActivityDetailActivity::class.java).apply {
putExtra(ActivityDetailActivity::class.java.name, historyActVo.activityId)
putExtra(AssociationActivity::class.java.name, associationId)
})
}), contentAlignment = Alignment.Center) {
Image(
painter = painterResource(id = R.drawable.history_activity_border),
contentDescription = null,
modifier = Modifier.fillMaxSize()
)
Image(
painter = painterResource(id = R.drawable.ic_launcher_foreground),
contentDescription = null,
modifier = Modifier.fillMaxSize()
)
Text(text = historyActVo.activityName)
}
}
@Preview
@Composable
fun NamePreview() {
@ -644,3 +586,4 @@ class AssociationActivity : ComponentActivity() {

@ -70,7 +70,6 @@ class RenameActivity : ComponentActivity() {
Spacer(modifier = Modifier.height(10.dp))
val oldNameStatus by model.oldName.statusForm.observeAsState()
val newNameStatus by model.newName.statusForm.observeAsState()

@ -34,6 +34,7 @@ import com.google.accompanist.pager.rememberPagerState
import com.gyf.csams.R
import com.gyf.csams.account.model.AccountViewModel
import com.gyf.csams.activity.ui.ActivityDetailActivity
import com.gyf.csams.activity.ui.TendencyActivity
import com.gyf.csams.association.ui.AssociationActivity
import com.gyf.csams.association.ui.RegAssociationActivity
import com.gyf.csams.main.model.*
@ -141,9 +142,25 @@ class MainActivity : BaseActivity() {
putExtra(AssociationActivity::class.java.name, it)
})
}
// CenterMenuItem(text = model.myJoinActivity)
CenterMenuItem(text = model.myLikeActivity)
CenterMenuItem(text = model.myCollectActivity)
CenterMenuItem(text = model.myLikeActivity) {
startActivity(
Intent(
this@MainActivity,
TendencyActivity::class.java
).apply {
putExtra(TendencyType::class.java.name, TendencyType.Like)
})
}
CenterMenuItem(text = model.myCollectActivity) {
startActivity(
Intent(
this@MainActivity,
TendencyActivity::class.java
).apply {
putExtra(TendencyType::class.java.name, TendencyType.Collect)
})
}
}
CenterMenuItem(text = "退出登录") {
@ -245,8 +262,6 @@ class MainActivity : BaseActivity() {
*/
@Composable
private fun RegisterAssociation(
model: AssociationListViewModel = viewModel(),
scaffoldModel: ScaffoldModel = viewModel(),
navController: NavHostController
) {
val launch =

@ -0,0 +1,72 @@
package com.gyf.csams.uikit
import android.content.Intent
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.Divider
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
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 com.gyf.csams.R
import com.gyf.csams.activity.ui.ActivityDetailActivity
import com.gyf.csams.module.ActivityVo
/**
* 历史活动
*
* @param modifier
*/
@Composable
private fun HistoryActivity(modifier: Modifier, activityVo: ActivityVo) {
val context = LocalContext.current
Box(modifier = modifier.clickable(onClick = {
context.startActivity(Intent(context, ActivityDetailActivity::class.java).apply {
putExtra(ActivityDetailActivity::class.java.name, activityVo.activityId)
})
}), contentAlignment = Alignment.Center) {
Image(
painter = painterResource(id = R.drawable.history_activity_border),
contentDescription = null,
modifier = Modifier.fillMaxSize()
)
Image(
painter = painterResource(id = R.drawable.ic_launcher_foreground),
contentDescription = null,
modifier = Modifier.fillMaxSize()
)
Text(text = activityVo.activityName)
}
}
@Composable
fun Activities(modifier: Modifier = Modifier, list: List<ActivityVo>?) {
val listState = rememberLazyListState()
LazyColumn(state = listState, modifier = modifier) {
list?.chunked(2)?.forEach {
item {
Row(modifier = Modifier.fillMaxWidth()) {
HistoryActivity(modifier = Modifier.weight(0.4F), it[0])
Spacer(modifier = Modifier.weight(0.2F))
if (it.size == 2) HistoryActivity(
modifier = Modifier.weight(0.4F),
it[1]
)
else Box(modifier = Modifier.weight(0.4F))
}
Spacer(modifier = Modifier.height(10.dp))
Divider(color = MaterialTheme.colors.background)
}
}
}
}

@ -447,9 +447,8 @@ enum class BackgroundImage(@DrawableRes val id: Int) {
*/
@Composable
fun Background(image: BackgroundImage, alpha: Float = DefaultAlpha) {
val app = LocalContext.current.applicationContext as MainApplication
LocalContext.current.applicationContext as MainApplication
// val img=app.getImage(image = image)
val backgroundImage = rememberCoilPainter(request = image.id)
Image(

@ -1,125 +0,0 @@
package com.gyf.csams.util
import com.google.gson.*
import com.google.gson.reflect.TypeToken
import com.gyf.csams.association.model.*
import com.gyf.lib.uikit.StringForm
import java.lang.reflect.Type
class OpenQuestionsVoSerializer : JsonSerializer<OpenQuestionsVo> {
override fun serialize(
vo: OpenQuestionsVo?,
p1: Type?,
p2: JsonSerializationContext?
): JsonElement {
val gson = Gson()
val c = JsonObject()
c.add("examType", gson.toJsonTree(vo?.examType?.name))
// c.add("question", gson.toJsonTree(vo?.question?.formValue?.value))
return c
}
}
class OpenQuestionsVoDeserializer : JsonDeserializer<OpenQuestionsVo> {
override fun deserialize(
json: JsonElement?,
p1: Type?,
p2: JsonDeserializationContext?
): OpenQuestionsVo {
val root = json?.asJsonObject
val value = root?.get("question")?.asString
val question = StringForm(formDesc = "问题", textLength = QUESTION_TEXT_LENGTH)
if (value != null) {
question.onChange(value)
TODO()
// return OpenQuestionsVo(question = question)
} else {
throw NullPointerException("问题无法解析!!!!")
}
}
}
class ChoiceQuestionVoSerializer : JsonSerializer<ChoiceQuestionVo> {
override fun serialize(
vo: ChoiceQuestionVo?,
p1: Type?,
p2: JsonSerializationContext?
): JsonElement {
val gson = Gson()
val c = JsonObject()
c.add("examType", gson.toJsonTree(vo?.examType?.name))
// c.add("question", gson.toJsonTree(vo?.question?.formValue?.value))
// c.add("answers", gson.toJsonTree(vo?.answers))
c.add("rightAnswer", gson.toJsonTree(vo?.rightAnswer))
return c
}
}
class ChoiceQuestionVoDeserializer : JsonDeserializer<ChoiceQuestionVo> {
override fun deserialize(
json: JsonElement?,
p1: Type?,
p2: JsonDeserializationContext?
): ChoiceQuestionVo {
val root = json?.asJsonObject
val value = root?.get("question")?.asString
val question = StringForm(formDesc = "问题", textLength = QUESTION_TEXT_LENGTH)
if (value != null) {
question.onChange(value)
val gson = Gson()
val answers: List<String> =
gson.fromJson(root.get("answers"), object : TypeToken<List<String>>() {}.type)
if (answers.size != ANSWER_SIZE) {
throw IllegalArgumentException("选项数量!=$QUESTION_TEXT_LENGTH")
}
val rightAnswer = root.get("rightAnswer").asInt
TODO()
// return ChoiceQuestionVo(
// question = question,
// answers = answers.map {
// StringForm(
// formDesc = "选项",
// textLength = ANSWER_TEXT_LENGTH,
// value = it
// )
// },
// rightAnswer = rightAnswer
// )
} else {
throw NullPointerException("问题无法解析!!!!")
}
}
}
/**
* 题目反序列化
*
*/
class ExamDeserializer : JsonDeserializer<Exam> {
companion object {
val gson: Gson = GsonBuilder()
.registerTypeAdapter(OpenQuestionsVo::class.java, OpenQuestionsVoDeserializer())
.registerTypeAdapter(ChoiceQuestionVo::class.java, ChoiceQuestionVoDeserializer())
.create()
}
override fun deserialize(json: JsonElement?, p1: Type?, p2: JsonDeserializationContext?): Exam {
val root = json?.asJsonObject
val type = root?.get("examType")?.asString
return when (gson.fromJson(type, ExamType::class.java)) {
ExamType.CQ -> gson.fromJson(
json,
object : TypeToken<ChoiceQuestionVo>() {}.type
)
ExamType.OQ -> gson.fromJson(
json,
object : TypeToken<OpenQuestionsVo>() {}.type
)
null -> throw NullPointerException("无法识别题目类型!")
}
}
}

@ -1,28 +0,0 @@
package com.gyf.csams.util
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.gyf.csams.association.model.Exam
import com.gyf.csams.module.ApiResponse
import com.gyf.lib.util.HttpCallback
import java.lang.reflect.Type
/**
* http请求回调
*
* @param T
* @property action
* @property onSuccess
* @property onFail
*/
class ExamCallback<T>(
private val action: String,
private val onSuccess: (res: ApiResponse<T>) -> Unit,
private val onFail: (error: String) -> Unit,
private val type: Type
) : HttpCallback<T>(action, onSuccess, onFail, type) {
override val gson: Gson = GsonBuilder()
.registerTypeAdapter(Exam::class.java, ExamDeserializer())
.create()
}

@ -0,0 +1 @@
1eae31cbbcf67f843d39243caf7df8c569c13b77

@ -0,0 +1 @@
4e6cdc0a5379ae11e7ecd9862df219a2e8e30966

@ -0,0 +1 @@
7758a1ac02f112f2cc4b9a770e6e503b51123cb7

@ -0,0 +1 @@
24b3200ded1804dbeede2ad13209502ecb694a94

@ -0,0 +1 @@
17a3a14f87bc6dfaa5222edd157e546f8c3d3b71

@ -0,0 +1 @@
40c3c72f459198c56917d4cf2dd095c14e98727f

@ -0,0 +1 @@
1ee13a1678f539bc50c1a6cf8c2a4cd3ad66d643

@ -0,0 +1 @@
6a42e4773be7fccb574c6021c78f8ff16c38268b

@ -0,0 +1 @@
0e6b6965957df34b335709e70db54ec18f85eb83

@ -0,0 +1 @@
a530f977cd4e84c53f98dc954e03290cf35cc443

@ -0,0 +1 @@
35980a5473e21920506edcbe0a31e75d9263e978

@ -0,0 +1 @@
d9686761bcd5d3992c8a1135838400ac61bb7e47

@ -0,0 +1 @@
110603101ef93e9ceca51de555a93b5e3d2de994

@ -20,4 +20,6 @@
<string name="upload_btn">上传</string>
<string name="close_btn">关闭</string>
<string name="cancel_apply">放弃申请</string>
<string name="cancel_like">取消点赞</string>
<string name="cancel_collect">取消收藏</string>
</resources>

@ -20,4 +20,6 @@
<string name="upload_btn">上传</string>
<string name="close_btn">关闭</string>
<string name="cancel_apply">放弃申请</string>
<string name="cancel_like">取消点赞</string>
<string name="cancel_collect">取消收藏</string>
</resources>

@ -20,4 +20,6 @@
<string name="upload_btn">上传</string>
<string name="close_btn">关闭</string>
<string name="cancel_apply">放弃申请</string>
<string name="cancel_like">取消点赞</string>
<string name="cancel_collect">取消收藏</string>
</resources>

@ -94,7 +94,7 @@ abstract class SysMessageViewModel(application: Application) :
abstract fun clientType(): ClientType
init {
load {}
load()
}
@ -102,7 +102,7 @@ abstract class SysMessageViewModel(application: Application) :
*加载通知列表
*
*/
fun load(callback: (message: String) -> Unit) {
fun load() {
viewModelScope.launch {
HttpClient.post(
Api.buildUrl(NotificationApi.List),

@ -204,8 +204,17 @@ enum class ActivityApi(val path: String) : UrlPath {
SendComment("${Comment.path}/send"),
//后台活动查看
ListAll("/list/all");
ListAll("/list/all"),
//修改活动倾向
Tendency("/tendency"),
//检查活动倾向
CheckTendency("${Tendency.path}/check"),
//查询活动倾向
FindTendency("${Tendency.path}/find")
;
override fun build(): String {
return "/api/activity${this.path}"

Loading…
Cancel
Save