react-native-video-trim 1.0.24 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/README.md +22 -0
  2. package/android/src/main/AndroidManifest.xml +2 -0
  3. package/android/src/main/java/com/videotrim/VideoTrimModule.java +8 -1
  4. package/android/src/main/java/com/videotrim/interfaces/VideoTrimListener.java +4 -0
  5. package/android/src/main/java/com/videotrim/utils/VideoTrimmerUtil.java +21 -0
  6. package/android/src/main/java/com/videotrim/widgets/VideoTrimmerView.java +406 -295
  7. package/android/src/main/res/drawable/chevron_compact_left.xml +15 -0
  8. package/android/src/main/res/drawable/chevron_compact_right.xml +15 -0
  9. package/android/src/main/res/drawable/chevron_right_with_bg.xml +13 -0
  10. package/android/src/main/res/drawable/pause_fill.xml +15 -0
  11. package/android/src/main/res/drawable/play_fill.xml +15 -0
  12. package/android/src/main/res/drawable/rounded_progress_indicator.xml +16 -0
  13. package/android/src/main/res/drawable/rounded_yellow_left_background.xml +8 -0
  14. package/android/src/main/res/drawable/rounded_yellow_right_background.xml +8 -0
  15. package/android/src/main/res/drawable/yellow_border.xml +9 -0
  16. package/android/src/main/res/layout/video_trimmer_view.xml +148 -76
  17. package/android/src/main/res/values/colors.xml +15 -13
  18. package/ios/VideoTrim.swift +26 -2
  19. package/ios/VideoTrimmerViewController.swift +1 -1
  20. package/package.json +1 -1
  21. package/android/src/main/java/com/videotrim/adapters/VideoTrimmerAdapter.java +0 -54
  22. package/android/src/main/java/com/videotrim/widgets/RangeSeekBarView.java +0 -534
  23. package/android/src/main/java/com/videotrim/widgets/SpacesItemDecoration2.java +0 -33
  24. package/android/src/main/java/com/videotrim/widgets/ZVideoView.java +0 -48
  25. package/android/src/main/res/drawable/ic_video_pause_black.png +0 -0
  26. package/android/src/main/res/drawable/ic_video_play_black.png +0 -0
  27. package/android/src/main/res/drawable/ic_video_thumb_handle.png +0 -0
  28. package/android/src/main/res/drawable/icon_seek_bar.png +0 -0
  29. package/android/src/main/res/layout/video_thumb_item_layout.xml +0 -16
