mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Added filter for recordings + legacy recording files
This commit is contained in:
parent
cda23c44c0
commit
ec207af81d
2 changed files with 87 additions and 30 deletions
|
|
@ -35,14 +35,19 @@ class RecordingModel @WorkerThread constructor(
|
|||
val filePath: String,
|
||||
val fileName: String,
|
||||
private val onPlay: ((model: RecordingModel) -> Unit),
|
||||
private val onPause: ((model: RecordingModel) -> Unit)
|
||||
private val onPause: ((model: RecordingModel) -> Unit),
|
||||
isLegacy: Boolean = false
|
||||
) {
|
||||
companion object {
|
||||
private const val TAG = "[Recording Model]"
|
||||
}
|
||||
|
||||
val sipUri: String
|
||||
|
||||
val displayName: String
|
||||
|
||||
val timestamp: Long
|
||||
|
||||
val month: String
|
||||
|
||||
val dateTime: String
|
||||
|
|
@ -58,36 +63,56 @@ class RecordingModel @WorkerThread constructor(
|
|||
init {
|
||||
isPlaying.postValue(false)
|
||||
|
||||
val withoutHeader = fileName.substring(LinphoneUtils.RECORDING_FILE_NAME_HEADER.length)
|
||||
val indexOfSeparator = withoutHeader.indexOf(
|
||||
LinphoneUtils.RECORDING_FILE_NAME_URI_TIMESTAMP_SEPARATOR
|
||||
)
|
||||
val sipUri = withoutHeader.substring(0, indexOfSeparator)
|
||||
val timestamp = withoutHeader.substring(
|
||||
indexOfSeparator + LinphoneUtils.RECORDING_FILE_NAME_URI_TIMESTAMP_SEPARATOR.length,
|
||||
withoutHeader.length - LinphoneUtils.RECORDING_FILE_EXTENSION.length
|
||||
)
|
||||
Log.i("$TAG Extract SIP URI [$sipUri] and timestamp [$timestamp] from file [$fileName]")
|
||||
if (isLegacy) {
|
||||
val username = fileName.split("_")[0]
|
||||
val sipAddress = coreContext.core.interpretUrl(username, false)
|
||||
sipUri = sipAddress?.asStringUriOnly() ?: username
|
||||
displayName = if (sipAddress != null) {
|
||||
val contact = coreContext.contactsManager.findContactByAddress(sipAddress)
|
||||
contact?.name ?: LinphoneUtils.getDisplayName(sipAddress)
|
||||
} else {
|
||||
sipUri
|
||||
}
|
||||
|
||||
val parsedTimestamp = timestamp.toLong()
|
||||
month = TimestampUtils.month(parsedTimestamp, timestampInSecs = false)
|
||||
val parsedDate = fileName.split("_")[1]
|
||||
val date = SimpleDateFormat("dd-MM-yyyy-HH-mm-ss", Locale.getDefault()).parse(
|
||||
parsedDate
|
||||
)
|
||||
timestamp = date?.time ?: 0L
|
||||
} else {
|
||||
val withoutHeader = fileName.substring(LinphoneUtils.RECORDING_FILE_NAME_HEADER.length)
|
||||
val indexOfSeparator = withoutHeader.indexOf(
|
||||
LinphoneUtils.RECORDING_FILE_NAME_URI_TIMESTAMP_SEPARATOR
|
||||
)
|
||||
sipUri = withoutHeader.substring(0, indexOfSeparator)
|
||||
val sipAddress = Factory.instance().createAddress(sipUri)
|
||||
displayName = if (sipAddress != null) {
|
||||
val contact = coreContext.contactsManager.findContactByAddress(sipAddress)
|
||||
contact?.name ?: LinphoneUtils.getDisplayName(sipAddress)
|
||||
} else {
|
||||
sipUri
|
||||
}
|
||||
|
||||
val parsedTimestamp = withoutHeader.substring(
|
||||
indexOfSeparator + LinphoneUtils.RECORDING_FILE_NAME_URI_TIMESTAMP_SEPARATOR.length,
|
||||
withoutHeader.length - LinphoneUtils.RECORDING_FILE_EXTENSION.length
|
||||
)
|
||||
Log.i(
|
||||
"$TAG Extract SIP URI [$sipUri] and timestamp [$parsedTimestamp] from file [$fileName]"
|
||||
)
|
||||
timestamp = parsedTimestamp.toLong()
|
||||
}
|
||||
|
||||
month = TimestampUtils.month(timestamp, timestampInSecs = false)
|
||||
val date = TimestampUtils.toString(
|
||||
parsedTimestamp,
|
||||
timestamp,
|
||||
timestampInSecs = false,
|
||||
onlyDate = true,
|
||||
shortDate = false
|
||||
)
|
||||
val time = TimestampUtils.timeToString(parsedTimestamp, timestampInSecs = false)
|
||||
val time = TimestampUtils.timeToString(timestamp, timestampInSecs = false)
|
||||
dateTime = "$date - $time"
|
||||
|
||||
val sipAddress = Factory.instance().createAddress(sipUri)
|
||||
displayName = if (sipAddress != null) {
|
||||
val contact = coreContext.contactsManager.findContactByAddress(sipAddress)
|
||||
contact?.name ?: LinphoneUtils.getDisplayName(sipAddress)
|
||||
} else {
|
||||
sipUri
|
||||
}
|
||||
|
||||
val audioPlayer = coreContext.core.createLocalPlayer(null, null, null)
|
||||
if (audioPlayer != null) {
|
||||
audioPlayer.open(filePath)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import androidx.annotation.WorkerThread
|
|||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.media.AudioFocusRequestCompat
|
||||
import java.util.regex.Pattern
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.channels.ticker
|
||||
|
|
@ -43,6 +44,9 @@ import org.linphone.utils.FileUtils
|
|||
class RecordingsListViewModel @UiThread constructor() : GenericViewModel() {
|
||||
companion object {
|
||||
private const val TAG = "[Recordings List ViewModel]"
|
||||
|
||||
private val LEGACY_RECORD_PATTERN: Pattern =
|
||||
Pattern.compile(".*/(.*)_(\\d{2}-\\d{2}-\\d{4}-\\d{2}-\\d{2}-\\d{2})\\..*")
|
||||
}
|
||||
|
||||
val recordings = MutableLiveData<ArrayList<RecordingModel>>()
|
||||
|
|
@ -217,13 +221,35 @@ class RecordingsListViewModel @UiThread constructor() : GenericViewModel() {
|
|||
recordings.value.orEmpty().forEach(RecordingModel::destroy)
|
||||
val list = arrayListOf<RecordingModel>()
|
||||
|
||||
// TODO FIXME: also load recordings from previous Linphone versions
|
||||
for (file in FileUtils.getFileStorageDir(isRecording = true).listFiles().orEmpty()) {
|
||||
val path = file.path
|
||||
val name = file.name
|
||||
Log.i("$TAG Found file $path")
|
||||
list.add(
|
||||
RecordingModel(
|
||||
|
||||
Log.d("$TAG Found file $path")
|
||||
val model = RecordingModel(
|
||||
path,
|
||||
name,
|
||||
{ model ->
|
||||
onRecordingStartedPlaying(model)
|
||||
},
|
||||
{ model ->
|
||||
onRecordingPaused(model)
|
||||
}
|
||||
)
|
||||
|
||||
if (filter.isEmpty() || model.sipUri.contains(filter)) {
|
||||
Log.i("$TAG Added file $path")
|
||||
list.add(model)
|
||||
}
|
||||
}
|
||||
// Legacy path where to find recordings
|
||||
for (file in FileUtils.getFileStorageDir().listFiles().orEmpty()) {
|
||||
val path = file.path
|
||||
val name = file.name
|
||||
|
||||
if (LEGACY_RECORD_PATTERN.matcher(path).matches()) {
|
||||
Log.d("$TAG Found legacy file $path")
|
||||
val model = RecordingModel(
|
||||
path,
|
||||
name,
|
||||
{ model ->
|
||||
|
|
@ -231,13 +257,19 @@ class RecordingsListViewModel @UiThread constructor() : GenericViewModel() {
|
|||
},
|
||||
{ model ->
|
||||
onRecordingPaused(model)
|
||||
}
|
||||
},
|
||||
true
|
||||
)
|
||||
)
|
||||
|
||||
if (filter.isEmpty() || model.sipUri.contains(filter)) {
|
||||
Log.i("$TAG Added legacy file $path")
|
||||
list.add(model)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
list.sortBy {
|
||||
it.filePath // TODO FIXME
|
||||
it.timestamp
|
||||
}
|
||||
recordings.postValue(list)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue