Skip to content

Commit a93eb85

Browse files
author
fengpeng
committed
添加照片选择元素获取
1 parent f25ccd5 commit a93eb85

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

picker/src/main/java/pizzk/media/picker/adapter/PhotoGroupAdapter.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,21 @@ class PhotoGroupAdapter(context: Context, fixedList: List<PhotoItem>?, lp: ViewG
8585
return true
8686
}
8787

88-
fun selects(): List<String> {
88+
fun selectItems(): List<PhotoItem> {
8989
val size: Int = selectCount()
90-
val list: MutableList<String> = ArrayList(size)
90+
val list: MutableList<PhotoItem> = ArrayList(size)
9191
for (i: Int in 0 until getList().size) {
92-
val el: String = getList()[i].path
93-
if (!isAppend || !TextUtils.isEmpty(el)) {
94-
list.add(el)
92+
val path: String = getList()[i].path
93+
if (!isAppend || !TextUtils.isEmpty(path)) {
94+
list.add(getList()[i])
9595
}
9696
}
9797
return list
9898
}
9999

100-
fun selectCount() = getList().count { !TextUtils.isEmpty(it.path) }
100+
fun selectPaths(): List<String> = selectItems().map { it.path }
101+
102+
fun selectCount() = if (isAppend) getList().count { !TextUtils.isEmpty(it.path) } else getList().size
101103

102104
override fun getLayoutId(viewType: Int): Int = R.layout.pick_photo_list_item
103105

picker/src/main/java/pizzk/media/picker/widget/PhotoGroupView.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ class PhotoGroupView : RecyclerView {
5555
if (el.path.isEmpty()) {
5656
if (pAdapter.isReadOnly()) return@setTapBlock
5757
//选择图片
58-
val selects: List<String> = if (pAdapter.isAppend) pAdapter.selects() else emptyList()
58+
val selects: List<String> = if (pAdapter.isAppend) pAdapter.selectPaths() else emptyList()
5959
PickChoseActivity.show(special.activity, choiceList) { key ->
6060
showPickPhoto(special.activity, key, selects, special.limit, pAdapter, index)
6161
}
6262
} else {
6363
//预览
64-
val selects: List<String> = if (pAdapter.isAppend) pAdapter.selects() else arrayListOf(el.path)
64+
val selects: List<String> = if (pAdapter.isAppend) pAdapter.selectPaths() else arrayListOf(el.path)
6565
showPreview(special.activity, selects, if (pAdapter.isAppend) index else 0)
6666
}
6767
}
@@ -101,7 +101,7 @@ class PhotoGroupView : RecyclerView {
101101
.callback { code, list ->
102102
if (code == PickControl.ACTION_CAMERA) {
103103
val allOf: MutableList<String> = ArrayList(adapter.selectCount() + 1)
104-
allOf.addAll(adapter.selects())
104+
allOf.addAll(adapter.selectPaths())
105105
allOf.addAll(list.map(Uri::toString))
106106
adapter.update(allOf, limit, index)
107107
} else {

0 commit comments

Comments
 (0)