Skip to content

Commit

Permalink
Support record video for sending
Browse files Browse the repository at this point in the history
  • Loading branch information
tien-awair committed May 17, 2022
1 parent 8e28771 commit b60b57e
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 4 deletions.
2 changes: 2 additions & 0 deletions uikit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@ dependencies {


implementation 'com.github.3llomi:RecordView:3.0.2'
implementation 'androidx.activity:activity:1.4.0'
implementation 'androidx.fragment:fragment:1.4.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -160,6 +163,15 @@ public class ChannelFragment extends BaseGroupChannelFragment implements OnIdent

private final ReplyType replyType = SendBirdUIKit.getReplyType();

ActivityResultLauncher<Uri> captureVideo = registerForActivityResult(new ActivityResultContracts.CaptureVideo(), result -> {
SendBird.setAutoBackgroundDetection(true);
if (result) {
if (this.mediaUri != null && isActive()) {
sendFileMessage(mediaUri);
}
}
});

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -880,9 +892,10 @@ private void scrollToBottom() {
protected void showMediaSelectDialog() {
if (getContext() == null || getFragmentManager() == null) return;
DialogListItem[] items = {
new DialogListItem(R.string.sb_text_channel_input_camera, R.drawable.icon_camera),
new DialogListItem(R.string.sb_text_channel_input_gallery, R.drawable.icon_photo),
new DialogListItem(R.string.sb_text_channel_input_document, R.drawable.icon_document)
new DialogListItem(R.string.sb_text_channel_input_video, R.drawable.icon_record_video),
new DialogListItem(R.string.sb_text_channel_input_camera, R.drawable.icon_take_image),
new DialogListItem(R.string.sb_text_channel_input_gallery, R.drawable.icon_gallery),
new DialogListItem(R.string.sb_text_channel_input_document, R.drawable.icon_file)
};
hideKeyboard();
DialogUtils.buildItemsBottom(items, (view, position, item) -> {
Expand All @@ -892,6 +905,8 @@ protected void showMediaSelectDialog() {
takeCamera();
} else if (key == R.string.sb_text_channel_input_gallery) {
takePhoto();
} else if (key == R.string.sb_text_channel_input_video) {
takeVideo();
} else {
takeFile();
}
Expand Down Expand Up @@ -938,6 +953,29 @@ public void onPermissionGranted(int requestCode) {
});
}

public void takeVideo() {
checkPermission(PERMISSION_REQUEST_ALL, new IPermissionHandler() {
@Override
public String[] getPermissions(int requestCode) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
return new String[]{Manifest.permission.CAMERA,
Manifest.permission.READ_EXTERNAL_STORAGE};
}
return new String[]{Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE};
}

@Override
public void onPermissionGranted(int requestCode) {
mediaUri = FileUtils.createVideoUri(getContext());
SendBird.setAutoBackgroundDetection(false);
captureVideo.launch(mediaUri);
}
});

}

/**
* Call taking gallery application.
*
Expand Down
10 changes: 9 additions & 1 deletion uikit/src/main/java/com/sendbird/uikit/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,18 @@ public static Uri createPictureImageUri(@NonNull Context context) {
ContentResolver contentResolver = context.getContentResolver();
ContentValues cv = new ContentValues();
String fileName = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
cv.put(MediaStore.Images.Media.TITLE, fileName);
cv.put(MediaStore.Images.Media.TITLE, fileName + ".png");
return contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, cv);
}

public static Uri createVideoUri(@NonNull Context context) {
ContentResolver contentResolver = context.getContentResolver();
ContentValues cv = new ContentValues();
String fileName = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
cv.put(MediaStore.Video.Media.TITLE, fileName + ".mp4");
return contentResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, cv);
}

@RequiresApi(api = Build.VERSION_CODES.Q)
public static Uri createDownloadFileUri(@NonNull Context context,
@NonNull String mimeType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public void onReconnectFailed() {
super();
this.userListQuery = SendBird.createApplicationUserListQuery();
this.userListQuery.setLimit(USER_LIST_LIMIT);
// this.userListQuery.setNicknameStartsWithFilter("Nguyen Dzung");
this.customUserListQueryHandler = customUserListQueryHandler == null ? SendBirdUIKit.getCustomUserListQueryHandler() : customUserListQueryHandler;
}

Expand Down
10 changes: 10 additions & 0 deletions uikit/src/main/res/drawable/icon_file.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/primary_400">
<path
android:fillColor="@color/primary_400"
android:pathData="M6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6L6,2zM13,9L13,3.5L18.5,9L13,9z"/>
</vector>
10 changes: 10 additions & 0 deletions uikit/src/main/res/drawable/icon_gallery.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/primary_400">
<path
android:fillColor="@color/primary_400"
android:pathData="M22,16L22,4c0,-1.1 -0.9,-2 -2,-2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2zM11,12l2.03,2.71L16,11l4,5L8,16l3,-4zM2,6v14c0,1.1 0.9,2 2,2h14v-2L4,20L4,6L2,6z"/>
</vector>
10 changes: 10 additions & 0 deletions uikit/src/main/res/drawable/icon_record_video.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/primary_400">
<path
android:fillColor="@color/primary_400"
android:pathData="M17,10.5V7c0,-0.55 -0.45,-1 -1,-1H4c-0.55,0 -1,0.45 -1,1v10c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1v-3.5l4,4v-11l-4,4z"/>
</vector>
10 changes: 10 additions & 0 deletions uikit/src/main/res/drawable/icon_take_image.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/primary_400">
<path
android:fillColor="@color/primary_400"
android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/>
</vector>
1 change: 1 addition & 0 deletions uikit/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<string name="sb_text_channel_input_text_hint">Enter message</string>
<string name="sb_text_channel_input_reply_text_hint">Reply to message</string>
<string name="sb_text_channel_input_camera">Camera</string>
<string name="sb_text_channel_input_video">Record Video</string>
<string name="sb_text_channel_input_gallery">Photo library</string>
<string name="sb_text_channel_input_document">Files</string>
<string name="sb_text_channel_typing_indicator_single">%s is typing&#8230;</string>
Expand Down

0 comments on commit b60b57e

Please sign in to comment.