@@ -23,15 +23,13 @@ import android.os.Bundle
2323import androidx.annotation.CheckResult
2424import androidx.annotation.VisibleForTesting
2525import com.ichi2.anki.CollectionManager.withCol
26- import com.ichi2.anki.CrashReportService
2726import com.ichi2.anki.FieldEditText
2827import com.ichi2.anki.libanki.Card
2928import com.ichi2.anki.libanki.Collection
3029import com.ichi2.anki.libanki.Note
3130import com.ichi2.anki.libanki.NoteTypeId
3231import com.ichi2.anki.libanki.NotetypeJson
3332import com.ichi2.anki.libanki.QueueType
34- import com.ichi2.anki.libanki.exception.EmptyMediaException
3533import com.ichi2.anki.multimediacard.IMultimediaEditableNote
3634import com.ichi2.anki.multimediacard.fields.AudioRecordingField
3735import com.ichi2.anki.multimediacard.fields.EFieldType
@@ -44,7 +42,6 @@ import com.ichi2.anki.observability.undoableOp
4442import org.json.JSONException
4543import timber.log.Timber
4644import java.io.File
47- import java.io.IOException
4845
4946object NoteService {
5047 /* *
@@ -129,39 +126,23 @@ object NoteService {
129126 */
130127 fun importMediaToDirectory (
131128 col : Collection ,
132- field : IField ? ,
129+ field : IField ,
133130 ) {
134- var tmpMediaPath: File ? = null
135- when (field!! .type) {
136- EFieldType .AUDIO_RECORDING , EFieldType .MEDIA_CLIP , EFieldType .IMAGE -> tmpMediaPath = field.mediaFile
137- EFieldType .TEXT -> {
138- }
139- }
140- if (tmpMediaPath != null ) {
141- try {
142- val inFile = tmpMediaPath
143- if (inFile.exists() && inFile.length() > 0 ) {
144- val fname = col.media.addFile(inFile)
145- val outFile = File (col.media.dir, fname)
146- Timber .v(""" File "%s" should be copied to "%s""" , fname, outFile)
147- if (field.hasTemporaryMedia && outFile != tmpMediaPath) {
148- // Delete original
149- inFile.delete()
150- }
151- when (field.type) {
152- EFieldType .AUDIO_RECORDING , EFieldType .MEDIA_CLIP , EFieldType .IMAGE -> field.mediaFile = outFile
153- else -> {
154- }
155- }
156- }
157- } catch (e: IOException ) {
158- throw RuntimeException (e)
159- } catch (mediaException: EmptyMediaException ) {
160- // This shouldn't happen, but we're fine to ignore it if it does.
161- Timber .w(mediaException)
162- CrashReportService .sendExceptionReport(mediaException, " noteService::importMediaToDirectory" )
163- }
131+ val inFile =
132+ when (field.type) {
133+ EFieldType .AUDIO_RECORDING , EFieldType .MEDIA_CLIP , EFieldType .IMAGE -> field.mediaFile
134+ EFieldType .TEXT -> null
135+ } ? : return
136+
137+ if (inFile.length() == 0L ) return
138+
139+ val fname = col.media.addFile(inFile)
140+ val outFile = File (col.media.dir, fname)
141+ Timber .v(""" File "%s" should be copied to "%s""" , fname, outFile)
142+ if (field.hasTemporaryMedia && outFile != inFile) {
143+ inFile.delete()
164144 }
145+ field.mediaFile = outFile
165146 }
166147
167148 /* *
0 commit comments