Skip to content

Commit 17a2772

Browse files
authored
Merge pull request #7 from getyoti/YM-15454
[TASK][YM-15454] Using pending intent so we get waken up when share is done
2 parents af8e725 + b8f6402 commit 17a2772

File tree

15 files changed

+128
-53
lines changed

15 files changed

+128
-53
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ supportLibraryVersion=25.3.1
3232
libJunitVersion=4.12
3333
libMockitoVersion=1.10.19
3434

35-
currentVersion=1.0.0
36-
currentVersionCode=000007
35+
currentVersion=1.1.0
36+
currentVersionCode=000008
3737
currentAppName=Mobile Button SDK
3838
artefactName=yoti-button-sdk
3939

sample-app-2/src/main/java/com/yoti/mobile/android/sampleapp2/MainActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.yoti.mobile.android.sdk.exceptions.YotiSDKException;
1212
import com.yoti.sampleapp2.R;
1313

14+
import static com.yoti.mobile.android.sampleapp2.ProfileActivity.BACKEND_DATA_ERROR_EXTRA;
1415
import static com.yoti.mobile.android.sampleapp2.ProfileActivity.PROFILE_EXTRA;
1516

1617
public class MainActivity extends AppCompatActivity {
@@ -74,6 +75,11 @@ private void processExtraData(Intent intent) {
7475
yotiSDKButton.setVisibility(View.VISIBLE);
7576
progress.setVisibility(View.GONE);
7677
message.setText("");
78+
79+
} else if (intent.getBooleanExtra(BACKEND_DATA_ERROR_EXTRA, false)) {
80+
yotiSDKButton.setVisibility(View.GONE);
81+
progress.setVisibility(View.GONE);
82+
message.setText(R.string.loc_error_processing_backend_response);
7783
}
7884
}
7985
}

sample-app-2/src/main/java/com/yoti/mobile/android/sampleapp2/ProfileActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class ProfileActivity extends AppCompatActivity {
2020
public static final String MOBILE_EXTRA = "com.yoti.services.MOBILE_EXTRA";
2121
public static final String GENDER_EXTRA = "com.yoti.services.GENDER_EXTRA";
2222
public static final String PROFILE_EXTRA = "com.yoti.services.PROFILE_EXTRA";
23+
public static final String BACKEND_DATA_ERROR_EXTRA = "com.yoti.services.BACKEND_DATA_ERROR_EXTRA";
2324

2425
@Override
2526
protected void onCreate(Bundle savedInstanceState) {

sample-app-2/src/main/java/com/yoti/mobile/android/sampleapp2/services/CallbackIntentService.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import javax.net.ssl.HttpsURLConnection;
1919

2020
import static com.yoti.mobile.android.sampleapp2.ProfileActivity.ADDRESS_EXTRA;
21+
import static com.yoti.mobile.android.sampleapp2.ProfileActivity.BACKEND_DATA_ERROR_EXTRA;
2122
import static com.yoti.mobile.android.sampleapp2.ProfileActivity.DOB_EXTRA;
2223
import static com.yoti.mobile.android.sampleapp2.ProfileActivity.EMAIL_EXTRA;
2324
import static com.yoti.mobile.android.sampleapp2.ProfileActivity.GENDER_EXTRA;
@@ -91,18 +92,25 @@ private void handleActionRetrieveProfile(String callbackUrl, String token, Strin
9192
}
9293

9394
Gson g = new GsonBuilder().create();
94-
Profile profile = g.fromJson(new String(response), Profile.class);
95-
96-
Intent intent = new Intent(this, MainActivity.class);
97-
intent.putExtra(NAME_EXTRA, profile.getGivenNames() + " " + profile.getFamilyName());
98-
intent.putExtra(EMAIL_EXTRA, profile.getEmailAddress());
99-
intent.putExtra(IMAGE_EXTRA, profile.getSelfie());
100-
intent.putExtra(DOB_EXTRA, profile.getDateOfBirth());
101-
intent.putExtra(ADDRESS_EXTRA, profile.getPostalAddress());
102-
intent.putExtra(MOBILE_EXTRA, profile.getMobNum());
103-
intent.putExtra(GENDER_EXTRA, profile.getGender());
104-
intent.putExtra(PROFILE_EXTRA, true);
105-
startActivity(intent);
95+
96+
try {
97+
Profile profile = g.fromJson(new String(response), Profile.class);
98+
99+
Intent intent = new Intent(this, MainActivity.class);
100+
intent.putExtra(NAME_EXTRA, profile.getGivenNames() + " " + profile.getFamilyName());
101+
intent.putExtra(EMAIL_EXTRA, profile.getEmailAddress());
102+
intent.putExtra(IMAGE_EXTRA, profile.getSelfie());
103+
intent.putExtra(DOB_EXTRA, profile.getDateOfBirth());
104+
intent.putExtra(ADDRESS_EXTRA, profile.getPostalAddress());
105+
intent.putExtra(MOBILE_EXTRA, profile.getMobNum());
106+
intent.putExtra(GENDER_EXTRA, profile.getGender());
107+
intent.putExtra(PROFILE_EXTRA, true);
108+
startActivity(intent);
109+
} catch (Exception e) {
110+
Intent intent = new Intent(this, MainActivity.class);
111+
intent.putExtra(BACKEND_DATA_ERROR_EXTRA, true);
112+
startActivity(intent);
113+
}
106114

107115
}
108116

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<string name="app_name">Yoti Android-SDK-Demo</string>
33
<string name="loc_error_unknow">Something went wrong :(</string>
44
<string name="loc_loading_message">Retrieving your data...</string>
5+
<string name="loc_error_processing_backend_response">There was an error processing the response from the backend but all the SDK functionality went well!</string>
56
</resources>

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>

yoti-sdk/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
android:allowBackup="true"
77
android:label="@string/app_name"
88
android:supportsRtl="true">
9+
<activity android:name=".ReceiverActivity" android:theme="@style/Theme.AppCompat.Translucent"/>
910
<service
1011
android:name=".kernelSDK.KernelSDKIntentService"
1112
android:exported="false"/>

0 commit comments

Comments
 (0)