diff --git a/.gitignore b/.gitignore index 0df7064..09b993d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ *.iml .gradle /local.properties -/.idea/ +/.idea .DS_Store /build /captures diff --git a/app/src/main/java/io/github/chronosx88/influence/contracts/CoreContracts.kt b/app/src/main/java/io/github/chronosx88/influence/contracts/CoreContracts.kt index 998ce6f..3a2c099 100644 --- a/app/src/main/java/io/github/chronosx88/influence/contracts/CoreContracts.kt +++ b/app/src/main/java/io/github/chronosx88/influence/contracts/CoreContracts.kt @@ -87,5 +87,6 @@ interface CoreContracts { interface ISettingsView { fun loadingScreen(state: Boolean) fun showMessage(message: String) + fun refreshScreen() } } 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 3d9914e..8a538cf 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 @@ -61,6 +61,7 @@ class SettingsPresenter(private val view: CoreContracts.ISettingsView) : CoreCon UIActions.USERNAME_AVAILABLE -> { view.loadingScreen(false) view.showMessage(AppHelper.getContext().getString(R.string.username_saved)) + view.refreshScreen() } UIActions.USERNAME_ISNT_AVAILABLE -> { view.loadingScreen(false) 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 e7cc194..e333c28 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 @@ -13,6 +13,9 @@ import android.widget.Toast; import org.jetbrains.annotations.NotNull; import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.PreferenceScreen; +import androidx.recyclerview.widget.RecyclerView; + import io.github.chronosx88.influence.R; import io.github.chronosx88.influence.contracts.CoreContracts; import io.github.chronosx88.influence.helpers.AppHelper; @@ -43,6 +46,10 @@ public class SettingsFragment extends PreferenceFragmentCompat implements CoreCo setupUsernameEditDialog().show(); return true; }); + getPreferenceScreen().getPreference(1).setOnPreferenceChangeListener((p, nV) -> { + getPreferenceScreen().getPreference(1).setSummary((String) nV); + return true; + }); } @Override @@ -71,11 +78,15 @@ public class SettingsFragment extends PreferenceFragmentCompat implements CoreCo input.setText(AppHelper.getPreferences().getString("username", null)); alertDialog.setView(input); - alertDialog.setPositiveButton(getContext().getString(R.string.ok), (dialog, which) -> presenter.updateUsername(input.getText().toString())); - alertDialog.setNegativeButton(getContext().getString(R.string.cancel), (dialog, which) -> dialog.cancel()); return alertDialog; } + + @Override + public void refreshScreen() { + getPreferenceScreen().getPreference(1).callChangeListener(AppHelper.getPreferences().getString("username", null)); + } + }