Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions add_image_view/src/main/java/me/simple/view/AddImageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import android.os.VibrationAttributes
import android.os.Vibrator
import android.util.AttributeSet
import android.util.Log
import android.util.TypedValue
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
Expand Down Expand Up @@ -258,7 +259,8 @@ open class AddImageView @JvmOverloads constructor(
}
}
}



/**
* ViewHolder的基类代理
*/
Expand Down Expand Up @@ -330,18 +332,21 @@ open class AddImageView @JvmOverloads constructor(
return false
}

val fromPosition = viewHolder.bindingAdapterPosition
val toPosition = target.bindingAdapterPosition
val fromPosition = viewHolder.absoluteAdapterPosition
val toPosition = target.absoluteAdapterPosition
if (fromPosition != toPosition) {
vibrate()
// java.util.Collections.swap(mItems, fromPosition, toPosition)
//移动中的 Item
val movingItem = mItems[fromPosition]
//先删除再添加到移动后的位置
mItems.removeAt(fromPosition)
mItems.add(toPosition, movingItem)
mItems.add(toPosition,movingItem)
// java.util.Collections.swap(mItems, fromPosition, toPosition)


adapter?.notifyItemMoved(fromPosition, toPosition)
return true
}

return true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package demo.simple.addimageview

import android.graphics.Bitmap
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -30,7 +31,6 @@ class CustomItemView : AddImageView.ItemViewDelegate<CustomItemView.VH>() {
.load(path)
.apply(RequestOptions.bitmapTransform(multi))
.into(holder.ivCover)

holder.ivDel.setOnClickListener {
addImageView.removeItem(path)
}
Expand Down
31 changes: 23 additions & 8 deletions app/src/main/java/demo/simple/addimageview/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,29 @@ class MainActivity : AppCompatActivity() {
private val tvItems by lazy { findViewById<TextView>(R.id.tvItems) }

private val mImages by lazy {
mapOf(
"https://img0.baidu.com/it/u=962361882,2281204904&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500" to 0,
"https://img1.baidu.com/it/u=1507025561,3635944319&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=711" to 1,
"https://img0.baidu.com/it/u=3274713675,3050580903&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500" to 2,
"https://img0.baidu.com/it/u=3098099923,3369715583&fm=253&fmt=auto&app=120&f=JPEG?w=889&h=500" to 3,
"https://img0.baidu.com/it/u=2651423003,3415459398&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500" to 4,
"https://img0.baidu.com/it/u=501412934,626408000&fm=253&fmt=auto&app=120&f=JPEG?w=1024&h=640" to 5,
"https://img1.baidu.com/it/u=577114546,2771402770&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800" to 6

mutableListOf(
"https://p.qqan.com/up/2022-2/16454222068823469.jpg",
"https://p.qqan.com/up/2022-2/16454222074615293.jpg",
"https://p.qqan.com/up/2022-2/16454222079248915.jpg",
"https://p.qqan.com/up/2022-2/16454222074882536.jpg",
"https://p.qqan.com/up/2022-2/16454222077125944.jpg",
"https://p.qqan.com/up/2022-2/16454222079542524.jpg",

// "https://gank.io/images/ce66aa74d78f49919085b2b2808ecc50",
// "https://gank.io/images/02eb8ca3297f4931ab64b7ebd7b5b89c",
// "https://gank.io/images/0f536c69ada247429b8a9e38d3dba8bb",
// "https://gank.io/images/ccf0316264d245018fc651cffa6e90de",
// "https://gank.io/images/95ddb01b6bd34a85aedfda4c9e9bd003",
// "https://gank.io/images/e92911f5ff9446d5a899b652b1934b93",

// "https://gank.io/images/6e57b254da79416bbe58248b570ea85f",
// "https://gank.io/images/e0b652d2a0cb46ba888a935c525bd312",
// "https://gank.io/images/95ddb01b6bd34a85aedfda4c9e9bd003",
// "https://gank.io/images/4817628a6762410895f814079a6690a1",
// "https://gank.io/images/0f536c69ada247429b8a9e38d3dba8bb",
// "https://gank.io/images/1a515f1508e345e2bf24673c2c2d50c4",
// "https://gank.io/images/4002b1fd18544802b80193fad27eaa62"
)
}

Expand Down