Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private void setupModes(boolean isCurrentlyInDarkMode) {
}

if (etComment != null) {
etComment.setBackgroundResource(isCurrentlyInDarkMode ? R.drawable.et_text_bg_v2 : R.drawable.edit_text_bg);
etComment.setBackgroundResource(isCurrentlyInDarkMode ? R.drawable.edit_text_bg_night : R.drawable.et_text_bg_v2);
etComment.setHintTextColor(Color.parseColor(isCurrentlyInDarkMode ? editTextFeedbackCommentHintColor.second : editTextFeedbackCommentHintColor.first));
etComment.setTextColor(Color.parseColor(isCurrentlyInDarkMode ? textViewTitleColor.second : textViewTitleColor.first));
}
Expand Down Expand Up @@ -180,6 +180,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
feedbackContainer = view.findViewById(R.id.feedback_container);
tvTitle = view.findViewById(R.id.tv_feedback_title);
tvFeedbackTitle = view.findViewById(R.id.tv_feedback);
setupModes(isCurrentlyInDarkMode);

btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import io.kommunicate.ui.conversation.richmessaging.KmRichMessage;
import io.kommunicate.ui.conversation.richmessaging.form.KmDropdownItemAdapter;
import io.kommunicate.ui.conversation.richmessaging.helpers.KmFormStateHelper;
import io.kommunicate.ui.conversation.richmessaging.helpers.KmFormStyleHelper;
import io.kommunicate.ui.conversation.richmessaging.models.KmFormStateModel;
import io.kommunicate.ui.conversation.richmessaging.models.v2.KmFormPayloadModel;
import io.kommunicate.ui.conversation.richmessaging.views.KmFlowLayout;
Expand Down Expand Up @@ -210,6 +211,7 @@ public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
return false;
}
});
editText.setActivated(validationArray.get(position) == 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It marks the field as invalid so it gets a red border.

if (validationArray.get(position) == 1) {
formItemViewHolder.formValidationText.setVisibility(View.VISIBLE);
formItemViewHolder.formValidationText.setText(textModel.getValidation() != null
Expand Down Expand Up @@ -247,6 +249,7 @@ public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
return false;
}
});
editText.setActivated(validationArray.get(position) == 1);
if (validationArray.get(position) == 1) {
formItemViewHolder.formValidationText.setVisibility(View.VISIBLE);
formItemViewHolder.formValidationText.setText(textAreaModel.getValidation() != null
Expand Down Expand Up @@ -379,6 +382,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
handleItemVisibility(formItemViewHolder, formItemViewHolder.formDropdownListContainer);
if (dropdownList.getOptions() != null) {

formItemViewHolder.formDropdownListContainer.setActivated(validationArray.get(position) == 1);
if (validationArray.get(position) == 1) {
formItemViewHolder.formValidationText.setVisibility(View.VISIBLE);
formItemViewHolder.formValidationText.setText(dropdownList.getValidation() != null
Expand Down Expand Up @@ -654,21 +658,37 @@ public class KmFormItemViewHolder extends RecyclerView.ViewHolder {
public KmFormItemViewHolder(@NonNull View itemView) {
super(itemView);

KmFormStyleHelper styleHelper = new KmFormStyleHelper(context, customizationSettings);
formLabel = itemView.findViewById(R.id.km_form_label_text);
KmThemeHelper themeHelper = KmThemeHelper.getInstance(context, customizationSettings);
if (formLabel != null && themeHelper.isDarkModeEnabledForSDK()){
formLabel.setTextColor(context.getResources().getColor(R.color.white));
if (formLabel != null) {
formLabel.setTextColor(styleHelper.getLabelColor());
}
formEditText = itemView.findViewById(R.id.km_form_edit_text);
if (formEditText != null && themeHelper.isDarkModeEnabledForSDK()){
formEditText.setTextColor(context.getResources().getColor(R.color.received_message_bg_color_night));
if (formEditText != null) {
formEditText.setTextColor(styleHelper.getTextColor());
formEditText.setHintTextColor(styleHelper.getHintColor());
formEditText.setBackground(styleHelper.createFieldBackground());
}
formItemRootLayout = itemView.findViewById(R.id.km_form_item_root_layout);
formFlowLayout = itemView.findViewById(R.id.km_form_selection_layout);
formDatePicker = itemView.findViewById(R.id.km_form_date_picker);
if (formDatePicker != null) {
formDatePicker.setTextColor(styleHelper.getTextColor());
formDatePicker.setBackground(styleHelper.createFieldBackground());
formDatePicker.setCompoundDrawableTintList(ColorStateList.valueOf(styleHelper.getTextColor()));
}
formDropdownList = itemView.findViewById(R.id.km_form_dropdown_list);
if (formDropdownList != null) {
formDropdownList.setBackgroundTintList(ColorStateList.valueOf(styleHelper.getTextColor()));
}
formDropdownListContainer = itemView.findViewById(R.id.km_form_dropdown_list_container);
if (formDropdownListContainer != null) {
formDropdownListContainer.setBackground(styleHelper.createFieldBackground());
}
formValidationText = itemView.findViewById(R.id.km_form_validation_text);
if (formValidationText != null) {
formValidationText.setTextColor(styleHelper.getErrorColor());
}

if (formEditText != null) {
formEditText.addTextChangedListener(new TextWatcher() {
Expand Down Expand Up @@ -721,12 +741,14 @@ public void onClick(View v) {
}

public EditText getEditTextField() {
formEditText.setMinLines(1);
formEditText.setInputType(InputType.TYPE_CLASS_TEXT);
formEditText.setTransformationMethod(null);
return formEditText;
}

public EditText getPasswordTextField() {
formEditText.setMinLines(1);
formEditText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
formEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
return formEditText;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.kommunicate.ui.conversation.richmessaging.form;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
Expand All @@ -11,6 +10,7 @@
import androidx.annotation.Nullable;

import io.kommunicate.ui.CustomizationSettings;
import io.kommunicate.ui.conversation.richmessaging.helpers.KmFormStyleHelper;
import io.kommunicate.ui.conversation.richmessaging.models.v2.KmFormPayloadModel;
import io.kommunicate.ui.kommunicate.utils.KmThemeHelper;

Expand All @@ -20,31 +20,30 @@ public class KmDropdownItemAdapter extends ArrayAdapter<KmFormPayloadModel.Optio

private Context context;
private CustomizationSettings customizationSettings;
private KmFormStyleHelper styleHelper;

public KmDropdownItemAdapter(@NonNull Context context, CustomizationSettings customizationSettings, int textViewResourceId, List<KmFormPayloadModel.Options> itemList) {
super(context, textViewResourceId, itemList);
this.context = context;
this.customizationSettings = customizationSettings;
this.styleHelper = new KmFormStyleHelper(context, customizationSettings);
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
TextView label = (TextView) super.getView(position, convertView, parent);
label.setTextColor(Color.BLACK);
label.setTextColor(styleHelper.getTextColor());
label.setText(getItem(position).getLabel());
return label;
}

@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
TextView label = (TextView) super.getDropDownView(position, convertView, parent);
KmThemeHelper kmThemeHelper = KmThemeHelper.getInstance(context, customizationSettings);
if (kmThemeHelper.isDarkModeEnabledForSDK()){
label.setTextColor(Color.WHITE);
label.setBackgroundColor(Color.BLACK);
} else {
label.setTextColor(Color.BLACK);
label.setTextColor(styleHelper.getTextColor());
if (KmThemeHelper.getInstance(context, customizationSettings).isDarkModeEnabledForSDK()) {
label.setBackgroundColor(styleHelper.getFieldBackgroundColor());
}
label.setText(getItem(position).getLabel());
return label;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package io.kommunicate.ui.conversation.richmessaging.helpers;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;

import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.core.content.ContextCompat;

import io.kommunicate.ui.CustomizationSettings;
import io.kommunicate.ui.R;
import io.kommunicate.ui.kommunicate.utils.DimensionsUtils;
import io.kommunicate.ui.kommunicate.utils.KmThemeHelper;

/**
* Resolves the colors and field background used by the form rich message,
* based on whether dark mode is enabled for the SDK.
*/
public class KmFormStyleHelper {

private static final int FIELD_CORNER_RADIUS_DP = 8;
private static final int FIELD_STROKE_DP = 1;
private static final int FIELD_STROKE_FOCUSED_DP = 2;

private final Context context;
private final boolean isDarkMode;
private final int themeColor;

public KmFormStyleHelper(Context context, CustomizationSettings customizationSettings) {
this.context = context;
KmThemeHelper themeHelper = KmThemeHelper.getInstance(context, customizationSettings);
this.isDarkMode = themeHelper.isDarkModeEnabledForSDK();
this.themeColor = themeHelper.getRichMessageThemeColor();
}

@ColorInt
public int getTextColor() {
return getColor(R.color.km_form_text, R.color.km_form_text_night);
}

@ColorInt
public int getHintColor() {
return getColor(R.color.km_form_hint, R.color.km_form_hint_night);
}

@ColorInt
public int getLabelColor() {
return getColor(R.color.km_form_label, R.color.km_form_label_night);
}

@ColorInt
public int getErrorColor() {
return getColor(R.color.km_form_error, R.color.km_form_error_night);
}

@ColorInt
public int getFieldBackgroundColor() {
return getColor(R.color.km_form_field_background, R.color.km_form_field_background_night);
}

@ColorInt
private int getBorderColor() {
return getColor(R.color.km_form_field_border, R.color.km_form_field_border_night);
}

/**
* Rounded field background: error border when activated, theme colored border when focused.
* A new instance is returned on every call, so it is safe to set on multiple views.
*/
public Drawable createFieldBackground() {
StateListDrawable background = new StateListDrawable();
background.addState(new int[]{android.R.attr.state_activated}, createShape(getErrorColor(), FIELD_STROKE_DP));
background.addState(new int[]{android.R.attr.state_focused, android.R.attr.state_window_focused}, createShape(themeColor, FIELD_STROKE_FOCUSED_DP));
background.addState(new int[]{}, createShape(getBorderColor(), FIELD_STROKE_DP));
return background;
}

private GradientDrawable createShape(@ColorInt int strokeColor, int strokeWidthDp) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setColor(getFieldBackgroundColor());
shape.setCornerRadius(DimensionsUtils.convertDpToPx(FIELD_CORNER_RADIUS_DP));
shape.setStroke(DimensionsUtils.convertDpToPx(strokeWidthDp), strokeColor);
return shape;
}

@ColorInt
private int getColor(@ColorRes int lightColor, @ColorRes int nightColor) {
return ContextCompat.getColor(context, isDarkMode ? nightColor : lightColor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected void onCreate(Bundle savedInstanceState) {
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(RecyclerView.VERTICAL);
kmPreChatRecyclerView.setLayoutManager(layoutManager);
prechatInputAdapter = new KmPrechatInputAdapter((inputModelList != null && !inputModelList.isEmpty()) ? inputModelList : getDefaultModelList(), this);
prechatInputAdapter = new KmPrechatInputAdapter((inputModelList != null && !inputModelList.isEmpty()) ? inputModelList : getDefaultModelList(), this, themeHelper.getPrimaryColor());
kmPreChatRecyclerView.setAdapter(prechatInputAdapter);

Button startConversationButton = findViewById(R.id.start_conversation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.core.graphics.ColorUtils;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
Expand All @@ -21,22 +23,27 @@
import io.kommunicate.ui.kommunicate.models.KmCountryCode;

public class KmCountryCodeAdapter extends RecyclerView.Adapter<KmCountryCodeAdapter.CountryViewHolder> {
private static final int SELECTED_BACKGROUND_ALPHA = 0x1F;
private final Context context;
private final List<KmCountryCode> countries;
private final List<KmCountryCode> filteredCountries;
private final String selectedIsoCode;
private final KmClickHandler<KmCountryCode> kmClickHandler;
private final int themeColor;
private final int selectedBackgroundColor;
private final int defaultBackgroundColor;
private final int dialCodeColor;

public KmCountryCodeAdapter(Context context, List<KmCountryCode> countries, String selectedIsoCode, KmClickHandler<KmCountryCode> kmClickHandler) {
public KmCountryCodeAdapter(Context context, List<KmCountryCode> countries, String selectedIsoCode, @ColorInt int themeColor, KmClickHandler<KmCountryCode> kmClickHandler) {
this.context = context;
this.countries = countries;
this.filteredCountries = new ArrayList<>(countries);
this.selectedIsoCode = selectedIsoCode;
this.kmClickHandler = kmClickHandler;
this.selectedBackgroundColor = Utils.getColor(context, R.color.km_language_divider_color);
this.themeColor = themeColor;
this.selectedBackgroundColor = ColorUtils.setAlphaComponent(themeColor, SELECTED_BACKGROUND_ALPHA);
this.defaultBackgroundColor = Utils.getColor(context, R.color.core_transparent_color);
this.dialCodeColor = Utils.getColor(context, R.color.km_language_code_text_color);
}

@NonNull
Expand All @@ -54,6 +61,7 @@ public void onBindViewHolder(@NonNull CountryViewHolder viewHolder, int position
viewHolder.flag.setText(country.getFlag());
viewHolder.name.setText(country.getName());
viewHolder.dialCode.setText(country.getDialCode());
viewHolder.dialCode.setTextColor(isSelected ? themeColor : dialCodeColor);
viewHolder.parentView.setBackgroundColor(isSelected ? selectedBackgroundColor : defaultBackgroundColor);
}

Expand Down
Loading
Loading