From a8f09fd4a9a296152eb3813c209a47654b482f38 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Tue, 17 Sep 2013 13:58:33 +0100 Subject: [PATCH] Don't crash or trigger a voice update if there is no selected dictionary to import. --- .../preference/ImportVoicePreference.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/android/src/com/reecedunn/espeak/preference/ImportVoicePreference.java b/android/src/com/reecedunn/espeak/preference/ImportVoicePreference.java index ed73ae01..a1b798ee 100644 --- a/android/src/com/reecedunn/espeak/preference/ImportVoicePreference.java +++ b/android/src/com/reecedunn/espeak/preference/ImportVoicePreference.java @@ -91,23 +91,28 @@ public class ImportVoicePreference extends DialogPreference { public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: - new AsyncTask() { + new AsyncTask() { @Override - protected Object doInBackground(Object... objects) { + protected File doInBackground(Object... objects) { File source = (File)mDictionaries.getSelectedItem(); - File destination = new File(CheckVoiceData.getDataPath(getContext()), source.getName()); - try { - byte[] data = FileUtils.readBinary(source); - FileUtils.write(destination, data); - } catch (IOException e) { + if (source != null) { + File destination = new File(CheckVoiceData.getDataPath(getContext()), source.getName()); + try { + byte[] data = FileUtils.readBinary(source); + FileUtils.write(destination, data); + return source; + } catch (IOException e) { + } } return null; } @Override - protected void onPostExecute(Object object) { - final Intent intent = new Intent(DownloadVoiceData.BROADCAST_LANGUAGES_UPDATED); - getContext().sendBroadcast(intent); + protected void onPostExecute(File file) { + if (file != null) { + final Intent intent = new Intent(DownloadVoiceData.BROADCAST_LANGUAGES_UPDATED); + getContext().sendBroadcast(intent); + } } }.execute(); break;