Skip to content

Commit e7a9541

Browse files
prevent from requesting voice instructions if the cache has been previously closed and add a check to delete the cache if there are files (#1540)
1 parent 3c739dc commit e7a9541

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

app/src/main/java/com/mapbox/services/android/navigation/testapp/example/ui/ExampleViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import java.io.File
3333
import java.util.Locale.US
3434

3535
private const val ONE_SECOND_INTERVAL = 1000
36-
private const val EXAMPLE_INSTRUCTION_CACHE = "component-navigation-instruction-cache"
36+
private const val EXAMPLE_INSTRUCTION_CACHE = "example-navigation-instruction-cache"
3737
private const val TEN_MEGABYTE_CACHE_SIZE: Long = 10 * 1024 * 1024
3838

3939
class ExampleViewModel(application: Application) : AndroidViewModel(application) {

libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/voice/VoiceInstructionLoader.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,20 @@ void setupMapboxSpeechBuilder(String language) {
8282
}
8383

8484
void requestInstruction(String instruction, String textType, Callback<ResponseBody> callback) {
85-
MapboxSpeech mapboxSpeech = mapboxSpeechBuilder
86-
.instruction(instruction)
87-
.textType(textType)
88-
.build();
89-
mapboxSpeech.enqueueCall(callback);
85+
if (!cache.isClosed()) {
86+
MapboxSpeech mapboxSpeech = mapboxSpeechBuilder
87+
.instruction(instruction)
88+
.textType(textType)
89+
.build();
90+
mapboxSpeech.enqueueCall(callback);
91+
}
9092
}
9193

9294
void flushCache() {
9395
try {
94-
cache.delete();
96+
if (cache.directory().listFiles() != null) {
97+
cache.delete();
98+
}
9599
} catch (IOException exception) {
96100
Timber.e(exception);
97101
}

0 commit comments

Comments
 (0)