Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_40328769
BaseRecyclerViewAdapterHelper
提交
53644d00
B
BaseRecyclerViewAdapterHelper
项目概览
qq_40328769
/
BaseRecyclerViewAdapterHelper
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
BaseRecyclerViewAdapterHelper
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
53644d00
编写于
1月 03, 2020
作者:
limuyang2
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug
上级
453767de
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
106 addition
and
35 deletion
+106
-35
app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/node/NodeTreeUseActivity.java
...rviewadapterhelper/activity/node/NodeTreeUseActivity.java
+3
-1
app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/NodeTreeAdapter.java
...rviewadapterhelper/adapter/node/tree/NodeTreeAdapter.java
+2
-0
app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/FirstProvider.java
...apterhelper/adapter/node/tree/provider/FirstProvider.java
+44
-3
app/src/main/res/layout/item_node_first.xml
app/src/main/res/layout/item_node_first.xml
+2
-2
library/src/main/java/com/chad/library/adapter/base/BaseNodeAdapter.kt
...ain/java/com/chad/library/adapter/base/BaseNodeAdapter.kt
+51
-25
library/src/main/java/com/chad/library/adapter/base/viewholder/BaseViewHolder.kt
...om/chad/library/adapter/base/viewholder/BaseViewHolder.kt
+4
-4
未找到文件。
app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/node/NodeTreeUseActivity.java
浏览文件 @
53644d00
...
...
@@ -45,7 +45,9 @@ public class NodeTreeUseActivity extends BaseActivity {
nodes
.
add
(
seNode
);
nodes
.
add
(
seNode2
);
//第一个夫node,位置为子node的3号位置
adapter
.
nodeAddData
(
adapter
.
getData
().
get
(
0
),
2
,
nodes
);
// adapter.nodeAddData(adapter.getData().get(0), 2, nodes);
// adapter.nodeSetData(adapter.getData().get(0), 2, seNode2);
adapter
.
nodeReplaceChildData
(
adapter
.
getData
().
get
(
0
),
nodes
);
Tips
.
show
(
"新插入了两个node"
,
Toast
.
LENGTH_LONG
);
}
},
2000
);
...
...
app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/NodeTreeAdapter.java
浏览文件 @
53644d00
...
...
@@ -34,4 +34,6 @@ public class NodeTreeAdapter extends BaseNodeAdapter {
}
return
-
1
;
}
public
static
final
int
EXPAND_COLLAPSE_PAYLOAD
=
110
;
}
app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/node/tree/provider/FirstProvider.java
浏览文件 @
53644d00
package
com.chad.baserecyclerviewadapterhelper.adapter.node.tree.provider
;
import
android.view.View
;
import
android.view.animation.DecelerateInterpolator
;
import
android.widget.ImageView
;
import
androidx.core.view.ViewCompat
;
import
com.chad.baserecyclerviewadapterhelper.R
;
import
com.chad.baserecyclerviewadapterhelper.adapter.node.tree.NodeTreeAdapter
;
import
com.chad.baserecyclerviewadapterhelper.entity.node.tree.FirstNode
;
import
com.chad.library.adapter.base.entity.node.BaseNode
;
import
com.chad.library.adapter.base.provider.BaseNodeProvider
;
...
...
@@ -11,6 +16,8 @@ import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
java.util.List
;
public
class
FirstProvider
extends
BaseNodeProvider
{
@Override
...
...
@@ -27,16 +34,50 @@ public class FirstProvider extends BaseNodeProvider {
public
void
convert
(
@NotNull
BaseViewHolder
helper
,
@Nullable
BaseNode
data
)
{
FirstNode
entity
=
(
FirstNode
)
data
;
helper
.
setText
(
R
.
id
.
title
,
entity
.
getTitle
());
helper
.
setImageResource
(
R
.
id
.
iv
,
R
.
mipmap
.
arrow_r
);
setArrowSpin
(
helper
,
data
,
false
);
}
@Override
public
void
convert
(
@NotNull
BaseViewHolder
helper
,
@Nullable
BaseNode
data
,
@NotNull
List
<?>
payloads
)
{
for
(
Object
payload
:
payloads
)
{
if
(
payload
instanceof
Integer
&&
(
int
)
payload
==
NodeTreeAdapter
.
EXPAND_COLLAPSE_PAYLOAD
)
{
// 增量刷新,使用动画变化箭头
setArrowSpin
(
helper
,
data
,
true
);
}
}
}
private
void
setArrowSpin
(
BaseViewHolder
helper
,
BaseNode
data
,
boolean
isAnimate
)
{
FirstNode
entity
=
(
FirstNode
)
data
;
ImageView
imageView
=
helper
.
getView
(
R
.
id
.
iv
);
if
(
entity
.
isExpanded
())
{
helper
.
setImageResource
(
R
.
id
.
iv
,
R
.
mipmap
.
arrow_b
);
if
(
isAnimate
)
{
ViewCompat
.
animate
(
imageView
).
setDuration
(
200
)
.
setInterpolator
(
new
DecelerateInterpolator
())
.
rotation
(
0
f
)
.
start
();
}
else
{
imageView
.
setRotation
(
0
f
);
}
}
else
{
helper
.
setImageResource
(
R
.
id
.
iv
,
R
.
mipmap
.
arrow_r
);
if
(
isAnimate
)
{
ViewCompat
.
animate
(
imageView
).
setDuration
(
200
)
.
setInterpolator
(
new
DecelerateInterpolator
())
.
rotation
(
90
f
)
.
start
();
}
else
{
imageView
.
setRotation
(
90
f
);
}
}
}
@Override
public
void
onClick
(
@NotNull
BaseViewHolder
helper
,
@NotNull
View
view
,
BaseNode
data
,
int
position
)
{
getAdapter
().
expandOrCollapse
(
position
);
// 这里使用payload进行增量刷新(避免整个item刷新导致的闪烁,不自然)
getAdapter
().
expandOrCollapse
(
position
,
true
,
true
,
NodeTreeAdapter
.
EXPAND_COLLAPSE_PAYLOAD
);
}
}
app/src/main/res/layout/item_node_first.xml
浏览文件 @
53644d00
...
...
@@ -5,7 +5,8 @@
android:layout_marginBottom=
"1dp"
android:background=
"@android:color/white"
android:gravity=
"center_vertical"
android:orientation=
"horizontal"
>
android:orientation=
"horizontal"
android:paddingRight=
"16dp"
>
<ImageView
android:id=
"@+id/iv_head"
...
...
@@ -30,6 +31,5 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"right|center"
android:paddingRight=
"16dp"
android:src=
"@mipmap/arrow_r"
/>
</LinearLayout>
\ No newline at end of file
library/src/main/java/com/chad/library/adapter/base/BaseNodeAdapter.kt
浏览文件 @
53644d00
...
...
@@ -9,7 +9,6 @@ import com.chad.library.adapter.base.entity.node.NodeFooterImp
import
com.chad.library.adapter.base.provider.BaseItemProvider
import
com.chad.library.adapter.base.provider.BaseNodeProvider
import
com.chad.library.adapter.base.viewholder.BaseViewHolder
import
kotlin.math.max
abstract
class
BaseNodeAdapter
(
data
:
MutableList
<
BaseNode
>?
=
null
)
:
BaseProviderMultiAdapter
<
BaseNode
>(
data
)
{
...
...
@@ -131,7 +130,14 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
val
newFlatData
=
flatData
(
arrayListOf
(
data
))
this
.
data
.
addAll
(
index
,
newFlatData
)
notifyItemRangeChanged
(
index
+
getHeaderLayoutCount
(),
max
(
removeCount
,
newFlatData
.
size
))
if
(
removeCount
==
newFlatData
.
size
)
{
notifyItemRangeChanged
(
index
+
getHeaderLayoutCount
(),
removeCount
)
}
else
{
notifyItemRangeRemoved
(
index
+
getHeaderLayoutCount
(),
removeCount
)
notifyItemRangeInserted
(
index
+
getHeaderLayoutCount
(),
newFlatData
.
size
)
// notifyItemRangeChanged(index + getHeaderLayoutCount(), max(removeCount, newFlatData.size)
}
}
/**
...
...
@@ -369,7 +375,6 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
val
parentIndex
=
this
.
data
.
indexOf
(
parentNode
)
val
removeCount
=
removeChildAt
(
parentIndex
)
notifyItemRangeRemoved
(
parentIndex
+
1
+
getHeaderLayoutCount
(),
removeCount
)
it
.
clear
()
it
.
addAll
(
newData
)
...
...
@@ -377,7 +382,13 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
val
newFlatData
=
flatData
(
newData
)
this
.
data
.
addAll
(
parentIndex
+
1
,
newFlatData
)
notifyItemRangeInserted
(
parentIndex
+
1
+
getHeaderLayoutCount
(),
newFlatData
.
size
)
val
positionStart
=
parentIndex
+
1
+
getHeaderLayoutCount
()
if
(
removeCount
==
newFlatData
.
size
)
{
notifyItemRangeChanged
(
positionStart
,
removeCount
)
}
else
{
notifyItemRangeRemoved
(
positionStart
,
removeCount
)
notifyItemRangeInserted
(
positionStart
,
newFlatData
.
size
)
}
// notifyItemRangeChanged(parentIndex + 1 + getHeaderLayoutCount(), max(removeCount, newFlatData.size))
}
}
...
...
@@ -438,7 +449,8 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
private
fun
collapse
(
@IntRange
(
from
=
0
)
position
:
Int
,
isChangeChildCollapse
:
Boolean
=
false
,
animate
:
Boolean
=
true
,
notify
:
Boolean
=
true
):
Int
{
notify
:
Boolean
=
true
,
parentPayload
:
Any
?
=
null
):
Int
{
val
node
=
this
.
data
[
position
]
if
(
node
is
BaseExpandNode
&&
node
.
isExpanded
)
{
...
...
@@ -446,7 +458,7 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
node
.
isExpanded
=
false
if
(
node
.
childNode
.
isNullOrEmpty
())
{
notifyItemChanged
(
adapterPosition
)
notifyItemChanged
(
adapterPosition
,
parentPayload
)
return
0
}
val
items
=
flatData
(
node
.
childNode
!!
,
if
(
isChangeChildCollapse
)
false
else
null
)
...
...
@@ -454,7 +466,7 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
this
.
data
.
removeAll
(
items
)
if
(
notify
)
{
if
(
animate
)
{
notifyItemChanged
(
adapterPosition
)
notifyItemChanged
(
adapterPosition
,
parentPayload
)
notifyItemRangeRemoved
(
adapterPosition
+
1
,
size
)
}
else
{
notifyDataSetChanged
()
...
...
@@ -477,7 +489,8 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
private
fun
expand
(
@IntRange
(
from
=
0
)
position
:
Int
,
isChangeChildExpand
:
Boolean
=
false
,
animate
:
Boolean
=
true
,
notify
:
Boolean
=
true
):
Int
{
notify
:
Boolean
=
true
,
parentPayload
:
Any
?
=
null
):
Int
{
val
node
=
this
.
data
[
position
]
if
(
node
is
BaseExpandNode
&&
!
node
.
isExpanded
)
{
...
...
@@ -485,7 +498,7 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
node
.
isExpanded
=
true
if
(
node
.
childNode
.
isNullOrEmpty
())
{
notifyItemChanged
(
adapterPosition
)
notifyItemChanged
(
adapterPosition
,
parentPayload
)
return
0
}
val
items
=
flatData
(
node
.
childNode
!!
,
if
(
isChangeChildExpand
)
true
else
null
)
...
...
@@ -493,7 +506,7 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
this
.
data
.
addAll
(
position
+
1
,
items
)
if
(
notify
)
{
if
(
animate
)
{
notifyItemChanged
(
adapterPosition
)
notifyItemChanged
(
adapterPosition
,
parentPayload
)
notifyItemRangeInserted
(
adapterPosition
+
1
,
size
)
}
else
{
notifyDataSetChanged
()
...
...
@@ -513,8 +526,9 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
@JvmOverloads
fun
collapse
(
@IntRange
(
from
=
0
)
position
:
Int
,
animate
:
Boolean
=
true
,
notify
:
Boolean
=
true
):
Int
{
return
collapse
(
position
,
false
,
animate
,
notify
)
notify
:
Boolean
=
true
,
parentPayload
:
Any
?
=
null
):
Int
{
return
collapse
(
position
,
false
,
animate
,
notify
,
parentPayload
)
}
/**
...
...
@@ -526,8 +540,9 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
@JvmOverloads
fun
expand
(
@IntRange
(
from
=
0
)
position
:
Int
,
animate
:
Boolean
=
true
,
notify
:
Boolean
=
true
):
Int
{
return
expand
(
position
,
false
,
animate
,
notify
)
notify
:
Boolean
=
true
,
parentPayload
:
Any
?
=
null
):
Int
{
return
expand
(
position
,
false
,
animate
,
notify
,
parentPayload
)
}
/**
...
...
@@ -537,26 +552,35 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
* @param notify Boolean
*/
@JvmOverloads
fun
expandOrCollapse
(
@IntRange
(
from
=
0
)
position
:
Int
,
animate
:
Boolean
=
true
,
notify
:
Boolean
=
true
):
Int
{
fun
expandOrCollapse
(
@IntRange
(
from
=
0
)
position
:
Int
,
animate
:
Boolean
=
true
,
notify
:
Boolean
=
true
,
parentPayload
:
Any
?
=
null
):
Int
{
val
node
=
this
.
data
[
position
]
if
(
node
is
BaseExpandNode
)
{
return
if
(
node
.
isExpanded
)
{
collapse
(
position
,
false
,
animate
,
notify
)
collapse
(
position
,
false
,
animate
,
notify
,
parentPayload
)
}
else
{
expand
(
position
,
false
,
animate
,
notify
)
expand
(
position
,
false
,
animate
,
notify
,
parentPayload
)
}
}
return
0
}
@JvmOverloads
fun
expandAndChild
(
@IntRange
(
from
=
0
)
position
:
Int
,
animate
:
Boolean
=
true
,
notify
:
Boolean
=
true
):
Int
{
return
expand
(
position
,
true
,
animate
,
notify
)
fun
expandAndChild
(
@IntRange
(
from
=
0
)
position
:
Int
,
animate
:
Boolean
=
true
,
notify
:
Boolean
=
true
,
parentPayload
:
Any
?
=
null
):
Int
{
return
expand
(
position
,
true
,
animate
,
notify
,
parentPayload
)
}
@JvmOverloads
fun
collapseAndChild
(
@IntRange
(
from
=
0
)
position
:
Int
,
animate
:
Boolean
=
true
,
notify
:
Boolean
=
true
):
Int
{
return
collapse
(
position
,
true
,
animate
,
notify
)
fun
collapseAndChild
(
@IntRange
(
from
=
0
)
position
:
Int
,
animate
:
Boolean
=
true
,
notify
:
Boolean
=
true
,
parentPayload
:
Any
?
=
null
):
Int
{
return
collapse
(
position
,
true
,
animate
,
notify
,
parentPayload
)
}
/**
...
...
@@ -572,9 +596,11 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
isExpandedChild
:
Boolean
=
false
,
isCollapseChild
:
Boolean
=
true
,
animate
:
Boolean
=
true
,
notify
:
Boolean
=
true
)
{
notify
:
Boolean
=
true
,
expandPayload
:
Any
?
=
null
,
collapsePayload
:
Any
?
=
null
)
{
val
expandCount
=
expand
(
position
,
isExpandedChild
,
animate
,
notify
)
val
expandCount
=
expand
(
position
,
isExpandedChild
,
animate
,
notify
,
expandPayload
)
if
(
expandCount
==
0
)
{
return
}
...
...
@@ -597,7 +623,7 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
// 从顶部开始位置循环
var
i
=
firstPosition
do
{
val
collapseSize
=
collapse
(
i
,
isCollapseChild
,
animate
,
notify
)
val
collapseSize
=
collapse
(
i
,
isCollapseChild
,
animate
,
notify
,
collapsePayload
)
i
++
// 每次折叠后,重新计算新的 Position
newPosition
-=
collapseSize
...
...
@@ -616,7 +642,7 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
if
((
newPosition
+
expandCount
)
<
lastPosition
)
{
var
i
=
newPosition
+
expandCount
+
1
while
(
i
<=
lastPosition
)
{
val
collapseSize
=
collapse
(
i
,
isCollapseChild
,
animate
,
notify
)
val
collapseSize
=
collapse
(
i
,
isCollapseChild
,
animate
,
notify
,
collapsePayload
)
i
++
lastPosition
-=
collapseSize
}
...
...
library/src/main/java/com/chad/library/adapter/base/viewholder/BaseViewHolder.kt
浏览文件 @
53644d00
...
...
@@ -73,22 +73,22 @@ open class BaseViewHolder(view: View) : RecyclerView.ViewHolder(view) {
return
this
}
open
fun
setImageDrawable
(
@IdRes
viewId
:
Int
,
drawable
:
Drawable
?):
BaseViewHolder
?
{
open
fun
setImageDrawable
(
@IdRes
viewId
:
Int
,
drawable
:
Drawable
?):
BaseViewHolder
{
getView
<
ImageView
>(
viewId
).
setImageDrawable
(
drawable
)
return
this
}
open
fun
setImageBitmap
(
@IdRes
viewId
:
Int
,
bitmap
:
Bitmap
?):
BaseViewHolder
?
{
open
fun
setImageBitmap
(
@IdRes
viewId
:
Int
,
bitmap
:
Bitmap
?):
BaseViewHolder
{
getView
<
ImageView
>(
viewId
).
setImageBitmap
(
bitmap
)
return
this
}
open
fun
setBackgroundColor
(
@IdRes
viewId
:
Int
,
@ColorInt
color
:
Int
):
BaseViewHolder
?
{
open
fun
setBackgroundColor
(
@IdRes
viewId
:
Int
,
@ColorInt
color
:
Int
):
BaseViewHolder
{
getView
<
View
>(
viewId
).
setBackgroundColor
(
color
)
return
this
}
open
fun
setBackgroundResource
(
@IdRes
viewId
:
Int
,
@DrawableRes
backgroundRes
:
Int
):
BaseViewHolder
?
{
open
fun
setBackgroundResource
(
@IdRes
viewId
:
Int
,
@DrawableRes
backgroundRes
:
Int
):
BaseViewHolder
{
getView
<
View
>(
viewId
).
setBackgroundResource
(
backgroundRes
)
return
this
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录