Commit 5676e18a authored by Torsten Grote's avatar Torsten Grote

[android] StartupActivity: Address first round of review comments

parent 5ece6505
package org.briarproject.briar.android;
import android.app.Activity;
import android.content.SharedPreferences;
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
import java.util.Collection;
import java.util.logging.LogRecord;
......@@ -11,6 +14,8 @@ import java.util.logging.LogRecord;
*/
public interface BriarApplication {
Class<? extends Activity> ENTRY_ACTIVITY = NavDrawerActivity.class;
Collection<LogRecord> getRecentLogRecords();
AndroidComponent getApplicationComponent();
......
......@@ -47,7 +47,7 @@ import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.ALREADY_RUNNING;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.SUCCESS;
import static org.briarproject.briar.android.activity.ActivityComponent.ENTRY_ACTIVITY;
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_CHANNEL_ID;
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_NOTIFICATION_ID;
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_ID;
......
......@@ -74,7 +74,7 @@ public class StartupFailureActivity extends BaseActivity implements
@Override
public void runOnDbThread(@NonNull Runnable runnable) {
throw new AssertionError("Deprecated and should not be used");
throw new UnsupportedOperationException();
}
}
......@@ -19,7 +19,7 @@ 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.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
import static org.briarproject.briar.android.activity.ActivityComponent.ENTRY_ACTIVITY;
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
......
......@@ -91,8 +91,6 @@ import dagger.Component;
dependencies = AndroidComponent.class)
public interface ActivityComponent {
Class<? extends Activity> ENTRY_ACTIVITY = NavDrawerActivity.class;
Activity activity();
void inject(SplashScreenActivity activity);
......
......@@ -26,7 +26,7 @@ import static org.briarproject.briar.android.login.StartupViewModel.State.MIGRAT
@ParametersNotNullByDefault
public class OpenDatabaseFragment extends BaseFragment {
final static String TAG = PasswordFragment.class.getName();
final static String TAG = OpenDatabaseFragment.class.getName();
@Inject
ViewModelProvider.Factory viewModelFactory;
......
......@@ -23,6 +23,7 @@ import javax.inject.Inject;
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.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
import static org.briarproject.briar.android.login.StartupViewModel.State.SIGNED_IN;
import static org.briarproject.briar.android.login.StartupViewModel.State.SIGNED_OUT;
import static org.briarproject.briar.android.login.StartupViewModel.State.STARTED;
......@@ -59,10 +60,12 @@ public class StartupActivity extends BaseActivity implements
// because if it exists, we assume the database also exists
// and when clearing app data, the folder does not get deleted.
viewModel.deleteAccount();
onAccountDeleted(true);
onAccountDeleted();
return;
}
viewModel.getAccountDeleted().observe(this, this::onAccountDeleted);
viewModel.getAccountDeleted().observe(this, deleted -> {
if (deleted != null && deleted) onAccountDeleted();
});
viewModel.getState().observe(this, this::onStateChanged);
}
......@@ -86,7 +89,10 @@ public class StartupActivity extends BaseActivity implements
} else if (state == SIGNED_IN) {
startService(new Intent(this, BriarService.class));
} else if (state == STARTING) {
// only show OpenDatabaseFragment if not already visible
// Only show OpenDatabaseFragment if not already visible.
// This can happen because several LifecycleManager states are
// mapped to STARTING, so this can get called several times
// as the app's lifecycle advances.
FragmentManager fm = getSupportFragmentManager();
Fragment f = fm.findFragmentByTag(OpenDatabaseFragment.TAG);
if (f == null || !f.isVisible()) {
......@@ -100,21 +106,19 @@ public class StartupActivity extends BaseActivity implements
}
}
private void onAccountDeleted(boolean accountDeleted) {
if (accountDeleted) {
setResult(RESULT_CANCELED);
finish();
Intent i = new Intent(this, SetupActivity.class);
i.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP |
FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
}
private void onAccountDeleted() {
setResult(RESULT_CANCELED);
finish();
Intent i = new Intent(this, SetupActivity.class);
i.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP |
FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_TASK_ON_HOME);
startActivity(i);
}
@Override
public void runOnDbThread(Runnable runnable) {
// we don't need this and shouldn't be forced to implement it
throw new AssertionError();
throw new UnsupportedOperationException();
}
}
......@@ -52,6 +52,7 @@ import javax.inject.Inject;
import static android.app.Activity.RESULT_OK;
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.media.RingtoneManager.ACTION_RINGTONE_PICKER;
import static android.media.RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI;
......@@ -79,7 +80,7 @@ import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.LogUtils.now;
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
import static org.briarproject.briar.android.activity.ActivityComponent.ENTRY_ACTIVITY;
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGTONE;
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.INTENT_SIGN_OUT;
import static org.briarproject.briar.android.util.UiUtils.hasScreenLock;
......@@ -576,7 +577,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
(dialogInterface, i) -> {
language.setValue(newValue);
Intent intent = new Intent(getContext(), ENTRY_ACTIVITY);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(INTENT_SIGN_OUT, true);
requireActivity().startActivity(intent);
requireActivity().finish();
......
......@@ -26,7 +26,7 @@ import static android.support.v7.preference.PreferenceManager.setDefaultValues;
import static java.lang.System.currentTimeMillis;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
import static org.briarproject.briar.android.activity.ActivityComponent.ENTRY_ACTIVITY;
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
......
......@@ -16,7 +16,7 @@ import org.briarproject.briar.api.test.TestDataCreator;
import javax.inject.Inject;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static org.briarproject.briar.android.activity.ActivityComponent.ENTRY_ACTIVITY;
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
public class TestDataActivity extends BriarActivity {
......
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