Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Commit

Permalink
Fix bug about duplicated requirement intents.
Browse files Browse the repository at this point in the history
For example when navigating to the UserProfileActivity, the user would be prompted to
login twice. This fixes that issue.

Signed-off-by: Roosembert Palacios <roosembert.palacios@epfl.ch>
  • Loading branch information
Roosembert Palacios committed Dec 17, 2018
1 parent b306a79 commit d65ea3f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private void enqueueAndFinishIfUnconfiguredDependencies() {
.orElseThrow(() -> new IllegalArgumentException(
"Cannot find Configurator for class " + depCls.getName())))
.map(DependencyCoordinator::dependencyConfigurationIntent)
.distinct()
.map(i -> i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME))
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public class LoggedUserCoordinator implements DependencyCoordinator<LoggedUser>
@Inject Context ctx;
@Inject UserManagementService ups;
private Optional<LoggedUser> currentLoggedUser = Optional.empty();
private final Intent configurationIntent;

@Inject public LoggedUserCoordinator() {
@Inject public LoggedUserCoordinator(Context ctx) {
configurationIntent = new Intent(ctx, LoginActivity.class);
}

private static <A> Consumer<A> failIfNull(String message, Consumer<A> next) {
Expand All @@ -41,7 +43,7 @@ private static <A> Consumer<A> failIfNull(String message, Consumer<A> next) {
}

@Override public Intent dependencyConfigurationIntent() {
return new Intent(ctx, LoginActivity.class);
return configurationIntent;
}

public void setCurrentLoggedUser(LoggedUser up) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ public class RemoteServicesProviderCoordinator implements DependencyCoordinator<
@Inject SharedPreferences sharedPreferences;
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private Optional<RemoteServicesProvider> currentProvider = Optional.empty();
private final Intent configurationIntent;

@Inject
public RemoteServicesProviderCoordinator(@Named(ErpaApplication.RES_APPLICATION_SCOPE) Scope scope, Context appCtx) {
this.applicationContext = appCtx;
Toothpick.inject(this, scope);
REMOTE_PROVIDER_KEY = appCtx.getString(R.string.prop_key_remote_provider);
rspClassFromApplicationPreferences().ifPresent(this::bindRemoteServicesProvider);
configurationIntent = new Intent(applicationContext, SelectRemoteServicesProviderActivity.class);
}

public void bindRemoteServicesProvider(@Nullable Class<? extends RemoteServicesProvider> rspClass) {
Expand Down Expand Up @@ -107,7 +109,7 @@ public boolean dependencyIsConfigured() {

@Override
public Intent dependencyConfigurationIntent() {
return new Intent(applicationContext, SelectRemoteServicesProviderActivity.class);
return configurationIntent;
}

@Override
Expand Down

0 comments on commit d65ea3f

Please sign in to comment.