Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Bug fixes and performance improvements #169

Merged
merged 6 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/src/main/java/com/bnyro/recorder/App.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.bnyro.recorder

import android.app.Application
import com.bnyro.recorder.util.FileRepository
import com.bnyro.recorder.util.FileRepositoryImpl
import com.bnyro.recorder.util.NotificationHelper
import com.bnyro.recorder.util.Preferences
import com.bnyro.recorder.util.ShortcutHelper

class App : Application() {
val fileRepository: FileRepository by lazy {
FileRepositoryImpl(this)
}
override fun onCreate() {
super.onCreate()
Preferences.init(this)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/bnyro/recorder/enums/SortOrder.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bnyro.recorder.enums

enum class SortOrder {
DEFAULT,
ALPHABETIC,
ALPHABETIC_REV,
SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationManagerCompat
import com.bnyro.recorder.App
import com.bnyro.recorder.services.RecorderService
import com.bnyro.recorder.util.IntentHelper
import com.bnyro.recorder.util.NotificationHelper
import com.bnyro.recorder.util.StorageHelper

class FinishedNotificationReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val fileName = intent.getStringExtra(RecorderService.FILE_NAME_EXTRA_KEY) ?: return
val file = StorageHelper.getOutputDir(context).findFile(fileName)
val file = (context.applicationContext as App).fileRepository
.getOutputDir().findFile(fileName)

when (intent.getStringExtra(RecorderService.ACTION_EXTRA_KEY)) {
RecorderService.SHARE_ACTION -> file?.let { IntentHelper.shareFile(context, it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.bnyro.recorder.services

import com.bnyro.recorder.App
import com.bnyro.recorder.R
import com.bnyro.recorder.enums.AudioChannels
import com.bnyro.recorder.enums.AudioDeviceSource
import com.bnyro.recorder.obj.AudioFormat
import com.bnyro.recorder.util.PlayerHelper
import com.bnyro.recorder.util.Preferences
import com.bnyro.recorder.util.StorageHelper

class AudioRecorderService : RecorderService() {
override val notificationTitle: String
Expand Down Expand Up @@ -38,8 +38,7 @@ class AudioRecorderService : RecorderService() {
setOutputFormat(audioFormat.format)
setAudioEncoder(audioFormat.codec)

outputFile = StorageHelper.getOutputFile(
this@AudioRecorderService,
outputFile = (application as App).fileRepository.getOutputFile(
audioFormat.extension
)
fileDescriptor = contentResolver.openFileDescriptor(outputFile!!.uri, "w")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import android.media.MediaRecorder
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.documentfile.provider.DocumentFile
import com.bnyro.recorder.App
import com.bnyro.recorder.R
import com.bnyro.recorder.enums.RecorderState
import com.bnyro.recorder.util.PcmConverter
import com.bnyro.recorder.util.StorageHelper
import java.io.File
import kotlin.concurrent.thread
import kotlin.experimental.and
Expand Down Expand Up @@ -110,9 +110,11 @@ class LosslessRecorderService : RecorderService() {

private fun convertToWav() {
val inputStream = contentResolver.openInputStream(outputFile?.uri ?: return) ?: return
val outputStream = StorageHelper.getOutputFile(this, FILE_NAME_EXTENSION_WAV).let {
contentResolver.openOutputStream(it.uri) ?: return
}
val outputStream = (application as App).fileRepository
.getOutputFile(FILE_NAME_EXTENSION_WAV)
.let {
contentResolver.openOutputStream(it.uri) ?: return
}
pcmConverter?.convertToWave(inputStream, outputStream, BUFFER_SIZE_IN_BYTES)
outputFile?.delete()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.util.DisplayMetrics
import android.util.Log
import android.view.Display
import androidx.activity.result.ActivityResult
import com.bnyro.recorder.App
import com.bnyro.recorder.R
import com.bnyro.recorder.enums.AudioChannels
import com.bnyro.recorder.enums.AudioDeviceSource
Expand All @@ -21,7 +22,6 @@ import com.bnyro.recorder.enums.VideoFormat
import com.bnyro.recorder.obj.VideoResolution
import com.bnyro.recorder.util.PlayerHelper
import com.bnyro.recorder.util.Preferences
import com.bnyro.recorder.util.StorageHelper

class ScreenRecorderService : RecorderService() {
override val notificationTitle: String
Expand Down Expand Up @@ -115,10 +115,8 @@ class ScreenRecorderService : RecorderService() {
null
)

outputFile = StorageHelper.getOutputFile(
this@ScreenRecorderService,
videoFormat.extension
)
outputFile = (application as App).fileRepository
.getOutputFile(videoFormat.extension)
fileDescriptor = contentResolver.openFileDescriptor(outputFile!!.uri, "w")
setOutputFile(fileDescriptor?.fileDescriptor)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.bnyro.recorder.R
import com.bnyro.recorder.ui.common.DialogButton
import com.bnyro.recorder.util.FileRepositoryImpl
import com.bnyro.recorder.util.Preferences
import com.bnyro.recorder.util.StorageHelper

@Composable
fun NamingPatternPref() {
Expand Down Expand Up @@ -48,7 +48,7 @@ fun NamingPatternPref() {
mutableStateOf(
Preferences.getString(
Preferences.namingPatternKey,
StorageHelper.DEFAULT_NAMING_PATTERN
FileRepositoryImpl.DEFAULT_NAMING_PATTERN
)
)
}
Expand Down
36 changes: 4 additions & 32 deletions app/src/main/java/com/bnyro/recorder/ui/components/PlayerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,20 @@ import androidx.compose.material3.TabRow
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.bnyro.recorder.R
import com.bnyro.recorder.obj.RecordingItemData
import com.bnyro.recorder.ui.dialogs.ConfirmationDialog
import com.bnyro.recorder.ui.models.PlayerModel
import kotlinx.coroutines.launch

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun PlayerView(
showVideoModeInitially: Boolean,
showDeleteDialog: Boolean,
selectedFiles: MutableState<List<RecordingItemData>>,
onDeleteAllDialogDismissed: () -> Unit
showVideoModeInitially: Boolean
) {
val playerModel: PlayerModel = viewModel()
val context = LocalContext.current

LaunchedEffect(Unit) {
playerModel.loadFiles(context)
}
val playerModel: PlayerModel = viewModel(factory = PlayerModel.Factory)

Column(
modifier = Modifier.fillMaxSize()
Expand Down Expand Up @@ -90,32 +79,15 @@ fun PlayerView(
) { index ->
when (index) {
0 -> RecordingItemList(
items = playerModel.recordingItems.filter { it.isAudio },
selectedFiles,
items = playerModel.audioRecordingItems,
isVideoList = false
)

1 -> RecordingItemList(
items = playerModel.recordingItems.filter { it.isVideo },
selectedFiles,
items = playerModel.screenRecordingItems,
isVideoList = true
)
}
}
}

if (showDeleteDialog) {
ConfirmationDialog(
title = if (selectedFiles.value.isEmpty()) R.string.delete_all else R.string.delete,
onDismissRequest = onDeleteAllDialogDismissed
) {
val filesToDelete =
selectedFiles.value.takeIf { it.isNotEmpty() } ?: playerModel.recordingItems
filesToDelete.forEach {
if (it.recordingFile.exists()) it.recordingFile.delete()
playerModel.recordingItems.remove(it)
selectedFiles.value -= it
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fun RecordingItem(
onClick: (wasLongClick: Boolean) -> Unit,
startPlayingAudio: () -> Unit
) {
val playerModel: PlayerModel = viewModel()
val playerModel: PlayerModel = viewModel(factory = PlayerModel.Factory)
val context = LocalContext.current
val view = LocalView.current
val haptic = LocalHapticFeedback.current
Expand Down Expand Up @@ -215,9 +215,7 @@ fun RecordingItem(
confirmButton = {
DialogButton(stringResource(R.string.okay)) {
recordingFile.renameTo(fileName)
val index = playerModel.files.indexOf(recordingFile)
playerModel.files.removeAt(index)
playerModel.files.add(index, recordingFile)
playerModel.loadFiles()
showRenameDialog = false
}
},
Expand All @@ -236,7 +234,7 @@ fun RecordingItem(
) {
playerModel.stopPlaying()
recordingFile.delete()
playerModel.files.remove(recordingFile)
playerModel.loadFiles()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.material.icons.filled.VideoFile
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
Expand All @@ -30,7 +29,6 @@ import com.bnyro.recorder.ui.models.PlayerModel
@Composable
fun RecordingItemList(
items: List<RecordingItemData>,
selectedFiles: MutableState<List<RecordingItemData>>,
isVideoList: Boolean,
playerModel: PlayerModel = viewModel()
) {
Expand All @@ -46,15 +44,15 @@ fun RecordingItemList(
items(items) {
RecordingItem(
it,
isSelected = selectedFiles.value.contains(it),
isSelected = playerModel.selectedFiles.contains(it),
onClick = { wasLongPress ->
when {
wasLongPress -> selectedFiles.value += it
selectedFiles.value.isNotEmpty() -> {
if (selectedFiles.value.contains(it)) {
selectedFiles.value -= it
wasLongPress -> playerModel.selectedFiles += it
playerModel.selectedFiles.isNotEmpty() -> {
if (playerModel.selectedFiles.contains(it)) {
playerModel.selectedFiles -= it
} else {
selectedFiles.value += it
playerModel.selectedFiles += it
}
}
}
Expand Down
Loading
Loading