Skip to content

Commit bbee195

Browse files
committed
Improving behaviour of sample app 1
Specially with error cases. YM-15454
1 parent 933cd1f commit bbee195

File tree

4 files changed

+57
-30
lines changed

4 files changed

+57
-30
lines changed

sample-app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
android:roundIcon="@mipmap/ic_launcher_round"
1313
android:supportsRtl="true"
1414
android:theme="@style/AppTheme">
15-
<activity android:name=".MainActivity">
15+
<activity android:name=".MainActivity"
16+
android:launchMode="singleInstance">
1617
<intent-filter>
1718
<action android:name="android.intent.action.MAIN" />
1819

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.yoti.mobile.android.sdk.sampleapp;
22

3+
import android.content.Intent;
34
import android.support.v7.app.AppCompatActivity;
45
import android.os.Bundle;
56
import android.view.View;
@@ -14,67 +15,85 @@ public class MainActivity extends AppCompatActivity {
1415

1516
private static final String TAG = MainActivity.class.getSimpleName();
1617

18+
private YotiSDKButton mYotiSDKButton;
19+
private ProgressBar mProgress;
20+
private TextView mMessage;
21+
1722
@Override
1823
protected void onCreate(Bundle savedInstanceState) {
1924
super.onCreate(savedInstanceState);
2025

2126
setContentView(R.layout.activity_main);
2227

23-
final YotiSDKButton yotiSDKButton = (YotiSDKButton) findViewById(R.id.button);
24-
final ProgressBar progress = (ProgressBar) findViewById(R.id.progress);
25-
final TextView message = (TextView)findViewById(R.id.text);
28+
mYotiSDKButton = (YotiSDKButton) findViewById(R.id.button);
29+
mProgress = (ProgressBar) findViewById(R.id.progress);
30+
mMessage = (TextView)findViewById(R.id.text);
2631

27-
yotiSDKButton.setOnYotiButtonClickListener(new YotiSDKButton.OnYotiButtonClickListener() {
32+
mYotiSDKButton.setOnYotiButtonClickListener(new YotiSDKButton.OnYotiButtonClickListener() {
2833
@Override
2934
public void onStartScenario() {
30-
yotiSDKButton.setVisibility(View.GONE);
31-
progress.setVisibility(View.VISIBLE);
32-
message.setText(null);
35+
mYotiSDKButton.setVisibility(View.GONE);
36+
mProgress.setVisibility(View.VISIBLE);
37+
mMessage.setText(null);
3338
}
3439

3540
@Override
3641
public void onStartScenarioError(YotiSDKException cause) {
37-
yotiSDKButton.setVisibility(View.VISIBLE);
38-
progress.setVisibility(View.GONE);
39-
message.setText(R.string.loc_error_unknow);
42+
mYotiSDKButton.setVisibility(View.VISIBLE);
43+
mProgress.setVisibility(View.GONE);
44+
mMessage.setText(R.string.loc_error_unknow);
4045
}
4146
});
4247

43-
yotiSDKButton.setOnYotiAppNotInstalledListener(new YotiSDKButton.OnYotiAppNotInstalledListener() {
48+
mYotiSDKButton.setOnYotiAppNotInstalledListener(new YotiSDKButton.OnYotiAppNotInstalledListener() {
4449
@Override
4550
public void onYotiAppNotInstalledError(YotiSDKNoYotiAppException cause) {
4651
//The Yoti app is not installed, let's deal with it
47-
yotiSDKButton.setVisibility(View.VISIBLE);
48-
progress.setVisibility(View.GONE);
49-
message.setText(R.string.loc_no_yoti_app_error);
52+
mYotiSDKButton.setVisibility(View.VISIBLE);
53+
mProgress.setVisibility(View.GONE);
54+
mMessage.setText(R.string.loc_no_yoti_app_error);
5055
}
5156
});
5257

53-
yotiSDKButton.setOnYotiCalledListener(new YotiSDKButton.OnYotiCalledListener() {
58+
mYotiSDKButton.setOnYotiCalledListener(new YotiSDKButton.OnYotiCalledListener() {
5459
@Override
5560
public void onYotiCalled() {
5661
// Restore the original state
57-
yotiSDKButton.setVisibility(View.VISIBLE);
58-
progress.setVisibility(View.GONE);
62+
mYotiSDKButton.setVisibility(View.VISIBLE);
63+
mProgress.setVisibility(View.GONE);
5964
}
6065
});
66+
}
67+
68+
@Override
69+
protected void onNewIntent(Intent intent) {
70+
super.onNewIntent(intent);
71+
setIntent(intent);
72+
processExtraData(intent);
73+
}
6174

62-
if (getIntent().hasExtra(ShareAttributesResultBroadcastReceiver.EXTRA_CANCELLED_BY_USER)) {
63-
yotiSDKButton.setVisibility(View.VISIBLE);
64-
progress.setVisibility(View.GONE);
65-
message.setText(R.string.loc_error_not_completed_on_yoti);
75+
private void processExtraData(Intent intent) {
76+
if (intent.hasExtra(ShareAttributesResultBroadcastReceiver.EXTRA_CANCELLED_BY_USER)) {
77+
mYotiSDKButton.setVisibility(View.VISIBLE);
78+
mProgress.setVisibility(View.GONE);
79+
mMessage.setText(R.string.loc_error_not_completed_on_yoti);
6680
}
6781

68-
if (getIntent().hasExtra(ShareAttributesResultBroadcastReceiver.EXTRA_IS_FAILED)) {
69-
yotiSDKButton.setVisibility(View.VISIBLE);
70-
progress.setVisibility(View.GONE);
71-
message.setText(R.string.loc_error_unknow);
82+
if (intent.hasExtra(ShareAttributesResultBroadcastReceiver.EXTRA_IS_FAILED)) {
83+
mYotiSDKButton.setVisibility(View.VISIBLE);
84+
mProgress.setVisibility(View.GONE);
85+
mMessage.setText(R.string.loc_error_unknow);
7286
}
7387

74-
if (getIntent().hasExtra(ShareAttributesResultBroadcastReceiver.EXTRA_RESPONSE)) {
75-
String phone = getIntent().getStringExtra(ShareAttributesResultBroadcastReceiver.EXTRA_RESPONSE);
76-
message.setText(String.format(getString(R.string.loc_phone_number), phone));
88+
if (intent.hasExtra(ShareAttributesResultBroadcastReceiver.EXTRA_RESPONSE)) {
89+
String response = getIntent().getStringExtra(ShareAttributesResultBroadcastReceiver.EXTRA_RESPONSE);
90+
if (response != null) {
91+
mMessage.setText(R.string.loc_success_status);
92+
}
7793
}
78-
}
7994

95+
if (intent.hasExtra(ShareAttributesResultBroadcastReceiver.EXTRA_LOADING)) {
96+
mMessage.setText(R.string.loc_loading_status);
97+
}
98+
}
8099
}

sample-app/src/main/java/com/yoti/mobile/android/sdk/sampleapp/ShareAttributesResultBroadcastReceiver.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ public class ShareAttributesResultBroadcastReceiver extends AbstractShareAttribu
1717
public static final String EXTRA_CANCELLED_BY_USER = "com.yoti.mobile.android.sdk.EXTRA_CANCELLED_BY_USER";
1818
public static final String EXTRA_IS_FAILED = "com.yoti.mobile.android.sdk.EXTRA_IS_FAILED";
1919
public static final String EXTRA_RESPONSE = "com.yoti.mobile.android.sdk.EXTRA_RESPONSE";
20+
public static final String EXTRA_LOADING = "com.yoti.mobile.android.sdk.EXTRA_LOADING";
2021

2122
@Override
2223
public boolean onCallbackReceived(String useCaseId, String callbackRoot, String token, String fullUrl) {
24+
Intent intent = new Intent(mContext, MainActivity.class);
25+
intent.putExtra(EXTRA_LOADING, true);
26+
intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
27+
mContext.startActivity(intent);
2328
return false;
2429
}
2530

sample-app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
<string name="loc_no_yoti_app_error">The Yoti app is not install in this device</string>
88
<string name="loc_error_not_completed_on_yoti">Process not completed on the Yoti App</string>
99
<string name="loc_phone_number">Your phone number is : %s</string>
10+
<string name="loc_success_status">Success!!</string>
11+
<string name="loc_loading_status">Loading...</string>
1012
</resources>

0 commit comments

Comments
 (0)