Skip to content

Commit

Permalink
Added QueueItEngineOptions to help with config
Browse files Browse the repository at this point in the history
  • Loading branch information
sp0x committed Jun 18, 2021
1 parent f47563f commit 38e45c9
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 14 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ This whitepaper contains the needed information to perform a successful integrat
Using Gradle:

```gradle
implementation 'com.queue-it.androidsdk:library:2.0.33'
implementation 'com.queue-it.androidsdk:library:2.0.34'
//For AndroidX
//implementation 'com.queue-it.androidsdk:library-androidx:2.0.33'
//implementation 'com.queue-it.androidsdk:library-androidx:2.0.34'
```

## Usage

Invoke QueueITEngine as per example below. Parameters `layoutName` and `language` are optional.
Invoke QueueITEngine as per example below. Parameters `layoutName`, `language` and `options` are optional.

```java
QueueITEngine engine = new QueueITEngine(YourActivity.this, customerId, eventIdOrAlias, layoutName, language,
Expand Down Expand Up @@ -89,6 +89,15 @@ When the user clicks back, the same check needs to be done.

If your application is using an API that's protected by a Queue-it connector (KnownUser) you can check out [this documentation](https://github.com/queueit/android-webui-sdk/blob/master/documentation/protected_apis.md).

### QueueITEngine options

The QueueITEngine can be configured if you use the `options` argument in it's constructor. Here's an example.

```java
QueueItEngineOptions options = new QueueItEngineOptions();
// Use this if you want to disable the back button when the waiting room is shown
options.setBackButtonDisabledFromWR(true);
```

## Required permissions

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ allprojects {
groupId = 'com.queue-it.androidsdk'
libraryName = 'com.queue_it.androidsdk'
libraryDescription = 'Android SDK to integrate with Queue-it'
libraryVersion = "2.0.33"
libraryVersion = "2.0.34"
organization = "Queue-it"
organizationUrl = "https://queue-it.com"

Expand Down
7 changes: 5 additions & 2 deletions demoapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
//implementation project(path: ':library')
library_androidxImplementation 'com.queue-it.androidsdk:library-androidx:2.0.33'
libraryImplementation 'com.queue-it.androidsdk:library:2.0.33'
//library_androidxImplementation 'com.queue-it.androidsdk:library-androidx:2.0.34'
library_androidxImplementation project(path: ':library')
//libraryImplementation 'com.queue-it.androidsdk:library:2.0.34'
libraryImplementation project(path: ':library')

testImplementation 'junit:junit:4.13'

library_androidxImplementation 'androidx.appcompat:appcompat:1.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void onClick(View v) {
editor.commit();

Toast.makeText(getApplicationContext(), "Please wait for your turn.", Toast.LENGTH_SHORT).show();
QueueItEngineOptions options = new QueueItEngineOptions();

QueueITEngine queueITEngine = new QueueITEngine(MainActivity.this, customerId, eventOrAliasId, layoutName, language, new QueueListener() {
@Override
Expand Down Expand Up @@ -114,7 +115,7 @@ public void onWebViewClosed(){
showResultActivity("WebView closed ", false);
queue_button.setEnabled(true);
}
});
}, options);
try {
queueITEngine.run(MainActivity.this, !enableCacheRadioButton.isChecked());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ protected void onCreate(Bundle savedInstanceState) {
base.initialize(savedInstanceState);
}

@Override
public void onBackPressed() {
if (base.getOptions().isBackButtonDisabledFromWR()) {
return;
}
super.onBackPressed();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ protected void onCreate(Bundle savedInstanceState) {
base.initialize(savedInstanceState);
}

@Override
public void onBackPressed() {
if (base.getOptions().isBackButtonDisabledFromWR()) {
return;
}
super.onBackPressed();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
Expand All @@ -29,12 +28,18 @@ public class QueueActivityBase {
private static WebView previousWebView;
private IUriOverrider uriOverrider;
private final IWaitingRoomStateBroadcaster broadcaster;
private QueueItEngineOptions options;

public QueueActivityBase(Activity context) {
_context = context;
options = QueueItEngineOptions.getDefault();
broadcaster = new WaitingRoomStateBroadcaster(_context);
}

public QueueItEngineOptions getOptions(){
return options;
}

WebViewClient webviewClient = new WebViewClient() {

@Override
Expand Down Expand Up @@ -107,7 +112,7 @@ private static void cleanupWebView() {
public void initialize(Bundle savedInstanceState) {
uriOverrider = new UriOverrider();
_context.setContentView(R.layout.activity_queue);
readActivityUrls(savedInstanceState);
readActivityExtras(savedInstanceState);
cleanupWebView();
final ProgressBar progressBar = _context.findViewById(R.id.progressBar);

Expand Down Expand Up @@ -147,7 +152,7 @@ public void destroy() {
}
}

private void readActivityUrls(Bundle savedInstanceState) {
private void readActivityExtras(Bundle savedInstanceState) {
if (savedInstanceState == null) {
Bundle extras = _context.getIntent().getExtras();
if (extras == null) {
Expand All @@ -157,6 +162,7 @@ private void readActivityUrls(Bundle savedInstanceState) {
queueUrl = extras.getString("queueUrl");
targetUrl = extras.getString("targetUrl");
uriOverrider.setUserId(extras.getString("userId"));
options = (QueueItEngineOptions)extras.getParcelable("options");
}
} else {
queueUrl = (String) savedInstanceState.getSerializable("queueUrl");
Expand Down
28 changes: 24 additions & 4 deletions library/src/main/java/com/queue_it/androidsdk/QueueITEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class QueueITEngine {
private final String _language;
private final QueueListener _queueListener;
private final QueueCache _queueCache;
private final QueueItEngineOptions _options;
private Context _context;
private final AtomicBoolean _requestInProgress;
private boolean _isInQueue;
Expand All @@ -37,11 +38,28 @@ public class QueueITEngine {
private int _isOnlineRetry = 0;

public QueueITEngine(Activity applicationContext, String customerId, String eventOrAliasId, QueueListener queueListener) {
this(applicationContext, customerId, eventOrAliasId, "", "", queueListener);
this(applicationContext, customerId, eventOrAliasId, "", "", queueListener, QueueItEngineOptions.getDefault());
}

public QueueITEngine(Activity activityContext, String customerId, String eventOrAliasId, String layoutName,
String language, QueueListener queueListener) {
public QueueITEngine(Activity activityContext,
String customerId,
String eventOrAliasId,
String layoutName,
String language,
QueueListener queueListener) {
this(activityContext, customerId, eventOrAliasId, layoutName, language, queueListener, QueueItEngineOptions.getDefault());
}

public QueueITEngine(Activity activityContext,
String customerId,
String eventOrAliasId,
String layoutName,
String language,
QueueListener queueListener,
QueueItEngineOptions options) {
if (options == null) {
options = QueueItEngineOptions.getDefault();
}
_requestInProgress = new AtomicBoolean(false);
UserAgentManager.initialize(activityContext);
if (TextUtils.isEmpty(customerId)) {
Expand All @@ -59,6 +77,7 @@ public QueueITEngine(Activity activityContext, String customerId, String eventOr
_queueCache = new QueueCache(_context, customerId, eventOrAliasId);
_deltaSec = INITIAL_WAIT_RETRY_SEC;
_stateBroadcaster = new WaitingRoomStateBroadcaster(_context);
_options = options;
}

public void setViewDelay(int delayInterval) {
Expand Down Expand Up @@ -212,6 +231,7 @@ private void showQueue(String queueUrl, final String targetUrl) {
intent.putExtra("queueUrl", queueUrl);
intent.putExtra("targetUrl", targetUrl);
intent.putExtra("userId", getUserId());
intent.putExtra("options", _options);
_context.startActivity(intent);
}

Expand Down Expand Up @@ -320,4 +340,4 @@ private void updateQueuePageUrl(String queueUrl) {
public String getSdkVersion() {
return "Android-" + BuildConfig.VERSION_NAME;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.queue_it.androidsdk;

import android.os.Parcel;
import android.os.Parcelable;

public class QueueItEngineOptions implements Parcelable {
private boolean disableBackButtonFromWR;

public QueueItEngineOptions() {
}

public QueueItEngineOptions(boolean disableBackButtonFromWR) {
this.disableBackButtonFromWR = disableBackButtonFromWR;
}

protected QueueItEngineOptions(Parcel in) {
disableBackButtonFromWR = in.readInt() != 0;
}

public static final Creator<QueueItEngineOptions> CREATOR = new Creator<QueueItEngineOptions>() {
@Override
public QueueItEngineOptions createFromParcel(Parcel in) {
return new QueueItEngineOptions(in);
}

@Override
public QueueItEngineOptions[] newArray(int size) {
return new QueueItEngineOptions[size];
}
};

public boolean isBackButtonDisabledFromWR() {
return disableBackButtonFromWR;
}

public void setBackButtonDisabledFromWR(boolean disableBackButtonFromWR) {
this.disableBackButtonFromWR = disableBackButtonFromWR;
}

public static QueueItEngineOptions getDefault() {
return new QueueItEngineOptions(true);
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.disableBackButtonFromWR ? 1 : 0);
}
}

0 comments on commit 38e45c9

Please sign in to comment.