作者 杨谦

1.搜索

2.todo:班级任务跳转条件限制未知,我的各个页面数据业务逻辑未知
正在显示 18 个修改的文件 包含 601 行增加101 行删除
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.CommonList
import com.br_technology.securitytrain_master.ui.bean.RegisterCompany
import com.br_technology.securitytrain_master.ui.bean.SearchLog
import com.br_technology.securitytrain_master.ui.bean.UserRule
import com.br_technology.securitytrain_master.base.network.response.BaseResponse
import com.br_technology.securitytrain_master.base.network.response.CommonList
import io.reactivex.rxjava3.core.Observable
import retrofit2.http.*
... ... @@ -53,14 +53,12 @@ interface CommonApi : ApiService {
/**
* 历史搜索记录
*/
@FormUrlEncoded
@POST("/api/common/search_log")
fun searchLog(): Observable<BaseResponse<CommonList<SearchLog>>>
/**
* 清除搜索记录
*/
@FormUrlEncoded
@POST("/api/common/search_log_clear")
fun searchLogClear(): Observable<BaseResponse<CommonList<SearchLog>>>
... ...
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.*
import com.br_technology.securitytrain_master.ui.view.home.bean.VideoLessonBean
import io.reactivex.rxjava3.core.Observable
import retrofit2.http.Field
import retrofit2.http.FieldMap
... ... @@ -31,7 +30,7 @@ interface LessonApi : ApiService {
@Field("pos_id") pos_id: Int,
@Field("page") page: Int,
@Field("page_num") page_num: Int,
): Observable<BaseResponse<CommonList<LessonBean>>>
): Observable<BaseResponse<CommonDataList<CommonPage<LessonBean>>>>
/**
* 文本课程详情
... ... @@ -61,7 +60,7 @@ interface LessonApi : ApiService {
@Field("pos_id") pos_id: String, // 工种id
@Field("page") page: Int,
@Field("page_num") page_num: Int,
): Observable<BaseResponse<CommonList<LessonVideo>>>
): Observable<BaseResponse<CommonDataList<CommonPage<LessonVideo>>>>
/**
* 视频课程详情
... ... @@ -88,6 +87,38 @@ interface LessonApi : ApiService {
): Observable<BaseResponse<CommonDetail<LessonClassDetail>>>
/**
* 资料库列表
* @param keyword 搜索关键词
* @param page 页数
* @param page_num 每页显示数量
*/
@FormUrlEncoded
@POST("/api/material/material_list")
fun searchDocList(
@Field("keyword") keyword: String,
@Field("sort_id") sort_id: Int,
@Field("page") page: Int,
@Field("page_num") page_num: Int
): Observable<BaseResponse<MaterialPage>>
/**
* 视频课程列表
* @param is_rec: Int, // 是否为推荐课程0=否1=是
* @param keyword: String, // 搜索关键词
* @param pos_id: String, // 工种id
* @param page 页数
* @param page_num 每页显示数量
*/
@FormUrlEncoded
@POST("/api/lesson/lesson")
fun searchVideoList(
@Field("keyword") keyword: String, // 搜索关键词
@Field("pos_id") pos_id: String, // 工种id
@Field("page") page: Int,
@Field("page_num") page_num: Int,
): Observable<BaseResponse<VideoLessonBean>>
/**
* 直播课程列表
* @param keyword 搜索关键词
* @param type 直播类型1=正在直播2=回放直播3=即将开播
... ... @@ -101,7 +132,22 @@ interface LessonApi : ApiService {
@Field("type") type: Int, // 直播类型1=正在直播2=回放直播3=即将开播
@Field("page") page: String,
@Field("page_num") page_num: String,
): Observable<BaseResponse<CommonList<LessonLive>>>
): Observable<BaseResponse<CommonDataList<CommonPage<LessonLive>>>>
/**
* 直播课程列表
* @param keyword 搜索关键词
* @param type 直播类型1=正在直播2=回放直播3=即将开播
* @param page 页数
* @param page_num 每页显示数量
*/
@FormUrlEncoded
@POST("/api/lesson/lesson_live")
fun lessonLiveList(
@Field("keyword") keyword: String, // 搜索关键词
@Field("page") page: String,
@Field("page_num") page_num: String,
): Observable<BaseResponse<CommonDataList<CommonPage<LessonLive>>>>
/**
* 直播课程详情
... ...
... ... @@ -3,10 +3,12 @@ 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.CommonDataList
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.CommonPage
import com.br_technology.securitytrain_master.ui.bean.*
import com.br_technology.securitytrain_master.ui.view.home.bean.TextLessonDetailBean
import com.br_technology.securitytrain_master.ui.view.home.bean.VideoLessonBean
import com.br_technology.securitytrain_master.ui.view.home.bean.WorkTypeBean
/**
... ... @@ -27,7 +29,7 @@ class LessonRepository(loadState: MutableLiveData<State>) : ApiRepository(loadSt
keyword: String,
pos_id: Int,
page: Int, page_num: Int,
liveData: MutableLiveData<BaseResponse<CommonList<LessonBean>>>
liveData: MutableLiveData<BaseResponse<CommonDataList<CommonPage<LessonBean>>>>
) {
addRequest(lessonService.lessonTxtList(keyword, pos_id, page, page_num), liveData)
}
... ... @@ -52,7 +54,7 @@ class LessonRepository(loadState: MutableLiveData<State>) : ApiRepository(loadSt
pos_id: String,
page: Int,
page_num: Int,
liveData: MutableLiveData<BaseResponse<CommonList<LessonVideo>>>
liveData: MutableLiveData<BaseResponse<CommonDataList<CommonPage<LessonVideo>>>>
) {
addRequest(lessonService.lessonVideoList(is_rec, keyword, pos_id, page, page_num), liveData)
}
... ... @@ -76,11 +78,48 @@ class LessonRepository(loadState: MutableLiveData<State>) : ApiRepository(loadSt
type: Int,
page: String,
page_num: String,
liveData: MutableLiveData<BaseResponse<CommonList<LessonLive>>>
liveData: MutableLiveData<BaseResponse<CommonDataList<CommonPage<LessonLive>>>>
) {
addRequest(lessonService.lessonLiveList(keyword, type, page, page_num), liveData)
}
fun searchLiveList(
keyword: String,
page: String,
page_num: String,
liveData: MutableLiveData<BaseResponse<CommonDataList<CommonPage<LessonLive>>>>
) {
addRequest(lessonService.lessonLiveList(keyword, page, page_num), liveData)
}
fun searchVideoList(
keyword: String,
pos_id: String,
page: Int,
page_num: Int,
liveData: MutableLiveData<BaseResponse<VideoLessonBean>>
) {
addRequest(lessonService.searchVideoList(keyword, pos_id, page, page_num), liveData)
}
fun searchTxtList(
keyword: String,
pos_id: Int,
page: Int, page_num: Int,
liveData: MutableLiveData<BaseResponse<CommonDataList<CommonPage<LessonBean>>>>
) {
addRequest(lessonService.lessonTxtList(keyword, pos_id, page, page_num), liveData)
}
fun searchMaterialList(
keyword: String,
pos_id: Int,
page: Int, page_num: Int,
liveData: MutableLiveData<BaseResponse<MaterialPage>>
) {
addRequest(lessonService.searchDocList(keyword, pos_id, page, page_num), liveData)
}
fun lessonLiveDetail(
id: Int,
liveData: MutableLiveData<BaseResponse<CommonDetail<LessonLive>>>
... ...
package com.br_technology.securitytrain_master.ui.bean
import java.io.Serializable
/**
* Author by YSir
* Date on 2022/1/8.
... ... @@ -18,7 +20,7 @@ open class Teacher(
var id: Int,
var name: String,//"测试讲师2", // 讲师名称
var avatar: String//"http://security.cn/assets/img/avatar.png" // 讲师头像
)
) : Serializable
//注册企业
open class RegisterCompany(
... ...
... ... @@ -2,6 +2,8 @@ package com.br_technology.securitytrain_master.ui.bean
import android.os.Parcel
import android.os.Parcelable
import com.br_technology.securitytrain_master.ui.view.home.bean.RecommendBean
import com.br_technology.securitytrain_master.ui.view.home.bean.VideoLessonBean
import com.chad.library.adapter.base.entity.MultiItemEntity
/**
... ... @@ -134,3 +136,15 @@ open class TrainCourseDetailItemChild(var type: Int, var pos: Int) : MultiItemEn
get() = type
}
open class SearchEvent(var search: String)
open class SearchBean(var type: Int) : MultiItemEntity {
var txtData: LessonBean? = null
var videoData: VideoLessonBean.ListBean.DataBean? = null
var liveData: LessonLive? = null
var materialData: RecommendBean.ListBean? = null
override val itemType: Int
get() = type
}
... ...
... ... @@ -3,14 +3,18 @@ package com.br_technology.securitytrain_master.ui.view.home.activity
import android.os.Bundle
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.ActivitySearchBinding
import com.br_technology.securitytrain_master.ui.bean.SearchEvent
import com.br_technology.securitytrain_master.ui.bean.SearchLog
import com.br_technology.securitytrain_master.ui.view.home.adapter.HistoryAdapter
import com.br_technology.securitytrain_master.base.view.BasePagerAdapter
import com.br_technology.securitytrain_master.ui.view.home.fragment.ResultFragment
import com.br_technology.securitytrain_master.ui.view.home.viewmodel.SearchViewModel
import com.br_technology.securitytrain_master.view.DialogSureCancel
import com.br_technology.securitytrain_master.view.listener.DialogListener
import com.br_technology.securitytrain_master.view.listener.OnItemClickListener
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
import org.greenrobot.eventbus.EventBus
/**
* createTime:2021/7/28 11:13
... ... @@ -26,23 +30,12 @@ class SearchActivity :
finish()
}
val historyAdapter = HistoryAdapter()
historyRecycler.adapter = historyAdapter
val listOf = listOf(
"历史标签记录历史标签记录历史标签记录历史标签记录",
"历史标签记录",
"历史标签记录",
"d",
"历史标签记录历史标签记录",
"历史标签记录历史标签记录历史标签记录",
"历史标签记录历史标签记录历史标签记录历史标签记录",
)
historyAdapter.addList(listOf)
// 清空历史记录
clear.setOnClickListener {
DialogSureCancel(it.context).setListener(object : DialogListener {
DialogSureCancel(this@SearchActivity).setListener(object : DialogListener {
override fun determine() {
// 清空记录
mViewModel.clearLog()
}
}).show()
}
... ... @@ -57,6 +50,7 @@ class SearchActivity :
historyRecycler.visibility = View.GONE
tabLayout.visibility = View.VISIBLE
viewPager.visibility = View.VISIBLE
EventBus.getDefault().post(SearchEvent(searchEdit.text.toString()))
}
searchEdit.setOnClickListener {
... ... @@ -72,18 +66,43 @@ class SearchActivity :
FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
)
val list =
mutableListOf(ResultFragment(), ResultFragment(), ResultFragment(), ResultFragment())
mutableListOf(
ResultFragment(0),
ResultFragment(1),
ResultFragment(2),
ResultFragment(3)
)
val titles = listOf("在线课程", "直播课程", "文本课程", "资料库")
searchResultAdapter.addData(list.toMutableList())
searchResultAdapter.addTitle(titles)
viewPager.adapter = searchResultAdapter
viewPager.offscreenPageLimit = 3
tabLayout.setupWithViewPager(viewPager)
}
}
override fun initDataObserver() {
override fun initData() {
super.initData()
mViewModel.searchLog()
}
override fun initDataObserver() {
mViewModel.liveData.observe(this, {
val historyAdapter = HistoryAdapter()
binding.historyRecycler.adapter = historyAdapter
historyAdapter.addList(it.data.list)
historyAdapter.addListener(object : OnItemClickListener<SearchLog> {
override fun onClick(position: Int, data: SearchLog) {
EventBus.getDefault().post(SearchEvent(data.keyword))
binding.historyRecycler.visibility = View.GONE
binding.historyGroup.visibility = View.GONE
binding.tabLayout.visibility = View.VISIBLE
binding.viewPager.visibility = View.VISIBLE
}
})
})
mViewModel.clearData.observe(this, {
mViewModel.searchLog()
})
}
}
\ No newline at end of file
... ...
... ... @@ -5,16 +5,17 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import com.br_technology.securitytrain_master.base.view.BaseAdapter
import com.br_technology.securitytrain_master.databinding.AdapterHistoryBinding
import com.br_technology.securitytrain_master.ui.bean.SearchLog
/**
* createTime:2021/7/28 11:50
* auth:张继
* des:
*/
class HistoryAdapter : BaseAdapter<String, AdapterHistoryBinding>() {
class HistoryAdapter : BaseAdapter<SearchLog, AdapterHistoryBinding>() {
override fun onBind(holder: AdapterHistoryBinding, position: Int, data: String) {
holder.name.text = data
override fun onBind(holder: AdapterHistoryBinding, position: Int, data: SearchLog) {
holder.name.text = data.keyword
}
override fun getViewBinding(
... ...
package com.br_technology.securitytrain_master.ui.view.home.adapter
import android.annotation.SuppressLint
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.expand.glideRound
import com.br_technology.securitytrain_master.ui.bean.LessonBean
import com.br_technology.securitytrain_master.ui.bean.LessonLive
import com.br_technology.securitytrain_master.ui.bean.SearchBean
import com.br_technology.securitytrain_master.ui.view.home.bean.RecommendBean
import com.br_technology.securitytrain_master.ui.view.home.bean.VideoLessonBean
import com.br_technology.securitytrain_master.util.CommonUtil
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
/**
* Author by YSir
* Date on 2022/1/26.c
* description
* PS: Not easy to write code, please indicate.
*/
class SearchAdapter : BaseMultiItemQuickAdapter<SearchBean, BaseViewHolder>() {
init {
addItemType(0, R.layout.adapter_video_course)
addItemType(1, R.layout.item_course)
addItemType(2, R.layout.adapter_recommend_data)
addItemType(3, R.layout.adapter_recommend_data)
}
interface ISearchClick {
fun clickItem(item: SearchBean)
}
private var mClickItem: ISearchClick? = null
fun setIClickItem(iClickItem: ISearchClick) {
mClickItem = iClickItem
}
override fun convert(holder: BaseViewHolder, item: SearchBean) {
when (item.type) {
0 -> {
item.videoData?.let {
initVideo(holder, it)
}
}
1 -> {
item.liveData?.let {
initLive(holder, it)
}
}
2 -> {
item.txtData?.let {
initTxt(holder, it)
}
}
3 -> {
item.materialData?.let {
initMaterial(holder, it)
}
}
}
holder.itemView.setOnClickListener {
mClickItem?.clickItem(item)
}
}
@SuppressLint("SetTextI18n")
private fun initVideo(holder: BaseViewHolder, data: VideoLessonBean.ListBean.DataBean) {
holder.apply {
getView<ImageView>(R.id.video_pic).glideRound(data.image, 16)
getView<ImageView>(R.id.head).glideRound(data.teacher.avatar, 16)
getView<TextView>(R.id.name).text = data.teacher.name
getView<TextView>(R.id.course_name).text = data.name
getView<TextView>(R.id.lesson).text = "${data.class_hours}课时"
}
}
@SuppressLint("SetTextI18n")
private fun initLive(holder: BaseViewHolder, data: LessonLive) {
holder.apply {
getView<TextView>(R.id.tv_title).text = CommonUtil.getTransStr(data.name)
getView<TextView>(R.id.tv_status).visibility = View.GONE
getView<TextView>(R.id.tv_time).text = ""
getView<TextView>(R.id.tv_lesson).text = "${data.class_hours}学时"
Glide.with(holder.itemView).load(data.image).error(R.mipmap.placeholder_head)
.into(getView(R.id.iv_pic))
}
}
private fun initTxt(holder: BaseViewHolder, item: LessonBean) {
holder.apply {
getView<TextView>(R.id.name).text = item.name
getView<TextView>(R.id.info).text = item.des
Glide.with(context).load(item.image)
.apply(RequestOptions.bitmapTransform(RoundedCorners(16)))
.into(holder.getView(R.id.pic))
}
}
private fun initMaterial(holder: BaseViewHolder, item: RecommendBean.ListBean) {
holder.apply {
getView<TextView>(R.id.name).text = item.name
getView<TextView>(R.id.info).text = item.des
Glide.with(context).load(item.image)
.apply(RequestOptions.bitmapTransform(RoundedCorners(16)))
.into(holder.getView(R.id.pic))
}
}
}
\ No newline at end of file
... ...
package com.br_technology.securitytrain_master.ui.view.home.fragment
import com.br_technology.securitytrain_master.R
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.br_technology.securitytrain_master.base.common.ConstantParamKey
import com.br_technology.securitytrain_master.databinding.FragmentResultBinding
import com.br_technology.securitytrain_master.ui.view.home.adapter.ResultAdapter
import com.br_technology.securitytrain_master.ui.view.home.bean.RecommendData
import com.br_technology.securitytrain_master.expand.addItemDecoration2
import com.br_technology.securitytrain_master.ui.bean.*
import com.br_technology.securitytrain_master.ui.view.home.activity.DatabaseDetailActivity
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.SearchAdapter
import com.br_technology.securitytrain_master.ui.view.home.bean.RecommendBean
import com.br_technology.securitytrain_master.ui.view.home.bean.VideoLessonBean
import com.br_technology.securitytrain_master.ui.view.home.viewmodel.ResultViewModel
import com.br_technology.securitytrain_master.util.TranslateUnit
import com.br_technology.securitytrain_master.view.VerticalDecoration
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleFragment
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
/**
* createTime:2021/7/28 15:39
* auth:张继
* des:
*/
class ResultFragment : BaseLifeCycleFragment<ResultViewModel,FragmentResultBinding>(FragmentResultBinding::inflate) {
class ResultFragment(val type: Int) :
BaseLifeCycleFragment<ResultViewModel, FragmentResultBinding>(FragmentResultBinding::inflate),
SearchAdapter.ISearchClick {
override fun initData() {
super.initData()
var page = 1
var keywords = ""
override fun initView() {
super.initView()
var str = ""
when (type) {
ResultViewModel.ResultType.TYPE_ZERO -> {
str = "暂无在线课程"
}
ResultViewModel.ResultType.TYPE_ONE -> {
str = "暂无直播课程"
}
ResultViewModel.ResultType.TYPE_TWO -> {
str = "暂无文本课程"
}
ResultViewModel.ResultType.TYPE_THREE -> {
str = "暂无资料库"
}
}
binding.tvNoData.text = str
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, "思维导图高分作文法(高中)议论", "从这个角度看,康得在不经意间这样说过,既然我已踏上了这条道路,那么"),
when (type) {
0 -> {
result.addItemDecoration2(2, 15, 16)
result.layoutManager = GridLayoutManager(requireActivity(), 2)
}
else -> {
result.addItemDecoration(
VerticalDecoration(
TranslateUnit.dp2px(context, 16f),
0
)
)
val resultAdapter = ResultAdapter()
result.adapter = resultAdapter
// resultAdapter.addList(recommendList)
result.layoutManager = LinearLayoutManager(requireActivity())
}
}
}
}
var searchAdapter: SearchAdapter? = null
override fun initData() {
super.initData()
refresh()
}
override fun initDataObserver() {
mViewModel.videoData.observe(this, {
val data = it.data.list.data
setData(transData(data))
})
mViewModel.liveData.observe(this, {
val data = it.data.list.data
setData(transData(data))
})
mViewModel.txtData.observe(this, {
val data = it.data.list.data
setData(transData(data))
})
mViewModel.materialData.observe(this, {
val data = it.data.list.data
setData(transData(data))
})
}
private fun setData(data: List<SearchBean>) {
binding.smartRefresh.finishLoadMore()
binding.smartRefresh.finishRefresh()
binding.smartRefresh.setEnableLoadMore(data.size == 10)
if (page == 1) {
searchAdapter = SearchAdapter()
searchAdapter?.setList(data)
searchAdapter?.setIClickItem(this)
binding.result.adapter = searchAdapter
} else {
searchAdapter?.addData(data)
}
binding.smartRefresh.visibility = if (searchAdapter?.itemCount!! > 0) {
View.VISIBLE
} else {
View.GONE
}
binding.tvNoData.visibility = if (searchAdapter?.itemCount!! > 0) {
View.GONE
} else {
View.VISIBLE
}
}
private fun transData(data: List<Any>): List<SearchBean> {
val list = mutableListOf<SearchBean>()
for (item in data) {
val putData = SearchBean(type)
if (item is LessonBean) {
putData.txtData = item
}
if (item is LessonLive) {
putData.liveData = item
}
if (item is VideoLessonBean.ListBean.DataBean) {
putData.videoData = item
}
if (item is RecommendBean.ListBean) {
putData.materialData = item
}
list.add(putData)
}
return list
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
EventBus.getDefault().register(this)
}
override fun onDestroyView() {
EventBus.getDefault().unregister(this)
super.onDestroyView()
}
fun refresh() {
page = 1
mViewModel.loadData(type, keywords, page)
}
fun loadData() {
page++
mViewModel.loadData(type, keywords, page)
}
@Subscribe
fun search(search: SearchEvent) {
keywords = search.search
refresh()
}
override fun clickItem(item: SearchBean) {
when (type) {
ResultViewModel.ResultType.TYPE_ZERO -> {
val course = CourseParam()
val data = item.videoData
course.mLessonId = "${data?.id}"
course.isTrainClass = false
course.type = data?.type?.toInt() ?: 0
this@ResultFragment.startActivity(
Intent(
requireActivity(),
CourseDetailActivity::class.java
).putExtra(ConstantParamKey.COURSE_BEAN, course)
)
}
ResultViewModel.ResultType.TYPE_ONE -> {
}
ResultViewModel.ResultType.TYPE_TWO -> {
val course = CourseParam()
val data = item.txtData
course.mLessonId = "${data?.id}"
course.isTrainClass = true
course.mTrainClassId = "${data?.train_class_id}"
this@ResultFragment.startActivity(
Intent(
requireActivity(),
TextDetailActivity::class.java
).putExtra(ConstantParamKey.COURSE_BEAN, course)
)
}
ResultViewModel.ResultType.TYPE_THREE -> {
val data = item.materialData
this@ResultFragment.startActivity(
Intent(requireActivity(), DatabaseDetailActivity::class.java)
.putExtra(ConstantParamKey.DOC_ID, data?.id)
)
}
}
}
}
\ No newline at end of file
... ...
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.CommonPage
import com.br_technology.securitytrain_master.base.repository.LessonRepository
import com.br_technology.securitytrain_master.base.view.BaseViewModel
import com.br_technology.securitytrain_master.ui.view.home.repository.ResultRepository
import com.br_technology.securitytrain_master.ui.bean.LessonBean
import com.br_technology.securitytrain_master.ui.bean.LessonLive
import com.br_technology.securitytrain_master.ui.bean.MaterialPage
import com.br_technology.securitytrain_master.ui.view.home.bean.VideoLessonBean
import com.br_technology.securitytrain_master.util.sp_job_id
/**
* createTime:2021/7/27 15:48
* auth:张继
* des:
*/
class ResultViewModel: BaseViewModel<ResultRepository>() {
class ResultViewModel : BaseViewModel<LessonRepository>() {
val videoData = MutableLiveData<BaseResponse<VideoLessonBean>>()
val liveData = MutableLiveData<BaseResponse<CommonDataList<CommonPage<LessonLive>>>>()
val txtData = MutableLiveData<BaseResponse<CommonDataList<CommonPage<LessonBean>>>>()
val materialData = MutableLiveData<BaseResponse<MaterialPage>>()
object ResultType {
const val TYPE_ZERO = 0
const val TYPE_ONE = 1
const val TYPE_TWO = 2
const val TYPE_THREE = 3
}
fun loadData(
type:Int,
keyword: String,
page: Int
) {
when (type) {
ResultType.TYPE_ZERO -> {
searchVideoList(keyword, page)
}
ResultType.TYPE_ONE -> {
searchLiveList(keyword, page)
}
ResultType.TYPE_TWO -> {
searchTxtList(keyword, page)
}
ResultType.TYPE_THREE -> {
searchMaterialList(keyword, page)
}
}
}
fun searchVideoList(
keyword: String,
page: Int
) {
mRepository.searchVideoList(keyword, sp_job_id.toString(), page, 10, videoData)
}
fun searchLiveList(
keyword: String,
page: Int
) {
mRepository.searchLiveList(keyword, page.toString(), "10", liveData)
}
fun searchTxtList(
keyword: String,
page: Int
) {
mRepository.searchTxtList(keyword, sp_job_id, page, 10, txtData)
}
fun searchMaterialList(
keyword: String,
page: Int
) {
mRepository.searchMaterialList(keyword, sp_job_id, page, 10, materialData)
}
}
\ No newline at end of file
... ...
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.CommonList
import com.br_technology.securitytrain_master.base.repository.CommonRepository
import com.br_technology.securitytrain_master.base.view.BaseViewModel
import com.br_technology.securitytrain_master.ui.view.home.repository.SearchRepository
import com.br_technology.securitytrain_master.ui.bean.SearchLog
/**
* createTime:2021/7/27 15:48
* auth:张继
* des:
*/
class SearchViewModel: BaseViewModel<SearchRepository>() {
class SearchViewModel : BaseViewModel<CommonRepository>() {
val liveData = MutableLiveData<BaseResponse<CommonList<SearchLog>>>()
val clearData = MutableLiveData<BaseResponse<CommonList<SearchLog>>>()
fun searchLog() {
mRepository.searchLog(liveData)
}
fun clearLog() {
mRepository.searchLogClear(clearData)
}
}
\ No newline at end of file
... ...
... ... @@ -47,9 +47,6 @@ public class HtmlConvert {
element.removeAttr("class");
String souce = element.attr("src");
if (loadImage(BaseApplication.Companion.getInstance().getApplicationContext())) {
// if (!souce.startsWith("http")) {
// element.attr("src", ConnectUrl.BASE_URL_IMG() + souce);
// }
if (element.hasParent()) {
Element parent = element.parent();
if (parent.tagName().equals("a")) {
... ... @@ -65,15 +62,12 @@ public class HtmlConvert {
}
}
}
// element.attr("onclick",onClick(souce,arr));
}
doc.select("br").remove();
// int fontSize = SettingKits.getFontSize(BaseApplication.Companion.getInstance().getApplicationContext());
int fontSize = 0;
List<Element> spanList = doc.select("span");
for (Element element : spanList) {
updateStyle(element, "font-size", "small");
}
// for (Element element : spanList) {
// updateStyle(element, "font-size", "0.15rem");
// }
Element head = doc.head();
head.append("<meta charset=\"utf-8\">")
.append("<meta name=\"viewport\" content=\"initial-scale=1.0, maximum-scale=1.0, user-scalable=no\" />");
... ... @@ -85,10 +79,9 @@ public class HtmlConvert {
"img{max-width: 100%!important;height:auto}" +
"video{width: 100%;display: block;}" +
"p{padding:0px;overflow: hidden;" +
"font-size:" + TextKits.fontSize(fontSize) + "px;" +
"color:#ffffff;" +
"}" +
"span{color:#ffffff;text-indent:2em;}" +
"span{color:#ffffff;}" +
"</style>");
} else {
head.append("<style>" +
... ... @@ -96,22 +89,15 @@ public class HtmlConvert {
"text-align:justify!important;text-justify:inter-ideograph!important;" +
"word-break:break-all!important;}" +
"img{max-width: 100%!important;height:auto}" +
"p{font-size:" + TextKits.fontSize(fontSize) + "px" +
";}" +
"video{width:100%;}" +
"span{text-indent:2em;}" +
"</style>");
}
// if (listVideo.size() > 0) {
// head.append("<link href=\"file:///android_asset/video-js.min.css\" rel=\"stylesheet\"></link>" +
// "<script src=\"file:///android_asset/video.min.js\"></script>");
// }
List<Element> elements = doc.select("p");
for (Element element : elements) {
List<Element> list1 = element.children();
if (list1 == null || list1.isEmpty()) {
if (!isTextCenter(element)) {
updateStyle(element, "text-indent", "2em");
updateStyle(element, "text-indent", "0em");
}
} else {
int count = 0;
... ... @@ -126,7 +112,7 @@ public class HtmlConvert {
}
}
if (count == 0) {
updateStyle(element, "text-indent", "2em");
updateStyle(element, "text-indent", "0em");
}
}
}
... ... @@ -144,9 +130,6 @@ public class HtmlConvert {
element.removeAttr("class");
String souce = element.attr("src");
if (loadImage(BaseApplication.Companion.getInstance().getApplicationContext())) {
// if (!souce.startsWith("http")) {
// element.attr("src", ConnectUrl.BASE_URL_IMG() + souce);
// }
if (element.hasParent()) {
Element parent = element.parent();
if (parent.tagName().equals("a")) {
... ... @@ -157,14 +140,11 @@ public class HtmlConvert {
String url = "file:///android_res/mipmap/loading_web.png";
element.attr("src", url);
}
// element.attr("onclick",onClick(souce,arr));
}
doc.select("br").remove();
// int fontSize = SettingKits.getFontSize(BaseApplication.Companion.getInstance().getApplicationContext());
int fontSize = 0;
List<Element> spanList = doc.select("span");
for (Element element : spanList) {
updateStyle(element, "font-size", "small");
updateStyle(element, "font-size", "0.15rem");
}
Element head = doc.head();
head.append("<meta charset=\"utf-8\">")
... ... @@ -177,10 +157,9 @@ public class HtmlConvert {
"img{max-width: 100%!important;height:auto}" +
"video{width: 100%;display: block;}" +
"p{padding:0px;overflow: hidden;" +
"font-size:" + TextKits.fontSize(fontSize) + "px;" +
"color:#ffffff;" +
"}" +
"span{color:#ffffff;text-indent:2em;}" +
"span{color:#ffffff;text-indent:0em;}" +
"</style>");
} else {
head.append("<style>" +
... ... @@ -188,10 +167,8 @@ public class HtmlConvert {
"text-align:justify!important;text-justify:inter-ideograph!important;" +
"word-break:break-all!important;}" +
"img{max-width: 100%!important;height:auto}" +
"p{font-size:" + TextKits.fontSize(fontSize) + "px" +
";}" +
"video{width: 100%;height:260;}" +
"span{text-indent:2em;}" +
"span{text-indent:0em;}" +
"</style>");
}
List<Element> elements = doc.select("p");
... ... @@ -199,7 +176,7 @@ public class HtmlConvert {
List<Element> list1 = element.children();
if (list1 == null || list1.isEmpty()) {
if (!isTextCenter(element)) {
updateStyle(element, "text-indent", "2em");
updateStyle(element, "text-indent", "0em");
}
} else {
int count = 0;
... ... @@ -214,7 +191,7 @@ public class HtmlConvert {
}
}
if (count == 0) {
updateStyle(element, "text-indent", "2em");
updateStyle(element, "text-indent", "0m");
}
}
}
... ...
... ... @@ -38,6 +38,7 @@ open class DialogSureCancel(context: Context) : Dialog(context, R.style.UserDefa
// 确定
determine.setOnClickListener {
listener?.determine()
dismiss()
}
}
}
... ...
... ... @@ -16,8 +16,8 @@ class MyWebView(context: Context, attrs: AttributeSet?) : WebView(context, attrs
init {
settings.javaScriptEnabled = true
settings.minimumFontSize = 24.dp2px()
settings.defaultFixedFontSize = 32.dp2px()
settings.minimumFontSize = 14.dp2px()
settings.defaultFixedFontSize = 15.dp2px()
settings.useWideViewPort = true
settings.loadWithOverviewMode = true
settings.allowFileAccess = true
... ...
... ... @@ -94,7 +94,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/history_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:overScrollMode="never"
android:scrollbars="none"
... ...
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout 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">
<TextView
android:id="@+id/tv_no_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="24dp"
android:text="@string/app_name"
android:visibility="gone"
android:drawableTop="@mipmap/search_none" />
<com.scwang.smart.refresh.layout.SmartRefreshLayout
android:id="@+id/smart_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smart.refresh.header.MaterialHeader
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
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" />
android:scrollbars="none" />
<com.scwang.smart.refresh.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
</FrameLayout>
... ...
... ... @@ -5,6 +5,8 @@
android:layout_height="wrap_content"
android:background="@color/white"
android:layout_marginBottom="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:orientation="vertical">
<LinearLayout
... ...