Skip to content

Commit

Permalink
Added onWebViewClosed callback whenever a closing link is clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
sp0x committed Nov 23, 2020
1 parent 96b1fb6 commit ead4b21
Show file tree
Hide file tree
Showing 12 changed files with 473 additions and 314 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,22 @@ QueueITEngine engine = new QueueITEngine(YourActivity.this, customerId, eventOrA
}

// This callback will be triggered when the mobile application can't reach Queue-it's servers.
// It can be any one of these scenarioes:
// It can be any one of these scenarios:
// 1) Queue-it's servers can't be reached (connectivity issue).
// 2) SSL connection error if custom queue domain is used having an invalid certificate.
// 3) Client receives HTTP 4xx response.
// In all these cases is most likely a misconfiguration of the queue settings:
// Invalid customer ID, event alias ID or cname setting on queue (GO Queue-it portal -> event settings).
@Override
public void onError(Error error, String errorMessage) { } // Called on connectivity problems
public void onError(Error error, String errorMessage) {
} // Called on connectivity problems

// This callback will be triggered after a user clicks a close link in the layout and the WebView closes.
// The close link is "queueit://close". Whenever the user navigates to this link, the SDK intercepts the navigation
// and closes the WebView.
@Override
public void onWebViewClosed(){
}
});

try {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ allprojects {

libraryName = 'com.queue_it.androidsdk'
libraryDescription = 'Android SDK to integrate with Queue-it'
libraryVersion = "2.0.26"
libraryVersion = "2.0.27"

artifact = 'library'
siteUrl = "https://github.com/${org}/android-webui-sdk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public void onError(Error error, String errorMessage) {
queue_button.setEnabled(true);
}

@Override
public void onWebViewClosed(){
showResultActivity("WebView closed ", false);
queue_button.setEnabled(true);
}
});
try {
queueITEngine.run(MainActivity.this, !enableCacheRadioButton.isChecked());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,32 @@ public void registerReceivers(BroadcastReceiver onPassed,
BroadcastReceiver onUrlChanged,
BroadcastReceiver onActivityClosed,
BroadcastReceiver onUserExited,
BroadcastReceiver onError) {
BroadcastReceiver onError,
BroadcastReceiver onWebViewClosed) {
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(_context);

localBroadcastManager.registerReceiver(onPassed, new IntentFilter("on-queue-passed"));
localBroadcastManager.registerReceiver(onUrlChanged, new IntentFilter("on-changed-queue-url"));
localBroadcastManager.registerReceiver(onActivityClosed, new IntentFilter("queue-activity-closed"));
localBroadcastManager.registerReceiver(onUserExited, new IntentFilter("queue-user-exited"));
localBroadcastManager.registerReceiver(onError, new IntentFilter("on-queue-error"));
localBroadcastManager.registerReceiver(onWebViewClosed, new IntentFilter("on-webview-close"));
}

public void unregisterReceivers(BroadcastReceiver onPassed,
BroadcastReceiver onUrlChanged,
BroadcastReceiver onActivityClosed,
BroadcastReceiver onUserExited,
BroadcastReceiver onError) {
BroadcastReceiver onError,
BroadcastReceiver onWebViewClosed) {
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(_context);

localBroadcastManager.unregisterReceiver(onPassed);
localBroadcastManager.unregisterReceiver(onUrlChanged);
localBroadcastManager.unregisterReceiver(onActivityClosed);
localBroadcastManager.unregisterReceiver(onUserExited);
localBroadcastManager.unregisterReceiver(onError);
localBroadcastManager.unregisterReceiver(onWebViewClosed);
}

@Override
Expand Down Expand Up @@ -74,4 +78,10 @@ public void broadcastQueueError(String errorMessage) {
intent.putExtra("error-message", errorMessage);
LocalBroadcastManager.getInstance(_context).sendBroadcast(intent);
}

@Override
public void broadcastWebViewClosed() {
Intent intent = new Intent("on-webview-close");
LocalBroadcastManager.getInstance(_context).sendBroadcast(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,32 @@ public void registerReceivers(BroadcastReceiver onPassed,
BroadcastReceiver onUrlChanged,
BroadcastReceiver onActivityClosed,
BroadcastReceiver onUserExited,
BroadcastReceiver onError) {
BroadcastReceiver onError,
BroadcastReceiver onWebViewClosed) {
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(_context);

localBroadcastManager.registerReceiver(onPassed, new IntentFilter("on-queue-passed"));
localBroadcastManager.registerReceiver(onUrlChanged, new IntentFilter("on-changed-queue-url"));
localBroadcastManager.registerReceiver(onActivityClosed, new IntentFilter("queue-activity-closed"));
localBroadcastManager.registerReceiver(onUserExited, new IntentFilter("queue-user-exited"));
localBroadcastManager.registerReceiver(onError, new IntentFilter("on-queue-error"));
localBroadcastManager.registerReceiver(onWebViewClosed, new IntentFilter("on-webview-close"));
}

public void unregisterReceivers(BroadcastReceiver onPassed,
BroadcastReceiver onUrlChanged,
BroadcastReceiver onActivityClosed,
BroadcastReceiver onUserExited,
BroadcastReceiver onError) {
BroadcastReceiver onError,
BroadcastReceiver onWebViewClosed) {
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(_context);

localBroadcastManager.unregisterReceiver(onPassed);
localBroadcastManager.unregisterReceiver(onUrlChanged);
localBroadcastManager.unregisterReceiver(onActivityClosed);
localBroadcastManager.unregisterReceiver(onUserExited);
localBroadcastManager.unregisterReceiver(onError);
localBroadcastManager.unregisterReceiver(onWebViewClosed);
}

@Override
Expand Down Expand Up @@ -75,4 +79,10 @@ public void broadcastQueueError(String errorMessage) {
intent.putExtra("error-message", errorMessage);
LocalBroadcastManager.getInstance(_context).sendBroadcast(intent);
}

@Override
public void broadcastWebViewClosed() {
Intent intent = new Intent("on-webview-close");
LocalBroadcastManager.getInstance(_context).sendBroadcast(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ public interface IWaitingRoomStateBroadcaster {

void broadcastQueueError(String errorMessage);

void broadcastWebViewClosed();

void registerReceivers(BroadcastReceiver queuePassedBroadcastReceiver,
BroadcastReceiver queueUrlChangedBroadcastReceiver,
BroadcastReceiver queueActivityClosedBroadcastReceiver,
BroadcastReceiver queueUserExitedBroadcastReceiver,
BroadcastReceiver queueErrorBroadcastReceiver);
BroadcastReceiver queueErrorBroadcastReceiver,
BroadcastReceiver webViewClosedBroadcastReceiver);

void unregisterReceivers(BroadcastReceiver queuePassedBroadcastReceiver,
BroadcastReceiver queueUrlChangedBroadcastReceiver,
BroadcastReceiver queueActivityClosedBroadcastReceiver,
BroadcastReceiver queueUserExitedBroadcastReceiver,
BroadcastReceiver queueErrorBroadcastReceiver);
BroadcastReceiver queueErrorBroadcastReceiver,
BroadcastReceiver webViewClosedBroadcastReceiver);
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ protected void onPassed(String queueItToken) {
broadcaster.broadcastQueuePassed(queueItToken);
disposeWebview(webview);
}

@Override
protected void onCloseClicked() {
broadcaster.broadcastWebViewClosed();
disposeWebview(webview);
}
});
}
};
Expand Down
17 changes: 15 additions & 2 deletions library/src/main/java/com/queue_it/androidsdk/QueueITEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,22 @@ public void onReceive(Context context, Intent intent) {
}
};

