Skip to content

Commit

Permalink
prevent from requesting voice instructions if the cache has been prev…
Browse files Browse the repository at this point in the history
…iously closed and add a check to delete the cache if there are files (#1540)
  • Loading branch information
Guardiola31337 authored Nov 15, 2018
1 parent 3c739dc commit e7a9541
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import java.io.File
import java.util.Locale.US

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

class ExampleViewModel(application: Application) : AndroidViewModel(application) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,20 @@ void setupMapboxSpeechBuilder(String language) {
}

void requestInstruction(String instruction, String textType, Callback<ResponseBody> callback) {
MapboxSpeech mapboxSpeech = mapboxSpeechBuilder
.instruction(instruction)
.textType(textType)
.build();
mapboxSpeech.enqueueCall(callback);
if (!cache.isClosed()) {
MapboxSpeech mapboxSpeech = mapboxSpeechBuilder
.instruction(instruction)
.textType(textType)
.build();
mapboxSpeech.enqueueCall(callback);
}
}

void flushCache() {
try {
cache.delete();
if (cache.directory().listFiles() != null) {
cache.delete();
}
} catch (IOException exception) {
Timber.e(exception);
}
Expand Down

0 comments on commit e7a9541

Please sign in to comment.