Skip to content

Commit d14daa4

Browse files
authored
Merge pull request #153 from salemove/prelive
Release 1.6.16
2 parents 077e17b + 3f60fc3 commit d14daa4

File tree

18 files changed

+280
-91
lines changed

18 files changed

+280
-91
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**Jira issue:**
2+
https://glia.atlassian.net/browse/MUIC-xxx
3+
4+
**Additional info:**
5+
6+
**Screenshots:**

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ out/
104104
output.json
105105
proguard/
106106
vcs.xml
107+
/.idea/deploymentTargetDropDown.xml

app/src/main/java/com/glia/exampleapp/Utils.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static UiTheme getUiThemeByPrefs(SharedPreferences sharedPreferences, Res
4444
Integer botActionButtonSelectedBackgroundColor = getColorValueFromPrefs(R.string.pref_bot_action_button_selected_bg_color, sharedPreferences, resources);
4545
Integer botActionButtonSelectedTextColor = getColorValueFromPrefs(R.string.pref_bot_action_button_selected_txt_color, sharedPreferences, resources);
4646

47-
Integer whiteLabel = getWhiteLabelValueFromPrefs(sharedPreferences, resources);
47+
Boolean whiteLabel = sharedPreferences.getBoolean(resources.getString(R.string.pref_white_label), false);
4848

4949
Boolean gliaAlertDialogButtonUseVerticalAlignment = sharedPreferences.getBoolean(
5050
resources.getString(R.string.pref_use_alert_dialog_button_vertical_alignment),
@@ -66,11 +66,15 @@ public static UiTheme getUiThemeByPrefs(SharedPreferences sharedPreferences, Res
6666
builder.setVisitorMessageTextColor(visitorMessageTextColor);
6767
builder.setOperatorMessageBackgroundColor(operatorMessageBackgroundColor);
6868
builder.setOperatorMessageTextColor(operatorMessageTextColor);
69+
70+
builder.setWhiteLabel(whiteLabel);
71+
72+
// choice card attributes
73+
builder.setChoiceCardContentTextConfiguration(null);
6974
builder.setBotActionButtonBackgroundColor(botActionButtonBackgroundColor);
7075
builder.setBotActionButtonTextColor(botActionButtonTextColor);
7176
builder.setBotActionButtonSelectedBackgroundColor(botActionButtonSelectedBackgroundColor);
7277
builder.setBotActionButtonSelectedTextColor(botActionButtonSelectedTextColor);
73-
builder.setWhiteLabel(whiteLabel);
7478

7579
// to set alert buttons to align vertically in runtime
7680
builder.setGliaAlertDialogButtonUseVerticalAlignment(gliaAlertDialogButtonUseVerticalAlignment);
@@ -126,6 +130,14 @@ private static ButtonConfiguration getNegativeButtonTestingConfiguration(Context
126130
.build();
127131
}
128132

133+
private static TextConfiguration getChoiceCardContentTextConfiguration(Context context) {
134+
return TextConfiguration.builder()
135+
.textSize(16f) // in sp
136+
.fontFamily(R.font.tangerine)
137+
.textColor(ContextCompat.getColorStateList(context, R.color.color_dark_cyan))
138+
.build();
139+
}
140+
129141
public static Integer getColorValueFromPrefs(@StringRes int keyValue, SharedPreferences sharedPreferences, Resources resources) {
130142
String colorGrey = resources.getString(R.string.color_grey_value);
131143
String colorRed = resources.getString(R.string.color_red_value);
@@ -194,9 +206,4 @@ public static Integer getTypefaceFromPrefs(SharedPreferences sharedPreferences,
194206
public static boolean getUseOverlay(SharedPreferences sharedPreferences, Resources resources) {
195207
return sharedPreferences.getBoolean(resources.getString(R.string.pref_use_overlay), true);
196208
}
197-
198-
public static Integer getWhiteLabelValueFromPrefs(SharedPreferences sharedPreferences, Resources resources) {
199-
boolean whiteLabel = sharedPreferences.getBoolean(resources.getString(R.string.pref_white_label), false);
200-
return whiteLabel ? 1 : 0;
201-
}
202209
}

app/src/main/res/values/themes.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@
3131
<item name="buttonBarPositiveButtonStyle">
3232
@style/Application.GliaAndroidSdkWidgetsExample.Button.Positive
3333
</item>
34+
<item name="choiceCardContentTextStyle">
35+
@style/Application.GliaAndroidSdkWidgetsExample.ChoiceCard.ContentText
36+
</item>
3437

3538
<item name="gliaAlertDialogButtonUseVerticalAlignment">true</item>
39+
<item name="whiteLabel">false</item>
3640
</style>
3741

3842
<style name="Application.GliaAndroidSdkWidgetsExample.Button" parent="@style/Widget.MaterialComponents.Button.TextButton.Icon">
@@ -69,4 +73,10 @@
6973
<item name="android:textAllCaps">false</item>
7074
</style>
7175

76+
<style name="Application.GliaAndroidSdkWidgetsExample.ChoiceCard.ContentText" parent="TextAppearance.MaterialComponents.Body1">
77+
<item name="android:textSize">40sp</item>
78+
<item name="android:textColor">@color/color_dark_cyan</item>
79+
<!-- item name="fontFamily">@font/tangerine</item -->
80+
</style>
81+
7282
</resources>

widgetssdk/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 24
99
targetSdkVersion 30
10-
versionCode 20
11-
versionName "1.6.15"
10+
versionCode 21
11+
versionName "1.6.16"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
consumerProguardFiles "consumer-rules.pro"
1414
}

widgetssdk/src/main/java/com/glia/widgets/UiTheme.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import androidx.annotation.FontRes;
99

1010
import com.glia.widgets.view.configuration.ButtonConfiguration;
11+
import com.glia.widgets.view.configuration.TextConfiguration;
1112

1213

1314
public class UiTheme implements Parcelable {
@@ -221,9 +222,11 @@ public class UiTheme implements Parcelable {
221222
private @ColorRes
222223
final Integer chatStartedCaptionTextColor;
223224

224-
private final Integer whiteLabel;
225+
private final Boolean whiteLabel;
225226
private final Boolean gliaAlertDialogButtonUseVerticalAlignment;
226227

228+
private final TextConfiguration choiceCardContentTextConfiguration;
229+
227230
private final ButtonConfiguration headerEndButtonConfiguration;
228231
private final ButtonConfiguration positiveButtonConfiguration;
229232
private final ButtonConfiguration negativeButtonConfiguration;
@@ -277,6 +280,7 @@ private UiTheme(UiThemeBuilder builder) {
277280
this.chatStartingHeadingTextColor = builder.chatStartingHeadingTextColor;
278281
this.chatStartedCaptionTextColor = builder.chatStartedCaptionTextColor;
279282
this.chatStartedHeadingTextColor = builder.chatStartedHeadingTextColor;
283+
this.choiceCardContentTextConfiguration = builder.choiceCardContentTextConfiguration;
280284
}
281285

282286
public static class UiThemeBuilder {
@@ -491,7 +495,7 @@ public static class UiThemeBuilder {
491495
Integer chatStartedCaptionTextColor;
492496

493497
private
494-
Integer whiteLabel;
498+
Boolean whiteLabel;
495499

496500
private
497501
Boolean gliaAlertDialogButtonUseVerticalAlignment;
@@ -508,6 +512,9 @@ public static class UiThemeBuilder {
508512
private
509513
ButtonConfiguration neutralButtonConfiguration;
510514

515+
private
516+
TextConfiguration choiceCardContentTextConfiguration;
517+
511518
public void setAppBarTitle(String appBarTitle) {
512519
this.appBarTitle = appBarTitle;
513520
}
@@ -648,7 +655,7 @@ public void setIconPlaceholder(@DrawableRes Integer iconPlaceholder) {
648655
this.iconPlaceholder = iconPlaceholder;
649656
}
650657

651-
public void setWhiteLabel(Integer whiteLabel) {
658+
public void setWhiteLabel(Boolean whiteLabel) {
652659
this.whiteLabel = whiteLabel;
653660
}
654661

@@ -700,6 +707,10 @@ public void setChatStartedCaptionTextColor(Integer color) {
700707
this.chatStartedCaptionTextColor = color;
701708
}
702709

710+
public void setChoiceCardContentTextConfiguration(TextConfiguration textConfiguration) {
711+
this.choiceCardContentTextConfiguration = textConfiguration;
712+
}
713+
703714
public void setTheme(UiTheme theme) {
704715
this.appBarTitle = theme.appBarTitle;
705716
this.brandPrimaryColor = theme.brandPrimaryColor;
@@ -735,6 +746,7 @@ public void setTheme(UiTheme theme) {
735746
this.iconCallSpeakerOff = theme.iconCallSpeakerOff;
736747
this.iconCallMinimize = theme.iconCallMinimize;
737748
this.iconPlaceholder = theme.iconPlaceholder;
749+
this.whiteLabel = theme.whiteLabel;
738750
this.headerEndButtonConfiguration = theme.headerEndButtonConfiguration;
739751
this.positiveButtonConfiguration = theme.positiveButtonConfiguration;
740752
this.negativeButtonConfiguration = theme.negativeButtonConfiguration;
@@ -746,6 +758,7 @@ public void setTheme(UiTheme theme) {
746758
this.chatStartingHeadingTextColor = theme.chatStartingHeadingTextColor;
747759
this.chatStartedCaptionTextColor = theme.chatStartedCaptionTextColor;
748760
this.chatStartedHeadingTextColor = theme.chatStartedHeadingTextColor;
761+
this.choiceCardContentTextConfiguration = theme.choiceCardContentTextConfiguration;
749762
}
750763

751764
public UiTheme build() {
@@ -955,13 +968,11 @@ protected UiTheme(Parcel in) {
955968
} else {
956969
chatStartedCaptionTextColor = in.readInt();
957970
}
958-
if (in.readByte() == 0) {
959-
whiteLabel = null;
960-
} else {
961-
whiteLabel = in.readInt();
962-
}
971+
byte tmpWhiteLabel = in.readByte();
972+
whiteLabel = tmpWhiteLabel == 0 ? null : tmpWhiteLabel == 1;
963973
byte tmpGliaAlertDialogButtonUseVerticalAlignment = in.readByte();
964974
gliaAlertDialogButtonUseVerticalAlignment = tmpGliaAlertDialogButtonUseVerticalAlignment == 0 ? null : tmpGliaAlertDialogButtonUseVerticalAlignment == 1;
975+
choiceCardContentTextConfiguration = in.readParcelable(TextConfiguration.class.getClassLoader());
965976
headerEndButtonConfiguration = in.readParcelable(ButtonConfiguration.class.getClassLoader());
966977
positiveButtonConfiguration = in.readParcelable(ButtonConfiguration.class.getClassLoader());
967978
negativeButtonConfiguration = in.readParcelable(ButtonConfiguration.class.getClassLoader());
@@ -1211,13 +1222,9 @@ public void writeToParcel(Parcel dest, int flags) {
12111222
dest.writeByte((byte) 1);
12121223
dest.writeInt(chatStartedCaptionTextColor);
12131224
}
1214-
if (whiteLabel == null) {
1215-
dest.writeByte((byte) 0);
1216-
} else {
1217-
dest.writeByte((byte) 1);
1218-
dest.writeInt(whiteLabel);
1219-
}
1225+
dest.writeByte((byte) (whiteLabel == null ? 0 : whiteLabel ? 1 : 2));
12201226
dest.writeByte((byte) (gliaAlertDialogButtonUseVerticalAlignment == null ? 0 : gliaAlertDialogButtonUseVerticalAlignment ? 1 : 2));
1227+
dest.writeParcelable(choiceCardContentTextConfiguration, flags);
12211228
dest.writeParcelable(headerEndButtonConfiguration, flags);
12221229
dest.writeParcelable(positiveButtonConfiguration, flags);
12231230
dest.writeParcelable(negativeButtonConfiguration, flags);
@@ -1389,7 +1396,7 @@ public Integer getIconPlaceholder() {
13891396
return iconPlaceholder;
13901397
}
13911398

1392-
public Integer getWhiteLabel() {
1399+
public Boolean getWhiteLabel() {
13931400
return whiteLabel;
13941401
}
13951402

@@ -1413,6 +1420,10 @@ public ButtonConfiguration getGliaNeutralButtonConfiguration() {
14131420
return neutralButtonConfiguration;
14141421
}
14151422

1423+
public TextConfiguration getGliaChoiceCardContentTextConfiguration() {
1424+
return choiceCardContentTextConfiguration;
1425+
}
1426+
14161427
public Integer getGliaChatStartingHeadingTextColor() {
14171428
return chatStartingHeadingTextColor;
14181429
}

widgetssdk/src/main/java/com/glia/widgets/chat/ChatView.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,21 +1234,37 @@ private void dismissAlertDialog() {
12341234
}
12351235
}
12361236

1237-
private static Uri chooseUriByRequestCode(int requestCode, Uri galeryImgUri, Uri cameraImgUri) {
1238-
if (requestCode == OPEN_DOCUMENT_ACTION_REQUEST) return galeryImgUri;
1239-
else if (requestCode == CAPTURE_IMAGE_ACTION_REQUEST) return cameraImgUri;
1240-
else return null;
1237+
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
1238+
1239+
if (resultCode != Activity.RESULT_OK) return;
1240+
1241+
switch (requestCode) {
1242+
case OPEN_DOCUMENT_ACTION_REQUEST:
1243+
case CAPTURE_VIDEO_ACTION_REQUEST:
1244+
handleDocumentOrVideoActionResult(intent);
1245+
break;
1246+
case CAPTURE_IMAGE_ACTION_REQUEST:
1247+
handleCaptureImageActionResult();
1248+
break;
1249+
}
12411250
}
12421251

1243-
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
1244-
if ((requestCode == OPEN_DOCUMENT_ACTION_REQUEST || requestCode == CAPTURE_IMAGE_ACTION_REQUEST || requestCode == CAPTURE_VIDEO_ACTION_REQUEST)
1245-
&& resultCode == Activity.RESULT_OK) {
1246-
Uri dataUri = intent != null ? intent.getData() : null;
1247-
Uri uri = chooseUriByRequestCode(requestCode, dataUri, controller.getPhotoCaptureFileUri());
1248-
controller.setPhotoCaptureFileUri(null);
1249-
if (uri != null) {
1250-
controller.onAttachmentReceived(Utils.mapUriToFileAttachment(getContext().getContentResolver(), uri));
1251-
}
1252+
private void handleDocumentOrVideoActionResult(Intent intent) {
1253+
Uri uri = intent != null ? intent.getData() : null;
1254+
if (uri != null) {
1255+
controller.onAttachmentReceived(Utils.mapUriToFileAttachment(getContext().getContentResolver(), uri));
1256+
}
1257+
}
1258+
1259+
private void handleCaptureImageActionResult() {
1260+
Uri photoCaptureFileUri = controller != null ? controller.getPhotoCaptureFileUri() : null;
1261+
if (photoCaptureFileUri != null) {
1262+
FileHelper.fixCapturedPhotoRotation(getContext(), photoCaptureFileUri);
1263+
FileAttachment fa = Utils.mapUriToFileAttachment(
1264+
getContext().getContentResolver(),
1265+
photoCaptureFileUri
1266+
);
1267+
controller.onAttachmentReceived(fa);
12521268
}
12531269
}
12541270

@@ -1313,7 +1329,7 @@ private ChatItem updatedDownloadingItemState(AttachmentFile attachmentFile, Chat
13131329

13141330
@Override
13151331
public void onFileOpenClick(AttachmentFile attachment) {
1316-
Uri contentUri = null;
1332+
Uri contentUri;
13171333
Context context = getContext();
13181334
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
13191335
Uri downloadsContentUri = MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL);

widgetssdk/src/main/java/com/glia/widgets/chat/helper/FileHelper.java

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
import android.graphics.Bitmap;
55
import android.graphics.BitmapFactory;
66
import android.graphics.Matrix;
7+
import android.net.Uri;
78
import android.os.Build;
89
import android.os.Environment;
910

11+
import androidx.exifinterface.media.ExifInterface;
12+
1013
import com.glia.androidsdk.chat.AttachmentFile;
1114

1215
import java.io.File;
16+
import java.io.IOException;
1317
import java.io.InputStream;
18+
import java.io.OutputStream;
1419

1520
import io.reactivex.Maybe;
1621

1722
public class FileHelper {
18-
private static final String TAG = FileHelper.class.getSimpleName();
1923
private static final String FILE_PROVIDER_AUTHORITY = "com.glia.widgets.fileprovider";
2024
private static final int DESIRED_IMAGE_SIZE = 640;
2125

@@ -27,21 +31,12 @@ public static Maybe<Bitmap> decodeSampledBitmapFromInputStream(InputStream input
2731

2832
double ratio = ((double) rawWidth) / ((double) rawHeight);
2933
Bitmap scaledBitmap = Bitmap.createScaledBitmap(rawBitmap, (int) (DESIRED_IMAGE_SIZE * ratio), DESIRED_IMAGE_SIZE, false);
30-
if (scaledBitmap != null)
31-
emitter.onSuccess(rotateImage(scaledBitmap, 90));
32-
else {
33-
emitter.onError(new Exception());
34-
}
34+
if (scaledBitmap != null) emitter.onSuccess(scaledBitmap);
35+
else emitter.onError(new Exception());
3536
}
3637
);
3738
}
3839

39-
public static Bitmap rotateImage(Bitmap source, float angle) {
40-
Matrix matrix = new Matrix();
41-
matrix.postRotate(angle);
42-
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
43-
}
44-
4540
public static String getFileProviderAuthority(Context context) {
4641
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
4742
return String.join(".", context.getPackageName(), FILE_PROVIDER_AUTHORITY);
@@ -70,4 +65,45 @@ public static String getFileExtension(String fullName) {
7065
int dotIndex = fileName.lastIndexOf('.');
7166
return (dotIndex == -1) ? "" : fileName.substring(dotIndex);
7267
}
68+
69+
public static void fixCapturedPhotoRotation(Context context, Uri uri) {
70+
int rotation = getRotationFromExif(context, uri);
71+
72+
try (InputStream in = context.getContentResolver().openInputStream(uri)) {
73+
Matrix matrix = new Matrix();
74+
matrix.postRotate(rotation);
75+
Bitmap bitmap = BitmapFactory.decodeStream(in);
76+
Bitmap bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
77+
78+
try (OutputStream os = context.getContentResolver().openOutputStream(uri)) {
79+
bmp.compress(Bitmap.CompressFormat.JPEG, 100, os);
80+
}
81+
} catch (IOException e) {
82+
e.printStackTrace();
83+
}
84+
}
85+
86+
private static int getRotationFromExif(Context context, Uri uri) {
87+
int rotation = 0;
88+
try (InputStream in = context.getContentResolver().openInputStream(uri)) {
89+
int orientation = new ExifInterface(in).getAttributeInt(
90+
ExifInterface.TAG_ORIENTATION,
91+
ExifInterface.ORIENTATION_NORMAL);
92+
switch (orientation) {
93+
case ExifInterface.ORIENTATION_ROTATE_90:
94+
rotation = 90;
95+
break;
96+
case ExifInterface.ORIENTATION_ROTATE_180:
97+
rotation = 180;
98+
break;
99+
case ExifInterface.ORIENTATION_ROTATE_270:
100+
rotation = 270;
101+
break;
102+
}
103+
} catch (IOException e) {
104+
e.printStackTrace();
105+
}
106+
107+
return rotation;
108+
}
73109
}

0 commit comments

Comments
 (0)