Verified Commit c85102fe authored by Sebastian's avatar Sebastian
Browse files

Use BriarActivity#signOut() to exit app after updating language

parent bebf3bbc
Pipeline #6315 passed with stages
in 38 minutes and 57 seconds
......@@ -179,6 +179,13 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
LOG.info("Stopping services");
state = STOPPING;
eventBus.broadcast(new LifecycleEvent(STOPPING));
LOG.info("Sleeping a bit to simulate slowness");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
LOG.info("Done simulating slowness");
for (Service s : services) {
long start = now();
s.stopService();
......
......@@ -37,6 +37,7 @@ import org.briarproject.briar.android.conversation.glide.BriarModelLoader;
import org.briarproject.briar.android.logging.CachingLogHandler;
import org.briarproject.briar.android.login.SignInReminderReceiver;
import org.briarproject.briar.android.settings.ConnectionsFragment;
import org.briarproject.briar.android.settings.DisplayFragment;
import org.briarproject.briar.android.settings.NotificationsFragment;
import org.briarproject.briar.android.settings.SecurityFragment;
import org.briarproject.briar.android.settings.SettingsFragment;
......@@ -200,6 +201,8 @@ public interface AndroidComponent
void inject(SettingsFragment settingsFragment);
void inject(DisplayFragment displayFragment);
void inject(ConnectionsFragment connectionsFragment);
void inject(SecurityFragment securityFragment);
......
......@@ -97,8 +97,6 @@ public class NavDrawerActivity extends BriarActivity implements
Uri.parse("briar-content://org.briarproject.briar/blog");
public static Uri CONTACT_ADDED_URI =
Uri.parse("briar-content://org.briarproject.briar/contact/added");
public static Uri SIGN_OUT_URI =
Uri.parse("briar-content://org.briarproject.briar/sign-out");
private final List<Transport> transports = new ArrayList<>(3);
private final MutableLiveData<ImageView> torIcon = new MutableLiveData<>();
......@@ -224,8 +222,6 @@ public class NavDrawerActivity extends BriarActivity implements
startFragment(ForumListFragment.newInstance(), R.id.nav_btn_forums);
} else if (BLOG_URI.equals(uri)) {
startFragment(FeedFragment.newInstance(), R.id.nav_btn_blogs);
} else if (SIGN_OUT_URI.equals(uri)) {
signOut(false, false);
}
}
......
package org.briarproject.briar.android.settings;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
......@@ -15,22 +16,25 @@ import java.util.List;
import java.util.Locale;
import java.util.logging.Logger;
import javax.inject.Inject;
import androidx.annotation.NonNull;
import androidx.core.text.TextUtilsCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.os.Build.VERSION.SDK_INT;
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_LTR;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Level.INFO;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.briar.android.AppModule.getAndroidComponent;
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.SIGN_OUT_URI;
import static org.briarproject.briar.android.settings.SettingsActivity.EXTRA_THEME_CHANGE;
@NotNullByDefault
......@@ -42,6 +46,19 @@ public class DisplayFragment extends PreferenceFragmentCompat {
private static final Logger LOG =
getLogger(DisplayFragment.class.getName());
@Inject
ViewModelProvider.Factory viewModelFactory;
private SettingsViewModel viewModel;
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
getAndroidComponent(context).inject(this);
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
.get(SettingsViewModel.class);
}
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.settings_display);
......@@ -148,11 +165,7 @@ public class DisplayFragment extends PreferenceFragmentCompat {
builder.setMessage(R.string.pref_language_changed);
builder.setPositiveButton(R.string.sign_out_button, (d, i) -> {
language.setValue((String) newValue);
Intent intent = new Intent(getContext(), ENTRY_ACTIVITY);
intent.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
intent.setData(SIGN_OUT_URI);
requireActivity().startActivity(intent);
requireActivity().finish();
viewModel.languageChanged();
});
builder.setNegativeButton(R.string.cancel, null);
builder.setCancelable(false);
......
......@@ -9,11 +9,14 @@ import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity;
import javax.inject.Inject;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentFactory;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceFragmentCompat.OnPreferenceStartFragmentCallback;
......@@ -25,6 +28,11 @@ public class SettingsActivity extends BriarActivity
static final String EXTRA_THEME_CHANGE = "themeChange";
@Inject
ViewModelProvider.Factory viewModelFactory;
private SettingsViewModel viewModel;
@Override
public void injectActivity(ActivityComponent component) {
component.inject(this);
......@@ -49,6 +57,15 @@ public class SettingsActivity extends BriarActivity
}
setContentView(R.layout.activity_settings);
ViewModelProvider provider =
new ViewModelProvider(this, viewModelFactory);
viewModel = provider.get(SettingsViewModel.class);
viewModel.getLanguageChange().observeEvent(this, b -> {
signOut(false, false);
finishAffinity();
});
}
@Override
......
......@@ -31,6 +31,8 @@ import org.briarproject.briar.R;
import org.briarproject.briar.android.attachment.UnsupportedMimeTypeException;
import org.briarproject.briar.android.attachment.media.ImageCompressor;
import org.briarproject.briar.android.viewmodel.DbViewModel;
import org.briarproject.briar.android.viewmodel.LiveEvent;
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
import org.briarproject.briar.api.avatar.AvatarManager;
import org.briarproject.briar.api.identity.AuthorInfo;
import org.briarproject.briar.api.identity.AuthorManager;
......@@ -92,6 +94,8 @@ class SettingsViewModel extends DbViewModel implements EventListener {
new MutableLiveData<>();
private final MutableLiveData<String> screenLockTimeout =
new MutableLiveData<>();
private final MutableLiveEvent<Boolean> languageChanged =
new MutableLiveEvent<>();
@Inject
SettingsViewModel(Application application,
......@@ -250,6 +254,10 @@ class SettingsViewModel extends DbViewModel implements EventListener {
.show());
}
void languageChanged() {
languageChanged.setEvent(true);
}
LiveData<OwnIdentityInfo> getOwnIdentityInfo() {
return ownIdentityInfo;
}
......@@ -262,4 +270,8 @@ class SettingsViewModel extends DbViewModel implements EventListener {
return screenLockTimeout;
}
LiveEvent<Boolean> getLanguageChange() {
return languageChanged;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment