Repository navigation
TDH-4292 : Improve agent app form UI #706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ayushsharmakm
wants to merge
2
commits into
development
Choose a base branch
from
TDH-4292
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...src/main/java/io/kommunicate/ui/conversation/richmessaging/helpers/KmFormStyleHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this check?
There was a problem hiding this comment.
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.