mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Implement signout after language change via view model event
This commit is contained in:
@@ -46,11 +46,16 @@ public class SettingsActivity extends BriarActivity {
|
||||
|
||||
setContentView(R.layout.activity_settings);
|
||||
|
||||
if (featureFlags.shouldEnableProfilePictures()) {
|
||||
ViewModelProvider provider =
|
||||
new ViewModelProvider(this, viewModelFactory);
|
||||
settingsViewModel = provider.get(SettingsViewModel.class);
|
||||
ViewModelProvider provider =
|
||||
new ViewModelProvider(this, viewModelFactory);
|
||||
settingsViewModel = provider.get(SettingsViewModel.class);
|
||||
|
||||
settingsViewModel.getLanguageChange().observeEvent(this, b -> {
|
||||
signOut(false, false);
|
||||
finishAffinity();
|
||||
});
|
||||
|
||||
if (featureFlags.shouldEnableProfilePictures()) {
|
||||
TextView textViewUserName = findViewById(R.id.username);
|
||||
CircleImageView imageViewAvatar =
|
||||
findViewById(R.id.avatarImage);
|
||||
@@ -118,9 +123,4 @@ public class SettingsActivity extends BriarActivity {
|
||||
ConfirmAvatarDialogFragment.TAG);
|
||||
}
|
||||
|
||||
void languageChanged() {
|
||||
signOut(false, false);
|
||||
finishAffinity();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.text.TextUtilsCompat;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
@@ -163,12 +164,19 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
LocationUtils locationUtils;
|
||||
@Inject
|
||||
CircumventionProvider circumventionProvider;
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
|
||||
private SettingsViewModel viewModel;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
listener = (SettingsActivity) context;
|
||||
listener.getActivityComponent().inject(this);
|
||||
|
||||
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||
.get(SettingsViewModel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -636,7 +644,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
builder.setPositiveButton(R.string.sign_out_button,
|
||||
(dialogInterface, i) -> {
|
||||
language.setValue(newValue);
|
||||
listener.languageChanged();
|
||||
viewModel.languageChanged();
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
builder.setCancelable(false);
|
||||
|
||||
@@ -56,6 +56,9 @@ class SettingsViewModel extends AndroidViewModel {
|
||||
private final MutableLiveEvent<Boolean> setAvatarFailed =
|
||||
new MutableLiveEvent<>();
|
||||
|
||||
private final MutableLiveEvent<Boolean> languageChanged =
|
||||
new MutableLiveEvent<>();
|
||||
|
||||
@Inject
|
||||
SettingsViewModel(Application application,
|
||||
IdentityManager identityManager,
|
||||
@@ -83,6 +86,10 @@ class SettingsViewModel extends AndroidViewModel {
|
||||
return setAvatarFailed;
|
||||
}
|
||||
|
||||
LiveEvent<Boolean> getLanguageChange() {
|
||||
return languageChanged;
|
||||
}
|
||||
|
||||
private void loadOwnIdentityInfo() {
|
||||
dbExecutor.execute(() -> {
|
||||
try {
|
||||
@@ -131,4 +138,8 @@ class SettingsViewModel extends AndroidViewModel {
|
||||
});
|
||||
}
|
||||
|
||||
void languageChanged() {
|
||||
languageChanged.setEvent(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user