@@ -0,0 +1,15 @@
1
+ <vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+ android:width="14.531dp"
3
+ android:height="53.086dp"
4
+ android:viewportWidth="14.531"
5
+ android:viewportHeight="53.086">
6
+ <path
7
+ android:fillColor="#FF000000"
8
+ android:pathData="M0,0h14.531v53.086h-14.531z"
9
+ android:strokeAlpha="0"
10
+ android:fillAlpha="0"/>
11
+ <path
12
+ android:pathData="M9.398,51.328C9.797,52.336 10.664,52.945 11.578,52.945C13.055,52.945 14.18,51.844 14.18,50.367C14.18,49.594 13.758,48.609 13.523,47.953L4.289,24.703L4.289,28.219L13.523,4.969C13.758,4.313 14.18,3.305 14.18,2.578C14.18,1.102 13.055,0 11.578,0C10.664,0 9.797,0.609 9.398,1.594L1.008,22.758C0.539,23.906 0,25.359 0,26.461C0,27.586 0.539,28.992 1.008,30.164Z"
13
+ android:fillColor="#ffffff"
14
+ android:fillAlpha="0.85"/>
15
+ </vector>
@@ -0,0 +1,15 @@
1
+ <vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+ android:width="14.531dp"
3
+ android:height="53.086dp"
4
+ android:viewportWidth="14.531"
5
+ android:viewportHeight="53.086">
6
+ <path
7
+ android:fillColor="#FF000000"
8
+ android:pathData="M0,0h14.531v53.086h-14.531z"
9
+ android:strokeAlpha="0"
10
+ android:fillAlpha="0"/>
11
+ <path
12
+ android:pathData="M4.781,51.328L13.172,30.164C13.641,28.992 14.18,27.586 14.18,26.461C14.18,25.359 13.641,23.906 13.172,22.758L4.781,1.594C4.383,0.609 3.516,0 2.602,0C1.125,0 0,1.102 0,2.578C0,3.305 0.398,4.313 0.656,4.969L9.867,28.219L9.867,24.703L0.656,47.953C0.398,48.609 0,49.594 0,50.367C0,51.844 1.125,52.945 2.602,52.945C3.516,52.945 4.383,52.336 4.781,51.328Z"
13
+ android:fillColor="#ffffff"
14
+ android:fillAlpha="0.85"/>
15
+ </vector>
@@ -0,0 +1,13 @@
1
+ <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <item android:drawable="@drawable/rounded_yellow_right_background"/>
3
+ <item>
4
+ <inset
5
+ android:insetLeft="8dp"
6
+ android:insetTop="8dp"
7
+ android:insetRight="8dp"
8
+ android:insetBottom="8dp"
9
+ android:drawable="@drawable/chevron_compact_right">
10
+ </inset>
11
+ </item>
12
+ </layer-list>
13
+
@@ -0,0 +1,15 @@
1
+ <vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+ android:width="35.953dp"
3
+ android:height="48.586dp"
4
+ android:viewportWidth="35.953"
5
+ android:viewportHeight="48.586">
6
+ <path
7
+ android:fillColor="#FF000000"
8
+ android:pathData="M0,0h35.953v48.586h-35.953z"
9
+ android:strokeAlpha="0"
10
+ android:fillAlpha="0"/>
11
+ <path
12
+ android:pathData="M3.75,48.563L10.5,48.563C13.008,48.563 14.25,47.32 14.25,44.813L14.25,3.75C14.25,1.172 13.008,0 10.5,0L3.75,0C1.242,0 0,1.266 0,3.75L0,44.813C0,47.32 1.242,48.563 3.75,48.563ZM25.102,48.563L31.852,48.563C34.359,48.563 35.602,47.32 35.602,44.813L35.602,3.75C35.602,1.172 34.359,0 31.852,0L25.102,0C22.594,0 21.352,1.266 21.352,3.75L21.352,44.813C21.352,47.32 22.594,48.563 25.102,48.563Z"
13
+ android:fillColor="#ffffff"
14
+ android:fillAlpha="1"/>
15
+ </vector>
@@ -0,0 +1,15 @@
1
+ <vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+ android:width="51.82dp"
3
+ android:height="50.977dp"
4
+ android:viewportWidth="51.82"
5
+ android:viewportHeight="50.977">
6
+ <path
7
+ android:fillColor="#FF000000"
8
+ android:pathData="M0,0h51.82v50.977h-51.82z"
9
+ android:strokeAlpha="0"
10
+ android:fillAlpha="0"/>
11
+ <path
12
+ android:pathData="M9.867,50.977C10.969,50.977 11.859,50.602 12.984,49.945L48.773,29.133C51,27.867 51.82,26.977 51.82,25.5C51.82,24.047 51,23.156 48.773,21.867L12.984,1.078C11.859,0.422 10.969,0.023 9.867,0.023C7.852,0.023 6.586,1.547 6.586,3.961L6.586,47.063C6.586,49.453 7.852,50.977 9.867,50.977Z"
13
+ android:fillColor="#ffffff"
14
+ android:fillAlpha="1"/>
15
+ </vector>
@@ -0,0 +1,16 @@
1
+ <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <!-- Shadow -->
3
+ <item>
4
+ <shape android:shape="rectangle">
5
+ <corners android:radius="5dp"/>
6
+ <solid android:color="#80000000"/> <!-- semi-transparent black for shadow -->
7
+ </shape>
8
+ </item>
9
+ <!-- Rounded corners -->
10
+ <item android:right="2dp" android:left="2dp" android:top="2dp" android:bottom="2dp">
11
+ <shape android:shape="rectangle">
12
+ <corners android:radius="5dp"/>
13
+ <solid android:color="@android:color/white"/>
14
+ </shape>
15
+ </item>
16
+ </layer-list>
@@ -0,0 +1,8 @@
1
+ <shape xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <solid android:color="@color/trim_color" />
3
+ <corners
4
+ android:topLeftRadius="6dp"
5
+ android:bottomLeftRadius="6dp"
6
+ android:topRightRadius="0dp"
7
+ android:bottomRightRadius="0dp" />
8
+ </shape>
@@ -0,0 +1,8 @@
1
+ <shape xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <solid android:color="@color/trim_color" />
3
+ <corners
4
+ android:topLeftRadius="0dp"
5
+ android:bottomLeftRadius="0dp"
6
+ android:topRightRadius="6dp"
7
+ android:bottomRightRadius="6dp" />
8
+ </shape>
@@ -0,0 +1,9 @@
1
+ <inset xmlns:android="http://schemas.android.com/apk/res/android"
2
+ android:insetLeft="-4dp" android:insetRight="-4dp" >
3
+ <shape xmlns:android="http://schemas.android.com/apk/res/android">
4
+ <solid android:color="@android:color/transparent" />
5
+ <stroke
6
+ android:width="4dp"
7
+ android:color="@color/trim_color" />
8
+ </shape>
9
+ </inset>
@@ -1,26 +1,20 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
- <RelativeLayout
3
- xmlns:android="http://schemas.android.com/apk/res/android"
4
- xmlns:tools="http://schemas.android.com/tools"
2
+ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
5
3
  android:layout_width="match_parent"
6
4
  android:layout_height="match_parent"
7
- android:orientation="vertical"
8
- >
5
+ android:orientation="vertical">
9
6
 
10
7
  <RelativeLayout
11
- android:id="@+id/layout_surface_view"
12
8
  android:layout_width="match_parent"
13
9
  android:layout_height="match_parent"
14
10
  android:layout_above="@+id/layout"
15
11
  android:background="@android:color/black"
16
- android:gravity="center"
17
- >
12
+ android:gravity="center">
18
13
 
19
- <com.videotrim.widgets.ZVideoView
14
+ <VideoView
20
15
  android:id="@+id/video_loader"
21
16
  android:layout_width="match_parent"
22
- android:layout_height="match_parent"
23
- android:layout_centerInParent="true" />
17
+ android:layout_height="match_parent" />
24
18
 
25
19
  </RelativeLayout>
26
20
 
@@ -29,87 +23,165 @@
29
23
  android:layout_width="match_parent"
30
24
  android:layout_height="wrap_content"
31
25
  android:layout_alignParentBottom="true"
32
- android:background="@android:color/black"
33
- >
34
-
35
- <!-- <TextView-->
36
- <!-- android:id="@+id/video_shoot_tip"-->
37
- <!-- android:layout_width="match_parent"-->
38
- <!-- android:layout_height="30dp"-->
39
- <!-- android:layout_alignParentLeft="true"-->
40
- <!-- android:layout_alignParentStart="true"-->
41
- <!-- android:layout_alignParentTop="true"-->
42
- <!-- android:gravity="center"-->
43
- <!-- android:textColor="@android:color/white"-->
44
- <!-- android:textSize="12dp"-->
45
- <!-- tools:text="拖动选择你要发表的10秒以内片段"-->
46
- <!-- />-->
47
- <FrameLayout
48
- android:id="@+id/video_frames_layout"
49
- android:layout_width="match_parent"
50
- android:layout_height="60dp"
51
- >
26
+ android:background="@android:color/black">
52
27
 
53
- <androidx.recyclerview.widget.RecyclerView
54
- android:id="@+id/video_frames_recyclerView"
55
- android:layout_width="match_parent"
56
- android:layout_height="50dp"
57
- android:layout_gravity="bottom"
58
- tools:background="@android:color/holo_green_light"
59
- />
60
28
 
61
- <ImageView
62
- android:id="@+id/positionIcon"
63
- android:layout_width="wrap_content"
64
- android:layout_height="50dp"
65
- android:layout_gravity="bottom"
66
- android:layout_marginLeft="35dp"
67
- android:contentDescription="@null"
68
- android:src="@drawable/icon_seek_bar"
69
- />
29
+ <RelativeLayout
30
+ android:id="@+id/trimmerView"
31
+ android:layout_width="match_parent"
32
+ android:layout_height="50dp"
33
+ android:layout_margin="8dp">
70
34
 
71
35
  <LinearLayout
36
+ android:id="@+id/thumbnailContainer"
72
37
  android:layout_width="match_parent"
73
- android:layout_height="wrap_content"
74
- android:layout_gravity="bottom"
38
+ android:layout_height="match_parent"
39
+ android:layout_marginHorizontal="20dp"
75
40
  android:orientation="horizontal"
76
- >
41
+ android:padding="4dp" />
77
42
 
