Android Open Source - jive-android-core-sdk-example Jive Connection From Project Back to project page jive-android-core-sdk-example .
License The source code is released under:
Apache License
If you think the Android project jive-android-core-sdk-example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.jivesoftware.example.jive.dao;
/ / f r o m w w w . j a v a 2 s . c o m
import android.util.Log;
import com.jivesoftware.android.mobile.sdk.core.JiveCore;
import com.jivesoftware.android.mobile.sdk.core.JiveCoreUnauthenticated;
import com.jivesoftware.android.mobile.sdk.entity.PersonEntity;
import com.jivesoftware.android.mobile.sdk.entity.PersonListEntity;
import com.jivesoftware.android.mobile.sdk.entity.TokenEntity;
import com.jivesoftware.android.mobile.sdk.json.JiveJson;
import com.jivesoftware.example.Constants;
import com.jivesoftware.example.destroyer.IDestroyable;
import com.jivesoftware.example.utils.BackgroundRunner;
import com.jivesoftware.example.utils.BackgroundThread;
import com.jivesoftware.example.utils.PersistedKeyValueStore;
import org.apache.http.impl.client.DefaultHttpClient;
import javax.inject.Inject;
import java.net.URL;
import static com.jivesoftware.example.utils.BackgroundRunner.JiveBackgroundRunnable;
import static com.jivesoftware.example.utils.BackgroundRunner.JiveResultCallback;
/**
* Created by mark.schisler on 10/15/14.
*/
public class JiveConnection implements IDestroyable {
private final String TAG = getClass().getName();
private final JiveJson jiveJson;
private final BackgroundRunner backgroundRunner;
private final PersistedKeyValueStore keyValueStore;
private JiveTokenProvider jiveTokenProvider;
private JiveCore jiveCoreAuthenticated;
private JiveCoreUnauthenticated jiveCoreUnauthenticated;
private DefaultHttpClient httpClientUnauthenticated;
private DefaultHttpClient httpClientAuthenticated;
@Inject
public JiveConnection(PersistedKeyValueStore keyValueStore) {
this.keyValueStore = keyValueStore;
this.backgroundRunner = new BackgroundRunner(new BackgroundThread());
this.jiveJson = new JiveJson();
updateFromPersistedStore(keyValueStore);
}
@Override
public void destroy() {
backgroundRunner.destroy();
httpClientAuthenticated.getConnectionManager().shutdown();
httpClientUnauthenticated.getConnectionManager().shutdown();
}
private void setEndpoint(final URL endpoint) {
this.httpClientUnauthenticated = new DefaultHttpClient();
this.jiveCoreUnauthenticated = new JiveCoreUnauthenticated(endpoint, Constants.OAUTH_CREDENTIALS, Constants.OAUTH_ADDON_UUID, httpClientUnauthenticated, jiveJson);
this.jiveTokenProvider = new JiveTokenProvider(keyValueStore, jiveCoreUnauthenticated);
this.httpClientAuthenticated = new DefaultHttpClient();
this.jiveCoreAuthenticated = new JiveCore(endpoint, httpClientAuthenticated,jiveTokenProvider, jiveTokenProvider, jiveJson);
}
public void authenticate(final String username, final String password, final URL endpoint, JiveResultCallback<TokenEntity> callback) {
setEndpoint(endpoint);
backgroundRunner.post(new JiveBackgroundRunnable<TokenEntity>() {
@Override
public TokenEntity run() throws Exception {
jiveTokenProvider.setCredentials(username, password);
TokenEntity entity = jiveCoreUnauthenticated.authorizeDevice(username, password).call();
keyValueStore.putTokenEntity(entity);
return entity;
}
}, callback);
}
public void fetchMePerson(JiveResultCallback<PersonEntity> callback) {
backgroundRunner.post(new JiveBackgroundRunnable<PersonEntity>() {
@Override
public PersonEntity run() throws Exception {
return jiveCoreAuthenticated.fetchMePerson().call();
}
}, callback);
}
public void fetchPerson(final String pathAndQueryString, JiveResultCallback<PersonEntity> callback) {
backgroundRunner.post(new JiveBackgroundRunnable<PersonEntity>() {
@Override
public PersonEntity run() throws Exception {
return jiveCoreAuthenticated.fetchPerson(pathAndQueryString).call();
}
}, callback);
}
public void fetchFollowing(final String pathAndQueryString, JiveResultCallback<PersonListEntity> callback) {
backgroundRunner.post(new JiveBackgroundRunnable<PersonListEntity>() {
@Override
public PersonListEntity run() throws Exception {
return jiveCoreAuthenticated.fetchList(pathAndQueryString, PersonListEntity.class).call();
}
}, callback);
}
private void updateFromPersistedStore(PersistedKeyValueStore store) {
String endpoint = store.getEndpoint();
try {
setEndpoint(new URL(endpoint));
} catch (Exception e) {
Log.w(TAG, "Failed to update endpoint" , e);
}
}
}
Java Source Code List com.jivesoftware.example.BuildConfig.java com.jivesoftware.example.Constants.java com.jivesoftware.example.collaborators.CollaboratorActivity.java com.jivesoftware.example.collaborators.CollaboratorModel.java com.jivesoftware.example.collaborators.CollaboratorPresenter.java com.jivesoftware.example.collaborators.CollaboratorsView.java com.jivesoftware.example.collaborators.UserView.java com.jivesoftware.example.collaborators.UsersAdapter.java com.jivesoftware.example.collaborators.events.CollaboratorDeleteEvent.java com.jivesoftware.example.collaborators.events.CollaboratorSelectedEvent.java com.jivesoftware.example.destroyer.Destroyer.java com.jivesoftware.example.destroyer.IDestroyable.java com.jivesoftware.example.exceptions.AuthenticationException.java com.jivesoftware.example.exceptions.TwoFactorException.java com.jivesoftware.example.followers.FollowersActivity.java com.jivesoftware.example.followers.FollowersModel.java com.jivesoftware.example.followers.FollowersPresenter.java com.jivesoftware.example.followers.FollowersView.java com.jivesoftware.example.followers.GitHubUsersModel.java com.jivesoftware.example.followers.events.FollowerSelected.java com.jivesoftware.example.followers.events.FollowersUpdate.java com.jivesoftware.example.github.AuthenticationTokenFactory.java com.jivesoftware.example.github.GitHubBasicAuthRequestInterceptor.java com.jivesoftware.example.github.GitHubOauthRequestInterceptor.java com.jivesoftware.example.github.GitHubServiceFactory.java com.jivesoftware.example.github.authentication.GitHubAuthenticationActivity.java com.jivesoftware.example.github.authentication.GitHubAuthenticationErrorHandler.java com.jivesoftware.example.github.authentication.GitHubAuthenticationModel.java com.jivesoftware.example.github.authentication.GitHubAuthenticationPresenter.java com.jivesoftware.example.github.authentication.GitHubAuthenticationView.java com.jivesoftware.example.github.authentication.events.GitHubLoginPressed.java com.jivesoftware.example.github.dao.AuthorizationRequest.java com.jivesoftware.example.github.dao.Authorization.java com.jivesoftware.example.github.dao.GitHubList.java com.jivesoftware.example.github.dao.Organization.java com.jivesoftware.example.github.dao.Owner.java com.jivesoftware.example.github.dao.Repository.java com.jivesoftware.example.github.dao.Team.java com.jivesoftware.example.github.dao.User.java com.jivesoftware.example.github.service.IGitHubAuthService.java com.jivesoftware.example.github.service.IGitHubRepoService.java com.jivesoftware.example.github.service.IGitHubUserService.java com.jivesoftware.example.injection.BaseModule.java com.jivesoftware.example.jive.authentication.JiveAuthenticationActivity.java com.jivesoftware.example.jive.authentication.JiveAuthenticationModel.java com.jivesoftware.example.jive.authentication.JiveAuthenticationPresenter.java com.jivesoftware.example.jive.authentication.JiveAuthenticationView.java com.jivesoftware.example.jive.authentication.events.JiveLoginPressed.java com.jivesoftware.example.jive.dao.JiveConnection.java com.jivesoftware.example.jive.dao.JiveTokenProvider.java com.jivesoftware.example.listenable.IListener.java com.jivesoftware.example.listenable.ITypeListenable.java com.jivesoftware.example.listenable.IValueListener.java com.jivesoftware.example.listenable.TypeListenable.java com.jivesoftware.example.profile.ProfileActivity.java com.jivesoftware.example.profile.ProfileModel.java com.jivesoftware.example.profile.ProfilePresenter.java com.jivesoftware.example.profile.ProfileView.java com.jivesoftware.example.profiles.ProfilesModel.java com.jivesoftware.example.profiles.ProfilesPresenter.java com.jivesoftware.example.profiles.ProfilesView.java com.jivesoftware.example.profiles.events.GitHubProfileEvent.java com.jivesoftware.example.profiles.events.JiveProfileEvent.java com.jivesoftware.example.repositories.RepositoriesActivity.java com.jivesoftware.example.repositories.RepositoriesModel.java com.jivesoftware.example.repositories.RepositoriesPresenter.java com.jivesoftware.example.repositories.RepositoriesView.java com.jivesoftware.example.repositories.RepositoryAdapter.java com.jivesoftware.example.repositories.RepositoryView.java com.jivesoftware.example.team.TeamCollaboratorsActivity.java com.jivesoftware.example.team.TeamCollaboratorsModel.java com.jivesoftware.example.team.TeamCollaboratorsPresenter.java com.jivesoftware.example.team.TeamCollaboratorsView.java com.jivesoftware.example.team.events.TeamCollaboratorLongPressed.java com.jivesoftware.example.team.events.TeamCollaboratorPressed.java com.jivesoftware.example.team.events.TeamCollaborators.java com.jivesoftware.example.teams.TeamView.java com.jivesoftware.example.teams.TeamsActivity.java com.jivesoftware.example.teams.TeamsAdapter.java com.jivesoftware.example.teams.TeamsModel.java com.jivesoftware.example.teams.TeamsPresenter.java com.jivesoftware.example.teams.TeamsView.java com.jivesoftware.example.teams.events.TeamPressed.java com.jivesoftware.example.utils.ActivityLauncher.java com.jivesoftware.example.utils.AuthenticatedDownloader.java com.jivesoftware.example.utils.AuthorizationReset.java com.jivesoftware.example.utils.BackgroundRunner.java com.jivesoftware.example.utils.BackgroundThread.java com.jivesoftware.example.utils.IntentExtraNames.java com.jivesoftware.example.utils.IntentUtils.java com.jivesoftware.example.utils.JivePicasso.java com.jivesoftware.example.utils.Joiner.java com.jivesoftware.example.utils.PersistedKeyValueStore.java com.jivesoftware.example.utils.ToastMaker.java com.jivesoftware.example.utils.URLUtils.java