Commit 504f2b08 authored by Habib Kazemi's avatar Habib Kazemi Committed by Geoffrey Métais
Browse files

Use ListPreference for setLocale


Signed-off-by: default avatarGeoffrey Métais <geoffrey.metais@gmail.com>
parent d01ae6bf
......@@ -29,10 +29,9 @@
android:summary="@string/playback_speed_summary"
android:title="@string/playback_speed_title" />
<EditTextPreference
<ListPreference
android:defaultValue=""
android:key="set_locale"
android:summary="@string/set_locale_detail"
android:title="@string/set_locale" />
<CheckBoxPreference
......
......@@ -83,6 +83,7 @@ import org.videolan.vlc.gui.dialogs.SavePlaylistDialog;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.FileUtils;
import org.videolan.vlc.util.LocalePair;
import org.videolan.vlc.viewmodels.BaseModel;
import java.util.List;
......@@ -505,4 +506,13 @@ public class UiTools {
.create()
.show();
}
public static LocalePair getLocalesUsedInProject(Context context) {
final String[] localesEntryValues = context.getAssets().getLocales();
final String[] localesEntry = new String[localesEntryValues.length];
for (int i=0; i<localesEntryValues.length; i++) {
localesEntry[i] = new Locale(localesEntryValues[i]).getDisplayLanguage(new Locale(localesEntryValues[i]));
}
return new LocalePair(localesEntry, localesEntryValues);
}
}
......@@ -26,12 +26,15 @@ package org.videolan.vlc.gui.preferences;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.SwitchPreferenceCompat;
import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.util.LocalePair;
public class PreferencesUi extends BasePreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
......@@ -64,6 +67,7 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
super.onCreate(savedInstanceState);
findPreference("tv_ui").setVisible(AndroidUtil.isJellyBeanMR1OrLater);
findPreference("blurred_cover_background").setVisible(AndroidUtil.isJellyBeanMR1OrLater);
prepareLocaleList();
}
@Override
......@@ -88,4 +92,11 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
if (key.equals("set_locale"))
UiTools.restartDialog(getActivity());
}
private void prepareLocaleList() {
final LocalePair localePair = UiTools.getLocalesUsedInProject(getActivity());
final ListPreference lp = (ListPreference)findPreference("set_locale");
lp.setEntries(localePair.getLocaleEntries());
lp.setEntryValues(localePair.getLocaleEntryValues());
}
}
......@@ -27,10 +27,13 @@ import android.annotation.TargetApi;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.preference.ListPreference;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.LocalePair;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class PreferencesUi extends BasePreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
......@@ -56,6 +59,7 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
findPreference("secondary_display_category_summary").setVisible(false);
findPreference("daynight").setVisible(false);
findPreference("blurred_cover_background").setVisible(false);
prepareLocaleList();
}
@Override
......@@ -82,4 +86,11 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
break;
}
}
private void prepareLocaleList() {
LocalePair localePair = UiTools.getLocalesUsedInProject(getActivity());
ListPreference lp = (ListPreference)findPreference("set_locale");
lp.setEntries(localePair.getLocaleEntries());
lp.setEntryValues(localePair.getLocaleEntryValues());
}
}
package org.videolan.vlc.util
class LocalePair(val localeEntries: Array<String>, val localeEntryValues: Array<String>)
\ No newline at end of file
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