78
- <View
79
- android:layout_width="35dp"
80
- android:layout_height="50dp"
81
- android:layout_gravity="bottom"
82
- android:background="@color/shadow_color"
83
- />
84
-
85
- <LinearLayout
86
- android:id="@+id/seekBarLayout"
87
- android:layout_width="0dp"
88
- android:layout_height="60dp"
89
- android:layout_gravity="bottom"
90
- android:layout_weight="1"
91
- android:gravity="bottom"
92
- android:orientation="vertical"
93
- />
43
+ <RelativeLayout
44
+ android:id="@+id/trimmerContainerWrapper"
45
+ android:layout_width="match_parent"
46
+ android:layout_height="match_parent">
94
47
 
95
48
  <View
96
- android:layout_width="35dp"
49
+ android:id="@+id/trimmerContainerBg"
50
+ android:layout_width="match_parent"
51
+ android:layout_height="match_parent"
52
+ android:layout_toStartOf="@id/trailingHandle"
53
+ android:layout_toEndOf="@id/leadingHandle" />
54
+
55
+ <RelativeLayout
56
+ android:layout_width="match_parent"
57
+ android:layout_height="match_parent">
58
+
59
+ <View
60
+ android:id="@+id/leadingOverlay"
61
+ android:layout_width="20dp"
62
+ android:layout_height="match_parent"
63
+ android:layout_alignParentStart="true"
64
+ android:background="@color/shadow_color" />
65
+
66
+ <View
67
+ android:id="@+id/trimmerContainer"
68
+ android:layout_width="match_parent"
69
+ android:layout_height="match_parent"
70
+ android:layout_toStartOf="@id/trailingOverlay"
71
+ android:layout_toEndOf="@id/leadingOverlay"
72
+ android:background="@drawable/yellow_border" />
73
+
74
+ <View
75
+ android:id="@+id/progressIndicator"
76
+ android:layout_width="10dp"
77
+ android:layout_height="match_parent"
78
+ android:layout_marginHorizontal="20dp"
79
+ android:background="@drawable/rounded_progress_indicator" />
80
+
81
+ <View
82
+ android:id="@+id/trailingOverlay"
83
+ android:layout_width="20dp"
84
+ android:layout_height="match_parent"
85
+ android:layout_alignParentEnd="true"
86
+ android:background="@color/shadow_color" />
87
+ </RelativeLayout>
88
+
89
+ <FrameLayout
90
+ android:id="@+id/leadingHandle"
91
+ android:layout_width="20dp"
97
92
  android:layout_height="match_parent"
98
- android:layout_gravity="bottom"
99
- android:background="@color/shadow_color"
100
- />
101
- </LinearLayout>
93
+ android:layout_alignParentStart="true"
94
+ android:layout_centerVertical="true"
95
+ android:background="@drawable/rounded_yellow_left_background"
96
+ android:paddingVertical="10dp">
97
+
98
+ <ImageView
99
+ android:layout_width="20dp"
100
+ android:layout_height="match_parent"
101
+ android:contentDescription="LeadingHandle"
102
+ android:src="@drawable/chevron_compact_left"
103
+ android:tint="@color/black" />
104
+ </FrameLayout>
105
+
106
+ <FrameLayout
107
+ android:id="@+id/trailingHandle"
108
+ android:layout_width="20dp"
109
+ android:layout_height="match_parent"
110
+ android:layout_alignParentEnd="true"
111
+ android:layout_centerVertical="true"
112
+ android:background="@drawable/rounded_yellow_right_background"
113
+ android:paddingVertical="10dp">
114
+
115
+ <ImageView
116
+ android:layout_width="20dp"
117
+ android:layout_height="match_parent"
118
+ android:contentDescription="TrailingHandle"
119
+ android:src="@drawable/chevron_compact_right"
120
+ android:tint="@color/black" />
121
+ </FrameLayout>
122
+
123
+ </RelativeLayout>
124
+
125
+ </RelativeLayout>
126
+
127
+ <FrameLayout
128
+ android:id="@+id/timingStackView"
129
+ android:layout_width="match_parent"
130
+ android:layout_height="50dp"
131
+ android:layout_below="@+id/trimmerView"
132
+ android:layout_marginHorizontal="16dp"
133
+ android:orientation="horizontal"
134
+ android:visibility="visible">
135
+
136
+ <TextView
137
+ android:id="@+id/startTime"
138
+ android:layout_width="wrap_content"
139
+ android:layout_height="match_parent"
140
+ android:layout_gravity="left"
141
+ android:clickable="true"
142
+ android:focusable="true"
143
+ android:gravity="center"
144
+ android:padding="10dp"
145
+ android:text="00:00.00"
146
+ android:textColor="@android:color/white"
147
+ android:textSize="16sp" />
148
+
149
+ <TextView
150
+ android:id="@+id/currentTime"
151
+ android:layout_width="wrap_content"
152
+ android:layout_height="match_parent"
153
+ android:layout_gravity="center"
154
+ android:clickable="true"
155
+ android:focusable="true"
156
+ android:gravity="center"
157
+ android:padding="10dp"
158
+ android:text="00:00.00"
159
+ android:textColor="@android:color/white"
160
+ android:textSize="16sp" />
161
+
162
+ <TextView
163
+ android:id="@+id/endTime"
164
+ android:layout_width="wrap_content"
165
+ android:layout_height="match_parent"
166
+ android:layout_gravity="right"
167
+ android:clickable="true"
168
+ android:focusable="true"
169
+ android:gravity="center"
170
+ android:padding="10dp"
171
+ android:text="00:00.00"
172
+ android:textColor="@android:color/white"
173
+ android:textSize="16sp" />
174
+
102
175
  </FrameLayout>
