Skip to content

Commit bee46c0

Browse files
committed
Merge pull request #3 from rjam/develop
[new] Support for default providers config
2 parents 8c183c5 + 99db5bb commit bee46c0

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

oneallsdk/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
defaultConfig {
77
minSdkVersion 15
88
targetSdkVersion 22
9-
versionCode 5
10-
versionName "1.0"
9+
versionCode 6
10+
versionName "1.1"
1111
}
1212
buildTypes {
1313
release {

oneallsdk/src/main/java/com/oneall/oneallsdk/OAManager.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222
import android.content.Intent;
2323
import android.net.Uri;
2424
import android.os.Bundle;
25+
import android.support.annotation.Nullable;
26+
import android.util.Log;
2527
import android.view.WindowManager;
2628

2729
import java.util.ArrayList;
30+
import java.util.Arrays;
2831
import java.util.Collection;
32+
import java.util.List;
2933
import java.util.UUID;
3034

3135
import io.fabric.sdk.android.Fabric;
@@ -148,6 +152,31 @@ public void setup(
148152
String subdomain,
149153
String twitterConsumerKey,
150154
String twitterSecret) {
155+
setup(context, subdomain, null, twitterConsumerKey, twitterSecret);
156+
}
157+
158+
/**
159+
* setup manager instance. should be called before using the manager. Otherwise the manager will
160+
* not function.
161+
*
162+
* @param context context
163+
* @param subdomain subdomain of your OneAll application
164+
* @param defaultProviders The list of default providers used to immediately
165+
* populate the accepted providers list while we don't get a response
166+
* from the server (async) or cache (sync).
167+
* @param twitterConsumerKey (optional) Twitter consumer key from
168+
* {@link <a href="https://apps.twitter.com/">https://apps.twitter.com/</a>}
169+
* @param twitterSecret (optional) Twitter secret key from
170+
* {@link <a href="https://apps.twitter.com/">https://apps.twitter.com/</a>}
171+
* @throws java.lang.NullPointerException if {@code context} is null
172+
* @throws java.lang.IllegalArgumentException if {@code subdomain} is null or empty
173+
*/
174+
public void setup(
175+
Context context,
176+
String subdomain,
177+
@Nullable List<Provider> defaultProviders,
178+
String twitterConsumerKey,
179+
String twitterSecret) {
151180

152181
if (context == null) {
153182
throw new NullPointerException("context cannot be null");
@@ -167,11 +196,11 @@ public void setup(
167196

168197
// if the parent app already initialized Fabric for some of its other modules
169198
// make sure it includes the required TwitterCore. Otherwise, init it ourselves
170-
if(!Fabric.isInitialized()) {
199+
if (!Fabric.isInitialized()) {
171200
TwitterAuthConfig authConfig = new TwitterAuthConfig(twitterConsumerKey, twitterSecret);
172201
Fabric.with(this.mAppContext, new TwitterCore(authConfig));
173202
} else {
174-
if(Fabric.getKit(TwitterCore.class) == null) {
203+
if (Fabric.getKit(TwitterCore.class) == null) {
175204
OALog.error("Twitter's Fabric is already init but it doesn't include TwitterCore kit which is required for Auth calls");
176205
} else {
177206
OALog.warn("Twitter's Fabric was already init with a TwitterCore kit. Reusing existing kit");
@@ -181,6 +210,12 @@ public void setup(
181210
OALog.info(String.format("SDK init with subdomain %s", subdomain));
182211

183212
Settings.getInstance().setSubdomain(subdomain);
213+
214+
if(defaultProviders != null) {
215+
// init ProviderManager with default providers
216+
ProviderManager.getInstance().updateProviders(defaultProviders);
217+
}
218+
184219
ProviderManager.getInstance().refreshProviders(mAppContext);
185220
}
186221

oneallsdk/src/main/java/com/oneall/oneallsdk/ProviderManager.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.oneall.oneallsdk;
22

3-
import android.content.Context;
4-
53
import com.oneall.oneallsdk.rest.ServiceManagerProvider;
6-
import com.oneall.oneallsdk.rest.models.ResponseProvidersList;
74
import com.oneall.oneallsdk.rest.models.Provider;
5+
import com.oneall.oneallsdk.rest.models.ResponseProvidersList;
6+
7+
import android.content.Context;
88

99
import java.io.FileInputStream;
1010
import java.io.FileNotFoundException;
@@ -63,6 +63,15 @@ public static ProviderManager getInstance() {
6363

6464
// region Interface methods
6565

66+
/**
67+
* Updates the list of providers without any additional changes.
68+
*
69+
* @param providers The new list of providers
70+
*/
71+
void updateProviders(List<Provider> providers) {
72+
this.providers = providers;
73+
}
74+
6675
/**
6776
* force providers refresh. Should be executed as early as possible during application start
6877
*

0 commit comments

Comments
 (0)