Commit a61ebc99 authored by Geoffrey Métais's avatar Geoffrey Métais

Abort subs download if language code is not found

Also show an error message to encourage user to manually choose its
preferred languages
parent b3011363
......@@ -681,6 +681,7 @@
<string name="list_languages_download_summary">Languages to download when fetching subtitles</string>
<string name="list_languages_download_title">Subtitles download languages</string>
<string name="service_unavailable">Service unavailable</string>
<string name="subs_dl_lang_fail">Failed to set subtitles language, try to set it in application settings</string>
<string name="downloading_subtitles">Downloading subtitles</string>
<string name="browse_folder">Browse folder</string>
<string name="listen">Listen</string>
......
......@@ -24,11 +24,13 @@
package org.videolan.vlc.util;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
......@@ -42,13 +44,13 @@ import android.view.WindowManager;
import android.widget.Toast;
import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.media.MediaDatabase;
import org.videolan.medialibrary.media.MediaWrapper;
import java.io.File;
import java.io.FileOutputStream;
......@@ -99,18 +101,21 @@ public class SubtitlesDownloader {
mContext = activity;
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void downloadSubs(final List<MediaWrapper> mediaList, Callback cb) {
stop = false;
mCallback = cb;
Set<String> languages;
Set<String> languages = null;
try {
languages = Collections.singleton(Locale.getDefault().getISO3Language().toLowerCase());
} catch (MissingResourceException e) {
languages = Collections.singleton(Locale.ENGLISH.getISO3Language().toLowerCase());
}
languages = Collections.singleton(Locale.getDefault().getISO3Language().toLowerCase());
} catch (MissingResourceException ignored) {}
if (AndroidUtil.isHoneycombOrLater) {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
languages = pref.getStringSet("languages_download_list", languages);
languages = pref.getStringSet("languages_download_list", languages);
}
if (languages == null) { // In case getDefault().getISO3Language() fails
Toast.makeText(mContext, R.string.subs_dl_lang_fail, Toast.LENGTH_SHORT).show();
return;
}
final ArrayList<String> finalLanguages = new ArrayList<>(languages);
VLCApplication.runBackground(new Runnable() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment