Added updating preferences view when username is changed

This commit is contained in:
ChronosX88 2019-04-25 17:17:39 +03:00
parent a5ef1569e6
commit 56297d2290
4 changed files with 16 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,7 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/
/.idea
.DS_Store
/build
/captures

View File

@ -87,5 +87,6 @@ interface CoreContracts {
interface ISettingsView {
fun loadingScreen(state: Boolean)
fun showMessage(message: String)
fun refreshScreen()
}
}

View File

@ -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)

View File

@ -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));
}
}