react-native-video-trim 2.2.2 → 2.2.3

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.
@@ -260,14 +260,6 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
260
260
  sendEvent(getReactApplicationContext(), "onLoad", map);
261
261
  }
262
262
 
263
- @Override
264
- public void onStartTrim() {
265
- sendEvent(getReactApplicationContext(), "onStartTrimming", null);
266
- runOnUiThread(() -> {
267
- buildDialog();
268
- });
269
- }
270
-
271
263
  @Override
272
264
  public void onTrimmingProgress(int percentage) {
273
265
  // prevent onTrimmingProgress is called after onFinishTrim (some rare cases)
@@ -361,7 +353,7 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
361
353
  @Override
362
354
  public void onSave() {
363
355
  if (!enableSaveDialog) {
364
- trimmerView.onSaveClicked();
356
+ startTrim();
365
357
  return;
366
358
  }
367
359
 
@@ -371,7 +363,7 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
371
363
  builder.setCancelable(false);
372
364
  builder.setPositiveButton(saveDialogConfirmText, (dialog, which) -> {
373
365
  dialog.cancel();
374
- trimmerView.onSaveClicked();
366
+ startTrim();
375
367
  });
376
368
  builder.setNegativeButton(saveDialogCancelText, (dialog, which) -> {
377
369
  dialog.cancel();
@@ -390,32 +382,7 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
390
382
  sendEvent(getReactApplicationContext(), "onStatistics", statistics);
391
383
  }
392
384
 
393
- private void hideDialog(boolean shouldCloseEditor) {
394
- // handle the case when the cancel dialog is still showing but the trimming is finished
395
- if (cancelTrimmingConfirmDialog != null) {
396
- if (cancelTrimmingConfirmDialog.isShowing()) {
397
- cancelTrimmingConfirmDialog.dismiss();
398
- }
399
- cancelTrimmingConfirmDialog = null;
400
- }
401
-
402
- if (mProgressDialog != null) {
403
- if (mProgressDialog.isShowing()) mProgressDialog.dismiss();
404
- mProgressBar = null;
405
- mProgressDialog = null;
406
- }
407
-
408
- if (shouldCloseEditor) {
409
- if (alertDialog != null) {
410
- if (alertDialog.isShowing()) {
411
- alertDialog.dismiss();
412
- }
413
- alertDialog = null;
414
- }
415
- }
416
- }
417
-
418
- private void buildDialog() {
385
+ private void startTrim() {
419
386
  Activity activity = getReactApplicationContext().getCurrentActivity();
420
387
  // Create the parent layout for the dialog
421
388
  LinearLayout layout = new LinearLayout(activity);
@@ -469,10 +436,7 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
469
436
  builder.setTitle(cancelTrimmingDialogTitle);
470
437
  builder.setCancelable(false);
471
438
  builder.setPositiveButton(cancelTrimmingDialogConfirmText, (dialog, which) -> {
472
- if (trimmerView != null) {
473
- // prevent trimmerView is null in some rare cases
474
- trimmerView.onCancelTrimClicked();
475
- }
439
+ trimmerView.onCancelTrimClicked();
476
440
 
477
441
  if (mProgressDialog != null && mProgressDialog.isShowing()) {
478
442
  mProgressDialog.dismiss();
@@ -484,10 +448,7 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
484
448
  cancelTrimmingConfirmDialog = builder.create();
485
449
  cancelTrimmingConfirmDialog.show();
486
450
  } else {
487
- if (trimmerView != null) {
488
- // prevent trimmerView is null in some rare cases
489
- trimmerView.onCancelTrimClicked();
490
- }
451
+ trimmerView.onCancelTrimClicked();
491
452
 
492
453
  if (mProgressDialog != null && mProgressDialog.isShowing()) {
493
454
  mProgressDialog.dismiss();
@@ -504,9 +465,40 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
504
465
 
505
466
  // Show the dialog
506
467
  mProgressDialog = builder.create();
468
+
469
+ mProgressDialog.setOnShowListener(dialog -> {
470
+ sendEvent(getReactApplicationContext(), "onStartTrimming", null);
471
+ trimmerView.onSaveClicked();
472
+ });
473
+
507
474
  mProgressDialog.show();
508
475
  }
509
476
 
477
+ private void hideDialog(boolean shouldCloseEditor) {
478
+ // handle the case when the cancel dialog is still showing but the trimming is finished
479
+ if (cancelTrimmingConfirmDialog != null) {
480
+ if (cancelTrimmingConfirmDialog.isShowing()) {
481
+ cancelTrimmingConfirmDialog.dismiss();
482
+ }
483
+ cancelTrimmingConfirmDialog = null;
484
+ }
485
+
486
+ if (mProgressDialog != null) {
487
+ if (mProgressDialog.isShowing()) mProgressDialog.dismiss();
488
+ mProgressBar = null;
489
+ mProgressDialog = null;
490
+ }
491
+
492
+ if (shouldCloseEditor) {
493
+ if (alertDialog != null) {
494
+ if (alertDialog.isShowing()) {
495
+ alertDialog.dismiss();
496
+ }
497
+ alertDialog = null;
498
+ }
499
+ }
500
+ }
501
+
510
502
  @ReactMethod
511
503
  public void addListener(String eventName) {
512
504
  // This method is required by React
@@ -5,7 +5,6 @@ import com.videotrim.enums.ErrorCode;
5
5
 
6
6
  public interface VideoTrimListener {
7
7
  void onLoad(int duration);
8
- void onStartTrim();
9
8
  void onTrimmingProgress(int percentage);
10
9
  void onFinishTrim(String url, long startMs, long endMs, int videoDuration);
11
10
  void onCancelTrim();
@@ -52,8 +52,6 @@ public class VideoTrimmerUtil {
52
52
  // Format the current date and time
53
53
  String formattedDateTime = dateFormat.format(currentDate);
54
54
 
55
- callback.onStartTrim();
56
-
57
55
  String[] cmds = {
58
56
  "-ss",
59
57
  startMs + "ms",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-video-trim",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "Video trimmer for your React Native app",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",