103
176
 
104
177
  <FrameLayout
105
178
  android:layout_width="match_parent"
106
179
  android:layout_height="50dp"
107
- android:layout_below="@+id/video_frames_layout"
180
+ android:layout_below="@+id/timingStackView"
108
181
  android:layout_marginLeft="10dp"
109
182
  android:layout_marginRight="10dp"
110
183
  android:orientation="horizontal"
111
- android:visibility="visible"
112
- >
184
+ android:visibility="visible">
113
185
 
114
186
  <TextView
115
187
  android:id="@+id/cancelBtn"
@@ -128,8 +200,8 @@
128
200
  android:layout_height="match_parent"
129
201
  android:layout_gravity="center"
130
202
  android:padding="12dp"
131
- android:src="@drawable/ic_video_play_black"
132
- />
203
+ android:src="@drawable/play_fill"
204
+ android:tint="@color/white"/>
133
205
 
134
206
  <TextView
135
207
  android:id="@+id/saveBtn"
@@ -1,17 +1,19 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
2
  <resources>
3
- <color name="colorPrimary">#3F51B5</color>
4
- <color name="colorPrimaryDark">#303F9F</color>
5
- <color name="colorAccent">#FF4081</color>
3
+ <color name="colorPrimary">#3F51B5</color>
4
+ <color name="colorPrimaryDark">#303F9F</color>
5
+ <color name="colorAccent">#FF4081</color>
6
6
 
7
- <color name="white">#ffffffff</color>
8
- <color name="red">#aacc0000</color>
9
- <color name="background_video_color">#2f3031</color>
10
- <color name="background_progress_color">#6C6D6D</color>
11
- <color name="progress_color">#aacc0000</color>
12
- <color name="line_color">#FF15FF00</color>
13
- <color name="shadow_color">#7F000000</color>
14
- <color name="line_button">#565758</color>
15
- <color name="black_translucent">#50000000</color>
16
- <color name="top_bottom">#42BAF8</color>
7
+ <color name="white">#ffffffff</color>
8
+ <color name="red">#aacc0000</color>
9
+ <color name="background_video_color">#2f3031</color>
10
+ <color name="background_progress_color">#6C6D6D</color>
11
+ <color name="progress_color">#aacc0000</color>
12
+ <color name="line_color">#FF15FF00</color>
13
+ <color name="shadow_color">#7F000000</color>
14
+ <color name="line_button">#565758</color>
15
+ <color name="black_translucent">#50000000</color>
16
+ <color name="top_bottom">#42BAF8</color>
17
+ <color name="trim_color">#f1d247</color>
18
+ <color name="black">#000000</color>
17
19
  </resources>
@@ -368,15 +368,39 @@ class VideoTrim: RCTEventEmitter {
368
368
  })
369
369
  }
