Skip to content

Commit 8525925

Browse files
committed
lazily creating the voice directory references, avoid eagerly reading the file on the main thread
1 parent c2ce10f commit 8525925

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

vector/src/main/java/im/vector/app/features/voice/AbstractVoiceRecorder.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ abstract class AbstractVoiceRecorder(
2626
context: Context,
2727
private val filenameExt: String
2828
) : VoiceRecorder {
29-
private val outputDirectory = File(context.cacheDir, "voice_records")
29+
private val outputDirectory: File by lazy {
30+
File(context.cacheDir, "voice_records").also {
31+
if (!it.exists()) {
32+
it.mkdirs()
33+
}
34+
}
35+
}
3036

3137
private var mediaRecorder: MediaRecorder? = null
3238
private var outputFile: File? = null
3339

34-
init {
35-
if (!outputDirectory.exists()) {
36-
outputDirectory.mkdirs()
37-
}
38-
}
39-
4040
abstract fun setOutputFormat(mediaRecorder: MediaRecorder)
4141
abstract fun convertFile(recordedFile: File?): File?
4242

vector/src/main/java/im/vector/app/features/voice/VoicePlayerHelper.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import javax.inject.Inject
2727
class VoicePlayerHelper @Inject constructor(
2828
context: Context
2929
) {
30-
private val outputDirectory = File(context.cacheDir, "voice_records")
31-
32-
init {
33-
if (!outputDirectory.exists()) {
34-
outputDirectory.mkdirs()
30+
private val outputDirectory: File by lazy {
31+
File(context.cacheDir, "voice_records").also {
32+
if (!it.exists()) {
33+
it.mkdirs()
34+
}
3535
}
3636
}
3737

0 commit comments

Comments
 (0)