作者 杨谦

1.资料库

2.网页配置
... ... @@ -20,7 +20,7 @@ open class MaterialClassify(
var name: String,
var weigh: Int,
var level: String,
var list: List<MaterialChild>
var child: List<MaterialChild>
)
open class MaterialPage(
... ... @@ -37,6 +37,20 @@ open class MaterialChild(
var type: Int,
var name: String,
var weigh: Int,
var level: String,
var child: List<MaterialChildSecond>?
)
/**
* 资料库分类子次级分类
*/
open class MaterialChildSecond(
var id: Int,
var company_id: Int,
var pid: Int,
var type: Int,
var name: String,
var weigh: Int,
var level: String
)
... ...
... ... @@ -11,6 +11,7 @@ import com.br_technology.securitytrain_master.ui.view.bank.bean.PracticeBean
import com.br_technology.securitytrain_master.ui.view.bank.viewmodel.BankViewModel
import com.br_technology.securitytrain_master.ui.view.home.bean.WorkTypeBean
import com.br_technology.securitytrain_master.util.TYPE_All
import com.br_technology.securitytrain_master.util.sp_job_id
import com.br_technology.securitytrain_master.util.sp_job_id_select
import com.br_technology.securitytrain_master.util.sp_job_name_select
import com.br_technology.securitytrain_master.view.ClassifyPop
... ... @@ -35,7 +36,11 @@ class BankFragment :
DialogStar(requireActivity())
}
private var posId: Int = sp_job_id_select
private var posId: Int = if (sp_job_id_select == 0) {
sp_job_id
} else {
sp_job_id_select
}
override fun initData() {
super.initData()
... ...
... ... @@ -8,12 +8,18 @@ import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.base.common.ConstantParamKey.DOC_ID
import com.br_technology.securitytrain_master.base.network.response.BaseResponse
import com.br_technology.securitytrain_master.base.network.response.CommonPage
import com.br_technology.securitytrain_master.databinding.ActivityDatabaseBinding
import com.br_technology.securitytrain_master.ui.bean.MaterialChild
import com.br_technology.securitytrain_master.ui.bean.MaterialChildSecond
import com.br_technology.securitytrain_master.ui.bean.MaterialClassify
import com.br_technology.securitytrain_master.ui.bean.MaterialPage
import com.br_technology.securitytrain_master.ui.view.home.adapter.ClassifyAdapter
import com.br_technology.securitytrain_master.ui.view.home.adapter.RecommendDataAdapter
import com.br_technology.securitytrain_master.ui.view.home.bean.RecommendBean
import com.br_technology.securitytrain_master.ui.view.home.viewmodel.DatabaseFViewModel
import com.br_technology.securitytrain_master.view.DatabaseListPop
import com.br_technology.securitytrain_master.view.listener.OnItemClickListener
import com.google.android.material.tabs.TabLayout
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
... ... @@ -25,11 +31,28 @@ import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
*/
class DatabaseActivity :
BaseLifeCycleActivity<DatabaseFViewModel, ActivityDatabaseBinding>(ActivityDatabaseBinding::inflate) {
var page = 1
var mClassifyAdapter: ClassifyAdapter? = null
var mRecommendAdapter: RecommendDataAdapter? = null
private var mRecommendAdapter: RecommendDataAdapter? = null
private var popData: DatabaseListPop? = null
private fun showPopData() {
popData = DatabaseListPop(this)
val list = mViewModel.selectClassify.value?.child
var popChild = mViewModel.popChild.value
if (popChild == null) {
popChild = mViewModel.sortChild.value
}
mViewModel.sortSecond.value?.let { second -> popData?.addList(list!!, second, popChild!!) }
popData?.iClickChild = object : DatabaseListPop.IClickChild {
override fun child(child: MaterialChild, data: MaterialChildSecond) {
mViewModel.popChild.value = child
mViewModel.sortSecond.value = data
}
}
popData?.showAsDropDown(binding.type)
}
override fun initView() {
super.initView()
... ... @@ -97,6 +120,10 @@ class DatabaseActivity :
}
}
})
type.setOnClickListener {
showPopData()
}
}
}
... ... @@ -124,7 +151,7 @@ class DatabaseActivity :
binding.classify.adapter = mClassifyAdapter
mClassifyAdapter?.addListener(object : OnItemClickListener<MaterialClassify> {
override fun onClick(position: Int, data: MaterialClassify) {
mViewModel.sortId.value = data.id
val list = data.child
mClassifyAdapter?.let { classifyAdapter ->
val oldIndex = classifyAdapter.index;
if (oldIndex != position) {
... ... @@ -135,15 +162,37 @@ class DatabaseActivity :
classifyAdapter.notifyItemChanged(position)
}
}
if (list.isNotEmpty()) {
mViewModel.selectClassify.value = data
} else {
mViewModel.classifyDataList.value = BaseResponse(
MaterialPage(CommonPage(0, "10", 1, 1, listOf()))
)
}
}
})
if (data.list.isNotEmpty()) {
page = 1
mViewModel.sortId.value = data.list[0].id
val dataClassify = data.list[0]
mViewModel.selectClassify.value = dataClassify
}
})
mViewModel.sortId.observe(this, {
mViewModel.selectClassify.observe(this, {
val list = it.child
if (list.isNotEmpty()) {
mViewModel.sortChild.value = list[0]
mViewModel.popChild.value = list[0]
}
})
mViewModel.sortSecond.observe(this, {
mViewModel.getDataList(page)
binding.type.text = it.name
})
mViewModel.sortChild.observe(this, {
val child = it.child
if (child != null && child.isNotEmpty()) {
mViewModel.sortSecond.value = child[0]
}
})
mViewModel.classifyDataList.observe(this, {
val data = it.data
... ...
package com.br_technology.securitytrain_master.ui.view.home.activity
import android.annotation.SuppressLint
import android.content.Intent
import android.net.http.SslError
import android.os.Build
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 android.webkit.*
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
... ... @@ -25,13 +24,15 @@ import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
* auth:张继
* des:
*/
class WebViewActivity : BaseLifeCycleActivity<BaseViewModel<BaseRepository>,ActivityWebBinding>(ActivityWebBinding::inflate) {
class WebViewActivity :
BaseLifeCycleActivity<BaseViewModel<BaseRepository>, ActivityWebBinding>(ActivityWebBinding::inflate) {
var webView: WebView? = null
override fun initData() {
intent.getStringExtra(COMMON_URL)?.let { webView?.loadUrl(it) }
}
@SuppressLint("SetJavaScriptEnabled")
override fun initView() {
webView = findViewById(R.id.web_view)
val toolBar = findViewById<ViewToolBar>(R.id.tool_bar)
... ... @@ -46,8 +47,64 @@ class WebViewActivity : BaseLifeCycleActivity<BaseViewModel<BaseRepository>,Acti
}
}
})
webView?.settings?.let {
it.javaScriptEnabled = true
val ws = webView!!.settings
// 网页内容的宽度是否可大于WebView控件的宽度
// 网页内容的宽度是否可大于WebView控件的宽度
ws.loadWithOverviewMode = false
// 保存表单数据
// 保存表单数据
ws.saveFormData = true
// 是否应该支持使用其屏幕缩放控件和手势缩放
// 是否应该支持使用其屏幕缩放控件和手势缩放
ws.setSupportZoom(true)
ws.builtInZoomControls = true
ws.displayZoomControls = false
ws.allowFileAccessFromFileURLs = true
ws.allowFileAccess = true
// 启动应用缓存
// 启动应用缓存
ws.setAppCacheEnabled(true)
// 设置缓存模式
// 设置缓存模式
ws.cacheMode = WebSettings.LOAD_DEFAULT
// setDefaultZoom api19被弃用
// 设置此属性,可任意比例缩放。
// setDefaultZoom api19被弃用
// 设置此属性,可任意比例缩放。
ws.useWideViewPort = true
// 不缩放
// 不缩放
webView!!.setInitialScale(100)
// 告诉WebView启用JavaScript执行。默认的是false。
// 告诉WebView启用JavaScript执行。默认的是false。
ws.javaScriptEnabled = true
// 页面加载好以后,再放开图片
// 页面加载好以后,再放开图片
ws.blockNetworkImage = false
// 使用localStorage则必须打开
// 使用localStorage则必须打开
ws.domStorageEnabled = true
// 排版适应屏幕
// 排版适应屏幕
ws.layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS
// WebView是否新窗口打开(加了后可能打不开网页)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ws.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
}
}
// WebView.setWebContentsDebuggingEnabled(true)
webView?.webViewClient =
object : WebViewClient() {
override fun onReceivedSslError(
view: WebView?,
handler: SslErrorHandler?,
error: SslError?
) {
super.onReceivedSslError(view, handler, error)
handler?.proceed()
}
override fun shouldOverrideUrlLoading(
view: WebView?,
... ... @@ -59,14 +116,13 @@ class WebViewActivity : BaseLifeCycleActivity<BaseViewModel<BaseRepository>,Acti
Intent(
this@WebViewActivity,
FileReadActivity::class.java
).putExtra(ConstantParamKey.COMMON_URL, url.toString())
).putExtra(COMMON_URL, url.toString())
)
return true
}
}
return !request?.url.toString().contains("http") || !request?.url.toString()
.startsWith("http")
}
}
... ...
... ... @@ -161,9 +161,11 @@ class HomeFragment :
.into(it.imageView)
it.imageView.setOnClickListener {
data?.let { res ->
val url = "https://mobile.anqixing.com"
startActivity(
Intent(requireContext(), WebViewActivity::class.java)
.putExtra(COMMON_URL, res.href)
// .putExtra(COMMON_URL, res.href)
.putExtra(COMMON_URL, url)
)
}
}
... ...
... ... @@ -7,9 +7,7 @@ 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
import com.br_technology.securitytrain_master.ui.bean.*
/**
* createTime:2021/7/27 15:48
... ... @@ -26,7 +24,11 @@ class DatabaseFViewModel : BaseViewModel<DocRepository>() {
val classify = MutableLiveData<BaseResponse<CommonList<MaterialClassify>>>()
val classifyDataList = MutableLiveData<BaseResponse<MaterialPage>>()
val type = MutableLiveData<Int>()
val sortId = MutableLiveData<Int>()
val selectClassify = MutableLiveData<MaterialClassify>()
val sortChild = MutableLiveData<MaterialChild>()
val sortSecond = MutableLiveData<MaterialChildSecond>()
val popChild = MutableLiveData<MaterialChild>()
var favoriteResponse = MutableLiveData<BaseResponse<Void>>()
fun collect(
... ... @@ -43,10 +45,10 @@ class DatabaseFViewModel : BaseViewModel<DocRepository>() {
fun getDataList(page: Int) {
type.value?.let {
sortId.value?.let { it1 ->
sortSecond.value?.let { it1 ->
mRepository.getDocList(
it,
it1, "", page, 10, classifyDataList
it1.id, "", page, 10, classifyDataList
)
}
}
... ...
package com.br_technology.securitytrain_master.view
import android.app.Activity
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import androidx.core.content.ContextCompat
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.base.view.BaseAdapter
import com.br_technology.securitytrain_master.databinding.ItemDatabaseChild1Binding
import com.br_technology.securitytrain_master.databinding.ItemDatabaseChild2Binding
import com.br_technology.securitytrain_master.databinding.PopDatabaseListBinding
import com.br_technology.securitytrain_master.expand.addItemDecorationCustom
import com.br_technology.securitytrain_master.expand.screenHeight
import com.br_technology.securitytrain_master.expand.screenWidth
import com.br_technology.securitytrain_master.ui.bean.MaterialChild
import com.br_technology.securitytrain_master.ui.bean.MaterialChildSecond
class DatabaseListPop(activity: Activity) : PopupWindow(activity) {
private var mMaterialChild = mutableListOf<MaterialChild>()
private val binding by lazy {
PopDatabaseListBinding.inflate(LayoutInflater.from(activity))
}
var iClickChild: IClickChild? = null
private var childAdapter: DataListChild1? = null
private var childSecond: MaterialChildSecond? = null
private var child: MaterialChild? = null
interface IClickChild {
fun child(child: MaterialChild, data: MaterialChildSecond)
}
init {
contentView = binding.root
width = contentView.screenWidth()
height = contentView.screenHeight()
setBackgroundDrawable(ContextCompat.getDrawable(activity, android.R.color.transparent))
isOutsideTouchable = false
binding.apply {
dataList.addItemDecorationCustom(1)
childAdapter = DataListChild1().apply {
addList(mMaterialChild)
}
dataList.adapter = childAdapter
}
}
fun addList(list: List<MaterialChild>, second: MaterialChildSecond, child: MaterialChild) {
childAdapter?.addList(list)
childSecond = second
this.child = child
}
inner class DataListChild1 : BaseAdapter<MaterialChild, ItemDatabaseChild1Binding>() {
override fun getViewBinding(
context: Context,
parent: ViewGroup,
viewType: Int,
from: LayoutInflater
): ItemDatabaseChild1Binding {
return ItemDatabaseChild1Binding.inflate(from, parent, false)
}
override fun onBind(holder: ItemDatabaseChild1Binding, position: Int, data: MaterialChild) {
holder.tvTitleChild1.text = data.name
holder.tvTitleChild1.setTextColor(
ContextCompat.getColor(
binding.root.context,
R.color.color_26292C
)
)
data.child?.let {
holder.listChild.adapter = DataListChild2().apply {
addList(it)
setChild(data)
}
}
val isChild = child?.id == data.id
holder.listChild.visibility = if (isChild) {
View.VISIBLE
} else {
View.GONE
}
holder.llTitle.setOnClickListener {
val isVis = holder.listChild.visibility == View.VISIBLE
holder.listChild.visibility = if (isVis) {
View.GONE
} else {
View.VISIBLE
}
}
}
}
inner class DataListChild2 : BaseAdapter<MaterialChildSecond, ItemDatabaseChild2Binding>() {
override fun getViewBinding(
context: Context,
parent: ViewGroup,
viewType: Int,
from: LayoutInflater
): ItemDatabaseChild2Binding {
return ItemDatabaseChild2Binding.inflate(from, parent, false)
}
private var childData: MaterialChild? = null
fun setChild(child: MaterialChild) {
childData = child
}
override fun onBind(
holder: ItemDatabaseChild2Binding,
position: Int,
data: MaterialChildSecond
) {
val bool = childSecond != null && childSecond?.id == data.id
val color = if (bool) {
ContextCompat.getColor(binding.root.context, R.color.color_25)
} else {
ContextCompat.getColor(binding.root.context, R.color.color_26292C)
}
holder.tvTitleChild2.setTextColor(color)
holder.tvTitleChild2.text = data.name
holder.tvTitleChild2.setOnClickListener {
childData?.let {
if (iClickChild != null) {
iClickChild!!.child(childData!!, data)
}
}
dismiss()
}
}
}
}
... ...
... ... @@ -26,7 +26,7 @@
android:nestedScrollingEnabled="false"
android:overScrollMode="never"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"></androidx.recyclerview.widget.RecyclerView>
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
\ No newline at end of file
... ...
... ... @@ -36,6 +36,7 @@
android:id="@+id/classify"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:overScrollMode="never"
android:paddingTop="10dp"
... ... @@ -45,7 +46,7 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_height="30dp"
android:background="@color/color_f2f3">
<TextView
... ... @@ -59,7 +60,7 @@
android:text="通用知识"
android:textColor="@color/color_25"
android:textSize="12sp"
android:visibility="gone" />
android:visibility="visible" />
</FrameLayout>
<FrameLayout
... ...
... ... @@ -14,16 +14,12 @@
android:visibility="visible"
app:toolTitle="课程详情" />
<!-- <com.br_technology.securitytrain_master.view.MyVideoPlayer-->
<!-- android:id="@+id/video_player"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="210dp" />-->
<ImageView
android:scaleType="fitXY"
android:id="@+id/iv_top"
android:layout_width="match_parent"
android:layout_height="210dp"/>
android:layout_height="210dp"
android:contentDescription="@null" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
... ...
... ... @@ -2,7 +2,7 @@
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/classify"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="28dp"
android:background="@drawable/classify_text_back"
android:gravity="center"
android:paddingStart="16dp"
... ...
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_title"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/white"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<TextView
android:id="@+id/tv_title_child_1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:rotation="90"
android:src="@mipmap/ic_arrow" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@color/color_c8" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_child"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:overScrollMode="never"
android:scrollbars="none"
android:visibility="gone"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>
\ No newline at end of file
... ...
<?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="vertical">
<TextView
android:id="@+id/tv_title_child_2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/white"
android:gravity="center_vertical"
android:paddingStart="26dp"
android:paddingEnd="26dp" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@color/color_c8" />
</LinearLayout>
... ...
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="@android:color/transparent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="?actionBarSize" />
<View
android:layout_width="match_parent"
android:layout_height="80dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/data_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:overScrollMode="never"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>
\ No newline at end of file
... ...