370
370
  }, withLogCallback: { log in
371
- print("FFmpeg process started with log " + (log?.getMessage() ?? ""));
371
+ guard let log = log else { return }
372
+
373
+ print("FFmpeg process started with log " + (log.getMessage()));
374
+
375
+ let eventPayload: [String: Any] = [
376
+ "level": log.getLevel(),
377
+ "message": log.getMessage() ?? "",
378
+ "sessionId": log.getSessionId(),
379
+ ]
380
+ self.emitEventToJS("onLog", eventData: eventPayload)
381
+
372
382
  }, withStatisticsCallback: { statistics in
373
- let timeInMilliseconds = statistics?.getTime() ?? 0;
383
+ guard let statistics = statistics else { return }
384
+
385
+ let timeInMilliseconds = statistics.getTime()
374
386
  if timeInMilliseconds > 0 {
375
387
  let completePercentage = timeInMilliseconds / (videoDuration * 1000); // from 0 -> 1
376
388
  DispatchQueue.main.async {
377
389
  progressView.setProgress(Float(completePercentage), animated: true)
378
390
  }
379
391
  }
392
+
393
+ let eventPayload: [String: Any] = [
394
+ "sessionId": statistics.getSessionId(),
395
+ "videoFrameNumber": statistics.getVideoFrameNumber(),
396
+ "videoFps": statistics.getVideoFps(),
397
+ "videoQuality": statistics.getVideoQuality(),
398
+ "size": statistics.getSize(),
399
+ "time": statistics.getTime(),
400
+ "bitrate": statistics.getBitrate(),
401
+ "speed": statistics.getSpeed()
402
+ ]
403
+ self.emitEventToJS("onStatistics", eventData: eventPayload)
380
404
  })
381
405
  }
382
406
  }
@@ -169,7 +169,7 @@ class VideoTrimmerViewController: UIViewController {
169
169
 
170
170
  private func setupButtons() {
171
171
  cancelBtn = UIButton.createButton(title: cancelBtnText, font: .systemFont(ofSize: 18), titleColor: .white, target: self, action: #selector(onCancelBtnClicked))
172
- playBtn = UIButton.createButton(image: playIcon, tintColor: .systemBlue, target: self, action: #selector(togglePlay(sender:)))
172
+ playBtn = UIButton.createButton(image: playIcon, tintColor: .white, target: self, action: #selector(togglePlay(sender:)))
173
173
  saveBtn = UIButton.createButton(title: saveButtonText, font: .systemFont(ofSize: 18), titleColor: .systemBlue, target: self, action: #selector(onSaveBtnClicked))
174
174
 
175
175
  btnStackView = UIStackView(arrangedSubviews: [cancelBtn, playBtn, saveBtn])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-video-trim",
3
- "version": "1.0.24",
3
+ "version": "2.0.0",
4
4
  "description": "Video trimmer for your React Native app",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -1,54 +0,0 @@
1
- package com.videotrim.adapters;
2
-
3
- import android.content.Context;
4
- import android.graphics.Bitmap;
5
- import android.view.LayoutInflater;
6
- import android.view.View;
7
- import android.view.ViewGroup;
8
- import android.widget.ImageView;
9
- import android.widget.LinearLayout;
10
- import androidx.annotation.NonNull;
11
- import androidx.recyclerview.widget.RecyclerView;
12
- import com.videotrim.R;
13
- import com.videotrim.utils.VideoTrimmerUtil;
14
- import java.util.ArrayList;
15
- import java.util.List;
16
-
17
- public class VideoTrimmerAdapter extends RecyclerView.Adapter {
18
- private final List<Bitmap> mBitmaps = new ArrayList<>();
19
- private final LayoutInflater mInflater;
20
-
21
- public VideoTrimmerAdapter(Context context) {
22
- this.mInflater = LayoutInflater.from(context);
23
- }
24
-
25
- @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
26
- return new TrimmerViewHolder(mInflater.inflate(R.layout.video_thumb_item_layout, parent, false));
27
- }
28
-
29
- @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
30
- ((TrimmerViewHolder) holder).thumbImageView.setImageBitmap(mBitmaps.get(position));
31
- }
32
-
33
- @Override public int getItemCount() {
34
- return mBitmaps.size();
35
- }
36
-
37
- public void addBitmaps(Bitmap bitmap) {
38
- mBitmaps.add(bitmap);
39
- notifyItemInserted(mBitmaps.size() - 1);
40
- }
41
-
42
- private static final class TrimmerViewHolder extends RecyclerView.ViewHolder {
43
- ImageView thumbImageView;
44
-
45
- TrimmerViewHolder(View itemView) {
46
- super(itemView);
47
- thumbImageView = itemView.findViewById(R.id.thumb);
48
- LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) thumbImageView.getLayoutParams();
49
- layoutParams.width = VideoTrimmerUtil.VIDEO_FRAMES_WIDTH / VideoTrimmerUtil.MAX_COUNT_RANGE;
50
- thumbImageView.setLayoutParams(layoutParams);
51
- }
52
- }
53
- }
54
-