作者 杨谦

1.班级任务,专项练习完善

2.todo:任务提交,班级任务详情相关
正在显示 29 个修改的文件 包含 355 行增加173 行删除
... ... @@ -65,6 +65,7 @@ dependencies {
implementation 'com.scwang.smart:refresh-header-material:2.0.3'
//经典刷新头
implementation 'com.scwang.smart:refresh-footer-classics:2.0.1'
implementation 'com.alibaba:fastjson:1.1.68.android'
// liveData
... ...
... ... @@ -159,7 +159,7 @@ interface AllItemApi : ApiService {
@FormUrlEncoded
@POST("/api/item/item_sub")
fun subAnswer(
@Field("item_id") item_id: Int,
@Field("item_id") item_id: String,
@Field("answer") answer: String
): Observable<BaseResponse<SubResult>>
... ... @@ -170,7 +170,7 @@ interface AllItemApi : ApiService {
@FormUrlEncoded
@POST("/api/item/item_sub_paper")
fun subPaper(
@Field("user_item_id") user_item_id: Int
@Field("user_item_id") user_item_id: String
): Observable<BaseResponse<SubResult>>
/**
... ...
... ... @@ -5,7 +5,6 @@ import com.wjx.android.wanandroidmvvm.network.ApiService
import com.wjx.android.wanandroidmvvm.network.response.BaseResponse
import com.wjx.android.wanandroidmvvm.network.response.CommonDetail
import com.wjx.android.wanandroidmvvm.network.response.CommonList
import com.wjx.android.wanandroidmvvm.network.response.CommonPage
import io.reactivex.rxjava3.core.Observable
import retrofit2.http.Field
import retrofit2.http.FieldMap
... ... @@ -33,7 +32,7 @@ interface LessonApi : ApiService {
@Field("pos_id") pos_id: Int,
@Field("page") page: Int,
@Field("page_num") page_num: Int,
): Observable<BaseResponse<CommonPage<LessonWord>>>
): Observable<BaseResponse<CommonList<LessonBean>>>
/**
* 文本课程详情
... ...
... ... @@ -112,7 +112,7 @@ class ItemRepository(loadState: MutableLiveData<State>) : ApiRepository(loadStat
//subAnswer
fun subAnswer(
item_id: Int,
item_id: String,
answer: String,
liveData: MutableLiveData<BaseResponse<SubResult>>
) {
... ... @@ -120,7 +120,7 @@ class ItemRepository(loadState: MutableLiveData<State>) : ApiRepository(loadStat
}
//交卷
fun subPaper(user_item_id: Int, liveData: MutableLiveData<BaseResponse<SubResult>>) {
fun subPaper(user_item_id: String, liveData: MutableLiveData<BaseResponse<SubResult>>) {
addRequest(itemService.subPaper(user_item_id), liveData)
}
... ...
... ... @@ -7,7 +7,6 @@ import com.br_technology.securitytrain_master.ui.bean.*
import com.wjx.android.wanandroidmvvm.network.response.BaseResponse
import com.wjx.android.wanandroidmvvm.network.response.CommonDetail
import com.wjx.android.wanandroidmvvm.network.response.CommonList
import com.wjx.android.wanandroidmvvm.network.response.CommonPage
/**
* Author by YSir
... ... @@ -21,7 +20,7 @@ class LessonRepository(loadState: MutableLiveData<State>) : ApiRepository(loadSt
keyword: String,
pos_id: Int,
page: Int, page_num: Int,
liveData: MutableLiveData<BaseResponse<CommonPage<LessonWord>>>
liveData: MutableLiveData<BaseResponse<CommonList<LessonBean>>>
) {
addRequest(lessonService.lessonTxtList(keyword, pos_id, page, page_num), liveData)
}
... ...
... ... @@ -9,7 +9,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import com.br_technology.electricityandroid.util.pos_id
import com.br_technology.electricityandroid.util.sp_job_id
import com.br_technology.electricityandroid.util.token
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.base.common.CommonUtil
... ... @@ -103,7 +103,7 @@ abstract class BaseLifeCycleActivity<VM : BaseViewModel<*>, VB : ViewBinding>(pr
private fun toLogin() {
token = ""
pos_id = 0
sp_job_id = 0
startActivity(AccountLoginActivity::class.java)
}
... ...
... ... @@ -12,7 +12,7 @@ import android.widget.Toast
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import com.br_technology.electricityandroid.util.pos_id
import com.br_technology.electricityandroid.util.sp_job_id
import com.br_technology.electricityandroid.util.token
import com.br_technology.securitytrain_master.base.common.CommonUtil
import com.br_technology.securitytrain_master.base.common.State
... ... @@ -112,7 +112,7 @@ abstract class BaseLifeCycleFragment<VM : BaseViewModel<*>, VB : ViewBinding>(
private fun toLogin() {
token = ""
pos_id = 0
sp_job_id = 0
startActivity(AccountLoginActivity::class.java)
}
... ...
package com.br_technology.securitytrain_master.ext
/**
* Author by YSir
* Date on 2022/1/13.
* description
* PS: Not easy to write code, please indicate.
*/
object ConstantParamKey {
// 班级id
const val CLASS_ID = "class_id"
// 课程id
const val LESSON_ID = "lesson_id"
}
\ No newline at end of file
... ...
... ... @@ -6,7 +6,7 @@ package com.br_technology.securitytrain_master.ext
* description
* PS: Not easy to write code, please indicate.
*/
object CommonConstant {
object ConstantType {
// 考试类型专项练习
const val TEST_TYPE_PRACTICE = 0
... ...
... ... @@ -36,4 +36,7 @@ open class SearchLog(
var keyword: String
)
// 做题答案
open class Answer(var id: Int, var str: String)
... ...
package com.br_technology.securitytrain_master.ui.bean
import com.chad.library.adapter.base.entity.MultiItemEntity
/**
* Author by YSir
* Date on 2022/1/8.
... ... @@ -30,7 +32,14 @@ open class LessonBean(
var user_hours: Int, // 已学习课时
var user_status: Int, // 是否进行过学习0=否1=是
var create_time_text: String // 时间
)
) : MultiItemEntity {
override val itemType: Int
get() = when (sort_id.toInt()) {
1, 2 -> 0
3, 4 -> 1
else -> 0
}
}
/**
* 我的任务(练习)
... ...
... ... @@ -7,7 +7,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.databinding.ActivityPracticeBinding
import com.br_technology.securitytrain_master.ext.CommonConstant
import com.br_technology.securitytrain_master.ext.ConstantType
import com.br_technology.securitytrain_master.ui.view.bank.adapter.PracticePaperAdapter
import com.br_technology.securitytrain_master.ui.view.bank.viewmodel.PracticeViewModel
import com.br_technology.securitytrain_master.view.DialogSureCancel
... ... @@ -51,7 +51,7 @@ class PracticeActivity :
override fun initData() {
super.initData()
contentId = intent.getStringExtra("contentId").toString()
binding.toolBar.setTitle(CommonConstant.getTestType(intent.getIntExtra("contentType", 0)))
binding.toolBar.setTitle(ConstantType.getTestType(intent.getIntExtra("contentType", 0)))
mViewModel.getTestData(contentId)
binding.apply {
toolBar.setRightText("答题卡")
... ... @@ -111,7 +111,7 @@ class PracticeActivity :
override fun determine() {
cancelDialog.dismiss()
if (!titleDialog.isShowing) {
titleDialog.setTitleSpan("答对6道题").show()
titleDialog.setTitleSpan("答对${mPagerAdapter.getCount()}道题").show()
}
}
})
... ...
... ... @@ -5,6 +5,7 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.base.view.BaseAdapter
import com.br_technology.securitytrain_master.databinding.AdapterAnswerSheetBinding
... ... @@ -26,6 +27,13 @@ class AnswerSheetAdapter : BaseAdapter<String, AdapterAnswerSheetBinding>() {
@SuppressLint("SetTextI18n")
override fun onBind(holder: AdapterAnswerSheetBinding, position: Int, data: String) {
holder.txtIndex.text = "${position + 1}"
holder.iconError.visibility = if (data == "1") View.GONE else View.VISIBLE
holder.iconError.setImageResource(
if (data == "1") {
R.mipmap.success
} else {
R.mipmap.error
}
)
holder.iconError.visibility = if (data == "") View.GONE else View.VISIBLE
}
}
\ No newline at end of file
... ...
... ... @@ -12,9 +12,13 @@ import com.br_technology.securitytrain_master.base.view.BaseAdapter
import com.br_technology.securitytrain_master.base.view.BaseViewHolder
import com.br_technology.securitytrain_master.databinding.AdapterContentPracticeItemBinding
import com.br_technology.securitytrain_master.databinding.AdapterTopicBinding
import com.br_technology.securitytrain_master.ui.bean.Answer
import com.br_technology.securitytrain_master.ui.view.bank.bean.OptionArr
import com.br_technology.securitytrain_master.ui.view.bank.bean.TestSubject
import com.br_technology.securitytrain_master.view.listener.OnItemListener
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
/**
* createTime:2021/7/30 15:45
... ... @@ -75,23 +79,29 @@ class TopicAdapter : BaseAdapter<OptionArr, AdapterTopicBinding>() {
@SuppressLint("SetTextI18n")
override fun onBind(holder: AdapterTopicBinding, position: Int, data: OptionArr) {
holder.name.text = "${data.option_name}.${data.value}"
setTextDefault(holder.name)
holder.tvName.text = "${data.option_name}.${data.value}"
if (data.pic.isNotEmpty()) {
Glide.with(holder.root.context)
.load(data.pic)
.apply(RequestOptions.bitmapTransform(RoundedCorners(12)))
.into(holder.ivPic)
}
setTextDefault(holder.contentTopic, holder.tvName)
// 单选 / 判断
if (type == 1 || type == 3) {
if (mSelectIndex.isNotEmpty() && mSelectIndex[0] == position) {
if (showCorrect) {
if (data.is_correct == 1) {
setTextGreen(holder.name)
setTextGreen(holder.contentTopic, holder.tvName)
} else {
setTextRed(holder.name)
setTextRed(holder.contentTopic, holder.tvName)
}
} else {
setTextGreen(holder.name)
setTextGreen(holder.contentTopic, holder.tvName)
}
} else {
if (showCorrect && data.is_correct == 1) {
setTextGreen(holder.name)
setTextGreen(holder.contentTopic, holder.tvName)
}
}
}
... ... @@ -100,33 +110,33 @@ class TopicAdapter : BaseAdapter<OptionArr, AdapterTopicBinding>() {
if (isSelected(position)) {
if (showCorrect) {
if (data.is_correct == 1) {
setTextGreen(holder.name)
setTextGreen(holder.contentTopic, holder.tvName)
} else {
setTextRed(holder.name)
setTextRed(holder.contentTopic, holder.tvName)
}
} else {
setTextGreen(holder.name)
setTextGreen(holder.contentTopic, holder.tvName)
}
} else {
if (showCorrect && data.is_correct == 1) {
setTextGreen(holder.name)
setTextGreen(holder.contentTopic, holder.tvName)
}
}
}
}
private fun setTextDefault(textView: TextView) {
textView.setBackgroundResource(R.drawable.stroke_eb_4)
private fun setTextDefault(view: View, textView: TextView) {
view.setBackgroundResource(R.drawable.stroke_eb_4)
textView.setTextColor(ContextCompat.getColor(textView.context, R.color.color_32))
}
private fun setTextRed(textView: TextView) {
textView.setBackgroundResource(R.drawable.topic_back_error)
private fun setTextRed(view: View, textView: TextView) {
view.setBackgroundResource(R.drawable.topic_back_error)
textView.setTextColor(ContextCompat.getColor(textView.context, R.color.color_e9))
}
private fun setTextGreen(textView: TextView) {
textView.setBackgroundResource(R.drawable.solid_a2_4_08a2)
private fun setTextGreen(view: View, textView: TextView) {
view.setBackgroundResource(R.drawable.solid_a2_4_08a2)
textView.setTextColor(ContextCompat.getColor(textView.context, R.color.color_e8))
}
}
... ... @@ -134,7 +144,7 @@ class TopicAdapter : BaseAdapter<OptionArr, AdapterTopicBinding>() {
class PracticePaperAdapter : BaseAdapter<TestSubject, AdapterContentPracticeItemBinding>() {
// 是否显示正确答案
var showCorrect = false
var selectResultData = mutableMapOf<Int, List<Int>>()
var selectResultData = HashMap<Int, List<Int>>()
override fun getViewBinding(
context: Context,
... ... @@ -195,15 +205,46 @@ class PracticePaperAdapter : BaseAdapter<TestSubject, AdapterContentPracticeItem
}
}
fun getResultData(): ArrayList<List<Int>> {
private fun getResultData(): ArrayList<List<Int>> {
val data = ArrayList<List<Int>>()
val result = selectResultData.values
val result = selectResultData.keys
val dataKey = mutableListOf<Int>()
for (item in result) {
data.add(item)
dataKey.add(item)
}
dataKey.sort()
for (index in dataKey) {
selectResultData.get(index)?.let {
data.add(it)
}
}
return data
}
fun getAnswer(): ArrayList<Answer> {
val data = ArrayList<Answer>()
val list = getResultData()
val listSubject = getData()
for (res in list) {
val pos = list.indexOf(res)
val ppp = listSubject[pos]
data.add(Answer(ppp.id, getAnswer(ppp.options_arr, res)))
}
return data
}
fun getAnswer(optionArr: List<OptionArr>, data: List<Int>): String {
var str = ""
if (data.isNotEmpty()) {
for (res in data) {
if (res < optionArr.size) {
str = str + optionArr[res].option_name + ","
}
}
}
return str.substringBeforeLast(",");
}
fun getCount(): Int {
var count = 0
for (data in selectResultData) {
... ... @@ -216,15 +257,14 @@ class PracticePaperAdapter : BaseAdapter<TestSubject, AdapterContentPracticeItem
fun getArrayList(): ArrayList<String> {
val list = ArrayList<String>()
val dataList = getResultData()
for (data in getData()) {
val position = getData().indexOf(data)
selectResultData[position]?.let { dataGet ->
if (dataList[position].isEmpty()) {
list.add("")
} else {
list.add(
if (isTrue(
data,
dataGet,
data.options_arr
)
if (isTrue(data, dataList[position], data.options_arr)
) "1" else "0"
)
}
... ...
... ... @@ -5,7 +5,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.databinding.FragmentBankBinding
import com.br_technology.securitytrain_master.ext.CommonConstant
import com.br_technology.securitytrain_master.ext.ConstantType
import com.br_technology.securitytrain_master.ui.view.bank.activity.ChallengeActivity
import com.br_technology.securitytrain_master.ui.view.bank.activity.LeaderboardActivity
import com.br_technology.securitytrain_master.ui.view.bank.activity.MockExamActivity
... ... @@ -77,7 +77,7 @@ class BankFragment :
PracticeActivity::class.java
)
.putExtra("contentId", "${practiceAdapter?.data?.get(position)?.id}")
.putExtra("contentType", CommonConstant.TEST_TYPE_PRACTICE)
.putExtra("contentType", ConstantType.TEST_TYPE_PRACTICE)
)
}
... ... @@ -89,7 +89,6 @@ class BankFragment :
page = 1
mViewModel.practiceList(page, 10)
}
})
}
... ...
... ... @@ -7,7 +7,7 @@ import com.br_technology.securitytrain_master.ui.view.bank.repository.BankReposi
import com.br_technology.securitytrain_master.ui.view.home.bean.WorkTypeBean
import com.wjx.android.wanandroidmvvm.network.response.BaseResponse
import com.wjx.android.wanandroidmvvm.network.response.CommonList
import com.br_technology.electricityandroid.util.pos_id
import com.br_technology.electricityandroid.util.sp_job_id
/**
* createTime:2021/7/27 15:48
... ... @@ -27,6 +27,6 @@ class BankViewModel : BaseViewModel<BankRepository>() {
page: Int,
page_num: Int
) {
mRepository.practiceList(pos_id, page, page_num, mPracticeBean)
mRepository.practiceList(sp_job_id, page, page_num, mPracticeBean)
}
}
\ No newline at end of file
... ...
package com.br_technology.securitytrain_master.ui.view.bank.viewmodel
import androidx.lifecycle.MutableLiveData
import com.alibaba.fastjson.JSON
import com.br_technology.securitytrain_master.base.network.repository.ItemRepository
import com.br_technology.securitytrain_master.base.view.BaseViewModel
import com.br_technology.securitytrain_master.ui.bean.Answer
import com.br_technology.securitytrain_master.ui.bean.SubResult
import com.br_technology.securitytrain_master.ui.view.bank.bean.OptionArr
import com.br_technology.securitytrain_master.ui.view.bank.bean.TestSubject
import com.wjx.android.wanandroidmvvm.network.response.BaseResponse
... ... @@ -15,6 +18,8 @@ import com.wjx.android.wanandroidmvvm.network.response.CommonList
*/
class PracticeViewModel : BaseViewModel<ItemRepository>() {
var testData: MutableLiveData<BaseResponse<CommonList<TestSubject>>> = MutableLiveData()
var subAnswer: MutableLiveData<BaseResponse<SubResult>> = MutableLiveData()
var subFinish: MutableLiveData<BaseResponse<SubResult>> = MutableLiveData()
fun getTestData(id: String) {
mRepository.getTestSubject(testData, id)
... ... @@ -31,4 +36,13 @@ class PracticeViewModel : BaseViewModel<ItemRepository>() {
fun updatePagerListData(dataList: List<SelectData>) {
pagerListData.value = dataList
}
fun submitAnswer(str: String, list: ArrayList<Answer>) {
val jsonArray = JSON.toJSONString(list)
mRepository.subAnswer(str, jsonArray, subAnswer)
}
fun subFinish(str:String){
mRepository.subPaper(str, subFinish)
}
}
\ No newline at end of file
... ...
... ... @@ -8,6 +8,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.databinding.ActivityOnlineBinding
import com.br_technology.securitytrain_master.expand.addItemDecoration2
import com.br_technology.securitytrain_master.ext.ConstantParamKey.LESSON_ID
import com.br_technology.securitytrain_master.ui.view.home.adapter.VideoCourseAdapter
import com.br_technology.securitytrain_master.ui.view.home.bean.VideoLessonBean
import com.br_technology.securitytrain_master.ui.view.home.event.GetWorkTypeEvent
... ... @@ -64,7 +65,7 @@ class OnlineActivity :
Intent(
this@OnlineActivity,
OnlineDetailActivity::class.java
).putExtra("id", videoLessonList!![position].id)
).putExtra(LESSON_ID, videoLessonList!![position].id)
)
}
... ...
package com.br_technology.securitytrain_master.ui.view.home.activity
import android.content.res.Configuration
import android.view.View
import androidx.fragment.app.FragmentPagerAdapter
import com.br_technology.securitytrain_master.base.view.BasePagerAdapter
import com.br_technology.securitytrain_master.databinding.ActivityOnlineDetailBinding
import com.br_technology.securitytrain_master.ext.ConstantParamKey.CLASS_ID
import com.br_technology.securitytrain_master.ext.ConstantParamKey.LESSON_ID
import com.br_technology.securitytrain_master.ui.view.home.bean.VideoLessonDetailBean
import com.br_technology.securitytrain_master.ui.view.home.fragment.CourseListFragment
import com.br_technology.securitytrain_master.ui.view.home.fragment.OnlineDetailFragment
import com.br_technology.securitytrain_master.ui.view.home.viewmodel.OnlineDetailViewModel
import com.bumptech.glide.Glide
import com.shuyu.gsyvideoplayer.GSYVideoManager
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
... ... @@ -24,7 +23,7 @@ class OnlineDetailActivity
ActivityOnlineDetailBinding::inflate
) {
private var dataBean: VideoLessonDetailBean? = null
private var searchResultAdapter : BasePagerAdapter ?= null
private var searchResultAdapter: BasePagerAdapter? = null
override fun initDataObserver() {
mViewModel.mVideoLessonDetailBean.observe(this, {
binding.apply {
... ... @@ -45,7 +44,10 @@ class OnlineDetailActivity
FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
)
val list =
mutableListOf(OnlineDetailFragment().newInstance(dataBean!!), CourseListFragment().newInstance(dataBean!!))
mutableListOf(
OnlineDetailFragment().newInstance(dataBean!!),
CourseListFragment().newInstance(dataBean!!)
)
val titles = listOf("课程详情", "课程列表")
searchResultAdapter?.addData(list.toMutableList())
searchResultAdapter?.addTitle(titles)
... ... @@ -55,16 +57,17 @@ class OnlineDetailActivity
})
}
var mClassId: String? = null
override fun initData() {
super.initData()
dataBean = VideoLessonDetailBean()
val id = intent.getIntExtra("id", 0)
mViewModel.videoLessonsDetail(id)
val lessonId = intent.getIntExtra(LESSON_ID, 0)
mClassId = intent.getStringExtra(CLASS_ID)
mViewModel.videoLessonsDetail(lessonId)
binding.apply {
}
}
... ...
package com.br_technology.securitytrain_master.ui.view.home.activity
import android.content.Intent
import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.databinding.ActivityTextCourseBinding
import com.br_technology.securitytrain_master.ui.view.home.adapter.TextLessonsAdapter
import com.br_technology.securitytrain_master.ui.view.home.bean.TextLessonBean
import com.br_technology.securitytrain_master.ui.view.home.event.GetWorkTypeEvent
import com.br_technology.securitytrain_master.ui.view.home.viewmodel.TextCourseViewModel
import com.br_technology.securitytrain_master.view.ClassifyPop
import com.br_technology.securitytrain_master.view.listener.ToolBarClickListener
import com.chad.library.adapter.base.listener.OnLoadMoreListener
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
... ... @@ -32,40 +23,21 @@ class TextCourseActivity :
private var textLessonList: MutableList<TextLessonBean.ListBean.DataBean>? = null
private var textLessonsAdapter: TextLessonsAdapter? = null
private var page = 1
private val classifyPop by lazy {
ClassifyPop(this)
}
override fun initData() {
super.initData()
mViewModel.textLessons("", 0, page, 10)
mViewModel.textLessons("", page)
binding.apply {
toolBar.setRightText("工种")
toolBar.setRightTextDrawable(
ContextCompat.getDrawable(
baseContext,
R.mipmap.down_arrow
)
)
toolBar.addRightListener(object : ToolBarClickListener {
override fun onClick(view: View) {
mViewModel.workType()
}
})
initAdapter()
initLoadMore()
swipeRefreshlayout.setOnRefreshListener(object : SwipeRefreshLayout.OnRefreshListener {
override fun onRefresh() {
textLessonsAdapter?.loadMoreModule?.isEnableLoadMore = false
page = 1
mViewModel.textLessons("", 0, page, 10)
}
})
swipeRefreshlayout.setOnRefreshListener {
textLessonsAdapter?.loadMoreModule?.isEnableLoadMore = false
page = 1
mViewModel.textLessons("", page)
}
}
}
... ... @@ -91,7 +63,7 @@ class TextCourseActivity :
override fun onLoadMore() {
binding.swipeRefreshlayout.isRefreshing = false
textLessonsAdapter?.loadMoreModule?.isEnableLoadMore = true
mViewModel.textLessons("", 0, page, 10)
mViewModel.textLessons("", page)
}
})
... ... @@ -120,30 +92,5 @@ class TextCourseActivity :
}
++page
})
mViewModel.mWorkTypeBean.observe(this, {
classifyPop.setList(it.data.list)
if (!classifyPop.isShowing) {
classifyPop.showAsDropDown(binding.toolBar)
}
})
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(event: GetWorkTypeEvent?) { /* Do something */
val id = event?.id
val name = event?.name
id?.let { mViewModel.textLessons("", it, page, 10) }
name?.let { binding.toolBar.setRightText(it) }
}
override fun onStart() {
super.onStart()
EventBus.getDefault().register(this)
}
override fun onStop() {
super.onStop()
EventBus.getDefault().unregister(this)
}
}
\ No newline at end of file
... ...
package com.br_technology.securitytrain_master.ui.view.home.viewmodel
import androidx.lifecycle.MutableLiveData
import com.br_technology.electricityandroid.util.sp_job_id
import com.br_technology.securitytrain_master.base.view.BaseViewModel
import com.br_technology.securitytrain_master.ui.view.home.bean.TextLessonBean
import com.br_technology.securitytrain_master.ui.view.home.bean.VideoLessonBean
import com.br_technology.securitytrain_master.ui.view.home.bean.WorkTypeBean
import com.br_technology.securitytrain_master.ui.view.home.repository.TextCourseRepository
import com.wjx.android.wanandroidmvvm.network.response.BaseResponse
... ... @@ -13,16 +13,14 @@ import com.wjx.android.wanandroidmvvm.network.response.BaseResponse
* auth:张继
* des:
*/
class TextCourseViewModel: BaseViewModel<TextCourseRepository>() {
class TextCourseViewModel : BaseViewModel<TextCourseRepository>() {
var mTextLessonBean: MutableLiveData<BaseResponse<TextLessonBean>> = MutableLiveData()
fun textLessons(
keyword: String,
pos_id: Int,
page: Int,
page_num: Int,
) {
mRepository.textLessons(keyword, pos_id,page,page_num,mTextLessonBean)
mRepository.textLessons(keyword, sp_job_id, page, 10, mTextLessonBean)
}
... ...
... ... @@ -4,7 +4,7 @@ import android.os.Bundle
import android.text.TextUtils
import android.text.method.HideReturnsTransformationMethod
import android.text.method.PasswordTransformationMethod
import com.br_technology.electricityandroid.util.pos_id
import com.br_technology.electricityandroid.util.sp_job_id
import com.br_technology.electricityandroid.util.token
import com.br_technology.securitytrain_master.databinding.ActivityAccountLoginBinding
import com.br_technology.securitytrain_master.ui.view.login.viewmode.AccountLoginViewModel
... ... @@ -68,7 +68,7 @@ class AccountLoginActivity :
override fun initDataObserver() {
mViewModel.mLoginBean.observe(this, {
token = it.data.userinfo.token
pos_id = it.data.userinfo.pos_id
sp_job_id = it.data.userinfo.pos_id
showTip("登录成功")
startActivity(MainActivity::class.java)
finish()
... ...
... ... @@ -6,9 +6,9 @@ import androidx.fragment.app.FragmentPagerAdapter
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.base.view.BasePagerAdapter
import com.br_technology.securitytrain_master.databinding.ActivityClassDutyBinding
import com.br_technology.securitytrain_master.ext.CommonConstant.TYPE_CLASS_COURSE
import com.br_technology.securitytrain_master.ext.CommonConstant.TYPE_CLASS_EXAM
import com.br_technology.securitytrain_master.ext.CommonConstant.TYPE_CLASS_PRACTICE
import com.br_technology.securitytrain_master.ext.ConstantType.TYPE_CLASS_COURSE
import com.br_technology.securitytrain_master.ext.ConstantType.TYPE_CLASS_EXAM
import com.br_technology.securitytrain_master.ext.ConstantType.TYPE_CLASS_PRACTICE
import com.br_technology.securitytrain_master.ui.view.mine.fragment.ClassDutyCourseFragment
import com.br_technology.securitytrain_master.ui.view.mine.viewmodel.ClassDutyViewModel
import com.br_technology.securitytrain_master.view.ClassifyPop
... ...
package com.br_technology.securitytrain_master.ui.view.mine.adapter
import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.base.view.BaseAdapter
import com.br_technology.securitytrain_master.databinding.ItemCourseBinding
import com.br_technology.securitytrain_master.ui.bean.LessonBean
import com.br_technology.securitytrain_master.util.CommonUtil
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
/**
* Time: 8/3/2021 11:29
* Author: Captain
* Description: 初见时你很迷人
*/
class CourseAdapter : BaseAdapter<LessonBean, ItemCourseBinding>() {
override fun getViewBinding(
context: Context,
parent: ViewGroup,
viewType: Int,
from: LayoutInflater
): ItemCourseBinding {
return ItemCourseBinding.inflate(from, parent, false)
class CourseAdapter : BaseMultiItemQuickAdapter<LessonBean, BaseViewHolder>(), LoadMoreModule {
init {
addItemType(0, R.layout.item_course)
addItemType(1, R.layout.adapter_content_txt)
}
var listener: IOnItemClick? = null
interface IOnItemClick {
fun callback(type: Int, data: LessonBean)
}
fun setItemListener(listener: IOnItemClick) {
this.listener = listener
}
@SuppressLint("SetTextI18n")
override fun onBind(holder: ItemCourseBinding, position: Int, data: LessonBean) {
holder.tvTitle.text = data.name
holder.tvStatus.text = if (data.status == "0") {
"未完成"
} else {
"已完成"
override fun convert(holder: BaseViewHolder, item: LessonBean) {
when (getItemViewType(holder.layoutPosition)) {
0 -> {
holder.apply {
itemView.findViewById<TextView>(R.id.tv_title).text =
CommonUtil.getTransStr(item.name)
itemView.findViewById<TextView>(R.id.tv_status).text = if (item.status == "0") {
"未完成"
} else {
"已完成"
}
itemView.findViewById<TextView>(R.id.tv_time).text =
CommonUtil.getTransStr(item.create_time_text)
itemView.findViewById<TextView>(R.id.tv_lesson).text = "${item.class_hours}学时"
Glide.with(itemView.context).load(item.image).error(R.mipmap.placeholder_head)
.into(itemView.findViewById(R.id.iv_pic))
}
}
1 -> {
holder.apply {
itemView.findViewById<TextView>(R.id.name).text =
CommonUtil.getTransStr(item.name)
itemView.findViewById<TextView>(R.id.info).text =
CommonUtil.getTransStr(item.des)
Glide.with(itemView.context).load(item.image).error(R.mipmap.placeholder_head)
.into(itemView.findViewById(R.id.pic))
}
}
else -> {
}
}
holder.itemView.setOnClickListener {
listener?.callback(getItemViewType(holder.layoutPosition), item)
}
holder.tvTime.text = data.create_time_text
holder.tvLesson.text = "${data.class_hours}学时"
Glide.with(holder.root.context).load(data.image).error(R.mipmap.placeholder_head)
.into(holder.ivPic)
}
}
\ No newline at end of file
... ...
package com.br_technology.securitytrain_master.ui.view.mine.fragment
import android.content.Intent
import com.br_technology.securitytrain_master.databinding.FragmentClassDutyCourseBinding
import com.br_technology.securitytrain_master.ext.CommonConstant
import com.br_technology.securitytrain_master.ext.ConstantParamKey
import com.br_technology.securitytrain_master.ext.ConstantType
import com.br_technology.securitytrain_master.ui.bean.LessonBean
import com.br_technology.securitytrain_master.ui.view.home.activity.OnlineDetailActivity
import com.br_technology.securitytrain_master.ui.view.home.activity.TextDetailActivity
import com.br_technology.securitytrain_master.ui.view.mine.adapter.CourseAdapter
import com.br_technology.securitytrain_master.ui.view.mine.viewmodel.ClassDutyCourseViewModel
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleFragment
... ... @@ -22,18 +27,22 @@ class ClassDutyCourseFragment(val type: Int) :
override fun initDataObserver() {
mViewModel.listCourse.observe(this, {
when (type) {
CommonConstant.TYPE_CLASS_COURSE -> {
ConstantType.TYPE_CLASS_COURSE -> {
val list = it.data.list
if (list.isNotEmpty()) {
courseAdapter?.addList(list)
if (page == 1) {
courseAdapter?.setList(list)
} else {
courseAdapter?.addData(list)
}
}
binding.smartRefresh.setEnableLoadMore(list.size == 10)
binding.smartRefresh.finishLoadMore()
binding.smartRefresh.finishRefresh()
}
CommonConstant.TYPE_CLASS_PRACTICE -> {
ConstantType.TYPE_CLASS_PRACTICE -> {
}
CommonConstant.TYPE_CLASS_EXAM -> {
ConstantType.TYPE_CLASS_EXAM -> {
}
else -> {
}
... ... @@ -43,9 +52,9 @@ class ClassDutyCourseFragment(val type: Int) :
private fun getData() {
when (type) {
CommonConstant.TYPE_CLASS_COURSE -> mViewModel.getTrainLessonList(0, page)
CommonConstant.TYPE_CLASS_PRACTICE -> mViewModel.getTrainPractiseList(0, page)
CommonConstant.TYPE_CLASS_EXAM -> mViewModel.getTrainExamList(0, page)
ConstantType.TYPE_CLASS_COURSE -> mViewModel.getTrainLessonList(0, page)
ConstantType.TYPE_CLASS_PRACTICE -> mViewModel.getTrainPractiseList(0, page)
ConstantType.TYPE_CLASS_EXAM -> mViewModel.getTrainExamList(0, page)
else -> {
}
}
... ... @@ -60,7 +69,36 @@ class ClassDutyCourseFragment(val type: Int) :
smartRefresh.setOnLoadMoreListener {
loadMore()
}
courseAdapter?.setItemListener(object : CourseAdapter.IOnItemClick {
override fun callback(type: Int, data: LessonBean) {
when (type) {
0 -> {
this@ClassDutyCourseFragment.startActivity(
Intent(
requireActivity(),
OnlineDetailActivity::class.java
).putExtra(ConstantParamKey.LESSON_ID, data.id).putExtra(
ConstantParamKey.CLASS_ID, data.class_id
)
)
}
1 -> {
this@ClassDutyCourseFragment.startActivity(
Intent(
requireActivity(),
TextDetailActivity::class.java
).putExtra(ConstantParamKey.LESSON_ID, data.id).putExtra(
ConstantParamKey.CLASS_ID, data.class_id
)
)
}
}
}
})
prUploadValue.progress = 70
}
}
private fun refreshData() {
... ... @@ -73,13 +111,16 @@ class ClassDutyCourseFragment(val type: Int) :
getData()
}
override fun initView() {
super.initView()
courseAdapter = CourseAdapter()
binding.recyclerview.adapter = courseAdapter
courseAdapter?.loadMoreModule?.isAutoLoadMore = true
courseAdapter?.loadMoreModule?.isEnableLoadMoreIfNotFullPage = false
}
override fun initData() {
super.initData()
getData()
binding.apply {
courseAdapter = CourseAdapter()
recyclerview.adapter = courseAdapter
prUploadValue.progress = 70
}
}
}
\ No newline at end of file
... ...
package com.br_technology.securitytrain_master.util
import android.text.TextUtils
/**
* Author by YSir
* Date on 2022/1/13.
* description
* PS: Not easy to write code, please indicate.
*/
object CommonUtil {
fun getTransStr(str: String): String {
return if (TextUtils.isEmpty(str)) "" else str.trim()
}
}
\ No newline at end of file
... ...
... ... @@ -19,6 +19,6 @@ var token by SpUtil(TOKEN,"")
var userId by SpUtil(USERID,0)
var phone_number by SpUtil(PHONE_NUMBER,"")
var is_login by SpUtil(IS_LOGIN,false)
var pos_id by SpUtil(POI_ID,0)
var sp_job_id by SpUtil(POI_ID,0)
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="15dp"
android:paddingBottom="15dp">
<ImageView
android:id="@+id/pic"
android:layout_width="97dp"
android:layout_height="72dp"
android:contentDescription="@string/logo"
android:scaleType="fitXY" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:minHeight="22dp"
android:textColor="@color/color_32"
android:textSize="14sp" />
<TextView
android:id="@+id/info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/color_96"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/name"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:gravity="center_vertical"
android:minHeight="62dp"
android:orientation="vertical"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:textSize="14sp" />
android:paddingTop="10dp"
android:minHeight="62dp"
android:id="@+id/content_topic"
android:gravity="center_vertical"
android:paddingBottom="10dp"
android:layout_marginBottom="12dp"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textSize="14sp" />
<ImageView
android:id="@+id/iv_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
... ...