Skip to content

Commit f28c1e8

Browse files
author
Ricardo Moutinho
committed
[upd] improved clean up on web login activity and replaced deprecated ActionBarActivity by AppCompatActivity;
[upd] OAManager now checks if any Fabric instance is already available before attempting to init it. Fabric includes lots of kits which may already be in use by the main application so we need to check before trying to init a potentially already init singleton. If TwitterCore kit is present we go with it, if not we crash with an informative log so the dev knows how to fix it.
1 parent 95afd52 commit f28c1e8

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class OALog {
1515
// region Constants
1616

1717
private final static String TAG = "oneall";
18+
// private final static boolean PRINT_LOGS = true;
1819
private final static boolean PRINT_LOGS = BuildConfig.DEBUG;
1920

2021
// endregion

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,18 @@ public void setup(
156156

157157
OALog.init(mAppContext);
158158

159-
TwitterAuthConfig authConfig = new TwitterAuthConfig(twitterConsumerKey, twitterSecret);
160-
Fabric.with(this.mAppContext, new TwitterCore(authConfig));
159+
// if the parent app already initialized Fabric for some of its other modules
160+
// make sure it includes the required TwitterCore. Otherwise, init it ourselves
161+
if(!Fabric.isInitialized()) {
162+
TwitterAuthConfig authConfig = new TwitterAuthConfig(twitterConsumerKey, twitterSecret);
163+
Fabric.with(this.mAppContext, new TwitterCore(authConfig));
164+
} else {
165+
if(Fabric.getKit(TwitterCore.class) == null) {
166+
OALog.error("Twitter's Fabric is already init but it doesn't include TwitterCore kit which is required for Auth calls");
167+
} else {
168+
OALog.warn("Twitter's Fabric was already init with a TwitterCore kit. Reusing existing kit");
169+
}
170+
}
161171

162172
OALog.info(String.format("SDK init with subdomain %s", subdomain));
163173

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import android.net.Uri;
99
import android.os.Bundle;
1010
import android.support.v7.app.ActionBar;
11-
import android.support.v7.app.ActionBarActivity;
11+
import android.support.v7.app.AppCompatActivity;
1212
import android.view.MenuItem;
1313
import android.view.WindowManager;
1414
import android.webkit.WebView;
@@ -17,11 +17,12 @@
1717
/**
1818
* Web view activity used to take the user through authentication
1919
*/
20-
public class WebLoginActivity extends ActionBarActivity {
20+
public class WebLoginActivity extends AppCompatActivity {
2121

2222
// region Properties
2323

2424
private ProgressDialog progressDialog;
25+
private WebView mWebView;
2526

2627
// endregion
2728

@@ -45,9 +46,9 @@ protected void onCreate(Bundle savedInstanceState) {
4546
supportActionBar.setDisplayHomeAsUpEnabled(true);
4647
}
4748

48-
WebView webView = (WebView) findViewById(R.id.web_login_web_view);
49-
webView.getSettings().setJavaScriptEnabled(true);
50-
webView.setWebViewClient(new WebViewClient() {
49+
mWebView = (WebView) findViewById(R.id.web_login_web_view);
50+
mWebView.getSettings().setJavaScriptEnabled(true);
51+
mWebView.setWebViewClient(new WebViewClient() {
5152

5253
@Override
5354
public boolean shouldOverrideUrlLoading(WebView view, String url) {
@@ -56,7 +57,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
5657

5758
@Override
5859
public void onPageStarted(WebView view, String url, Bitmap favicon) {
59-
OALog.info(String.format("Page loading state: %s", url));
60+
OALog.info(String.format("Page loading started: %s", url));
6061
try {
6162
if (progressDialog == null) {
6263
progressDialog = ProgressDialog.show(
@@ -91,7 +92,7 @@ public void onReceivedError(WebView view, int errorCode, String description, Str
9192
pageLoadFailed(failingUrl);
9293
}
9394
});
94-
webView.loadUrl(getIntent().getExtras().getString(INTENT_EXTRA_URL));
95+
mWebView.loadUrl(getIntent().getExtras().getString(INTENT_EXTRA_URL));
9596
}
9697

9798
@Override
@@ -101,6 +102,11 @@ protected void onDestroy() {
101102
progressDialog.dismiss();
102103
}
103104

105+
if (mWebView != null) {
106+
mWebView.stopLoading();
107+
mWebView.destroy();
108+
}
109+
104110
super.onDestroy();
105111
}
106112

0 commit comments

Comments
 (0)