Skip to content

Commit

Permalink
enhacement: add Audio and Video multimedia options
Browse files Browse the repository at this point in the history
* refactor: viewModel to use generic media terms and livedata
* refactor: use reselect string instead of restart
* refactor: extract MenuProvider class
* refactor: show multimedia bottomsheet in case result is cancelled
  • Loading branch information
criticalAY authored and david-allison committed Jul 31, 2024
1 parent de309bb commit 7d82d12
Show file tree
Hide file tree
Showing 20 changed files with 813 additions and 185 deletions.
4 changes: 4 additions & 0 deletions AnkiDroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,8 @@ dependencies {
androidTestImplementation libs.kotlin.test
androidTestImplementation libs.kotlin.test.junit
androidTestImplementation libs.androidx.fragment.testing

implementation libs.androidx.media3.exoplayer
implementation libs.androidx.media3.exoplayer.dash
implementation libs.androidx.media3.ui
}
27 changes: 24 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import com.ichi2.anki.dialogs.tags.TagsDialog
import com.ichi2.anki.dialogs.tags.TagsDialogFactory
import com.ichi2.anki.dialogs.tags.TagsDialogListener
import com.ichi2.anki.model.CardStateFilter
import com.ichi2.anki.multimedia.AudioVideoFragment
import com.ichi2.anki.multimedia.MultimediaActivity.Companion.MULTIMEDIA_RESULT
import com.ichi2.anki.multimedia.MultimediaActivity.Companion.MULTIMEDIA_RESULT_FIELD_INDEX
import com.ichi2.anki.multimedia.MultimediaActivityExtra
Expand Down Expand Up @@ -275,11 +276,13 @@ class NoteEditor : AnkiFragment(R.layout.note_editor), DeckSelectionListener, Su
NoteEditorActivityResultCallback { result ->
if (result.resultCode == RESULT_CANCELED) {
Timber.d("Multimedia result canceled")
val index = result.data?.extras?.getInt(MULTIMEDIA_RESULT_FIELD_INDEX) ?: return@NoteEditorActivityResultCallback
handleMultimediaActions(index)
return@NoteEditorActivityResultCallback
}

Timber.d("Getting multimedia result")
val extras = result.data!!.extras ?: return@NoteEditorActivityResultCallback
val extras = result.data?.extras ?: return@NoteEditorActivityResultCallback
handleMultimediaResult(extras)
}
)
Expand Down Expand Up @@ -1749,7 +1752,16 @@ class NoteEditor : AnkiFragment(R.layout.note_editor), DeckSelectionListener, Su
}

MultimediaBottomSheet.MultimediaAction.SELECT_AUDIO_FILE -> {
// TODO("Not yet implemented")
Timber.i("Selected audio clip option")
val field = MediaClipField()
note.setField(fieldIndex, field)
val mediaIntent = AudioVideoFragment.getIntent(
requireContext(),
MultimediaActivityExtra(fieldIndex, field, note),
AudioVideoFragment.MediaOption.AUDIO_CLIP
)

multimediaFragmentLauncher.launch(mediaIntent)
}

MultimediaBottomSheet.MultimediaAction.OPEN_DRAWING -> {
Expand All @@ -1761,7 +1773,16 @@ class NoteEditor : AnkiFragment(R.layout.note_editor), DeckSelectionListener, Su
}

MultimediaBottomSheet.MultimediaAction.SELECT_VIDEO_FILE -> {
// TODO("Not yet implemented")
Timber.i("Selected video clip option")
val field = MediaClipField()
note.setField(fieldIndex, field)
val mediaIntent = AudioVideoFragment.getIntent(
requireContext(),
MultimediaActivityExtra(fieldIndex, field, note),
AudioVideoFragment.MediaOption.VIDEO_CLIP
)

multimediaFragmentLauncher.launch(mediaIntent)
}

MultimediaBottomSheet.MultimediaAction.OPEN_CAMERA -> {
Expand Down
Loading

0 comments on commit 7d82d12

Please sign in to comment.