private BroadcastReceiver _webViewClosedBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
raiseWebViewClosed();
}
};

private BroadcastReceiver _queueActivityClosedBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
_stateBroadcaster.unregisterReceivers(_queuePassedBroadcastReceiver,
_queueUrlChangedBroadcastReceiver,
_queueActivityClosedBroadcastReceiver,
_queueUserExitedBroadcastReceiver,
_queueErrorBroadcastReceiver);
_queueErrorBroadcastReceiver,
_webViewClosedBroadcastReceiver);
}
};

Expand Down Expand Up @@ -197,7 +205,8 @@ private void showQueue(String queueUrl, final String targetUrl) {
_queueUrlChangedBroadcastReceiver,
_queueActivityClosedBroadcastReceiver,
_queueUserExitedBroadcastReceiver,
_queueErrorBroadcastReceiver);
_queueErrorBroadcastReceiver,
_webViewClosedBroadcastReceiver);

Intent intent = new Intent(_context, QueueActivity.class);
intent.putExtra("queueUrl", queueUrl);
Expand Down Expand Up @@ -227,6 +236,10 @@ private void raiseQueueDisabled() {
_queueListener.onQueueDisabled();
}

private void raiseWebViewClosed(){
_queueListener.onWebViewClosed();
}

private String getUserId() {
return Settings.Secure.getString(_context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
Expand Down
19 changes: 12 additions & 7 deletions library/src/main/java/com/queue_it/androidsdk/QueueListener.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.queue_it.androidsdk;


public interface QueueListener {
void onQueuePassed(QueuePassedInfo queuePassedInfo);
void onQueueViewWillOpen();
void onQueueDisabled();
void onQueueItUnavailable();
void onError(Error error, String errorMessage);
void onUserExited();
public abstract class QueueListener {
protected abstract void onQueuePassed(QueuePassedInfo queuePassedInfo);
protected abstract void onQueueViewWillOpen();
protected abstract void onQueueDisabled();
protected abstract void onQueueItUnavailable();
protected abstract void onError(Error error, String errorMessage);
protected void onWebViewClosed(){

}
protected void onUserExited(){

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public abstract class UriOverrideWrapper{
protected abstract void onQueueUrlChange(String uri);
protected abstract void onPassed(String queueItToken);
protected abstract void onCloseClicked();
}
15 changes: 13 additions & 2 deletions library/src/main/java/com/queue_it/androidsdk/UriOverrider.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@ private boolean isTargetUri(Uri destinationUri) {
&& destinationPath.equals(targetPath);
}

private boolean handleDeepLink(WebView webview, Uri destinationUri) {
private boolean isCloseLink(Uri uri){
if(!uri.getScheme().equals("queueit")){
return false;
}
return uri.getHost().equals("close");
}

private boolean handleDeepLink(WebView webview, Uri destinationUri, UriOverrideWrapper uriOverride){
if(isCloseLink(destinationUri)){
uriOverride.onCloseClicked();
return true;
}
Intent browserIntent = new Intent(Intent.ACTION_VIEW, destinationUri);
webview.getContext().startActivity(browserIntent);
return true;
Expand All @@ -69,7 +80,7 @@ public boolean handleNavigationRequest(final String destinationUrlStr, WebView w
boolean isWeb = destinationUri.getScheme() != null && (destinationUri.getScheme().equals("http")
|| destinationUri.getScheme().equals("https"));
if (!isWeb) {
return handleDeepLink(webview, destinationUri);
return handleDeepLink(webview, destinationUri, uriOverride);
}
if (isBlockedUri(destinationUri)) {
return true;
Expand Down
Loading

0 comments on commit ead4b21

Please sign in to comment.