@@ -18,6 +18,7 @@ import React, {
1818} from 'react' ;
1919import {
2020 ActivityIndicator ,
21+ Alert ,
2122 Image ,
2223 Linking ,
2324 Pressable ,
@@ -35,11 +36,13 @@ import { Icons } from './assets';
3536import {
3637 generateAudioList ,
3738 playbackSpeedSequence ,
39+ getRecordedAudios ,
3840 type ListItem ,
3941} from './constants' ;
4042import stylesheet from './styles' ;
4143import { Colors } from './theme' ;
4244import FastImage from 'react-native-fast-image' ;
45+ import fs from 'react-native-fs' ;
4346
4447const RenderListItem = React . memo (
4548 ( {
@@ -224,6 +227,7 @@ const AppContainer = () => {
224227 const [ shouldScroll , setShouldScroll ] = useState < boolean > ( true ) ;
225228 const [ currentPlaying , setCurrentPlaying ] = useState < string > ( '' ) ;
226229 const [ list , setList ] = useState < ListItem [ ] > ( [ ] ) ;
230+ const [ nbOfRecording , setNumberOfRecording ] = useState < number > ( 0 ) ;
227231 const [ currentPlaybackSpeed , setCurrentPlaybackSpeed ] =
228232 useState < PlaybackSpeedType > ( 1.0 ) ;
229233
@@ -238,6 +242,12 @@ const AppContainer = () => {
238242 } ) ;
239243 } , [ ] ) ;
240244
245+ useEffect ( ( ) => {
246+ getRecordedAudios ( ) . then ( recordedAudios =>
247+ setNumberOfRecording ( recordedAudios . length )
248+ ) ;
249+ } , [ list ] ) ;
250+
241251 const changeSpeed = ( ) => {
242252 setCurrentPlaybackSpeed (
243253 prev =>
@@ -248,6 +258,35 @@ const AppContainer = () => {
248258 ) ;
249259 } ;
250260
261+ const handleDeleteRecordings = async ( ) => {
262+ const recordings = await getRecordedAudios ( ) ;
263+
264+ const deleteRecordings = async ( ) => {
265+ await Promise . all ( recordings . map ( async recording => fs . unlink ( recording ) ) )
266+ . then ( ( ) => {
267+ generateAudioList ( ) . then ( audioListArray => {
268+ setList ( audioListArray ) ;
269+ } ) ;
270+ } )
271+ . catch ( error => {
272+ Alert . alert (
273+ 'Error deleting recordings' ,
274+ 'Below error happened while deleting recordings:\n' + error ,
275+ [ { text : 'Dismiss' } ]
276+ ) ;
277+ } ) ;
278+ } ;
279+
280+ Alert . alert (
281+ 'Delete all recording' ,
282+ `Continue to delete all ${ recordings . length } recordings.` ,
283+ [
284+ { text : 'Cancel' , style : 'cancel' } ,
285+ { text : 'OK' , onPress : deleteRecordings } ,
286+ ]
287+ ) ;
288+ } ;
289+
251290 return (
252291 < View style = { styles . appContainer } >
253292 < StatusBar
@@ -259,12 +298,28 @@ const AppContainer = () => {
259298 < GestureHandlerRootView style = { styles . appContainer } >
260299 < View style = { styles . screenBackground } >
261300 < View style = { styles . container } >
262- < View style = { styles . simformImageContainer } >
301+ < View style = { styles . headerContainer } >
263302 < Image
264303 source = { Icons . simform }
265304 style = { styles . simformImage }
266305 resizeMode = "contain"
267306 />
307+ < Pressable
308+ style = { [
309+ styles . deleteRecordingContainer ,
310+ { opacity : nbOfRecording ? 1 : 0.5 } ,
311+ ] }
312+ onPress = { handleDeleteRecordings }
313+ disabled = { ! nbOfRecording } >
314+ < Image
315+ source = { Icons . delete }
316+ style = { styles . pinkButtonImage }
317+ resizeMode = "contain"
318+ />
319+ < Text style = { styles . deleteRecordingTitle } >
320+ { 'Delete recorded audio files' }
321+ </ Text >
322+ </ Pressable >
268323 </ View >
269324 < ScrollView scrollEnabled = { shouldScroll } >
270325 { list . map ( item => (
0 commit comments