Fixed issue with usernames (when it's empty)

This commit is contained in:
ChronosX88 2019-04-25 15:32:36 +04:00
parent 93a2271be6
commit a5ef1569e6
2 changed files with 13 additions and 2 deletions

View File

@ -23,11 +23,20 @@ class SettingsPresenter(private val view: CoreContracts.ISettingsView) : CoreCon
override fun updateUsername(username: String) { override fun updateUsername(username: String) {
view.loadingScreen(true) view.loadingScreen(true)
val editor: SharedPreferences.Editor = AppHelper.getPreferences().edit()
GlobalScope.launch { GlobalScope.launch {
val oldUsername = AppHelper.getPreferences().getString("username", null)
if(username.equals("")) {
SettingsLogic.publishUsername(oldUsername, null)
editor.remove("username")
editor.apply()
AppHelper.updateUsername(null)
ObservableUtils.notifyUI(UIActions.USERNAME_AVAILABLE)
return@launch
}
if(!logic.checkUsernameExists(username)) { if(!logic.checkUsernameExists(username)) {
// Save username in SharedPreferences // Save username in SharedPreferences
val editor: SharedPreferences.Editor = AppHelper.getPreferences().edit()
val oldUsername = AppHelper.getPreferences().getString("username", null)
if(username.equals("")) { if(username.equals("")) {
editor.remove("username") editor.remove("username")
} else { } else {

View File

@ -68,6 +68,8 @@ public class SettingsFragment extends PreferenceFragmentCompat implements CoreCo
LinearLayout.LayoutParams.MATCH_PARENT); LinearLayout.LayoutParams.MATCH_PARENT);
input.setSingleLine(); input.setSingleLine();
input.setLayoutParams(lp); input.setLayoutParams(lp);
input.setText(AppHelper.getPreferences().getString("username", null));
alertDialog.setView(input); alertDialog.setView(input);
alertDialog.setPositiveButton(getContext().getString(R.string.ok), (dialog, which) -> presenter.updateUsername(input.getText().toString())); alertDialog.setPositiveButton(getContext().getString(R.string.ok), (dialog, which) -> presenter.updateUsername(input.getText().toString()));