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()));