Skip to content

Commit f74a5ef

Browse files
code cleaning
1 parent 120eef8 commit f74a5ef

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

video_trimmer_library/src/main/java/com/lb/video_trimmer_library/view/RangeSeekBarView.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ open class RangeSeekBarView @JvmOverloads constructor(context: Context, attrs: A
5656
private val shadowPaint = Paint()
5757
private val strokePaint = Paint()
5858
private val edgePaint = Paint()
59-
private var currentThumb = 0
59+
private var currentThumb = ThumbType.LEFT.index
6060

6161

6262
init {
@@ -96,7 +96,7 @@ open class RangeSeekBarView @JvmOverloads constructor(context: Context, attrs: A
9696
fun initMaxWidth() {
9797
maxWidth = thumbs[ThumbType.RIGHT.index].pos - thumbs[ThumbType.LEFT.index].pos
9898
onSeekStop(this, ThumbType.LEFT.index, thumbs[ThumbType.LEFT.index].value)
99-
onSeekStop(this, 1, thumbs[1].value)
99+
onSeekStop(this, ThumbType.RIGHT.index, thumbs[ThumbType.RIGHT.index].value)
100100
}
101101

102102
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
@@ -143,7 +143,6 @@ open class RangeSeekBarView @JvmOverloads constructor(context: Context, attrs: A
143143
timeLineHeight.toFloat(),
144144
strokePaint
145145
)
146-
147146
//draw edges
148147
val circleRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 6f, context.resources.displayMetrics)
149148
canvas.drawCircle(
@@ -223,16 +222,16 @@ open class RangeSeekBarView @JvmOverloads constructor(context: Context, attrs: A
223222
return false
224223
}
225224

226-
private fun checkPositionThumb(mThumbLeft: Thumb, mThumbRight: Thumb, dx: Float, isLeftMove: Boolean) {
225+
private fun checkPositionThumb(thumbLeft: Thumb, thumbRight: Thumb, dx: Float, isLeftMove: Boolean) {
227226
if (isLeftMove && dx < 0) {
228-
if (mThumbRight.pos - (mThumbLeft.pos + dx) > maxWidth) {
229-
mThumbRight.pos = mThumbLeft.pos + dx + maxWidth
230-
setThumbPos(ThumbType.RIGHT.index, mThumbRight.pos)
227+
if (thumbRight.pos - (thumbLeft.pos + dx) > maxWidth) {
228+
thumbRight.pos = thumbLeft.pos + dx + maxWidth
229+
setThumbPos(ThumbType.RIGHT.index, thumbRight.pos)
231230
}
232231
} else if (!isLeftMove && dx > 0) {
233-
if (mThumbRight.pos + dx - mThumbLeft.pos > maxWidth) {
234-
mThumbLeft.pos = mThumbRight.pos + dx - maxWidth
235-
setThumbPos(ThumbType.LEFT.index, mThumbLeft.pos)
232+
if (thumbRight.pos + dx - thumbLeft.pos > maxWidth) {
233+
thumbLeft.pos = thumbRight.pos + dx - maxWidth
234+
setThumbPos(ThumbType.LEFT.index, thumbLeft.pos)
236235
}
237236
}
238237
}

video_trimmer_library/src/main/java/com/lb/video_trimmer_library/view/TimeLineView.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ import com.lb.video_trimmer_library.utils.BackgroundExecutor
3939
import com.lb.video_trimmer_library.utils.UiThreadExecutor
4040

4141
open class TimeLineView @JvmOverloads constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int = 0) : View(context, attrs, defStyleAttr) {
42-
private var mVideoUri: Uri? = null
42+
private var videoUri: Uri? = null
4343
@Suppress("LeakingThis")
44-
private var mHeightView: Int = initHeightView()
45-
private var mBitmapList: LongSparseArray<Bitmap>? = null
44+
private var heightView: Int = initHeightView()
45+
private var bitmapList: LongSparseArray<Bitmap>? = null
4646

4747
open fun initHeightView(): Int = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40f, context.resources.displayMetrics).toInt().coerceAtLeast(1)
4848

4949
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
5050
val minW = paddingLeft + paddingRight + suggestedMinimumWidth
5151
val w = View.resolveSizeAndState(minW, widthMeasureSpec, 1)
52-
val minH = paddingBottom + paddingTop + mHeightView
52+
val minH = paddingBottom + paddingTop + heightView
5353
val h = View.resolveSizeAndState(minH, heightMeasureSpec, 1)
5454
setMeasuredDimension(w, h)
5555
}
@@ -66,11 +66,11 @@ open class TimeLineView @JvmOverloads constructor(context: Context, attrs: Attri
6666
try {
6767
val thumbnailList = LongSparseArray<Bitmap>()
6868
val mediaMetadataRetriever = MediaMetadataRetriever()
69-
mediaMetadataRetriever.setDataSource(context, mVideoUri)
69+
mediaMetadataRetriever.setDataSource(context, videoUri)
7070
// Retrieve media data
7171
val videoLengthInMs = (Integer.parseInt(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)) * 1000).toLong()
7272
// Set thumbnail properties (Thumbs are squares)
73-
val thumbSize = mHeightView
73+
val thumbSize = heightView
7474
val numThumbs = Math.ceil((viewWidth.toFloat() / thumbSize).toDouble()).toInt()
7575
val interval = videoLengthInMs / numThumbs
7676
for (i in 0 until numThumbs) {
@@ -96,18 +96,18 @@ open class TimeLineView @JvmOverloads constructor(context: Context, attrs: Attri
9696

9797
private fun returnBitmaps(thumbnailList: LongSparseArray<Bitmap>) {
9898
UiThreadExecutor.runTask("", Runnable {
99-
mBitmapList = thumbnailList
99+
bitmapList = thumbnailList
100100
invalidate()
101101
}, 0L)
102102
}
103103

104104
override fun onDraw(canvas: Canvas) {
105105
super.onDraw(canvas)
106-
if (mBitmapList != null) {
106+
if (bitmapList != null) {
107107
canvas.save()
108108
var x = 0
109-
for (i in 0 until mBitmapList!!.size()) {
110-
val bitmap = mBitmapList!!.get(i.toLong())
109+
for (i in 0 until bitmapList!!.size()) {
110+
val bitmap = bitmapList!!.get(i.toLong())
111111
if (bitmap != null) {
112112
canvas.drawBitmap(bitmap, x.toFloat(), 0f, null)
113113
x += bitmap.width
@@ -117,6 +117,6 @@ open class TimeLineView @JvmOverloads constructor(context: Context, attrs: Attri
117117
}
118118

119119
fun setVideo(data: Uri) {
120-
mVideoUri = data
120+
videoUri = data
121121
}
122122
}

0 commit comments

Comments
 (0)