作者 zhangji

在线课程写完

... ... @@ -27,6 +27,7 @@ fun View.screenWidth(): Int {
manager.defaultDisplay.getRealSize(point)
return point.x
}
fun View.screenHeight(): Int {
val manager: WindowManager =
this.context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
... ... @@ -35,7 +36,7 @@ fun View.screenHeight(): Int {
return point.y
}
fun RecyclerView.addItemDecoration(spanCount: Int, spacing: Int) {
fun RecyclerView.addItemDecoration3(spanCount: Int, spacing: Int) {
this.addItemDecoration(object : RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
... ... @@ -47,17 +48,42 @@ fun RecyclerView.addItemDecoration(spanCount: Int, spacing: Int) {
//这里是关键,需要根据你有几列来判断
val position: Int = parent.getChildAdapterPosition(view) // item position
val column = position % spanCount // item column
outRect.top=32
outRect.top = 32
when (column) {
0->{
outRect.right=spacing
0 -> {
outRect.right = spacing
}
1 -> {
outRect.left = spacing
outRect.right = spacing
}
else -> {
outRect.left = spacing
}
1->{
outRect.left=spacing
outRect.right=spacing
}
}
})
}
fun RecyclerView.addItemDecoration2(spanCount: Int, spacing: Int) {
this.addItemDecoration(object : RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
super.getItemOffsets(outRect, view, parent, state)
//这里是关键,需要根据你有几列来判断
val position: Int = parent.getChildAdapterPosition(view) // item position
when (position % spanCount) {
0 -> {
outRect.top = 24
outRect.right = spacing
}
else->{
outRect.left=spacing
else -> {
outRect.top = 24
outRect.left = spacing
}
}
}
... ...
package com.br_technology.securitytrain_master.ui.home.activity
import android.os.Bundle
import android.view.View
import androidx.core.content.ContextCompat
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.ui.home.adapter.VideoCourseAdapter
import com.br_technology.securitytrain_master.ui.home.pojo.VideoCourse
import com.br_technology.securitytrain_master.ui.home.viewmodel.OnlineViewModel
import com.br_technology.securitytrain_master.view.ClassifyPop
import com.br_technology.securitytrain_master.view.listener.ToolBarClickListener
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
/**
... ... @@ -15,9 +20,33 @@ import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
*/
class OnlineActivity :
BaseLifeCycleActivity<OnlineViewModel, ActivityOnlineBinding>(ActivityOnlineBinding::inflate) {
private val classifyPop by lazy {
ClassifyPop(this)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.apply {
toolBar.setRightText("焊工")
toolBar.setRightTextDrawable(
ContextCompat.getDrawable(
baseContext,
R.mipmap.down_arrow
)
)
toolBar.addRightListener(object : ToolBarClickListener {
override fun onClick(view: View) {
if (!classifyPop.isShowing) {
classifyPop.showAsDropDown(view)
}
}
})
onlineRecycler.addItemDecoration2(2, 15)
val videoCourseAdapter = VideoCourseAdapter()
val list = mutableListOf(
VideoCourse(R.mipmap.banner, "10课时", "自动化制作课程", "", "张钧-三岗职位培训班"),
... ... @@ -35,6 +64,7 @@ class OnlineActivity :
videoCourseAdapter.addList(list)
}
}
override fun initDataObserver() {
}
... ...
package com.br_technology.securitytrain_master.ui.home.activity
import android.graphics.Rect
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.databinding.ActivityTextCourseBinding
import com.br_technology.securitytrain_master.expand.addItemDecoration
import com.br_technology.securitytrain_master.ui.home.adapter.ResultAdapter
import com.br_technology.securitytrain_master.ui.home.adapter.TextCourseTypeAdapter
import com.br_technology.securitytrain_master.ui.home.pojo.RecommendData
import com.br_technology.securitytrain_master.ui.home.viewmodel.TextCourseViewModel
import com.br_technology.securitytrain_master.view.ClassifyPop
... ... @@ -44,7 +39,6 @@ class TextCourseActivity :
)
toolBar.addRightListener(object : ToolBarClickListener {
override fun onClick(view: View) {
// courseTypeGroup.visibility = View.VISIBLE
if (!classifyPop.isShowing) {
classifyPop.showAsDropDown(view)
}
... ... @@ -116,33 +110,6 @@ class TextCourseActivity :
})
courseRecycler.adapter = resultAdapter
resultAdapter.addList(recommendList)
complete.setOnClickListener {
courseTypeGroup.visibility = View.GONE
}
courseType.addItemDecoration(3, 14)
val list = listOf(
"测试",
"岗位1",
"岗位2",
"岗位3",
"gangw4",
"岗位5",
"岗位6",
"岗位8",
"岗位7",
"岗位9",
)
val textCourseTypeAdapter = TextCourseTypeAdapter()
textCourseTypeAdapter.addListener(object : OnItemClickListener<String> {
override fun onClick(position: Int, data: String) {
textCourseTypeAdapter.index = position
textCourseTypeAdapter.notifyDataSetChanged()
}
})
courseType.adapter = textCourseTypeAdapter
textCourseTypeAdapter.addList(list)
}
}
... ...
... ... @@ -12,6 +12,7 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.databinding.FragmentHomeBinding
import com.br_technology.securitytrain_master.expand.addItemDecoration2
import com.br_technology.securitytrain_master.ui.home.activity.DatabaseActivity
import com.br_technology.securitytrain_master.ui.home.activity.OnlineActivity
import com.br_technology.securitytrain_master.ui.home.activity.SearchActivity
... ... @@ -90,23 +91,7 @@ class HomeFragment :
}
// 视频课程
videoCourse.addItemDecoration(object : RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
super.getItemOffsets(outRect, view, parent, state)
if (parent.getChildAdapterPosition(view) % 2 == 0) {
outRect.top = 24
outRect.right = 15
} else {
outRect.top = 24
outRect.left = 15
}
}
})
videoCourse.addItemDecoration2(2,15)
val videoCourseAdapter = VideoCourseAdapter()
val list = mutableListOf(
VideoCourse(R.mipmap.banner, "10课时", "自动化制作课程", "", "张钧-三岗职位培训班"),
... ...
... ... @@ -3,14 +3,13 @@ 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.Window
import android.widget.PopupWindow
import androidx.core.content.ContextCompat
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.databinding.PopClassifyBinding
import com.br_technology.securitytrain_master.expand.addItemDecoration
import com.br_technology.securitytrain_master.expand.dp2px
import com.br_technology.securitytrain_master.expand.screenHeight
import com.br_technology.securitytrain_master.expand.screenWidth
import com.br_technology.securitytrain_master.expand.*
import com.br_technology.securitytrain_master.ui.home.adapter.TextCourseTypeAdapter
import com.br_technology.securitytrain_master.view.listener.OnItemClickListener
... ... @@ -26,24 +25,16 @@ class ClassifyPop(context: Activity) : PopupWindow(context) {
}
init {
contentView = binding.root
width = contentView.screenWidth()
height = 252.dp2px()
height = contentView.screenHeight()
setBackgroundDrawable(ContextCompat.getDrawable(context, android.R.color.transparent))
isOutsideTouchable = false
// val attributes = context.window.attributes
// attributes.alpha = 0.5f
// context.window.attributes = attributes
//
// setOnDismissListener {
// val attributes = context.window.attributes
// attributes.alpha = 1f
// context.window.attributes = attributes
// }
binding.apply {
courseType.addItemDecoration(3, 14)
courseType.addItemDecoration3(3, 14)
val list = listOf(
"测试",
"岗位1",
... ...
... ... @@ -10,7 +10,8 @@
<com.br_technology.securitytrain_master.view.ViewToolBar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
app:toolTitle="在线课程" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/online_recycler"
... ... @@ -19,7 +20,8 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:overScrollMode="never"
android:paddingTop="16dp"
android:paddingTop="4dp"
android:paddingBottom="12dp"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2" />
... ...
... ... @@ -13,69 +13,15 @@
android:layout_height="wrap_content"
app:toolTitle="文本课程" />
<RelativeLayout
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/course_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/course_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:overScrollMode="never"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<LinearLayout
android:id="@+id/course_type_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="252dp"
android:background="@color/white"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/course_type"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
android:overScrollMode="never"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="3" />
<TextView
android:id="@+id/complete"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="16dp"
android:background="@drawable/solid_25_4"
android:gravity="center"
android:text="完成"
android:textColor="@color/white"
android:textSize="15sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:alpha="0.3"
android:background="@color/black" />
</LinearLayout>
</RelativeLayout>
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:overScrollMode="never"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>
\ No newline at end of file
... ...
... ... @@ -3,31 +3,49 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:background="@android:color/transparent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/course_type"
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
android:overScrollMode="never"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="3" />
android:layout_height="?actionBarSize" />
<TextView
android:id="@+id/complete"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="16dp"
android:background="@drawable/solid_25_4"
android:gravity="center"
android:text="完成"
android:textColor="@color/white"
android:textSize="15sp" />
android:layout_height="252dp"
android:background="@color/white"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/course_type"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
android:overScrollMode="never"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:scrollbars="none"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="3" />
<TextView
android:id="@+id/complete"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="16dp"
android:background="@drawable/solid_25_4"
android:gravity="center"
android:text="完成"
android:textColor="@color/white"
android:textSize="15sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:alpha="0.5"
android:background="@color/black" />
</LinearLayout>
\ No newline at end of file
... ...