Fix issue #586
This commit is contained in:
parent
f65c7a9c42
commit
17d13c9933
|
@ -75,5 +75,6 @@ dependencies {
|
|||
implementation "com.koushikdutta.async:androidasync:2.+"
|
||||
implementation 'com.vanniktech:emoji-one:0.6.0-SNAPSHOT'
|
||||
implementation 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
|
||||
implementation 'com.github.franmontiel:LocaleChanger:0.9.2'
|
||||
playstoreImplementation "io.github.kobakei:ratethisapp:$ratethisappLibraryVersion"
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package fr.gouv.etalab.mastodon.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.franmontiel.localechanger.LocaleChanger;
|
||||
import com.vanniktech.emoji.EmojiManager;
|
||||
import com.vanniktech.emoji.one.EmojiOneProvider;
|
||||
|
||||
|
@ -19,4 +22,16 @@ public class BaseActivity extends AppCompatActivity {
|
|||
Helper.installProvider();
|
||||
EmojiManager.install(new EmojiOneProvider());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
LocaleChanger.onConfigurationChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
newBase = LocaleChanger.configureBaseContext(newBase);
|
||||
super.attachBaseContext(newBase);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,19 @@ package fr.gouv.etalab.mastodon.activities;
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.StrictMode;
|
||||
|
||||
import com.evernote.android.job.JobManager;
|
||||
import com.franmontiel.localechanger.LocaleChanger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.jobs.ApplicationJob;
|
||||
import fr.gouv.etalab.mastodon.jobs.HomeTimelineSyncJob;
|
||||
import fr.gouv.etalab.mastodon.jobs.NotificationsSyncJob;
|
||||
|
@ -37,5 +47,13 @@ public class MainApplication extends Application{
|
|||
HomeTimelineSyncJob.schedule(false);
|
||||
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
|
||||
StrictMode.setVmPolicy(builder.build());
|
||||
try {
|
||||
List<Locale> SUPPORTED_LOCALES = new ArrayList<>();
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
String defaultLocaleString = sharedpreferences.getString(Helper.SET_DEFAULT_LOCALE, Helper.localeToStringStorage(Locale.getDefault()));
|
||||
Locale defaultLocale = Helper.restoreLocaleFromString(defaultLocaleString);
|
||||
SUPPORTED_LOCALES.add(defaultLocale);
|
||||
LocaleChanger.initialize(getApplicationContext(), SUPPORTED_LOCALES);
|
||||
}catch (Exception ignored){ignored.printStackTrace();}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,13 @@ package fr.gouv.etalab.mastodon.fragments;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
|
@ -50,6 +52,8 @@ import android.widget.Spinner;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
|
@ -74,7 +78,7 @@ public class SettingsFragment extends Fragment {
|
|||
private Context context;
|
||||
private static final int ACTIVITY_CHOOSE_FILE = 411;
|
||||
private TextView set_folder;
|
||||
int count1, count2, count3 = 0;
|
||||
int count1, count2, count3, count4 = 0;
|
||||
private EditText your_api_key;
|
||||
|
||||
|
||||
|
@ -585,6 +589,72 @@ public class SettingsFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
final Spinner set_change_locale = rootView.findViewById(R.id.set_change_locale);
|
||||
ArrayAdapter<String> adapterLocale = new ArrayAdapter<>(context,
|
||||
android.R.layout.simple_spinner_dropdown_item, Helper.getLocales(context));
|
||||
|
||||
set_change_locale.setAdapter(adapterLocale);
|
||||
|
||||
int positionSpinnerLanguage = Helper.languageSpinnerPosition(context);
|
||||
set_change_locale.setSelection(positionSpinnerLanguage);
|
||||
set_change_locale.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
if( count4 > 0){
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
switch (position){
|
||||
case 0:
|
||||
editor.putString(Helper.SET_DEFAULT_LOCALE, Helper.localeToStringStorage(Locale.getDefault()));
|
||||
editor.commit();
|
||||
break;
|
||||
case 1:
|
||||
editor.putString(Helper.SET_DEFAULT_LOCALE, Helper.localeToStringStorage(Locale.ENGLISH));
|
||||
editor.commit();
|
||||
break;
|
||||
case 2:
|
||||
editor.putString(Helper.SET_DEFAULT_LOCALE, Helper.localeToStringStorage(Locale.FRANCE));
|
||||
editor.commit();
|
||||
break;
|
||||
case 3:
|
||||
editor.putString(Helper.SET_DEFAULT_LOCALE, Helper.localeToStringStorage(Locale.GERMAN));
|
||||
editor.commit();
|
||||
break;
|
||||
case 4:
|
||||
editor.putString(Helper.SET_DEFAULT_LOCALE, Helper.localeToStringStorage(Locale.ITALIAN));
|
||||
editor.commit();
|
||||
break;
|
||||
case 5:
|
||||
editor.putString(Helper.SET_DEFAULT_LOCALE, Helper.localeToStringStorage(Locale.JAPAN));
|
||||
editor.commit();
|
||||
break;
|
||||
case 6:
|
||||
editor.putString(Helper.SET_DEFAULT_LOCALE, Helper.localeToStringStorage(Locale.CHINESE));
|
||||
editor.commit();
|
||||
break;
|
||||
case 7:
|
||||
editor.putString(Helper.SET_DEFAULT_LOCALE, Helper.localeToStringStorage(Locale.CHINA));
|
||||
editor.commit();
|
||||
break;
|
||||
}
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
Intent intent = packageManager.getLaunchIntentForPackage(context.getPackageName());
|
||||
assert intent != null;
|
||||
ComponentName componentName = intent.getComponent();
|
||||
Intent mainIntent = Intent.makeRestartActivityTask(componentName);
|
||||
context.startActivity(mainIntent);
|
||||
Runtime.getRuntime().exit(0);
|
||||
|
||||
}else {
|
||||
count4++;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// NSFW Timeout
|
||||
SeekBar nsfwTimeoutSeekBar = rootView.findViewById(R.id.set_nsfw_timeout);
|
||||
final TextView set_nsfw_timeout_value = rootView.findViewById(R.id.set_nsfw_timeout_value);
|
||||
|
|
|
@ -281,6 +281,7 @@ public class Helper {
|
|||
public static final String SET_DISPLAY_VIDEO_PREVIEWS= "set_display_video_previews";
|
||||
public static final String SET_OLD_DIRECT_TIMELINE = "sset_old_direct_timeline";
|
||||
public static final String SET_BATTERY_PROFILE = "set_battery_profile";
|
||||
public static final String SET_DEFAULT_LOCALE = "set_default_locale";
|
||||
public static final int S_512KO = 1;
|
||||
public static final int S_1MO = 2;
|
||||
public static final int S_2MO = 3;
|
||||
|
@ -1247,7 +1248,7 @@ public class Helper {
|
|||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken());
|
||||
editor.putString(Helper.PREF_KEY_ID, account.getId());
|
||||
editor.putString(Helper.PREF_INSTANCE, account.getInstance().trim());
|
||||
editor.apply();
|
||||
editor.commit();
|
||||
activity.recreate();
|
||||
if( checkItem ) {
|
||||
Intent intent = new Intent(activity, MainActivity.class);
|
||||
|
@ -1910,6 +1911,29 @@ public class Helper {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unserialized a Locale
|
||||
* @param serializedLocale String serialized locale
|
||||
* @return Locale
|
||||
*/
|
||||
public static Locale restoreLocaleFromString(String serializedLocale){
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
return gson.fromJson(serializedLocale, Locale.class);
|
||||
}catch (Exception e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialized a Locale class
|
||||
* @param locale Locale to serialize
|
||||
* @return String serialized Locale
|
||||
*/
|
||||
public static String localeToStringStorage(Locale locale){
|
||||
Gson gson = new Gson();
|
||||
return gson.toJson(locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialized a Status class
|
||||
|
@ -2844,4 +2868,37 @@ public class Helper {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String[] getLocales(Context context){
|
||||
String[] locale = new String[8];
|
||||
locale[0] = context.getString(R.string.default_language);
|
||||
locale[1] = Locale.ENGLISH.getDisplayLanguage();
|
||||
locale[2] = Locale.FRANCE.getDisplayLanguage();
|
||||
locale[3] = Locale.GERMAN.getDisplayLanguage();
|
||||
locale[4] = Locale.ITALIAN.getDisplayLanguage();
|
||||
locale[5] = Locale.JAPAN.getDisplayLanguage();
|
||||
locale[6] = Locale.CHINESE.getDisplayLanguage();
|
||||
locale[7] = Locale.CHINA.getDisplayLanguage();
|
||||
return locale;
|
||||
}
|
||||
|
||||
public static int languageSpinnerPosition(Context context){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
String defaultLocaleString = sharedpreferences.getString(Helper.SET_DEFAULT_LOCALE, Helper.localeToStringStorage(Locale.getDefault()));
|
||||
Locale defaultLocale = Helper.restoreLocaleFromString(defaultLocaleString);
|
||||
if( defaultLocale == null)
|
||||
return 0;
|
||||
String language = defaultLocale.getDisplayLanguage();
|
||||
String[] locales = getLocales(context);
|
||||
int index = 0;
|
||||
for (int i=0;i<locales.length;i++) {
|
||||
if (locales[i].equals(language)) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,6 +206,24 @@
|
|||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Change locale -->
|
||||
<LinearLayout
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/set_change_locale"/>
|
||||
<Spinner
|
||||
android:id="@+id/set_change_locale"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Translation engine -->
|
||||
<LinearLayout
|
||||
android:layout_marginTop="10dp"
|
||||
|
|
|
@ -203,6 +203,24 @@
|
|||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Change locale -->
|
||||
<LinearLayout
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/set_change_locale"/>
|
||||
<Spinner
|
||||
android:id="@+id/set_change_locale"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Translation engine -->
|
||||
<LinearLayout
|
||||
android:layout_marginTop="10dp"
|
||||
|
|
|
@ -674,6 +674,8 @@
|
|||
<string name="bug_report_mail">Send a bug report</string>
|
||||
<string name="account_id_clipbloard">The account id has been copied in the clipboard!</string>
|
||||
<string name="settings_title_battery">Optimization of the battery</string>
|
||||
<string name="set_change_locale">Change the language</string>
|
||||
<string name="default_language">Default language</string>
|
||||
|
||||
<string-array name="filter_expire">
|
||||
<item>Never</item>
|
||||
|
|
Loading…
Reference in New Issue