Skip to content
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

Added the ability to change MessagesListStyle attributes programmatically #65

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# built application files
*.apk
*.ap_
*.jar
#*.jar

# files for the dex VM
*.dex
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.novoda:bintray-release:0.4.0'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
13 changes: 1 addition & 12 deletions chatkit/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
buildToolsVersion "25.0.3"

defaultConfig {
minSdkVersion 14
Expand All @@ -20,16 +19,6 @@ android {
}
}

publish {
groupId = 'com.github.stfalcon'
artifactId = 'chatkit'
publishVersion = '0.2.2'
desc = 'ChatKit - is a library designed to simplify the development of UI for such a trivial task as chat. It have flexible possibilities for styling, customizing and data management'
licences = ['Apache-2.0']
uploadName = 'ChatKit'
website = 'https://github.com/stfalcon-studio/ChatKit.git'
}

ext {
supportVersion = '25.3.1'
flexboxVersion = '0.2.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@SuppressWarnings({"WeakerAccess", "unused"})
public class MessageInput extends RelativeLayout
implements View.OnClickListener, TextWatcher {
private MessageInputStyle messageInputStyle;

protected EditText messageInput;
protected ImageButton messageSendButton;
Expand Down Expand Up @@ -153,42 +154,7 @@ private void onAddAttachments() {
private void init(Context context, AttributeSet attrs) {
init(context);
MessageInputStyle style = MessageInputStyle.parse(context, attrs);

this.messageInput.setMaxLines(style.getInputMaxLines());
this.messageInput.setHint(style.getInputHint());
this.messageInput.setText(style.getInputText());
this.messageInput.setTextSize(TypedValue.COMPLEX_UNIT_PX, style.getInputTextSize());
this.messageInput.setTextColor(style.getInputTextColor());
this.messageInput.setHintTextColor(style.getInputHintColor());
ViewCompat.setBackground(this.messageInput, style.getInputBackground());
setCursor(style.getInputCursorDrawable());

this.attachmentButton.setVisibility(style.showAttachmentButton() ? VISIBLE : GONE);
this.attachmentButton.setImageDrawable(style.getAttachmentButtonIcon());
this.attachmentButton.getLayoutParams().width = style.getAttachmentButtonWidth();
this.attachmentButton.getLayoutParams().height = style.getAttachmentButtonHeight();
ViewCompat.setBackground(this.attachmentButton, style.getAttachmentButtonBackground());

this.attachmentButtonSpace.setVisibility(style.showAttachmentButton() ? VISIBLE : GONE);
this.attachmentButtonSpace.getLayoutParams().width = style.getAttachmentButtonMargin();

this.messageSendButton.setImageDrawable(style.getInputButtonIcon());
this.messageSendButton.getLayoutParams().width = style.getInputButtonWidth();
this.messageSendButton.getLayoutParams().height = style.getInputButtonHeight();
ViewCompat.setBackground(messageSendButton, style.getInputButtonBackground());
this.sendButtonSpace.getLayoutParams().width = style.getInputButtonMargin();

if (getPaddingLeft() == 0
&& getPaddingRight() == 0
&& getPaddingTop() == 0
&& getPaddingBottom() == 0) {
setPadding(
style.getInputDefaultPaddingLeft(),
style.getInputDefaultPaddingTop(),
style.getInputDefaultPaddingRight(),
style.getInputDefaultPaddingBottom()
);
}
this.setStyle(style);
}

private void init(Context context) {
Expand Down Expand Up @@ -231,6 +197,42 @@ private void setCursor(Drawable drawable) {
}
}

public MessageInputStyle getStyle() {
return this.messageInputStyle;
}

public void setStyle(MessageInputStyle messageInputStyle) {
this.messageInputStyle = messageInputStyle;

this.messageInput.setMaxLines(messageInputStyle.getInputMaxLines());
this.messageInput.setHint(messageInputStyle.getInputHint());
this.messageInput.setText(messageInputStyle.getInputText());
this.messageInput.setTextSize(TypedValue.COMPLEX_UNIT_PX, messageInputStyle.getInputTextSize());
this.messageInput.setTextColor(messageInputStyle.getInputTextColor());
this.messageInput.setHintTextColor(messageInputStyle.getInputHintColor());
ViewCompat.setBackground(this.messageInput, messageInputStyle.getInputBackground());
setCursor(messageInputStyle.getInputCursorDrawable());

this.attachmentButton.setVisibility(messageInputStyle.showAttachmentButton() ? VISIBLE : GONE);
this.attachmentButton.setImageDrawable(messageInputStyle.getAttachmentButtonIcon());
this.attachmentButton.getLayoutParams().width = messageInputStyle.getAttachmentButtonWidth();
this.attachmentButton.getLayoutParams().height = messageInputStyle.getAttachmentButtonHeight();
ViewCompat.setBackground(this.attachmentButton, messageInputStyle.getAttachmentButtonBackground());

this.attachmentButtonSpace.setVisibility(messageInputStyle.showAttachmentButton() ? VISIBLE : GONE);
this.attachmentButtonSpace.getLayoutParams().width = messageInputStyle.getAttachmentButtonMargin();

this.messageSendButton.setImageDrawable(messageInputStyle.getInputButtonIcon());
this.messageSendButton.getLayoutParams().width = messageInputStyle.getInputButtonWidth();
this.messageSendButton.getLayoutParams().height = messageInputStyle.getInputButtonHeight();
ViewCompat.setBackground(messageSendButton, messageInputStyle.getInputButtonBackground());
this.sendButtonSpace.getLayoutParams().width = messageInputStyle.getInputButtonMargin();

if (getPaddingLeft() == 0 && getPaddingRight() == 0 && getPaddingTop() == 0 && getPaddingBottom() == 0) {
setPadding(messageInputStyle.getInputDefaultPaddingLeft(), messageInputStyle.getInputDefaultPaddingTop(), messageInputStyle.getInputDefaultPaddingRight(), messageInputStyle.getInputDefaultPaddingBottom());
}
}

/**
* Interface definition for a callback to be invoked when user pressed 'submit' button
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Style for MessageInputStyle customization by xml attributes
*/
@SuppressWarnings("WeakerAccess")
class MessageInputStyle extends Style {
public class MessageInputStyle extends Style {

private static final int DEFAULT_MAX_LINES = 5;

Expand Down Expand Up @@ -282,4 +282,192 @@ protected int getInputDefaultPaddingBottom() {
return inputDefaultPaddingBottom;
}

public int getAttachmentButtonDefaultBgColor() {
return attachmentButtonDefaultBgColor;
}

public int getAttachmentButtonDefaultBgPressedColor() {
return attachmentButtonDefaultBgPressedColor;
}

public int getAttachmentButtonDefaultBgDisabledColor() {
return attachmentButtonDefaultBgDisabledColor;
}

public int getAttachmentButtonDefaultIconColor() {
return attachmentButtonDefaultIconColor;
}

public int getAttachmentButtonDefaultIconPressedColor() {
return attachmentButtonDefaultIconPressedColor;
}

public int getAttachmentButtonDefaultIconDisabledColor() {
return attachmentButtonDefaultIconDisabledColor;
}

public int getInputButtonDefaultBgColor() {
return inputButtonDefaultBgColor;
}

public int getInputButtonDefaultBgPressedColor() {
return inputButtonDefaultBgPressedColor;
}

public int getInputButtonDefaultBgDisabledColor() {
return inputButtonDefaultBgDisabledColor;
}

public int getInputButtonDefaultIconColor() {
return inputButtonDefaultIconColor;
}

public int getInputButtonDefaultIconPressedColor() {
return inputButtonDefaultIconPressedColor;
}

public int getInputButtonDefaultIconDisabledColor() {
return inputButtonDefaultIconDisabledColor;
}

public void setShowAttachmentButton(boolean showAttachmentButton) {
this.showAttachmentButton = showAttachmentButton;
}

public void setAttachmentButtonBackground(int attachmentButtonBackground) {
this.attachmentButtonBackground = attachmentButtonBackground;
}

public void setAttachmentButtonDefaultBgColor(int attachmentButtonDefaultBgColor) {
this.attachmentButtonDefaultBgColor = attachmentButtonDefaultBgColor;
}

public void setAttachmentButtonDefaultBgPressedColor(int attachmentButtonDefaultBgPressedColor) {
this.attachmentButtonDefaultBgPressedColor = attachmentButtonDefaultBgPressedColor;
}

public void setAttachmentButtonDefaultBgDisabledColor(int attachmentButtonDefaultBgDisabledColor) {
this.attachmentButtonDefaultBgDisabledColor = attachmentButtonDefaultBgDisabledColor;
}

public void setAttachmentButtonIcon(int attachmentButtonIcon) {
this.attachmentButtonIcon = attachmentButtonIcon;
}

public void setAttachmentButtonDefaultIconColor(int attachmentButtonDefaultIconColor) {
this.attachmentButtonDefaultIconColor = attachmentButtonDefaultIconColor;
}

public void setAttachmentButtonDefaultIconPressedColor(int attachmentButtonDefaultIconPressedColor) {
this.attachmentButtonDefaultIconPressedColor = attachmentButtonDefaultIconPressedColor;
}

public void setAttachmentButtonDefaultIconDisabledColor(int attachmentButtonDefaultIconDisabledColor) {
this.attachmentButtonDefaultIconDisabledColor = attachmentButtonDefaultIconDisabledColor;
}

public void setAttachmentButtonWidth(int attachmentButtonWidth) {
this.attachmentButtonWidth = attachmentButtonWidth;
}

public void setAttachmentButtonHeight(int attachmentButtonHeight) {
this.attachmentButtonHeight = attachmentButtonHeight;
}

public void setAttachmentButtonMargin(int attachmentButtonMargin) {
this.attachmentButtonMargin = attachmentButtonMargin;
}

public void setInputButtonBackground(int inputButtonBackground) {
this.inputButtonBackground = inputButtonBackground;
}

public void setInputButtonDefaultBgColor(int inputButtonDefaultBgColor) {
this.inputButtonDefaultBgColor = inputButtonDefaultBgColor;
}

public void setInputButtonDefaultBgPressedColor(int inputButtonDefaultBgPressedColor) {
this.inputButtonDefaultBgPressedColor = inputButtonDefaultBgPressedColor;
}

public void setInputButtonDefaultBgDisabledColor(int inputButtonDefaultBgDisabledColor) {
this.inputButtonDefaultBgDisabledColor = inputButtonDefaultBgDisabledColor;
}

public void setInputButtonIcon(int inputButtonIcon) {
this.inputButtonIcon = inputButtonIcon;
}

public void setInputButtonDefaultIconColor(int inputButtonDefaultIconColor) {
this.inputButtonDefaultIconColor = inputButtonDefaultIconColor;
}

public void setInputButtonDefaultIconPressedColor(int inputButtonDefaultIconPressedColor) {
this.inputButtonDefaultIconPressedColor = inputButtonDefaultIconPressedColor;
}

public void setInputButtonDefaultIconDisabledColor(int inputButtonDefaultIconDisabledColor) {
this.inputButtonDefaultIconDisabledColor = inputButtonDefaultIconDisabledColor;
}

public void setInputButtonWidth(int inputButtonWidth) {
this.inputButtonWidth = inputButtonWidth;
}

public void setInputButtonHeight(int inputButtonHeight) {
this.inputButtonHeight = inputButtonHeight;
}

public void setInputButtonMargin(int inputButtonMargin) {
this.inputButtonMargin = inputButtonMargin;
}

public void setInputMaxLines(int inputMaxLines) {
this.inputMaxLines = inputMaxLines;
}

public void setInputHint(String inputHint) {
this.inputHint = inputHint;
}

public void setInputText(String inputText) {
this.inputText = inputText;
}

public void setInputTextSize(int inputTextSize) {
this.inputTextSize = inputTextSize;
}

public void setInputTextColor(int inputTextColor) {
this.inputTextColor = inputTextColor;
}

public void setInputHintColor(int inputHintColor) {
this.inputHintColor = inputHintColor;
}

public void setInputBackground(Drawable inputBackground) {
this.inputBackground = inputBackground;
}

public void setInputCursorDrawable(Drawable inputCursorDrawable) {
this.inputCursorDrawable = inputCursorDrawable;
}

public void setInputDefaultPaddingLeft(int inputDefaultPaddingLeft) {
this.inputDefaultPaddingLeft = inputDefaultPaddingLeft;
}

public void setInputDefaultPaddingRight(int inputDefaultPaddingRight) {
this.inputDefaultPaddingRight = inputDefaultPaddingRight;
}

public void setInputDefaultPaddingTop(int inputDefaultPaddingTop) {
this.inputDefaultPaddingTop = inputDefaultPaddingTop;
}

public void setInputDefaultPaddingBottom(int inputDefaultPaddingBottom) {
this.inputDefaultPaddingBottom = inputDefaultPaddingBottom;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,12 @@ void setAdapter(MessagesListAdapter<MESSAGE> adapter, boolean reverseLayout) {
private void parseStyle(Context context, AttributeSet attrs) {
messagesListStyle = MessagesListStyle.parse(context, attrs);
}

public MessagesListStyle getStyle() {
return this.messagesListStyle;
}

public void setStyle(MessagesListStyle messagesListStyle) {
this.messagesListStyle = messagesListStyle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,11 @@ void setLayoutManager(RecyclerView.LayoutManager layoutManager) {
this.layoutManager = layoutManager;
}

void setStyle(MessagesListStyle style) {
public MessagesListStyle getStyle() {
return this.messagesListStyle;
}

public void setStyle(MessagesListStyle style) {
this.messagesListStyle = style;
}

Expand Down
Loading