0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00

feat(media-import): Import Video

Importing only accepts one MIME type, so add a new button for video

We add a new string, as "Library" no longer makes sense

Issue 10315
This commit is contained in:
David Allison 2022-02-12 12:45:32 +00:00 committed by Mike Hardy
parent 4a53e869fa
commit 36f50c7cc4
2 changed files with 22 additions and 4 deletions

View File

@ -51,7 +51,7 @@ class BasicAudioClipFieldController : FieldControllerBase(), IFieldController {
// #9639: .opus is application/octet-stream in API 26,
// requires a workaround as we don't want to enable application/octet-stream by default
val btnLibrary = Button(mActivity)
btnLibrary.text = mActivity.getText(R.string.multimedia_editor_image_field_editing_library)
btnLibrary.text = mActivity.getText(R.string.multimedia_editor_import_audio)
btnLibrary.setOnClickListener {
openChooserPrompt(
"audio/*",
@ -61,6 +61,18 @@ class BasicAudioClipFieldController : FieldControllerBase(), IFieldController {
)
}
layout!!.addView(btnLibrary, ViewGroup.LayoutParams.MATCH_PARENT)
val btnVideo = Button(mActivity).apply {
text = mActivity.getText(R.string.multimedia_editor_import_video)
setOnClickListener {
openChooserPrompt(
"video/*",
emptyArray(),
R.string.multimedia_editor_popup_video_clip,
ACTIVITY_SELECT_VIDEO_CLIP
)
}
}
layout.addView(btnVideo, ViewGroup.LayoutParams.MATCH_PARENT)
tvAudioClip = FixedTextView(mActivity)
if (mField.audioPath == null) {
(tvAudioClip as FixedTextView).setVisibility(View.GONE)
@ -75,10 +87,9 @@ class BasicAudioClipFieldController : FieldControllerBase(), IFieldController {
val allowAllFiles = AnkiDroidApp.getSharedPrefs(this.mActivity).getBoolean("mediaImportAllowAllFiles", false)
val i = Intent()
i.type = if (allowAllFiles) "*/*" else initialMimeType
if (!allowAllFiles) {
if (!allowAllFiles && extraMimeTypes.any()) {
// application/ogg takes precedence over "*/*" for application/octet-stream
// so don't add it if we're want */*
val extraMimeTypes = extraMimeTypes // #9226 allows ogg on Android 8
i.putExtra(Intent.EXTRA_MIME_TYPES, extraMimeTypes)
}
i.action = Intent.ACTION_GET_CONTENT
@ -95,6 +106,11 @@ class BasicAudioClipFieldController : FieldControllerBase(), IFieldController {
handleMediaSelection(data!!, "ankidroid_audioclip_")
}
}
if (resultCode != Activity.RESULT_CANCELED && requestCode == ACTIVITY_SELECT_VIDEO_CLIP) {
executeSafe(mActivity, "handleMediaSelection:unhandled") {
handleMediaSelection(data!!, "ankidroid_videoclip_")
}
}
}
private fun handleMediaSelection(data: Intent, clipNamePrefix: String) {

View File

@ -16,6 +16,7 @@
<!-- Main editor popup menu items -->
<string name="multimedia_editor_popup_image">Add image</string>
<string name="multimedia_editor_popup_audio_clip">Add audio clip</string>
<string name="multimedia_editor_popup_video_clip">Add video clip</string>
<string name="multimedia_editor_popup_audio">Record audio</string>
<string name="multimedia_editor_popup_text">Advanced editor</string>
<string name="multimedia_editor_popup_cloze">Cloze deletion</string>
@ -74,7 +75,8 @@
<!-- for buttons -->
<string name="multimedia_editor_image_field_editing_galery">Gallery</string>
<string name="multimedia_editor_image_field_editing_photo">Camera</string>
<string name="multimedia_editor_image_field_editing_library">Library</string>
<string name="multimedia_editor_import_audio">Audio</string>
<string name="multimedia_editor_import_video">Video</string>
<!-- General -->
<!-- message on the progress dialog for the user to wait, means process -->