Commit b9294916 authored by fallenstardust's avatar fallenstardust

先按照设置资料语言优先再按照系统语言进行语言设置

parent be750111
...@@ -18,6 +18,7 @@ import static cn.garymb.ygomobile.Constants.DEF_PREF_KEEP_SCALE; ...@@ -18,6 +18,7 @@ import static cn.garymb.ygomobile.Constants.DEF_PREF_KEEP_SCALE;
import static cn.garymb.ygomobile.Constants.DEF_PREF_NOTCH_HEIGHT; import static cn.garymb.ygomobile.Constants.DEF_PREF_NOTCH_HEIGHT;
import static cn.garymb.ygomobile.Constants.DEF_PREF_ONLY_GAME; import static cn.garymb.ygomobile.Constants.DEF_PREF_ONLY_GAME;
import static cn.garymb.ygomobile.Constants.DEF_PREF_READ_EX; import static cn.garymb.ygomobile.Constants.DEF_PREF_READ_EX;
import static cn.garymb.ygomobile.Constants.PREF_DEF_DATA_LANGUAGE;
import static cn.garymb.ygomobile.Constants.PREF_DEF_IMMERSIVE_MODE; import static cn.garymb.ygomobile.Constants.PREF_DEF_IMMERSIVE_MODE;
import static cn.garymb.ygomobile.Constants.PREF_DEF_SENSOR_REFRESH; import static cn.garymb.ygomobile.Constants.PREF_DEF_SENSOR_REFRESH;
import static cn.garymb.ygomobile.Constants.PREF_FONT_SIZE; import static cn.garymb.ygomobile.Constants.PREF_FONT_SIZE;
...@@ -53,6 +54,7 @@ import java.util.List; ...@@ -53,6 +54,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import cn.garymb.ygomobile.core.IrrlichtBridge; import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.settings.PreferenceFragmentPlus; import cn.garymb.ygomobile.ui.settings.PreferenceFragmentPlus;
import cn.garymb.ygomobile.utils.DeckUtil; import cn.garymb.ygomobile.utils.DeckUtil;
...@@ -378,9 +380,10 @@ public class AppsSettings { ...@@ -378,9 +380,10 @@ public class AppsSettings {
*/ */
public int getDataLanguage() { public int getDataLanguage() {
try { try {
return Integer.valueOf(mSharedPreferences.getString(Constants.PREF_DATA_LANGUAGE, "" + Constants.PREF_DEF_DATA_LANGUAGE)); Log.i(BuildConfig.VERSION_NAME, mSharedPreferences.getString(Constants.PREF_DATA_LANGUAGE, "" + PREF_DEF_DATA_LANGUAGE));
return Integer.valueOf(mSharedPreferences.getString(Constants.PREF_DATA_LANGUAGE, "" + PREF_DEF_DATA_LANGUAGE));
} catch (Exception e) { } catch (Exception e) {
return Constants.PREF_DEF_DATA_LANGUAGE; return PREF_DEF_DATA_LANGUAGE;
} }
} }
...@@ -728,7 +731,7 @@ public class AppsSettings { ...@@ -728,7 +731,7 @@ public class AppsSettings {
fixString(stringConfPath); fixString(stringConfPath);
fixString(botConfPath); fixString(botConfPath);
//设置语言为0=中文 //设置语言为0=中文
AppsSettings.get().setDataLanguage(0); setDataLanguage(0);
} }
public void copyKorData() throws IOException { public void copyKorData() throws IOException {
...@@ -746,7 +749,7 @@ public class AppsSettings { ...@@ -746,7 +749,7 @@ public class AppsSettings {
fixString(stringConfPath); fixString(stringConfPath);
fixString(botConfPath); fixString(botConfPath);
//设置语言为1=조선말 //设置语言为1=조선말
AppsSettings.get().setDataLanguage(1); setDataLanguage(1);
} }
public void copyEnData() throws IOException { public void copyEnData() throws IOException {
...@@ -766,7 +769,7 @@ public class AppsSettings { ...@@ -766,7 +769,7 @@ public class AppsSettings {
fixString(stringConfPath); fixString(stringConfPath);
fixString(botConfPath); fixString(botConfPath);
//设置语言为2=English //设置语言为2=English
AppsSettings.get().setDataLanguage(2); setDataLanguage(2);
} }
private void fixString(String stringPath) { private void fixString(String stringPath) {
......
...@@ -21,7 +21,7 @@ public interface Constants { ...@@ -21,7 +21,7 @@ public interface Constants {
String PREF_IMAGE_QUALITY = "pref_key_game_image_quality"; String PREF_IMAGE_QUALITY = "pref_key_game_image_quality";
int PREF_DEF_IMAGE_QUALITY = 1; int PREF_DEF_IMAGE_QUALITY = 1;
String PREF_DATA_LANGUAGE = "pref_key_game_data_language"; String PREF_DATA_LANGUAGE = "pref_key_game_data_language";
int PREF_DEF_DATA_LANGUAGE = 0; int PREF_DEF_DATA_LANGUAGE = -1;
String PREF_GAME_FONT = "pref_key_game_font_name"; String PREF_GAME_FONT = "pref_key_game_font_name";
String PREF_USE_EXTRA_CARD_CARDS = "settings_game_diy_card_db"; String PREF_USE_EXTRA_CARD_CARDS = "settings_game_diy_card_db";
boolean PREF_DEF_USE_EXTRA_CARD_CARDS = true; boolean PREF_DEF_USE_EXTRA_CARD_CARDS = true;
......
...@@ -201,8 +201,8 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> { ...@@ -201,8 +201,8 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
return name.endsWith(".tmp"); return name.endsWith(".tmp");
} }
}); });
if(files != null){ if (files != null) {
for(File file : files){ for (File file : files) {
FileUtils.deleteFile(file); FileUtils.deleteFile(file);
} }
} }
...@@ -278,14 +278,20 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> { ...@@ -278,14 +278,20 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.WINDBOT_PATH), mSettings.getResourcePath(), needsUpdate); IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.WINDBOT_PATH), mSettings.getResourcePath(), needsUpdate);
//根据系统语言复制特定资料文件 //根据系统语言复制特定资料文件
String language = mContext.getResources().getConfiguration().locale.getLanguage(); String language = mContext.getResources().getConfiguration().locale.getLanguage();
Log.i(BuildConfig.VERSION_NAME,language); Log.i(BuildConfig.VERSION_NAME, language);
if(!language.isEmpty()){ if (!language.isEmpty()) {
if(language.equals("zh")) { if (mSettings.getDataLanguage() == -1) {
copyCnData(needsUpdate); if (language.equals("zh"))
}else if (language.equals("ko")){ copyCnData(needsUpdate);
copyKorData(needsUpdate); if (language.equals("ko")) {
copyKorData(needsUpdate);
} else {
copyEnData(needsUpdate);
}
} else { } else {
copyEnData(needsUpdate); if (mSettings.getDataLanguage() == 0) copyCnData(needsUpdate);
if (mSettings.getDataLanguage() == 1) copyKorData(needsUpdate);
if (mSettings.getDataLanguage() == 2) copyEnData(needsUpdate);
} }
} }
han.sendEmptyMessage(0); han.sendEmptyMessage(0);
...@@ -326,7 +332,7 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> { ...@@ -326,7 +332,7 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
IOUtils.copyFilesFromAssets(mContext, enSingle, mSettings.getSingleDir(), needsUpdate); IOUtils.copyFilesFromAssets(mContext, enSingle, mSettings.getSingleDir(), needsUpdate);
//复制游戏配置文件 //复制游戏配置文件
copyCoreConfig(enStringConf, enBotConf, mSettings.getResourcePath(), needsUpdate); copyCoreConfig(enStringConf, enBotConf, mSettings.getResourcePath(), needsUpdate);
AppsSettings.get().setDataLanguage(1); AppsSettings.get().setDataLanguage(2);
return ERROR_NONE; return ERROR_NONE;
} }
...@@ -342,7 +348,7 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> { ...@@ -342,7 +348,7 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
IOUtils.copyFilesFromAssets(mContext, korSingle, mSettings.getSingleDir(), needsUpdate); IOUtils.copyFilesFromAssets(mContext, korSingle, mSettings.getSingleDir(), needsUpdate);
//复制游戏配置文件 //复制游戏配置文件
copyCoreConfig(korStringConf, korBotConf, mSettings.getResourcePath(), needsUpdate); copyCoreConfig(korStringConf, korBotConf, mSettings.getResourcePath(), needsUpdate);
AppsSettings.get().setDataLanguage(2); //AppsSettings.get().setDataLanguage(1);
return ERROR_NONE; return ERROR_NONE;
} }
......
...@@ -86,8 +86,10 @@ import cn.garymb.ygomobile.ui.plus.VUiKit; ...@@ -86,8 +86,10 @@ import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.FileUtils; import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils; import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.OkhttpUtil; import cn.garymb.ygomobile.utils.OkhttpUtil;
import cn.garymb.ygomobile.utils.SharedPreferenceUtil;
import cn.garymb.ygomobile.utils.SystemUtils; import cn.garymb.ygomobile.utils.SystemUtils;
import cn.garymb.ygomobile.utils.glide.GlideCompat; import cn.garymb.ygomobile.utils.glide.GlideCompat;
import kotlin.collections.IndexedValue;
import ocgcore.DataManager; import ocgcore.DataManager;
import okhttp3.Call; import okhttp3.Call;
import okhttp3.Callback; import okhttp3.Callback;
...@@ -232,32 +234,34 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -232,32 +234,34 @@ public class SettingFragment extends PreferenceFragmentPlus {
boolean rs = super.onPreferenceChange(preference, value); boolean rs = super.onPreferenceChange(preference, value);
if (preference instanceof ListPreference) { if (preference instanceof ListPreference) {
ListPreference listPreference = (ListPreference) preference; ListPreference listPreference = (ListPreference) preference;
mSharedPreferences.edit().putString(preference.getKey(), listPreference.getValue()).apply();
if (preference.getKey().equals(PREF_DATA_LANGUAGE)) { if (preference.getKey().equals(PREF_DATA_LANGUAGE)) {
Log.i(BuildConfig.VERSION_NAME, mSettings.getDataLanguage()+"xxxx"); if (listPreference.getValue().equals("0")) {
if (mSettings.getDataLanguage() == 0) {
try { try {
mSettings.copyCnData(); mSettings.copyCnData();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (mSettings.getDataLanguage() == 1) { if (listPreference.getValue().equals("1")) {
try { try {
mSettings.copyKorData(); mSettings.copyKorData();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (mSettings.getDataLanguage() == 2) { if (listPreference.getValue().equals("2")) {
try { try {
mSettings.copyEnData(); mSettings.copyEnData();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
mSettings.setDataLanguage(Integer.valueOf(listPreference.getValue()));
Log.i(BuildConfig.VERSION_NAME, mSettings.getDataLanguage() + preference.getKey() + listPreference.getValue());
Toast.makeText(getContext(), R.string.restart_app, Toast.LENGTH_LONG).show();
DataManager.get().load(true); DataManager.get().load(true);
} }
mSharedPreferences.edit().putString(preference.getKey(), listPreference.getValue()).apply();
} else { } else {
mSharedPreferences.edit().putString(preference.getKey(), "" + value).apply(); mSharedPreferences.edit().putString(preference.getKey(), "" + value).apply();
} }
......
...@@ -340,4 +340,5 @@ ...@@ -340,4 +340,5 @@
<string name="login_succeed">채팅 방에 로그인되었습니다</string> <string name="login_succeed">채팅 방에 로그인되었습니다</string>
<string name="reChatJoining">다시 로그인 중\.\.\.</string> <string name="reChatJoining">다시 로그인 중\.\.\.</string>
<string name="settings_data_language">언어</string> <string name="settings_data_language">언어</string>
<string name="settings_data_language_about">change the game data language</string>
</resources> </resources>
...@@ -339,5 +339,6 @@ ...@@ -339,5 +339,6 @@
<string name="edit_your_message">输入聊天内容</string> <string name="edit_your_message">输入聊天内容</string>
<string name="login_succeed">登录成功</string> <string name="login_succeed">登录成功</string>
<string name="reChatJoining">连接断开,重新登陆中……</string> <string name="reChatJoining">连接断开,重新登陆中……</string>
<string name="settings_data_language">资料语言</string> <string name="settings_data_language">切换资料语言</string>
<string name="settings_data_language_about">切换ygopro界面和效果说明文字等的语言</string>
</resources> </resources>
...@@ -350,4 +350,5 @@ ...@@ -350,4 +350,5 @@
<string name="login_succeed">Chatroom logined</string> <string name="login_succeed">Chatroom logined</string>
<string name="reChatJoining">relogining\.\.\.</string> <string name="reChatJoining">relogining\.\.\.</string>
<string name="settings_data_language">Language</string> <string name="settings_data_language">Language</string>
<string name="settings_data_language_about">change language of YGOPro UI and card database </string>
</resources> </resources>
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