forked from mirror/monocles_chat_clean
update fork #128
4 changed files with 114 additions and 15 deletions
Allow creating videos for posts and add preview
commit
cd7e529b4d
|
|
@ -2457,6 +2457,24 @@ public class FileBackend {
|
|||
}
|
||||
}
|
||||
|
||||
public Uri getTakeVideoUri() {
|
||||
final String filename =
|
||||
String.format("IMG_%s.%s", IMAGE_DATE_FORMAT.format(new Date()), "mp4");
|
||||
final File directory;
|
||||
if (Config.ONLY_INTERNAL_STORAGE) {
|
||||
directory = new File(mXmppConnectionService.getCacheDir(), "Camera");
|
||||
} else {
|
||||
directory =
|
||||
new File(
|
||||
Environment.getExternalStoragePublicDirectory(
|
||||
Environment.DIRECTORY_DCIM),
|
||||
"Camera");
|
||||
}
|
||||
final File file = new File(directory, filename);
|
||||
file.getParentFile().mkdirs();
|
||||
return getUriForFile(mXmppConnectionService, file, filename);
|
||||
}
|
||||
|
||||
private static class Dimensions {
|
||||
public final int width;
|
||||
public final int height;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package eu.siacs.conversations.ui;
|
|||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
|
|
@ -15,9 +16,16 @@ import android.widget.Toast;
|
|||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
|
@ -54,6 +62,21 @@ public class CreatePostActivity extends XmppActivity {
|
|||
attachmentUri = mCameraUri;
|
||||
binding.attachmentPreview.setImageURI(attachmentUri);
|
||||
binding.attachmentPreview.setVisibility(View.VISIBLE);
|
||||
binding.attachmentVideoView.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
private final ActivityResultLauncher<Intent> takeVideoLauncher =
|
||||
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
||||
if (result.getResultCode() == RESULT_OK) {
|
||||
attachmentUri = mCameraUri;
|
||||
binding.attachmentVideoView.setVideoURI(attachmentUri);
|
||||
binding.attachmentVideoView.setOnPreparedListener(mp -> {
|
||||
mp.setLooping(true);
|
||||
binding.attachmentVideoView.start();
|
||||
});
|
||||
binding.attachmentVideoView.setVisibility(View.VISIBLE);
|
||||
binding.attachmentPreview.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -62,8 +85,20 @@ public class CreatePostActivity extends XmppActivity {
|
|||
uri -> {
|
||||
if (uri != null) {
|
||||
this.attachmentUri = uri;
|
||||
binding.attachmentPreview.setImageURI(attachmentUri);
|
||||
binding.attachmentPreview.setVisibility(View.VISIBLE);
|
||||
final String mimeType = getContentResolver().getType(attachmentUri);
|
||||
if (mimeType != null && mimeType.startsWith("image/")) {
|
||||
binding.attachmentPreview.setImageURI(attachmentUri);
|
||||
binding.attachmentPreview.setVisibility(View.VISIBLE);
|
||||
binding.attachmentVideoView.setVisibility(View.GONE);
|
||||
} else if (mimeType != null && mimeType.startsWith("video/")) {
|
||||
binding.attachmentVideoView.setVideoURI(attachmentUri);
|
||||
binding.attachmentVideoView.setOnPreparedListener(mp -> {
|
||||
mp.setLooping(true);
|
||||
binding.attachmentVideoView.start();
|
||||
});
|
||||
binding.attachmentVideoView.setVisibility(View.VISIBLE);
|
||||
binding.attachmentPreview.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
@ -101,6 +136,13 @@ public class CreatePostActivity extends XmppActivity {
|
|||
requestPermissionLauncher.launch(Manifest.permission.CAMERA);
|
||||
}
|
||||
});
|
||||
binding.attachVideoButton.setOnClickListener(v -> {
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
|
||||
openVideoCamera();
|
||||
} else {
|
||||
requestPermissionLauncher.launch(Manifest.permission.CAMERA);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void openCamera() {
|
||||
|
|
@ -114,13 +156,24 @@ public class CreatePostActivity extends XmppActivity {
|
|||
takePictureLauncher.launch(takePictureIntent);
|
||||
}
|
||||
|
||||
private void openVideoCamera() {
|
||||
if (xmppConnectionService == null) {
|
||||
Toast.makeText(this, R.string.not_connected_try_again, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
mCameraUri = xmppConnectionService.getFileBackend().getTakeVideoUri();
|
||||
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
|
||||
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraUri);
|
||||
takeVideoLauncher.launch(takeVideoIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshUiReal() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackendConnected() {
|
||||
public void onBackendConnected() {
|
||||
if (xmppConnectionService != null && accountUuid == null) {
|
||||
onlineAccounts.clear();
|
||||
List<String> accountJids = new ArrayList<>();
|
||||
|
|
@ -234,4 +287,4 @@ public class CreatePostActivity extends XmppActivity {
|
|||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,17 +21,35 @@
|
|||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/attachment_preview"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="150dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:visibility="gone"
|
||||
<LinearLayout
|
||||
android:id="@+id/posts_attachment_preview_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/app_bar"
|
||||
tools:src="@tools:sample/avatars"
|
||||
tools:visibility="visible"/>
|
||||
app:layout_constraintTop_toBottomOf="@+id/app_bar">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/attachment_preview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:visibility="gone"
|
||||
android:scaleType="fitCenter"
|
||||
tools:src="@tools:sample/avatars"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/attachment_video_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:visibility="gone"
|
||||
tools:src="@tools:sample/avatars"
|
||||
tools:visibility="visible" />
|
||||
</LinearLayout>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/account_spinner"
|
||||
|
|
@ -42,7 +60,7 @@
|
|||
android:layout_marginEnd="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/attachment_preview" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/posts_attachment_preview_layout" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/post_title_layout"
|
||||
|
|
@ -104,6 +122,14 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_camera_alt_24dp" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/attach_video_button"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_videocam_24dp"
|
||||
android:contentDescription="@string/attach_record_video" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
|
|
@ -19,7 +20,8 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="250dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:visibility="gone" />
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/publish_info_text"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue