diff options
author | Chris Warrington <cmw@google.com> | 2016-10-18 12:29:21 +0100 |
---|---|---|
committer | Chris Warrington <cmw@google.com> | 2016-10-18 12:34:18 +0100 |
commit | e3780081075c01aa1dff6d1f373cb43192b33e68 (patch) | |
tree | fb734615933a39f3d009210dc0d1457160479b35 /WordPress/src/main/java/org/wordpress/android/ui/suggestion/util/SuggestionServiceConnectionManager.java | |
parent | 7e05eb7e57827eddc885570bc00aed8a50320dbf (diff) | |
parent | 025b8b226c8d8edba2b309ca878572f40512eca7 (diff) | |
download | gradle-perf-android-medium-e3780081075c01aa1dff6d1f373cb43192b33e68.tar.gz |
Merge remote-tracking branch 'origin/upstream-master' into masterHEADstudio-3.4.0studio-3.2.1studio-3.1.2studio-3.0studio-2.3gradle_3.4.0gradle_3.1.2gradle_3.0.0gradle_2.3.0studio-master-devmirror-goog-studio-master-devmastermain
Change-Id: I63f5e16d09297c48432192761b840310935eb903
Diffstat (limited to 'WordPress/src/main/java/org/wordpress/android/ui/suggestion/util/SuggestionServiceConnectionManager.java')
-rw-r--r-- | WordPress/src/main/java/org/wordpress/android/ui/suggestion/util/SuggestionServiceConnectionManager.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/suggestion/util/SuggestionServiceConnectionManager.java b/WordPress/src/main/java/org/wordpress/android/ui/suggestion/util/SuggestionServiceConnectionManager.java new file mode 100644 index 000000000..bcbdebe30 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/suggestion/util/SuggestionServiceConnectionManager.java @@ -0,0 +1,55 @@ +package org.wordpress.android.ui.suggestion.util; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.IBinder; + +import org.wordpress.android.ui.suggestion.service.SuggestionService; + +public class SuggestionServiceConnectionManager implements ServiceConnection { + + private final Context mContext; + private final int mRemoteBlogId; + private boolean mAttemptingToBind = false; + private boolean mBindCalled = false; + + public SuggestionServiceConnectionManager(Context context, int remoteBlogId) { + mContext = context; + mRemoteBlogId = remoteBlogId; + } + + public void bindToService() { + if (!mAttemptingToBind) { + mAttemptingToBind = true; + mBindCalled = true; + Intent intent = new Intent(mContext, SuggestionService.class); + mContext.bindService(intent, this, Context.BIND_AUTO_CREATE); + } + } + + public void unbindFromService() { + mAttemptingToBind = false; + if (mBindCalled) { + mContext.unbindService(this); + mBindCalled = false; + } + } + + @Override + public void onServiceConnected(ComponentName componentName, IBinder iBinder) { + SuggestionService.SuggestionBinder b = (SuggestionService.SuggestionBinder) iBinder; + SuggestionService suggestionService = b.getService(); + + suggestionService.updateSuggestions(mRemoteBlogId); + suggestionService.updateTags(mRemoteBlogId); + + mAttemptingToBind = false; + } + + @Override + public void onServiceDisconnected(ComponentName componentName) { + // noop + } +} |