Code clean up

This commit is contained in:
ZaneYork 2020-03-20 18:40:47 +08:00
parent 36a64e4ad3
commit 362cb4f1bc
4 changed files with 86 additions and 76 deletions

View File

@ -162,81 +162,10 @@ public class MainActivity extends AppCompatActivity {
});
return true;
case R.id.settings_language:
DialogUtils.setCurrentDialog(new MaterialDialog.Builder(this).title(R.string.settings_set_language).items(R.array.languages).itemsCallback((dialog, itemView, position, text) -> {
boolean restart;
switch (position) {
case 0:
restart = LanguagesManager.setSystemLanguage(this);
break;
case 1:
restart = LanguagesManager.setAppLanguage(this, Locale.ENGLISH);
break;
case 2:
restart = LanguagesManager.setAppLanguage(this, Locale.SIMPLIFIED_CHINESE);
break;
case 3:
restart = LanguagesManager.setAppLanguage(this, Locale.TRADITIONAL_CHINESE);
break;
case 4:
restart = LanguagesManager.setAppLanguage(this, Locale.KOREA);
break;
case 5:
restart = LanguagesManager.setAppLanguage(this, new Locale("th", ""));
break;
case 6:
restart = LanguagesManager.setAppLanguage(this, new Locale("es", ""));
break;
case 7:
restart = LanguagesManager.setAppLanguage(this, Locale.FRENCH);
break;
case 8:
restart = LanguagesManager.setAppLanguage(this, new Locale("pt", ""));
break;
case 9:
restart = LanguagesManager.setAppLanguage(this, new Locale("in", ""));
break;
default:
return;
}
if (restart) {
// 我们可以充分运用 Activity 跳转动画在跳转的时候设置一个渐变的效果
startActivity(new Intent(this, MainActivity.class));
overridePendingTransition(R.anim.fragment_fade_enter, R.anim.fragment_fade_exit);
finish();
}
}).show());
selectLanguageLogic();
return true;
case R.id.settings_translation_service:
DialogUtils.setCurrentDialog(new MaterialDialog.Builder(this).title(R.string.settings_translation_service).items(R.array.translators).itemsCallback((dialog, itemView, position, text) -> {
DaoSession daoSession = ((MainApplication)this.getApplication()).getDaoSession();
AppConfigDao appConfigDao = daoSession.getAppConfigDao();
AppConfig activeTranslator = appConfigDao.queryBuilder().where(AppConfigDao.Properties.Name.eq(AppConfigKey.ACTIVE_TRANSLATOR)).build().unique();
switch (position) {
case 0:
if(activeTranslator != null) {
appConfigDao.delete(activeTranslator);
}
break;
case 1:
if(activeTranslator == null) {
activeTranslator = new AppConfig(null, AppConfigKey.ACTIVE_TRANSLATOR, TranslateUtil.GOOGLE);
} else {
activeTranslator.setValue(TranslateUtil.GOOGLE);
}
appConfigDao.insertOrReplace(activeTranslator);
break;
case 2:
if(activeTranslator == null) {
activeTranslator = new AppConfig(null, AppConfigKey.ACTIVE_TRANSLATOR, TranslateUtil.YOU_DAO);
} else {
activeTranslator.setValue(TranslateUtil.YOU_DAO);
}
appConfigDao.insertOrReplace(activeTranslator);
break;
default:
break;
}
}).show());
selectTranslateServiceLogic();
return true;
default:
return super.onOptionsItemSelected(item);
@ -245,6 +174,85 @@ public class MainActivity extends AppCompatActivity {
return true;
}
private void selectTranslateServiceLogic() {
DialogUtils.setCurrentDialog(new MaterialDialog.Builder(this).title(R.string.settings_translation_service).items(R.array.translators).itemsCallback((dialog, itemView, position, text) -> {
DaoSession daoSession = ((MainApplication)this.getApplication()).getDaoSession();
AppConfigDao appConfigDao = daoSession.getAppConfigDao();
AppConfig activeTranslator = appConfigDao.queryBuilder().where(AppConfigDao.Properties.Name.eq(AppConfigKey.ACTIVE_TRANSLATOR)).build().unique();
switch (position) {
case 0:
if(activeTranslator != null) {
appConfigDao.delete(activeTranslator);
}
break;
case 1:
if(activeTranslator == null) {
activeTranslator = new AppConfig(null, AppConfigKey.ACTIVE_TRANSLATOR, TranslateUtil.GOOGLE);
} else {
activeTranslator.setValue(TranslateUtil.GOOGLE);
}
appConfigDao.insertOrReplace(activeTranslator);
break;
case 2:
if(activeTranslator == null) {
activeTranslator = new AppConfig(null, AppConfigKey.ACTIVE_TRANSLATOR, TranslateUtil.YOU_DAO);
} else {
activeTranslator.setValue(TranslateUtil.YOU_DAO);
}
appConfigDao.insertOrReplace(activeTranslator);
break;
default:
break;
}
}).show());
}
private void selectLanguageLogic() {
DialogUtils.setCurrentDialog(new MaterialDialog.Builder(this).title(R.string.settings_set_language).items(R.array.languages).itemsCallback((dialog, itemView, position, text) -> {
boolean restart;
switch (position) {
case 0:
restart = LanguagesManager.setSystemLanguage(this);
break;
case 1:
restart = LanguagesManager.setAppLanguage(this, Locale.ENGLISH);
break;
case 2:
restart = LanguagesManager.setAppLanguage(this, Locale.SIMPLIFIED_CHINESE);
break;
case 3:
restart = LanguagesManager.setAppLanguage(this, Locale.TRADITIONAL_CHINESE);
break;
case 4:
restart = LanguagesManager.setAppLanguage(this, Locale.KOREA);
break;
case 5:
restart = LanguagesManager.setAppLanguage(this, new Locale("th", ""));
break;
case 6:
restart = LanguagesManager.setAppLanguage(this, new Locale("es", ""));
break;
case 7:
restart = LanguagesManager.setAppLanguage(this, Locale.FRENCH);
break;
case 8:
restart = LanguagesManager.setAppLanguage(this, new Locale("pt", ""));
break;
case 9:
restart = LanguagesManager.setAppLanguage(this, new Locale("in", ""));
break;
default:
return;
}
if (restart) {
// 我们可以充分运用 Activity 跳转动画在跳转的时候设置一个渐变的效果
startActivity(new Intent(this, MainActivity.class));
overridePendingTransition(R.anim.fragment_fade_enter, R.anim.fragment_fade_exit);
finish();
}
}).show());
}
@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);

View File

@ -9,7 +9,6 @@ import lombok.Data;
/**
* SMAPI的配置
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
@Data
@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY, getterVisibility= JsonAutoDetect.Visibility.NONE)
public class FrameworkConfig {

View File

@ -7,7 +7,6 @@ import lombok.Data;
/**
* Mod信息
*/
@SuppressWarnings("ALL")
@Data
public class ModManifestEntry {
/**

View File

@ -63,7 +63,11 @@ public class HelpItemAdapter extends RecyclerView.Adapter<HelpItemAdapter.ViewHo
void setHelpItem(HelpItem item) {
textTitle.setText(item.getTitle());
textAuthor.setText(item.getAuthor());
textContent.setText(Html.fromHtml(item.getContent()));
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
textContent.setText(Html.fromHtml(item.getContent(), Html.FROM_HTML_MODE_COMPACT));
} else {
textContent.setText(Html.fromHtml(item.getContent()));
}
textContent.setMovementMethod(LinkMovementMethod.getInstance());
}
}