Skip to content

Commit 7b61330

Browse files
author
Ricardo Moutinho
committed
[new] quick and dirty localization support on sdk..ideally the SDK would not need any strings and they would all be provided by the parent app
1 parent f28c1e8 commit 7b61330

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ public interface OAManagerPostHandler {
8686

8787
// endregion
8888

89+
// region Localization
90+
91+
private String loading;
92+
93+
// endregion
94+
8995
// region Lifecycle
9096

9197
/**
@@ -151,6 +157,9 @@ public void setup(
151157
throw new IllegalArgumentException("Subdomain cannot be empty");
152158
}
153159

160+
// init localization strings
161+
localize(context.getString(R.string.web_login_progress_title));
162+
154163
// make sure the ref we hold is from the application context
155164
mAppContext = context.getApplicationContext();
156165

@@ -175,6 +184,19 @@ public void setup(
175184
ProviderManager.getInstance().refreshProviders(mAppContext);
176185
}
177186

187+
/**
188+
* The SDK needs a few strings that are shown to the user
189+
* during certain tasks. This calls allows you to override the
190+
* default locale strings.
191+
* Be sure to call this after {@link #setup(Context, String, String, String)}.
192+
*
193+
* @param loading Shown on progress dialogs while loading web pages or obtaining
194+
* user info.
195+
*/
196+
public void localize(String loading) {
197+
this.loading = loading;
198+
}
199+
178200
/**
179201
* Starts authentication with OneAll using selected social network. If additional information is
180202
* required for provider, the user is shown a dialog with request for additional data. When all
@@ -454,6 +476,7 @@ private void webLoginWithLoginData(Activity activity, String userInput) {
454476
"Web login with provider %s and url: %s", selectedProvider.getKey(), url));
455477
Intent i = new Intent(activity, WebLoginActivity.class);
456478
i.putExtra(WebLoginActivity.INTENT_EXTRA_URL, url);
479+
i.putExtra(WebLoginActivity.INTENT_EXTRA_LOADING_STRING, loading);
457480

458481
activity.startActivityForResult(i, INTENT_REQUEST_CODE_LOGIN);
459482
}
@@ -578,7 +601,7 @@ private void retrieveConnectionInfo(
578601
final ProgressDialog pd = ProgressDialog.show(
579602
guiContext,
580603
"",
581-
guiContext.getString(R.string.web_login_progress_title),
604+
loading,
582605
true,
583606
true);
584607

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@ public class WebLoginActivity extends AppCompatActivity {
2222
// region Properties
2323

2424
private ProgressDialog progressDialog;
25-
private WebView mWebView;
25+
private WebView webView;
26+
27+
// endregion
28+
29+
// region l10n
30+
31+
private String loading;
2632

2733
// endregion
2834

2935
// region Constants
3036

3137
public final static String INTENT_EXTRA_URL = "url";
38+
public final static String INTENT_EXTRA_LOADING_STRING = "loading_string";
3239

3340
private final static String CUSTOM_URL_SCHEME = "oneall";
3441

@@ -46,9 +53,16 @@ protected void onCreate(Bundle savedInstanceState) {
4653
supportActionBar.setDisplayHomeAsUpEnabled(true);
4754
}
4855

49-
mWebView = (WebView) findViewById(R.id.web_login_web_view);
50-
mWebView.getSettings().setJavaScriptEnabled(true);
51-
mWebView.setWebViewClient(new WebViewClient() {
56+
final Intent intent = getIntent();
57+
if(intent.hasExtra(INTENT_EXTRA_LOADING_STRING)) {
58+
loading = intent.getStringExtra(INTENT_EXTRA_LOADING_STRING);
59+
} else {
60+
loading = getString(R.string.web_login_progress_title);
61+
}
62+
63+
webView = (WebView) findViewById(R.id.web_login_web_view);
64+
webView.getSettings().setJavaScriptEnabled(true);
65+
webView.setWebViewClient(new WebViewClient() {
5266

5367
@Override
5468
public boolean shouldOverrideUrlLoading(WebView view, String url) {
@@ -63,7 +77,7 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
6377
progressDialog = ProgressDialog.show(
6478
WebLoginActivity.this,
6579
"",
66-
getResources().getString(R.string.web_login_progress_title),
80+
loading,
6781
true,
6882
true,
6983
new OnCancelListener() {
@@ -92,7 +106,7 @@ public void onReceivedError(WebView view, int errorCode, String description, Str
92106
pageLoadFailed(failingUrl);
93107
}
94108
});
95-
mWebView.loadUrl(getIntent().getExtras().getString(INTENT_EXTRA_URL));
109+
webView.loadUrl(intent.getExtras().getString(INTENT_EXTRA_URL));
96110
}
97111

98112
@Override
@@ -102,9 +116,9 @@ protected void onDestroy() {
102116
progressDialog.dismiss();
103117
}
104118

105-
if (mWebView != null) {
106-
mWebView.stopLoading();
107-
mWebView.destroy();
119+
if (webView != null) {
120+
webView.stopLoading();
121+
webView.destroy();
108122
}
109123

110124
super.onDestroy();

oneallsdk/src/main/res/values/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
<string name="button_title_ok">OK</string>
1212
<string name="button_title_cancel">Cancel</string>
1313
<string name="title_activity_web_login">Login</string>
14-
<string name="web_login_progress_title">Loading</string>
14+
<string name="web_login_progress_title">Loading</string>
1515
<string name="connection_failure">Connection failure</string>
1616

17-
<!-- TODO: Remove or change this placeholder text -->
1817
<string name="hello_blank_fragment">Hello blank fragment</string>
1918
<string name="provider_fragment_provider_icon">Provider icon</string>
2019
<string name="providers_not_ready_try_again">Providers are not ready. Try again in a few seconds.</string>

0 commit comments

Comments
 (0)