Skip to content

Commit

Permalink
Merge pull request #41 from LiveTex/new_rating_system
Browse files Browse the repository at this point in the history
New rating system
  • Loading branch information
maxxx authored Sep 24, 2024
2 parents ed84e49 + 92fd9e7 commit 8fa967f
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 21 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.0'
classpath 'com.google.gms:google-services:4.4.0'
classpath 'com.android.tools.build:gradle:8.2.2'
classpath 'com.google.gms:google-services:4.4.2'
}
}

Expand Down
7 changes: 3 additions & 4 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ group='com.github.LiveTex' // for Jitpack
android {
namespace 'ru.livetex.sdk'

compileSdkVersion 33

defaultConfig {
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 34
compileSdkVersion 34
versionCode 1
versionName "1.0"
consumerProguardFiles = ['proguard-rules.pro']
Expand Down Expand Up @@ -61,7 +60,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// androidx
implementation "androidx.annotation:annotation:1.3.0"
implementation "androidx.annotation:annotation:1.8.2"
// network
implementation 'com.squareup.okhttp3:okhttp:3.14.7'
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.7'
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/ru/livetex/sdk/entity/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class BaseEntity {
public String type;

@Nullable
@SerializedName("error")
@SerializedName("errors")
public List<LiveTexError> error;

public BaseEntity() {
Expand Down
15 changes: 15 additions & 0 deletions sdk/src/main/java/ru/livetex/sdk/entity/DialogRating.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ru.livetex.sdk.entity;

import androidx.annotation.Nullable;

public class DialogRating {

// null when it's not allowed to rate
@Nullable
public DialogRatingType enabledType;

// null if dialog isn't rated yet
@Nullable
public DialogRatingData isSet;

}
18 changes: 18 additions & 0 deletions sdk/src/main/java/ru/livetex/sdk/entity/DialogRatingData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.livetex.sdk.entity;

import androidx.annotation.NonNull;

public class DialogRatingData {
@NonNull
public DialogRatingType type;

@NonNull
// fivePoint: "1" | "2" | "3" | "4" | "5".
// doublePoint: "0" | "1"
public String value;

public DialogRatingData(@NonNull DialogRatingType type, @NonNull String value) {
this.type = type;
this.value = value;
}
}
12 changes: 12 additions & 0 deletions sdk/src/main/java/ru/livetex/sdk/entity/DialogRatingType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.livetex.sdk.entity;

import com.google.gson.annotations.SerializedName;

public enum DialogRatingType {
// old "good-bad" rating system
@SerializedName("doublePoint")
DOUBLE_POINT,
// new "five stars" rating system
@SerializedName("fivePoint")
FIVE_POINT,
}
2 changes: 2 additions & 0 deletions sdk/src/main/java/ru/livetex/sdk/entity/DialogState.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public final class DialogState extends BaseEntity {
public Employee employee = null;
@NonNull
public Boolean showInput = true;
@Nullable
public DialogRating rate = null;

public enum DialogStatus {
@SerializedName("unassigned")
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/main/java/ru/livetex/sdk/entity/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public final class Employee implements Creator {
public String position;
@Nullable
public String avatarUrl;
// null means no feedback done.
// Old (2 scores) rating system. null means no feedback done.
@Deprecated
@Nullable
public String rating;
}
26 changes: 18 additions & 8 deletions sdk/src/main/java/ru/livetex/sdk/entity/LiveTexError.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@
public enum LiveTexError {
@SerializedName("systemUnavailable")
SYSTEM_UNAVAILABLE, // server-side error
@SerializedName("departmentNoId")
NO_DEPARTMENT_ID,
@SerializedName("departmentInvalidId")
INVALID_DEPARTMENT,
@SerializedName("attributesWrongFormat")
ATTRIBUTES_WRONG_FORMAT, // wrong format of attributes HashMap in AttributesEntity
@SerializedName("textContentIsEmpty")
EMPTY_MESSAGE,
@SerializedName("fileNoName")
FILE_NO_NAME,
@SerializedName("fileNoUrl")
FILE_NO_URL,
@SerializedName("textContentIsEmpty")
EMPTY_MESSAGE,
@SerializedName("attributesWrongFormat")
ATTRIBUTES_WRONG_FORMAT, // wrong format of attributes HashMap in AttributesEntity
@SerializedName("departmentNoId")
NO_DEPARTMENT_ID,
@SerializedName("departmentInvalidId")
INVALID_DEPARTMENT,
@SerializedName("historyFromMessageIdNotDefined")
INVALID_HISTORY_PARAMS,
@SerializedName("buttonPayloadIsEmpty")
BUTTON_PAYLOAD_IS_EMPTY,
@SerializedName("ratingRateIsEmpty")
RATING_RATE_IS_EMPTY,
@SerializedName("ratingIncorrectRateType")
RATING_INCORRECT_RATE_TYPE,
@SerializedName("ratingUnavailable")
RATING_UNAVAILABLE,
}
25 changes: 22 additions & 3 deletions sdk/src/main/java/ru/livetex/sdk/entity/RatingEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,29 @@
public final class RatingEvent extends BaseEntity {
public static final String TYPE = "rating";

public String value; // "0" or "1"
public DialogRatingData rate;

public RatingEvent(String value) {
this.value = value;
public RatingEvent(DialogRatingData rate) {
this.rate = rate;
}

public RatingEvent(DialogRatingType type, String rating) {
this.rate = new DialogRatingData(type, rating);
}

/**
* old system
*/
public static RatingEvent createEvent2point(boolean isPositiveFeedback) {
return new RatingEvent(new DialogRatingData(DialogRatingType.DOUBLE_POINT, isPositiveFeedback ? "1" : "0"));
}

/**
* new system
* @param rating from 1 to 5
*/
public static RatingEvent createEvent5points(short rating) {
return new RatingEvent(new DialogRatingData(DialogRatingType.FIVE_POINT, Short.toString(rating)));
}

@Override
Expand Down
15 changes: 13 additions & 2 deletions sdk/src/main/java/ru/livetex/sdk/logic/LiveTexMessagesHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,21 @@ public void sendAttributes(@Nullable String name,
}

/**
* Send feedback about dialog quality.
* Send feedback about dialog quality. Uses old 2points rating system
*/
public void sendRatingEvent(boolean isPositiveFeedback) {
RatingEvent event = new RatingEvent(isPositiveFeedback ? "1" : "0");
RatingEvent event = RatingEvent.createEvent2point(isPositiveFeedback);
String json = EntityMapper.gson.toJson(event);
sendJson(json);
}

/**
* Send feedback about dialog quality. Uses new 5points rating system
*
* @param rating - from 1 to 5
*/
public void sendRatingEvent(short rating) {
RatingEvent event = RatingEvent.createEvent5points(rating);
String json = EntityMapper.gson.toJson(event);
sendJson(json);
}
Expand Down

0 comments on commit 8fa967f

Please sign in to comment.