Skip to content

Commit

Permalink
service: toggle google:queue on service bind/unbind
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0rg committed Aug 4, 2014
1 parent 5e2212f commit 9458a20
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/org/yaxim/androidclient/service/XMPPService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ public class XMPPService extends GenericService {

@Override
public IBinder onBind(Intent intent) {
super.onBind(intent);
userStartedWatching();

String chatPartner = intent.getDataString();
if ((chatPartner != null)) {
resetNotificationCounter(chatPartner);
mIsBoundTo.add(chatPartner);
return mServiceChatConnection;
}

return mService2RosterConnection;
}

@Override
public void onRebind(Intent intent) {
super.onRebind(intent);
userStartedWatching();
String chatPartner = intent.getDataString();
if ((chatPartner != null)) {
mIsBoundTo.add(chatPartner);
Expand All @@ -77,6 +77,8 @@ public boolean onUnbind(Intent intent) {
if ((chatPartner != null)) {
mIsBoundTo.remove(chatPartner);
}
userStoppedWatching();

return true;
}

Expand Down Expand Up @@ -492,4 +494,23 @@ public void onReceive(Context ctx, Intent i) {
doConnect();
}
}

private int number_of_eyes = 0;
private void userStartedWatching() {
number_of_eyes += 1;
logInfo("userStartedWatching: " + number_of_eyes);
if (mSmackable != null)
mSmackable.setUserWatching(true);
}

private void userStoppedWatching() {
number_of_eyes -= 1;
logInfo("userStoppedWatching: " + number_of_eyes);
// delay deactivation by 3s, in case we happen to be immediately re-bound
mMainHandler.postDelayed(new Runnable() {
public void run() {
if (mSmackable != null && number_of_eyes == 0)
mSmackable.setUserWatching(false);
}}, 3000);
}
}

0 comments on commit 9458a20

Please sign in to comment.