From a5ef1569e62ba3b0e4eb849a6cbb912f0f7accf1 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Thu, 25 Apr 2019 15:32:36 +0400 Subject: [PATCH] Fixed issue with usernames (when it's empty) --- .../influence/presenters/SettingsPresenter.kt | 13 +++++++++++-- .../influence/views/fragments/SettingsFragment.java | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/github/chronosx88/influence/presenters/SettingsPresenter.kt b/app/src/main/java/io/github/chronosx88/influence/presenters/SettingsPresenter.kt index c3eb653..3d9914e 100644 --- a/app/src/main/java/io/github/chronosx88/influence/presenters/SettingsPresenter.kt +++ b/app/src/main/java/io/github/chronosx88/influence/presenters/SettingsPresenter.kt @@ -23,11 +23,20 @@ class SettingsPresenter(private val view: CoreContracts.ISettingsView) : CoreCon override fun updateUsername(username: String) { view.loadingScreen(true) + val editor: SharedPreferences.Editor = AppHelper.getPreferences().edit() + 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)) { // Save username in SharedPreferences - val editor: SharedPreferences.Editor = AppHelper.getPreferences().edit() - val oldUsername = AppHelper.getPreferences().getString("username", null) if(username.equals("")) { editor.remove("username") } else { diff --git a/app/src/main/java/io/github/chronosx88/influence/views/fragments/SettingsFragment.java b/app/src/main/java/io/github/chronosx88/influence/views/fragments/SettingsFragment.java index 3041fbc..e7cc194 100644 --- a/app/src/main/java/io/github/chronosx88/influence/views/fragments/SettingsFragment.java +++ b/app/src/main/java/io/github/chronosx88/influence/views/fragments/SettingsFragment.java @@ -68,6 +68,8 @@ public class SettingsFragment extends PreferenceFragmentCompat implements CoreCo LinearLayout.LayoutParams.MATCH_PARENT); input.setSingleLine(); input.setLayoutParams(lp); + input.setText(AppHelper.getPreferences().getString("username", null)); + alertDialog.setView(input); alertDialog.setPositiveButton(getContext().getString(R.string.ok), (dialog, which) -> presenter.updateUsername(input.getText().toString()));