Skip to content

Commit

Permalink
Fix checkbox type value formatting (#238)
Browse files Browse the repository at this point in the history
We should be expecting an array of JSON objects, with `label` and `value` in each object.
  • Loading branch information
lzanita09 authored Jun 16, 2023
1 parent 846dbd7 commit 3028698
Show file tree
Hide file tree
Showing 34 changed files with 303 additions and 176 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [push]
jobs:
test:
name: Run unit tests
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Setup JDK 11
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ This SDK uses the following libraries as dependencies:
### Gradle
```groovy
// Required for Connect API integration.
implementation "com.ifttt:connect-api:2.5.3"
implementation "com.ifttt:connect-api:2.5.4"
// Connect Button UI.
implementation "com.ifttt:connect-button:2.5.3"
implementation "com.ifttt:connect-button:2.5.4"
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ apply plugin: 'kotlin-android'

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

defaultConfig {
applicationId "com.ifttt.groceryexpress"
Expand All @@ -24,6 +23,7 @@ android {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
namespace 'com.ifttt.groceryexpress'
}

dependencies {
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ifttt.groceryexpress">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.6.21'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down Expand Up @@ -34,7 +34,7 @@ task clean(type: Delete) {

ext {
libVersion = '2.5.3'
okHttpVersion = '4.9.0'
okHttpVersion = '4.10.0'
retrofitVersion = '2.9.0'
moshiVersion = '1.8.0'
workManagerVersion = '2.7.1'
Expand Down
2 changes: 1 addition & 1 deletion connect-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.minSdkVersion
Expand All @@ -22,6 +21,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'com.ifttt.connect.api'
}

dependencies {
Expand Down
5 changes: 0 additions & 5 deletions connect-api/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ afterEvaluate {
name = 'Zhe Lu'
email = '[email protected]'
}
developer {
id = 'priyaashah'
name = 'Priya Shah'
email = '[email protected]'
}
}
scm {
connection = gitUrl
Expand Down
3 changes: 1 addition & 2 deletions connect-api/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ifttt.connect.api" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.ifttt.connect.api;

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

import java.util.List;
import java.util.Objects;

/**
* Data structure representing the checkbox field values.
*/
public final class CheckBoxFieldValue implements Parcelable {

public final List<CheckBoxValue> value;

public CheckBoxFieldValue(List<CheckBoxValue> value) {
this.value = value;
}

protected CheckBoxFieldValue(Parcel in) {
value = in.createTypedArrayList(CheckBoxValue.CREATOR);
}

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

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

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CheckBoxFieldValue that = (CheckBoxFieldValue) o;
return Objects.equals(value, that.value);
}

@Override
public int hashCode() {
return Objects.hash(value);
}

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

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeTypedList(value);
}
}
57 changes: 57 additions & 0 deletions connect-api/src/main/java/com/ifttt/connect/api/CheckBoxValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.ifttt.connect.api;

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

import java.util.Objects;

public final class CheckBoxValue implements Parcelable {
public final String label;
public final String value;

public CheckBoxValue(String label, String value) {
this.label = label;
this.value = value;
}

protected CheckBoxValue(Parcel in) {
label = in.readString();
value = in.readString();
}

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

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

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CheckBoxValue that = (CheckBoxValue) o;
return Objects.equals(label, that.label) && Objects.equals(value, that.value);
}

@Override
public int hashCode() {
return Objects.hash(label, value);
}

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

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(label);
dest.writeString(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.squareup.moshi.JsonReader;
import com.squareup.moshi.JsonWriter;
import com.squareup.moshi.ToJson;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -13,6 +14,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -51,7 +53,7 @@ Connection fromJson(
JsonAdapter<CoverImage> coverImageDelegate,
JsonAdapter<List<Service>> servicesDelegate,
JsonAdapter<CollectionFieldValue> collectionFieldDelegate,
JsonAdapter<List<String>> stringListDelegate
JsonAdapter<List<CheckBoxValue>> checkBoxValueDelegate
) throws IOException {
String id = null;
String name = null;
Expand Down Expand Up @@ -100,7 +102,7 @@ Connection fromJson(
checkNonNull(featureJsonList);
userFeatureGroup = fromJsonToUserFeature(jsonReader,
locationDelegate,
stringListDelegate,
checkBoxValueDelegate,
collectionFieldDelegate
);
break;
Expand Down Expand Up @@ -136,7 +138,7 @@ void toJson(JsonWriter jsonWriter, Connection connection) {
private Map<String, List<UserFeature>> fromJsonToUserFeature(
JsonReader jsonReader,
JsonAdapter<LocationFieldValue> locationDelegate,
JsonAdapter<List<String>> stringListDelegate,
JsonAdapter<List<CheckBoxValue>> checkBoxValueDelegate,
JsonAdapter<CollectionFieldValue> collectionFieldDelegate
) throws IOException {
ArrayList<UserFeature> userFeatures = new ArrayList<>();
Expand Down Expand Up @@ -175,7 +177,7 @@ private Map<String, List<UserFeature>> fromJsonToUserFeature(
triggerOptions,
locationDelegate,
collectionFieldDelegate,
stringListDelegate,
checkBoxValueDelegate,
steps
);
break;
Expand All @@ -186,7 +188,7 @@ private Map<String, List<UserFeature>> fromJsonToUserFeature(
queryOptions,
locationDelegate,
collectionFieldDelegate,
stringListDelegate,
checkBoxValueDelegate,
steps
);
break;
Expand All @@ -197,7 +199,7 @@ private Map<String, List<UserFeature>> fromJsonToUserFeature(
actionOptions,
locationDelegate,
collectionFieldDelegate,
stringListDelegate,
checkBoxValueDelegate,
steps
);
break;
Expand Down Expand Up @@ -233,7 +235,7 @@ private void parseUserSteps(
JsonReader.Options options,
JsonAdapter<LocationFieldValue> locationDelegate,
JsonAdapter<CollectionFieldValue> collectionFieldDelegate,
JsonAdapter<List<String>> stringArrayDelegate,
JsonAdapter<List<CheckBoxValue>> checkboxFieldDelegate,
List<UserFeatureStep> steps
) throws IOException {
jsonReader.beginArray();
Expand Down Expand Up @@ -286,12 +288,12 @@ private void parseUserSteps(
fieldId
));
} else if (FIELD_TYPE_CHECKBOX.equals(fieldType)) {
List<String> arrayValue = stringArrayDelegate.fromJson(jsonReader);
checkNonNull(arrayValue);
List<CheckBoxValue> checkBoxFieldValue =
checkboxFieldDelegate.fromJson(jsonReader);
checkNonNull(checkBoxFieldValue);

StringArrayFieldValue stringArrayFieldValue = new StringArrayFieldValue(
arrayValue);
fields.add(new UserFeatureField<>(stringArrayFieldValue,
fields.add(new UserFeatureField<>(
new CheckBoxFieldValue(checkBoxFieldValue),
fieldType,
fieldId
));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Data structure representing one configuration field for a {@link UserFeature}. Currently, the supported value types
* are
* - {@link CollectionFieldValue}
* - {@link StringArrayFieldValue}
* - {@link CheckBoxFieldValue}
* - {@link LocationFieldValue}
* - {@link StringFieldValue}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.ifttt.connect.api;

import static com.google.common.truth.Truth.assertThat;

import android.content.Context;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Test;
import org.junit.runner.RunWith;

import static com.google.common.truth.Truth.assertThat;

@RunWith(AndroidJUnit4.class)
public final class ConnectionApiClientTest {

@Test
public void newBuilderShouldOverrideUserTokenProvider() {
UserTokenProvider oldProvider = () -> null;
Context context = InstrumentationRegistry.getInstrumentation().getContext();
Context context = ApplicationProvider.getApplicationContext();
ConnectionApiClient client = new ConnectionApiClient.Builder(context, oldProvider).build();

UserTokenProvider newProvider = () -> "token";
Expand Down
Loading

0 comments on commit 3028698

Please sign in to comment.