作者 杨谦

1.文本,资料收藏逻辑

2.todo,课程进度等
正在显示 28 个修改的文件 包含 491 行增加233 行删除
package com.br_technology.securitytrain_master.base.network.api
import com.br_technology.securitytrain_master.base.network.response.BaseResponse
import com.br_technology.securitytrain_master.base.network.response.CommonDetail
import com.br_technology.securitytrain_master.base.network.response.CommonList
import com.br_technology.securitytrain_master.base.network.response.*
import com.br_technology.securitytrain_master.ui.bean.FavoriteData
import com.br_technology.securitytrain_master.ui.bean.MaterialDetail
import com.br_technology.securitytrain_master.ui.bean.UploadFileData
import com.br_technology.securitytrain_master.ui.view.bank.bean.PracticeBean
... ... @@ -267,4 +266,34 @@ interface ApiService {
@Field("id") id: Int
): Observable<BaseResponse<CommonDetail<MaterialDetail>>>
/**
* 收藏
*/
@FormUrlEncoded
@POST("/api/user/favorite")
fun collect(
@Field("type") type: String,
@Field("favorite_id") favorite_id: String
): Observable<BaseResponse<Void>>
/**
* 收藏资料列表
*/
@FormUrlEncoded
@POST("/api/user/my_favorite_material")
fun getCollectDocList(
@Field("page") page: Int,
@Field("page_num") page_num: String
): Observable<BaseResponse<CommonDataList<CommonPage<FavoriteData>>>>
/**
* 收藏文本课程列表
*/
@FormUrlEncoded
@POST("/api/user/my_favorite_lesson_word")
fun getCollectTxtLessonList(
@Field("page") page: Int,
@Field("page_num") page_num: String
): Observable<BaseResponse<CommonDataList<CommonPage<FavoriteData>>>>
}
\ No newline at end of file
... ...
... ... @@ -111,7 +111,7 @@ interface LessonApi : ApiService {
@POST("/api/lesson/lesson_live_detail")
fun lessonLiveDetail(
@Field("id") id: Int
): Observable<BaseResponse<LessonLive>>
): Observable<BaseResponse<CommonDetail<LessonLive>>>
/**
* 线下培训列表
... ... @@ -189,15 +189,4 @@ interface LessonApi : ApiService {
@FieldMap fieldMap: HashMap<String, String>
): Observable<BaseResponse<Void>>
/**
* 收藏/取消收藏
* @param type 收藏类型:1=资料库2=文本课程
* @param favorite_id 收藏id
*/
@FormUrlEncoded
@POST("/api/user/favorite")
fun favorite(
@Field("type") type: String,
@Field("favorite_id") favorite_id: String
): Observable<BaseResponse<Void>>
}
\ No newline at end of file
... ...
... ... @@ -8,6 +8,7 @@ package com.br_technology.securitytrain_master.base.network.response
open class BaseResponse<T>(var data: T, var code: Int = -1, var msg: String = "")
open class CommonList<T>(var list: List<T>)
open class CommonDataList<T>(var list: T)
open class CommonDetail<T>(var detail: T)
open class CommonDetailList<T>(var list: T)
open class CommonInfo<T>(var info: T)
... ...
... ... @@ -2,9 +2,8 @@ package com.br_technology.securitytrain_master.base.repository
import androidx.lifecycle.MutableLiveData
import com.br_technology.securitytrain_master.base.common.State
import com.br_technology.securitytrain_master.base.network.response.BaseResponse
import com.br_technology.securitytrain_master.base.network.response.CommonDetail
import com.br_technology.securitytrain_master.base.network.response.CommonList
import com.br_technology.securitytrain_master.base.network.response.*
import com.br_technology.securitytrain_master.ui.bean.FavoriteData
import com.br_technology.securitytrain_master.ui.bean.MaterialClassify
import com.br_technology.securitytrain_master.ui.bean.MaterialDetail
import com.br_technology.securitytrain_master.ui.bean.MaterialPage
... ... @@ -44,4 +43,18 @@ class DocRepository(loadState: MutableLiveData<State>) : ApiRepository(loadState
) {
addRequest(docService.getDocDetail(id), liveData)
}
fun getCollectDocList(
page: Int,
liveData: MutableLiveData<BaseResponse<CommonDataList<CommonPage<FavoriteData>>>>
) {
addRequest(docService.getCollectDocList(page, "10"), liveData)
}
fun getCollectTxtLessonList(
page: Int,
liveData: MutableLiveData<BaseResponse<CommonDataList<CommonPage<FavoriteData>>>>
) {
addRequest(docService.getCollectTxtLessonList(page, "10"), liveData)
}
}
\ No newline at end of file
... ...
... ... @@ -83,7 +83,7 @@ class LessonRepository(loadState: MutableLiveData<State>) : ApiRepository(loadSt
fun lessonLiveDetail(
id: Int,
liveData: MutableLiveData<BaseResponse<LessonLive>>
liveData: MutableLiveData<BaseResponse<CommonDetail<LessonLive>>>
) {
addRequest(lessonService.lessonLiveDetail(id), liveData)
}
... ... @@ -145,12 +145,11 @@ class LessonRepository(loadState: MutableLiveData<State>) : ApiRepository(loadSt
addRequest(lessonService.textLessonsDetail(id), liveData)
}
fun favorite(
fun collect(
type: String,
favorite_id: String,
liveData: MutableLiveData<BaseResponse<Void>>
) {
addRequest(lessonService.favorite(type, favorite_id), liveData)
addRequest(lessonService.collect(type, favorite_id), liveData)
}
}
\ No newline at end of file
... ...
... ... @@ -59,12 +59,14 @@ open class LessonClassDetail(
open class LessonLive(
var id: Int,
var company_id: String,
var name: String, // 课程名称
var image: String,//"http://security.cn/assets/img/qrcode.png", // 图片
var class_hours: Int, // 课时
var live_url: String,//"rtmp://153382.livepush.myqcloud.com/live/123456?txSecret=0c761f4fdf14b04ef745d2fb9182429d&txTime=6262D100", // rtmp直播地址
var webrtc_url: String,//"rtmp://153382.livepush.myqcloud.com/live/123456?txSecret=0c761f4fdf14b04ef745d2fb9182429d&txTime=6262D100", // web直播地址
var live_status: String, // 直播间状态:1=正在直播,2=回放,3=即将开播
var stream_name: String, // 直播间状态:1=正在直播,2=回放,3=即将开播
var teacher: Teacher
) : Serializable
... ...
... ... @@ -14,6 +14,9 @@ open class CourseParam() : Parcelable {
// 是否为班级任务类型
var isTrainClass = false
// 标题
var title = ""
// 类型 课程类型:1=视频课,2=直播课,3=线下培训课,4=文本课
var type: Int = 0
... ... @@ -44,6 +47,7 @@ open class CourseParam() : Parcelable {
lat = parcel.readString().toString()
lng = parcel.readString().toString()
mViewLen = parcel.readInt()
title = parcel.readString().toString()
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
... ... @@ -55,6 +59,7 @@ open class CourseParam() : Parcelable {
parcel.writeString(lat)
parcel.writeString(lng)
parcel.writeInt(mViewLen)
parcel.writeString(title)
}
override fun describeContents(): Int {
... ...
... ... @@ -33,10 +33,23 @@ class DatabaseDetailActivity :
}
videoPlayer.titleTextView.visibility = View.GONE
videoPlayer.backButton.visibility = View.GONE
start.setOnClickListener {
mViewModel.collect()
}
}
}
override fun initDataObserver() {
mViewModel.collectResponse.observe(this, {
if (it.msg.contains("取消收藏成功")) {
binding.start.isSelected = false
return@observe
}
if (it.msg.contains("收藏成功")) {
binding.start.isSelected = true
return@observe
}
})
mViewModel.mDetailMaterialNormal.observe(this, {
binding.videoPlayer.initVideoBuilderMode(
it.data.detail.image,
... ... @@ -46,6 +59,8 @@ class DatabaseDetailActivity :
lifecycle
)
binding.start.isSelected = it.data.detail.is_favorite == 1
binding.webView.loadData(it.data.detail.content)
binding.title.text = it.data.detail.name
... ...
... ... @@ -3,7 +3,9 @@ package com.br_technology.securitytrain_master.ui.view.home.activity
import android.content.Intent
import androidx.recyclerview.widget.LinearLayoutManager
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.base.common.ConstantParamKey
import com.br_technology.securitytrain_master.databinding.ActivityTextCourseBinding
import com.br_technology.securitytrain_master.ui.bean.CourseParam
import com.br_technology.securitytrain_master.ui.view.home.activity.course.TextDetailActivity
import com.br_technology.securitytrain_master.ui.view.home.adapter.TextLessonsAdapter
import com.br_technology.securitytrain_master.ui.view.home.bean.TextLessonBean
... ... @@ -12,8 +14,6 @@ import com.chad.library.adapter.base.listener.OnLoadMoreListener
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
/**
* createTime:2021/7/29 15:20
* auth:张继
... ... @@ -26,7 +26,7 @@ class TextCourseActivity :
private var page = 1
override fun initData() {
super.initData()
mViewModel.textLessons("", page)
mViewModel.textLessons("", page)
binding.apply {
... ... @@ -49,13 +49,16 @@ class TextCourseActivity :
binding.courseRecycler.layoutManager = LinearLayoutManager(this)
binding.courseRecycler.adapter = textLessonsAdapter
textLessonsAdapter?.setOnItemClickListener { adapter, view, position ->
val course = CourseParam()
val res = adapter.data[position] as TextLessonBean.ListBean.DataBean
course.mLessonId = "${res.id}"
course.isTrainClass = true
course.type = res.type.toInt()
course.title = res.name
startActivity(
Intent(this, TextDetailActivity::class.java).putExtra(
"id",
textLessonList!![position].id
)
Intent(this, TextDetailActivity::class.java)
.putExtra(ConstantParamKey.COURSE_BEAN, course)
)
}
}
... ...
package com.br_technology.securitytrain_master.ui.view.home.activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.webkit.WebChromeClient
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AppCompatActivity
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.base.common.ConstantParamKey
import com.br_technology.securitytrain_master.base.common.ConstantParamKey.COMMON_URL
import com.br_technology.securitytrain_master.base.repository.BaseRepository
import com.br_technology.securitytrain_master.base.view.BaseViewModel
import com.br_technology.securitytrain_master.databinding.ActivityWebBinding
import com.br_technology.securitytrain_master.ui.view.common.FileReadActivity
import com.br_technology.securitytrain_master.util.TrainFileUtil
import com.br_technology.securitytrain_master.view.ViewToolBar
import com.br_technology.securitytrain_master.view.listener.ToolBarClickListener
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
/**
... ... @@ -19,20 +25,30 @@ import com.br_technology.securitytrain_master.util.TrainFileUtil
* auth:张继
* des:
*/
class WebViewActivity : AppCompatActivity() {
class WebViewActivity : BaseLifeCycleActivity<BaseViewModel<BaseRepository>,ActivityWebBinding>(ActivityWebBinding::inflate) {
var webView: WebView? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_web)
initView()
initData()
override fun initData() {
intent.getStringExtra(COMMON_URL)?.let { webView?.loadUrl(it) }
}
fun initView() {
override fun initView() {
webView = findViewById(R.id.web_view)
val toolBar = findViewById<ViewToolBar>(R.id.tool_bar)
toolBar.addLeftListener(object : ToolBarClickListener {
override fun onClick(view: View) {
webView?.let {
if (it.canGoBack()) {
it.goBack()
} else {
finish()
}
}
}
})
webView?.webViewClient =
object : WebViewClient() {
override fun shouldOverrideUrlLoading(
view: WebView?,
request: WebResourceRequest?
... ... @@ -48,14 +64,29 @@ class WebViewActivity : AppCompatActivity() {
return true
}
}
return false
return !request?.url.toString().contains("http") || !request?.url.toString()
.startsWith("http")
}
}
webView?.webChromeClient = object : WebChromeClient() {
override fun onReceivedTitle(view: WebView?, title: String?) {
super.onReceivedTitle(view, title)
toolBar.setTitle(title ?: "")
}
}
}
fun initData(){
intent.getStringExtra(COMMON_URL)?.let { webView?.loadUrl(it) }
override fun onBackPressed() {
super.onBackPressed()
webView?.let {
if (it.canGoBack()) {
it.goBack()
} else {
finish()
}
}
}
override fun onDestroy() {
... ... @@ -66,4 +97,7 @@ class WebViewActivity : AppCompatActivity() {
webView?.removeAllViews()
}
}
override fun initDataObserver() {
}
}
\ No newline at end of file
... ...
... ... @@ -86,16 +86,16 @@ class CourseDetailActivity
mViewModel.mLiveLesson.observe(this, {
binding.apply {
Glide.with(this@CourseDetailActivity).load(it.data.image).into(ivTop)
Glide.with(this@CourseDetailActivity).load(it.data.detail.image).into(ivTop)
searchResultAdapter = BasePagerAdapter(
supportFragmentManager,
FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
)
val list =
mutableListOf(
OnlineDetailFragment(TrainClassDes(it.data.name, "", "")),
OnlineDetailFragment(TrainClassDes(it.data.detail.name, "", "")),
CourseListFragment(TrainCourseData(TYPE_COURSE_DETAIL_ITEM_LIVE).apply {
this.lessonLive = it.data
this.lessonLive = it.data.detail
})
)
val titles = listOf("课程详情", "课程列表")
... ...
... ... @@ -35,11 +35,23 @@ class TextDetailActivity :
override fun initData() {
super.initData()
courseBean = intent.getParcelableExtra(COURSE_BEAN)
courseBean?.let {
if (it.isTrainClass) {
mViewModel.textLessonsDetail(it.mLessonId.toInt())
courseBean?.let { course ->
if (course.isTrainClass) {
mViewModel.textLessonsDetail(course.mLessonId.toInt())
} else {
mViewModel.materialDetail(it.mLessonId.toInt())
mViewModel.materialDetail(course.mLessonId.toInt())
}
binding.start.setOnClickListener {
if (course.isTrainClass) {
mViewModel.lessonData()?.let { lesson ->
mViewModel.collect(lesson.id.toString())
}
} else {
mViewModel.materialData()?.let { lesson ->
mViewModel.collect(lesson.id.toString())
}
}
}
}
binding.apply {
... ... @@ -59,11 +71,15 @@ class TextDetailActivity :
return true
}
}
return false
return !request?.url.toString().contains("http") || !request?.url.toString()
.startsWith("http")
}
}
content.webChromeClient = WebChromeClient()
back.setOnClickListener {
finish()
}
}
}
... ... @@ -75,11 +91,23 @@ class TextDetailActivity :
binding.content.loadData(it.data.detail.content)
binding.tvTitle.text = it.data.detail.name
res = it.data
binding.start.isSelected = it.data.detail.is_favorite == 1
downLoadTime()
})
mViewModel.mDetailMaterialNormal.observe(this, {
binding.content.loadData(it.data.detail.content)
binding.tvTitle.text = it.data.detail.name
binding.start.isSelected = it.data.detail.is_favorite == 1
})
mViewModel.favoriteResponse.observe(this, { response ->
if (response.msg.contains("取消收藏成功")) {
binding.start.isSelected = false
return@observe
}
if (response.msg.contains("收藏成功")) {
binding.start.isSelected = true
return@observe
}
})
}
... ...
... ... @@ -94,7 +94,7 @@ class CourseListFragment(var data: TrainCourseData) :
TYPE_COURSE_DETAIL_ITEM_LIVE -> {
startActivity(
Intent(activity, VideoDetailActivity::class.java)
.putExtra(COMMON_URL, item.lessonVideoNormalChild?.video_url)
.putExtra(COMMON_URL, item.lessonLiveChild?.webrtc_url)
.putExtra(
COURSE_BEAN,
(activity as CourseDetailActivity).getCourseBean()
... ...
... ... @@ -4,12 +4,13 @@ import android.content.Intent
import android.view.View
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.base.common.ConstantParamKey
import com.br_technology.securitytrain_master.base.common.ConstantParamKey.COMMON_URL
import com.br_technology.securitytrain_master.base.common.ConstantParamKey.DOC_ID
import com.br_technology.securitytrain_master.databinding.FragmentHomeBinding
import com.br_technology.securitytrain_master.expand.addItemDecoration2
import com.br_technology.securitytrain_master.ui.bean.CourseParam
import com.br_technology.securitytrain_master.ui.view.home.activity.*
import com.br_technology.securitytrain_master.ui.view.home.activity.course.CourseDetailActivity
import com.br_technology.securitytrain_master.ui.view.home.activity.course.TextDetailActivity
import com.br_technology.securitytrain_master.ui.view.home.adapter.RecommendDataAdapter
import com.br_technology.securitytrain_master.ui.view.home.adapter.VideoCourseAdapter
import com.br_technology.securitytrain_master.ui.view.home.bean.BannerBean
... ... @@ -106,6 +107,14 @@ class HomeFragment :
.load(data?.image)
.apply(RequestOptions.bitmapTransform(RoundedCorners(8)))
.into(it.imageView)
it.imageView.setOnClickListener {
data?.let { res ->
startActivity(
Intent(requireContext(), WebViewActivity::class.java)
.putExtra(COMMON_URL, res.href)
)
}
}
}
}
}).addBannerLifecycleObserver(requireActivity())
... ... @@ -157,16 +166,9 @@ class HomeFragment :
recommendDataAdapter?.addList(recommendList!!)
recommendDataAdapter?.addListener(object : OnItemClickListener<RecommendBean.ListBean> {
override fun onClick(position: Int, data: RecommendBean.ListBean) {
val course = CourseParam()
course.mLessonId = "${data.id}"
course.isTrainClass = false
course.type = data.type.toInt()
//视频详情
startActivity(
Intent(
requireContext(),
TextDetailActivity::class.java
).putExtra(ConstantParamKey.COURSE_BEAN, course)
Intent(requireContext(), DatabaseDetailActivity::class.java)
.putExtra(DOC_ID, data.id)
)
}
})
... ...
... ... @@ -19,7 +19,7 @@ import com.br_technology.securitytrain_master.ui.view.home.bean.WorkTypeBean
class CourseDetailViewModel : BaseViewModel<LessonRepository>() {
var mVideoLesson = MutableLiveData<BaseResponse<LessonTrainVideoDetail>>()
var mVideoLessonNormal = MutableLiveData<BaseResponse<CommonDetail<LessonClassDetail>>>()
var mLiveLesson = MutableLiveData<BaseResponse<LessonLive>>()
var mLiveLesson = MutableLiveData<BaseResponse<CommonDetail<LessonLive>>>()
var mLessonOff = MutableLiveData<BaseResponse<CommonDetail<LessonOfflineDetail>>>()
var mWorkBean = MutableLiveData<BaseResponse<WorkTypeBean>>()
... ...
... ... @@ -12,10 +12,19 @@ import com.br_technology.securitytrain_master.ui.bean.MaterialDetail
* auth:张继
* des:
*/
class DatabaseDetailViewModel: BaseViewModel<LessonRepository>() {
class DatabaseDetailViewModel : BaseViewModel<LessonRepository>() {
var mDetailMaterialNormal = MutableLiveData<BaseResponse<CommonDetail<MaterialDetail>>>()
var collectResponse = MutableLiveData<BaseResponse<Void>>()
fun materialDetail(id: Int) {
mRepository.materialDetail(id, mDetailMaterialNormal)
}
fun collect() {
mRepository.collect(
"1",
"${mDetailMaterialNormal.value?.data?.detail?.id}",
collectResponse
)
}
}
\ No newline at end of file
... ...
... ... @@ -18,6 +18,14 @@ class TextDetailViewModel : BaseViewModel<LessonRepository>() {
var mDetailMaterialNormal = MutableLiveData<BaseResponse<CommonDetail<MaterialDetail>>>()
var recordCalss = MutableLiveData<BaseResponse<Void>>()
fun lessonData(): TextLessonDetailBean.DetailBean? {
return mTextLessonDetailBean.value?.data?.detail
}
fun materialData(): MaterialDetail? {
return mDetailMaterialNormal.value?.data?.detail
}
var favoriteResponse = MutableLiveData<BaseResponse<Void>>()
fun textLessonsDetail(
... ... @@ -30,11 +38,10 @@ class TextDetailViewModel : BaseViewModel<LessonRepository>() {
mRepository.materialDetail(id, mDetailMaterialNormal)
}
fun favorite(
type: String,
fun collect(
favorite_id: String
) {
mRepository.favorite(type, favorite_id, favoriteResponse)
mRepository.collect("2", favorite_id, favoriteResponse)
}
fun recordTxtClass(
... ...
... ... @@ -30,7 +30,7 @@ class CollectActivity :
val basePagerAdapter = BasePagerAdapter(
supportFragmentManager,
FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
FragmentPagerAdapter.BEHAVIOR_SET_USER_VISIBLE_HINT
)
basePagerAdapter.addTitle(listTitle)
basePagerAdapter.addData(fragments.toMutableList())
... ...
package com.br_technology.securitytrain_master.ui.view.mine.fragment
import com.br_technology.securitytrain_master.R
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.br_technology.securitytrain_master.base.common.ConstantParamKey
import com.br_technology.securitytrain_master.base.view.BaseAdapter
import com.br_technology.securitytrain_master.databinding.AdapterSideslipBinding
import com.br_technology.securitytrain_master.databinding.FragmentCourseBinding
import com.br_technology.securitytrain_master.ui.view.home.bean.RecommendData
import com.br_technology.securitytrain_master.expand.glideRound
import com.br_technology.securitytrain_master.ui.bean.CourseParam
import com.br_technology.securitytrain_master.ui.bean.FavoriteData
import com.br_technology.securitytrain_master.ui.view.home.activity.course.TextDetailActivity
import com.br_technology.securitytrain_master.ui.view.home.viewmodel.DatabaseFViewModel
import com.br_technology.securitytrain_master.ui.view.mine.adapter.SideslipAdapter
import com.br_technology.securitytrain_master.view.listener.OnItemClickListener
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleFragment
/**
... ... @@ -12,73 +22,79 @@ import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleFragment
* auth:张继
* des:资料
*/
class CourseFragment :BaseLifeCycleFragment<DatabaseFViewModel,FragmentCourseBinding>(FragmentCourseBinding::inflate){
class CourseFragment :
BaseLifeCycleFragment<DatabaseFViewModel, FragmentCourseBinding>(FragmentCourseBinding::inflate) {
var page = 1
var docAdapter = TxtAdapter()
override fun initData() {
super.initData()
binding.apply {
val recommendList = mutableListOf(
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
)
val resultAdapter = SideslipAdapter()
result.adapter = resultAdapter
resultAdapter.addList(recommendList)
refresh()
}
override fun initView() {
super.initView()
binding.smartRefresh.setOnRefreshListener {
refresh()
}
binding.smartRefresh.setOnLoadMoreListener {
loadMore()
}
binding.result.layoutManager = LinearLayoutManager(requireContext())
}
override fun initDataObserver() {
mViewModel.lessonList.observe(this, {
if (page == 1) {
docAdapter = TxtAdapter()
binding.result.adapter = docAdapter
docAdapter.addList(it.data.list.data)
docAdapter.apply {
addListener(object : OnItemClickListener<FavoriteData> {
override fun onClick(position: Int, data: FavoriteData) {
val course = CourseParam()
course.mLessonId = data.object_id
course.isTrainClass = true
course.title = data.title
this@CourseFragment.startActivity(
Intent(requireActivity(), TextDetailActivity::class.java)
.putExtra(ConstantParamKey.COURSE_BEAN, course)
)
}
})
}
} else {
docAdapter.addList(it.data.list.data)
}
}
)
}
private fun refresh() {
page = 1
mViewModel.getCollectLessonList(page)
binding.smartRefresh.setEnableLoadMore(false)
}
private fun loadMore() {
page++
mViewModel.getCollectDocList(page)
binding.smartRefresh.setEnableRefresh(false)
}
class TxtAdapter : BaseAdapter<FavoriteData, AdapterSideslipBinding>() {
override fun getViewBinding(
context: Context,
parent: ViewGroup,
viewType: Int,
from: LayoutInflater
): AdapterSideslipBinding {
return AdapterSideslipBinding.inflate(from, parent, false)
}
override fun onBind(holder: AdapterSideslipBinding, position: Int, data: FavoriteData) {
holder.pic.glideRound(data.image, 16)
holder.name.text = data.title
holder.info.text = data.des
}
}
}
\ No newline at end of file
... ...
package com.br_technology.securitytrain_master.ui.view.mine.fragment
import com.br_technology.securitytrain_master.R
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.br_technology.securitytrain_master.base.common.ConstantParamKey
import com.br_technology.securitytrain_master.base.view.BaseAdapter
import com.br_technology.securitytrain_master.databinding.AdapterSideslipBinding
import com.br_technology.securitytrain_master.databinding.FragmentDatabaseBinding
import com.br_technology.securitytrain_master.ui.view.home.bean.RecommendData
import com.br_technology.securitytrain_master.expand.glideRound
import com.br_technology.securitytrain_master.ui.bean.FavoriteData
import com.br_technology.securitytrain_master.ui.view.home.activity.DatabaseDetailActivity
import com.br_technology.securitytrain_master.ui.view.home.viewmodel.DatabaseFViewModel
import com.br_technology.securitytrain_master.ui.view.mine.adapter.SideslipAdapter
import com.br_technology.securitytrain_master.view.listener.OnItemClickListener
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleFragment
/**
... ... @@ -12,73 +21,77 @@ import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleFragment
* auth:张继
* des:资料
*/
class DatabaseFragment :BaseLifeCycleFragment<DatabaseFViewModel,FragmentDatabaseBinding>(FragmentDatabaseBinding::inflate){
class DatabaseFragment :
BaseLifeCycleFragment<DatabaseFViewModel, FragmentDatabaseBinding>(FragmentDatabaseBinding::inflate) {
var page = 1
var docAdapter = DocAdapter()
override fun initData() {
super.initData()
binding.apply {
val recommendList = mutableListOf(
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
RecommendData(
R.mipmap.banner,
"思维导图高分作文法(高中)议论",
"从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"
),
)
val resultAdapter = SideslipAdapter()
result.adapter = resultAdapter
resultAdapter.addList(recommendList)
refresh()
}
override fun initView() {
super.initView()
binding.smartRefresh.setOnRefreshListener {
refresh()
}
binding.smartRefresh.setOnLoadMoreListener {
loadMore()
}
binding.result.layoutManager = LinearLayoutManager(requireContext())
}
override fun initDataObserver() {
mViewModel.docList.observe(this, {
if (page == 1) {
docAdapter = DocAdapter()
binding.result.adapter = docAdapter
docAdapter.addList(it.data.list.data)
docAdapter.apply {
addListener(object : OnItemClickListener<FavoriteData> {
override fun onClick(position: Int, data: FavoriteData) {
this@DatabaseFragment.startActivity(
Intent(requireActivity(), DatabaseDetailActivity::class.java)
.putExtra(ConstantParamKey.DOC_ID, data.object_id.toInt())
)
}
})
}
} else {
docAdapter.addList(it.data.list.data)
}
}
)
}
private fun refresh() {
page = 1
mViewModel.getCollectDocList(page)
binding.smartRefresh.setEnableLoadMore(false)
}
private fun loadMore() {
page++
mViewModel.getCollectDocList(page)
binding.smartRefresh.setEnableRefresh(false)
}
class DocAdapter : BaseAdapter<FavoriteData, AdapterSideslipBinding>() {
override fun getViewBinding(
context: Context,
parent: ViewGroup,
viewType: Int,
from: LayoutInflater
): AdapterSideslipBinding {
return AdapterSideslipBinding.inflate(from, parent, false)
}
override fun onBind(holder: AdapterSideslipBinding, position: Int, data: FavoriteData) {
holder.pic.glideRound(data.image, 16)
holder.name.text = data.title
holder.info.text = data.des
}
}
}
\ No newline at end of file
... ...
... ... @@ -2,9 +2,12 @@ package com.br_technology.securitytrain_master.ui.view.home.viewmodel
import androidx.lifecycle.MutableLiveData
import com.br_technology.securitytrain_master.base.network.response.BaseResponse
import com.br_technology.securitytrain_master.base.network.response.CommonDataList
import com.br_technology.securitytrain_master.base.network.response.CommonList
import com.br_technology.securitytrain_master.base.network.response.CommonPage
import com.br_technology.securitytrain_master.base.repository.DocRepository
import com.br_technology.securitytrain_master.base.view.BaseViewModel
import com.br_technology.securitytrain_master.ui.bean.FavoriteData
import com.br_technology.securitytrain_master.ui.bean.MaterialClassify
import com.br_technology.securitytrain_master.ui.bean.MaterialPage
... ... @@ -14,6 +17,11 @@ import com.br_technology.securitytrain_master.ui.bean.MaterialPage
* des:
*/
class DatabaseFViewModel : BaseViewModel<DocRepository>() {
// 资料
val docList = MutableLiveData<BaseResponse<CommonDataList<CommonPage<FavoriteData>>>>()
// 文本课程
val lessonList = MutableLiveData<BaseResponse<CommonDataList<CommonPage<FavoriteData>>>>()
val classify = MutableLiveData<BaseResponse<CommonList<MaterialClassify>>>()
val classifyDataList = MutableLiveData<BaseResponse<MaterialPage>>()
val type = MutableLiveData<Int>()
... ... @@ -33,4 +41,12 @@ class DatabaseFViewModel : BaseViewModel<DocRepository>() {
}
}
}
fun getCollectDocList(page: Int) {
mRepository.getCollectDocList(page, docList)
}
fun getCollectLessonList(page: Int) {
mRepository.getCollectTxtLessonList(page, lessonList)
}
}
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/star_blue_y" android:state_selected="true" />
<item android:drawable="@mipmap/star_black_n" android:state_selected="false" />
<item android:drawable="@mipmap/star_black_n" />
</selector>
\ No newline at end of file
... ...
... ... @@ -11,15 +11,15 @@
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingEnd="16dp">
android:orientation="horizontal">
<ImageView
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="48dp"
android:layout_height="match_parent"
android:contentDescription="@string/logo"
android:foreground="?android:attr/selectableItemBackground"
android:padding="12dp"
android:src="@mipmap/ic_back" />
<View
... ... @@ -29,15 +29,18 @@
<ImageView
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_width="48dp"
android:layout_height="match_parent"
android:src="@mipmap/star_black_n" />
android:foreground="?android:attr/selectableItemBackground"
android:padding="12dp"
android:src="@drawable/selector_star_status" />
<ImageView
android:id="@+id/share"
android:layout_width="wrap_content"
android:layout_width="48dp"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:foreground="?android:attr/selectableItemBackground"
android:padding="12dp"
android:src="@mipmap/share" />
</LinearLayout>
... ...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
... ... @@ -7,17 +7,46 @@
<include layout="@layout/layout_tool_bar" />
<com.br_technology.securitytrain_master.view.ViewToolBar
android:id="@+id/tool_bar"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/status_bar" />
android:layout_height="?actionBarSize"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/back"
android:layout_width="48dp"
android:layout_height="match_parent"
android:contentDescription="@string/logo"
android:foreground="?android:attr/selectableItemBackground"
android:padding="12dp"
android:src="@mipmap/ic_back" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageView
android:id="@+id/start"
android:layout_width="48dp"
android:layout_height="match_parent"
android:foreground="?android:attr/selectableItemBackground"
android:padding="12dp"
android:src="@drawable/selector_star_status" />
<ImageView
android:id="@+id/share"
android:layout_width="48dp"
android:layout_height="match_parent"
android:foreground="?android:attr/selectableItemBackground"
android:padding="12dp"
android:src="@mipmap/share" />
</LinearLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tool_bar"
android:paddingBottom="48dp"
android:overScrollMode="never"
android:scrollbars="none">
... ... @@ -62,6 +91,7 @@
android:gravity="center"
android:text="去做题"
android:textColor="@color/white"
android:textSize="15sp" />
android:textSize="15sp"
android:visibility="gone" />
</RelativeLayout>
\ No newline at end of file
</LinearLayout>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<include layout="@layout/layout_tool_bar" />
... ... @@ -20,4 +21,4 @@
android:layout_height="200dp"
android:layout_below="@id/tool_bar" />
</RelativeLayout>
\ No newline at end of file
</LinearLayout>
\ No newline at end of file
... ...
... ... @@ -4,6 +4,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/layout_tool_bar" />
<com.br_technology.securitytrain_master.view.ViewToolBar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.br_technology.securitytrain_master.view.MyWebView
android:id="@+id/web_view"
android:layout_width="match_parent"
... ...
<?xml version="1.0" encoding="utf-8"?>
<com.br_technology.securitytrain_master.view.SlideRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
<com.scwang.smart.refresh.layout.SmartRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/result"
android:id="@+id/smart_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
android:layout_height="match_parent">
<com.scwang.smart.refresh.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.br_technology.securitytrain_master.view.SlideRecyclerView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<com.scwang.smart.refresh.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
... ...
<?xml version="1.0" encoding="utf-8"?>
<com.br_technology.securitytrain_master.view.SlideRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
<com.scwang.smart.refresh.layout.SmartRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/result"
android:id="@+id/smart_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
android:layout_height="match_parent">
<com.scwang.smart.refresh.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.br_technology.securitytrain_master.view.SlideRecyclerView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<com.scwang.smart.refresh.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
... ...