Skip to content

Commit

Permalink
Activate on all taps, not just focused one.
Browse files Browse the repository at this point in the history
Issue #78.
  • Loading branch information
mik3y committed May 6, 2014
1 parent 3e69fde commit 9ea6b69
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 66 deletions.
13 changes: 12 additions & 1 deletion kegtab/src/main/java/org/kegbot/app/AuthenticatingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,18 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

/**
* Starts the authentication activity for the supplied username. Upon
* successful authentication, a new flow will be started.
*
* @param context
* @param username
*
*/
public static void startAndAuthenticate(Context context, String username) {
startAndAuthenticate(context, username, (KegTap) null);
}

/**
* Starts the authentication activity for the supplied username. Upon
* successful authentication, a new flow will be started.
Expand All @@ -337,7 +349,6 @@ public static void startAndAuthenticate(Context context, String username, KegTap
context.startActivity(intent);
}


/**
* Starts the authentication activity for the supplied token. Upon successful
* authentication, a new flow will be started.
Expand Down
1 change: 0 additions & 1 deletion kegtab/src/main/java/org/kegbot/app/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ public void onConnectivityChangedEvent(ConnectivityChangedEvent event) {

private void setFocusedTap(KegTap tap) {
Log.d(LOG_TAG, "Set/replaced focused tap: " + tap.getId());
mCore.getTapManager().setFocusedTap(tap);
}

/**
Expand Down
6 changes: 2 additions & 4 deletions kegtab/src/main/java/org/kegbot/app/HomeControlsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
final String username =
data.getStringExtra(KegtabCommon.ACTIVITY_AUTH_DRINKER_RESULT_EXTRA_USERNAME);
if (!Strings.isNullOrEmpty(username)) {
AuthenticatingActivity.startAndAuthenticate(getActivity(), username,
mCore.getTapManager().getFocusedTap());
AuthenticatingActivity.startAndAuthenticate(getActivity(), username);
}
}
break;
Expand All @@ -141,8 +140,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
data.getStringExtra(KegtabCommon.ACTIVITY_CREATE_DRINKER_RESULT_EXTRA_USERNAME);
if (!Strings.isNullOrEmpty(username)) {
Log.d(TAG, "Authenticating newly-created user.");
AuthenticatingActivity.startAndAuthenticate(getActivity(), username,
mCore.getTapManager().getFocusedTap());
AuthenticatingActivity.startAndAuthenticate(getActivity(), username);
}
}
break;
Expand Down
29 changes: 1 addition & 28 deletions kegtab/src/main/java/org/kegbot/core/FlowManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,35 +357,8 @@ public synchronized void activateUserAmbiguousTap(final String username) {
return;
}

final Set<KegTap> activateTaps = Sets.newLinkedHashSet();

final KegTap focusedTap = mTapManager.getFocusedTap();
if (focusedTap != null && focusedTap.hasCurrentKeg()) {
Log.d(TAG, String.format("activateUserAmbiguousTap: using focused tap: %s",
Integer.valueOf(focusedTap.getId())));
activateTaps.add(focusedTap);
}

// Activate at all taps.
for (final KegTap tap : availableTaps) {
if (tap == focusedTap) {
continue;
}
if (!tap.hasToggle()) {
if (tap.hasCurrentKeg()) {
Log.d(TAG,
String.format("activateUserAmbiguousTap: also activating at unmanaged tap: %s",
Integer.valueOf(tap.getId())));
activateTaps.add(tap);
}
}
}

if (activateTaps.isEmpty()) {
Log.d(TAG, "activateUserAmbiguousTap: no focused or unmanaged taps; activating on all taps");
activateTaps.addAll(availableTaps);
}

for (final KegTap tap : activateTaps) {
activateUserAtTap(tap, username);
}
}
Expand Down
32 changes: 0 additions & 32 deletions kegtab/src/main/java/org/kegbot/core/TapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ public class TapManager extends Manager {

private ConfigurationStore mLocalConfig;

/**
* Stores the currently "focused" tap.
*
* Convenient bit of state storage for UI layer. May be {@code null}.
*/
private KegTap mFocusedTap = null;

public TapManager(Bus bus, ConfigurationStore configStore) {
super(bus);
mLocalConfig = configStore;
Expand All @@ -87,9 +80,6 @@ protected synchronized void stop() {
* otherwise.
*/
public synchronized boolean addTap(final KegTap newTap) {
if (mFocusedTap == null) {
mFocusedTap = newTap;
}
return mTaps.put(Integer.valueOf(newTap.getId()), newTap) != null;
}

Expand All @@ -102,30 +92,9 @@ public synchronized boolean addTap(final KegTap newTap) {
* otherwise.
*/
public synchronized boolean removeTap(final KegTap tap) {
if (mFocusedTap == tap) {
mFocusedTap = null;
}
return mTaps.remove(Integer.valueOf(tap.getId())) != null;
}

/**
* @return the currently-focused tap, or {@code null} if none set
*/
public synchronized KegTap getFocusedTap() {
return mFocusedTap;
}

/**
* Sets the currently focused tap.
*/
public synchronized void setFocusedTap(final KegTap tap) {
if (!mTaps.containsValue(tap)) {
Log.w(TAG, "setFocusedTap: tap unknown: " + tap);
return;
}
mFocusedTap = tap;
}

public synchronized KegTap getTap(int tapId) {
return mTaps.get(Integer.valueOf(tapId));
}
Expand Down Expand Up @@ -212,7 +181,6 @@ public synchronized void setTapVisibility(KegTap tap, boolean isVisible) {
@Override
protected synchronized void dump(IndentingPrintWriter writer) {
writer.printPair("numTaps", Integer.valueOf(mTaps.size())).println();
writer.printPair("mFocusedTap", mFocusedTap).println();

if (mTaps.size() > 0) {
writer.println();
Expand Down

0 comments on commit 9ea6b69

Please sign in to comment.