Skip to content

Commit

Permalink
sample: 示例-嵌套列表
Browse files Browse the repository at this point in the history
  • Loading branch information
liangjingkanji committed Jan 14, 2023
1 parent 5bba340 commit 8c7a64e
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.drake.brv.sample.model

@kotlinx.serialization.Serializable
data class NestedListModel(
var title: String = "",
var list: List<String> = listOf()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.drake.brv.sample.ui.fragment

import com.drake.brv.sample.R
import com.drake.brv.sample.component.net.SerializationConverter
import com.drake.brv.sample.databinding.FragmentNestedListBinding
import com.drake.brv.sample.databinding.ItemNestedHorizontalRvBinding
import com.drake.brv.sample.model.NestedListModel
import com.drake.brv.utils.models
import com.drake.brv.utils.setup
import com.drake.engine.base.EngineFragment
import kotlinx.serialization.json.decodeFromStream

class NestedListFragment : EngineFragment<FragmentNestedListBinding>(R.layout.fragment_nested_list) {
override fun initView() {
binding.rv.setup {
addType<NestedListModel>(R.layout.item_nested_horizontal_rv)
onCreate {
getBinding<ItemNestedHorizontalRvBinding>().rv.setup {
addType<String>(R.layout.item_simple_horizontal)
}
}
onBind {
val model = getModel<NestedListModel>()
getBinding<ItemNestedHorizontalRvBinding>().rv.models = model.list
}
}
}

override fun initData() {
binding.rv.models = SerializationConverter.jsonDecoder.decodeFromStream<List<NestedListModel>>(resources.openRawResource(R.raw.list_nested))
}
}
26 changes: 5 additions & 21 deletions sample/src/main/res/drawable/ic_group.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
<!--
~ Copyright (C) 2018 Drake, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M2,17h2v0.5L3,17.5v1h1v0.5L2,19v1h3v-4L2,16v1zM3,8h1L4,4L2,4v1h1v3zM2,11h1.8L2,13.1v0.9h3v-1L3.2,13L5,10.9L5,10L2,10v1zM7,5v2h14L21,5L7,5zM7,19h14v-2L7,17v2zM7,13h14v-2L7,11v2z" />
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M9,18h12v-2L9,16v2zM3,6v2h18L21,6L3,6zM9,13h12v-2L9,11v2z"
android:fillColor="#000000" />
</vector>
9 changes: 9 additions & 0 deletions sample/src/main/res/drawable/ic_nested_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M5,13h14v-2L5,11v2zM3,17h14v-2L3,15v2zM7,7v2h14L21,7L7,7z"
android:fillColor="#000000" />
</vector>
11 changes: 11 additions & 0 deletions sample/src/main/res/layout/fragment_nested_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</layout>
40 changes: 40 additions & 0 deletions sample/src/main/res/layout/item_nested_horizontal_rv.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="m"
type="com.drake.brv.sample.model.NestedListModel" />

</data>

<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="20dp">

<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:paddingHorizontal="16dp"
android:text="@{m.title}"
android:textSize="18dp"
android:textStyle="bold"
tools:text="视频" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_simple_horizontal" />

</androidx.appcompat.widget.LinearLayoutCompat>
</layout>
33 changes: 33 additions & 0 deletions sample/src/main/res/layout/item_simple_horizontal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2018 Drake, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<layout xmlns:android="http://schemas.android.com/apk/res/android">

<FrameLayout
android:id="@+id/item"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="16dp"
android:background="@drawable/bg_card"
android:foreground="?selectableItemBackgroundBorderless">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />

</FrameLayout>
</layout>
4 changes: 4 additions & 0 deletions sample/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
android:id="@+id/nav_group.xml"
android:icon="@drawable/ic_group"
android:title="分组" />
<item
android:id="@+id/nestedListFragment"
android:icon="@drawable/ic_nested_list"
android:title="嵌套列表" />
<item
android:id="@+id/nav_hover_header.xml"
android:icon="@drawable/ic_hover_header"
Expand Down
5 changes: 5 additions & 0 deletions sample/src/main/res/navigation/nav_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
android:name="com.drake.brv.sample.ui.fragment.home.HomeFragment"
android:label="首页布局"
tools:layout="@layout/fragment_home" />
<fragment
android:id="@+id/nestedListFragment"
android:name="com.drake.brv.sample.ui.fragment.NestedListFragment"
android:label="嵌套列表"
tools:layout="@layout/fragment_nested_list" />
<fragment
android:id="@+id/checkModeFragment"
android:name="com.drake.brv.sample.ui.fragment.CheckModeFragment"
Expand Down
93 changes: 93 additions & 0 deletions sample/src/main/res/raw/list_nested.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[
{
"title": "推荐",
"list": [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
]
},
{
"title": "课堂",
"list": [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
]
},
{
"title": "视频",
"list": [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
]
},
{
"title": "分享",
"list": [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
]
},
{
"title": "文档",
"list": [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
]
},
{
"title": "分享",
"list": [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
]
},
{
"title": "其他",
"list": [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
]
}
]

0 comments on commit 8c7a64e

Please sign in to comment.