Skip to content

Commit

Permalink
Merge branch 'release/v0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sangcomz committed Sep 8, 2018
2 parents f9c859d + 6181d66 commit c4c41fe
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 32 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

Chameleon deals with the Status of RecyclerView.

## What's New in 0.0.3? :tada:
- Add ability to access current state :clap: [@jordond](https://github.com/jordond)
## What's New in 0.1.0? :tada:
- Vector Image Support
- Add feature to set text gravity

## How to Use

Expand All @@ -20,7 +21,7 @@ Chameleon deals with the Status of RecyclerView.
}
dependencies {
compile 'com.github.sangcomz:Chameleon:v0.0.3'
compile 'com.github.sangcomz:Chameleon:v0.1.0'
}
```
### Usage
Expand Down Expand Up @@ -105,9 +106,11 @@ chameleon.setStateChangeListener { newState, oldState -> Log.d("Main", "Was $old
| emptyText | empty view Change text | "empty" |
| emptyTextColor | empty view Change text color | #808080 |
| emptyTextSize | empty view Change text size | 24sp |
| emptyTextGravity | empty view Change text gravity | 0 |
| emptySubText | empty view Change sub text | "empty content" |
| emptySubTextColor | empty view Change sub text color | #b7b7b7 |
| emptySubTextSize | empty view Change sub text size | 16sp |
| emptySubTextGravity | empty view Change sub text gravity | 0 |
| emptyDrawable | empty view Change drawable | R.drawable.ic_empty |
| emptyButtonText | empty view Change button text | "retry" |
| emptyButtonTextColor | empty view Change button text color | #808080 |
Expand All @@ -117,9 +120,11 @@ chameleon.setStateChangeListener { newState, oldState -> Log.d("Main", "Was $old
| errorText | error view Change text | "error" |
| errorTextColor | error view Change text color | #808080 |
| errorTextSize | error view Change text size | 24sp |
| errorTextGravity | empty view Change text gravity | 0 |
| errorSubText | error view Change sub text | "error content" |
| errorSubTextColor | error view Change sub text color | #b7b7b7 |
| errorSubTextSize | error view Change sub text size | 16sp |
| errorSubTextGravity | error view Change sub text gravity | 0 |
| errorDrawable | error view Change drawable | R.drawable.ic_error |
| errorButtonText | error view Change button text | "retry" |
| errorButtonTextColor | error view Change button text color | #808080 |
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support.constraint:constraint-layout:$constraint_version"
implementation 'com.squareup.picasso:picasso:2.71828'
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultState="LOADING"
app:emptyButtonBackgroundColor="@color/colorPrimary"
app:emptyButtonText="+Add Chameleon"
app:emptyButtonTextColor="#ffffff"
app:emptyButtonTextSize="12sp"
app:emptyDrawable="@drawable/ic_empty"
app:emptySubText="@string/sub_empty"
app:emptyText="@string/empty"
app:emptySubText="@string/long_sub_empty"
app:emptySubTextGravity="center"
app:emptyText="@string/long_empty"
app:emptyTextGravity="center"
app:errorButtonBackgroundColor="@color/colorPrimary"
app:errorButtonText="Retry"
app:errorButtonTextColor="#ffffff"
app:errorButtonTextSize="12sp"
app:errorDrawable="@drawable/ic_error"
app:errorSubText="@string/sub_error"
app:errorText="@string/error"
app:isLargeProgress="true"
app:progressDrawable="@drawable/drawable_progress"
app:useEmptyButton="true"
app:useErrorButton="true"
app:defaultState="LOADING"
tools:context="xyz.sangcomz.chameleonsample.MainActivity">

<android.support.v7.widget.RecyclerView
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<string name="error">Error</string>
<string name="empty">Empty</string>
<string name="sub_empty">Where is chameleon?</string>
<string name="long_empty">Empty Long Long Long Long Long Long Long</string>
<string name="long_sub_empty">Where is chameleon? Where is chameleon? Where is chameleon? Where is chameleon? Where is chameleon?</string>
<string name="sub_error">The chameleon is dead.</string>
<string name="display">Display State</string>
</resources>
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.30'
ext.kotlin_version = '1.2.61'
ext.support_version = '27.1.1'
ext.constraint_version = '1.1.0'
ext.constraint_version = '1.1.3'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion chameleon/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:appcompat-v7:$support_version"
compile "com.android.support:recyclerview-v7:$support_version"
compile "com.android.support.constraint:constraint-layout:$constraint_version"
Expand Down
26 changes: 14 additions & 12 deletions chameleon/src/main/java/xyz/sangcomz/chameleon/Chameleon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ open class Chameleon(context: Context?, attrs: AttributeSet?) : ConstraintLayout
it.getString(R.styleable.Chameleon_emptyText) ?: "empty",
it.getColor(R.styleable.Chameleon_emptyTextColor, ContextCompat.getColor(context, R.color.colorTitleText)),
it.getDimension(R.styleable.Chameleon_emptyTextSize, context.resources.getDimension(R.dimen.title_text_size)),
it.getInt(R.styleable.Chameleon_emptyTextGravity, 0),
it.getString(R.styleable.Chameleon_emptySubText) ?: "empty content",
it.getColor(R.styleable.Chameleon_emptySubTextColor, ContextCompat.getColor(context, R.color.colorSubText)),
it.getDimension(R.styleable.Chameleon_emptySubTextSize, context.resources.getDimension(R.dimen.sub_text_size)),
it.getInt(R.styleable.Chameleon_emptySubTextGravity, 0),
it.getResourceId(R.styleable.Chameleon_emptyDrawable, R.drawable.ic_chameleon_empty).getDrawable(context),
it.getString(R.styleable.Chameleon_emptyButtonText) ?: "retry",
it.getColor(R.styleable.Chameleon_emptyButtonTextColor, ContextCompat.getColor(context, R.color.colorTitleText)),
Expand All @@ -72,9 +74,11 @@ open class Chameleon(context: Context?, attrs: AttributeSet?) : ConstraintLayout
it.getString(R.styleable.Chameleon_errorText) ?: "error",
it.getColor(R.styleable.Chameleon_errorTextColor, ContextCompat.getColor(context, R.color.colorTitleText)),
it.getDimension(R.styleable.Chameleon_errorTextSize, context.resources.getDimension(R.dimen.title_text_size)),
it.getInt(R.styleable.Chameleon_errorTextGravity, 0),
it.getString(R.styleable.Chameleon_errorSubText) ?: "error content",
it.getColor(R.styleable.Chameleon_errorSubTextColor, ContextCompat.getColor(context, R.color.colorSubText)),
it.getDimension(R.styleable.Chameleon_errorSubTextSize, context.resources.getDimension(R.dimen.sub_text_size)),
it.getInt(R.styleable.Chameleon_errorSubTextGravity, 0),
it.getResourceId(R.styleable.Chameleon_errorDrawable, R.drawable.ic_chameleon_error).getDrawable(context),
it.getString(R.styleable.Chameleon_errorButtonText) ?: "retry",
it.getColor(R.styleable.Chameleon_errorButtonTextColor, ContextCompat.getColor(context, R.color.colorTitleText)),
Expand Down Expand Up @@ -141,8 +145,6 @@ open class Chameleon(context: Context?, attrs: AttributeSet?) : ConstraintLayout
val constraintSet = ConstraintSet()
constraintSet.clone(this)

// constraintSet.connect(R.id.tv)

constraintSet.connect(R.id.iv_state, TOP, PARENT_ID, TOP)
constraintSet.connect(R.id.iv_state, START, PARENT_ID, START)
constraintSet.connect(R.id.iv_state, BOTTOM, R.id.tv_title_state, TOP, 4.DP(context).toInt())
Expand Down Expand Up @@ -201,12 +203,11 @@ open class Chameleon(context: Context?, attrs: AttributeSet?) : ConstraintLayout
}

private fun initStateTitleTextView() {
val padding = 8.DP(context).toInt()
val padding = 32.DP(context).toInt()
stateTitleTextView = AppCompatTextView(context)
stateTitleTextView?.apply {
id = R.id.tv_title_state
setPadding(padding, 0, padding, 0)
maxLines = 1
ellipsize = TextUtils.TruncateAt.END
visibility = View.GONE
}
Expand All @@ -218,12 +219,11 @@ open class Chameleon(context: Context?, attrs: AttributeSet?) : ConstraintLayout
}

private fun initStateSubTextView() {
val padding = 8.DP(context).toInt()
val padding = 32.DP(context).toInt()
stateSubTextView = AppCompatTextView(context)
stateSubTextView?.apply {
id = R.id.tv_sub_state
setPadding(padding, 0, padding, 0)
maxLines = 1
ellipsize = TextUtils.TruncateAt.END
visibility = View.GONE
}
Expand Down Expand Up @@ -289,8 +289,8 @@ open class Chameleon(context: Context?, attrs: AttributeSet?) : ConstraintLayout
chameleonAttr?.let {
setStateImageView(it.errorDrawable
?: R.drawable.ic_chameleon_error.getDrawable(context))
setStateTitleTextView(it.errorText, it.errorTextSize, it.errorTextColor)
setStateSubTextView(it.errorSubText, it.errorSubTextSize, it.errorSubTextColor)
setStateTitleTextView(it.errorText, it.errorTextSize, it.errorTextColor, it.errorTextGravity)
setStateSubTextView(it.errorSubText, it.errorSubTextSize, it.errorSubTextColor, it.errorSubTextGravity)

if (it.useErrorButton)
setStateButton(it.errorButtonText,
Expand All @@ -312,8 +312,8 @@ open class Chameleon(context: Context?, attrs: AttributeSet?) : ConstraintLayout
chameleonAttr?.let {
setStateImageView(it.emptyDrawable
?: R.drawable.ic_chameleon_empty.getDrawable(context))
setStateTitleTextView(it.emptyText, it.emptyTextSize, it.emptyTextColor)
setStateSubTextView(it.emptySubText, it.emptySubTextSize, it.emptySubTextColor)
setStateTitleTextView(it.emptyText, it.emptyTextSize, it.emptyTextColor, it.emptyTextGravity)
setStateSubTextView(it.emptySubText, it.emptySubTextSize, it.emptySubTextColor, it.emptySubTextGravity)
if (it.useEmptyButton)
setStateButton(it.emptyButtonText,
it.emptyButtonTextSize,
Expand Down Expand Up @@ -358,16 +358,18 @@ open class Chameleon(context: Context?, attrs: AttributeSet?) : ConstraintLayout
stateImageView?.setImageDrawable(drawable)
}

private fun setStateTitleTextView(content: String, size: Float, color: Int) {
private fun setStateTitleTextView(content: String, size: Float, color: Int, gravity: Int) {
stateTitleTextView?.apply {
this.gravity = gravity
text = content
setTextSize(TypedValue.COMPLEX_UNIT_PX, size)
setTextColor(color)
}
}

private fun setStateSubTextView(content: String, size: Float, color: Int) {
private fun setStateSubTextView(content: String, size: Float, color: Int, gravity: Int) {
stateSubTextView?.apply {
this.gravity = gravity
text = content
setTextSize(TypedValue.COMPLEX_UNIT_PX, size)
setTextColor(color)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,31 @@ import xyz.sangcomz.chameleon.Chameleon
data class ChameleonAttr(var emptyText: String,
var emptyTextColor: Int,
var emptyTextSize: Float,
var emptyTextGravity: Int,
var emptySubText: String,
var emptySubTextColor: Int,
var emptySubTextSize: Float,
var emptySubTextGravity: Int,
var emptyDrawable: Drawable?,
var emptyButtonText: String,
var emptyButtonTextColor: Int,
var emptyButtonTextSize: Float,
var emptyButtonBackgroundColor: Int,
var useEmptyButton:Boolean,
var useEmptyButton: Boolean,
var errorText: String,
var errorTextColor: Int,
var errorTextSize: Float,
var errorTextGravity: Int,
var errorSubText: String,
var errorSubTextColor: Int,
var errorSubTextSize: Float,
var errorSubTextGravity: Int,
var errorDrawable: Drawable?,
var errorButtonText: String,
var errorButtonTextColor: Int,
var errorButtonTextSize: Float,
var errorButtonBackgroundColor: Int,
var useErrorButton:Boolean,
var useErrorButton: Boolean,
var progressDrawable: Drawable?,
var isLargeProgress: Boolean,
var defaultState: Chameleon.STATE
Expand Down
73 changes: 69 additions & 4 deletions chameleon/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<attr name="emptyText" format="string" />
<attr name="emptyTextColor" format="color" />
<attr name="emptyTextSize" format="dimension" />

<attr name="emptySubText" format="string" />
<attr name="emptySubTextColor" format="color" />
<attr name="emptySubTextSize" format="dimension" />
Expand Down Expand Up @@ -40,8 +41,72 @@
<enum name="CONTENT" value="5" />
</attr>

<!--<attr name="sectionBackgroundColor" format="color" />-->
<!--<attr name="timeLineWidth" format="dimension" />-->
<!--<attr name="isSticky" format="boolean" />-->
<attr name="emptyTextGravity" format="enum">
<enum name="center" value="17" />
<enum name="center_horizontal" value="1" />
<enum name="center_vertical" value="16" />
<enum name="bottom" value="80" />
<enum name="clip_horizontal" value="8" />
<enum name="clip_vertical" value="128" />
<enum name="end" value="8388613" />
<enum name="fill" value="119" />
<enum name="fill_horizontal" value="7" />
<enum name="fill_vertical" value="7" />
<enum name="left" value="3" />
<enum name="right" value="5" />
<enum name="start" value="8388611" />
<enum name="top" value="48" />
</attr>

<attr name="emptySubTextGravity" format="enum">
<enum name="center" value="17" />
<enum name="center_horizontal" value="1" />
<enum name="center_vertical" value="16" />
<enum name="bottom" value="80" />
<enum name="clip_horizontal" value="8" />
<enum name="clip_vertical" value="128" />
<enum name="end" value="8388613" />
<enum name="fill" value="119" />
<enum name="fill_horizontal" value="7" />
<enum name="fill_vertical" value="7" />
<enum name="left" value="3" />
<enum name="right" value="5" />
<enum name="start" value="8388611" />
<enum name="top" value="48" />
</attr>

<attr name="errorTextGravity" format="enum">
<enum name="center" value="17" />
<enum name="center_horizontal" value="1" />
<enum name="center_vertical" value="16" />
<enum name="bottom" value="80" />
<enum name="clip_horizontal" value="8" />
<enum name="clip_vertical" value="128" />
<enum name="end" value="8388613" />
<enum name="fill" value="119" />
<enum name="fill_horizontal" value="7" />
<enum name="fill_vertical" value="7" />
<enum name="left" value="3" />
<enum name="right" value="5" />
<enum name="start" value="8388611" />
<enum name="top" value="48" />
</attr>

<attr name="errorSubTextGravity" format="enum">
<enum name="center" value="17" />
<enum name="center_horizontal" value="1" />
<enum name="center_vertical" value="16" />
<enum name="bottom" value="80" />
<enum name="clip_horizontal" value="8" />
<enum name="clip_vertical" value="128" />
<enum name="end" value="8388613" />
<enum name="fill" value="119" />
<enum name="fill_horizontal" value="7" />
<enum name="fill_vertical" value="7" />
<enum name="left" value="3" />
<enum name="right" value="5" />
<enum name="start" value="8388611" />
<enum name="top" value="48" />
</attr>
</declare-styleable>
</resources>
</resources>
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include ':app', ':chameleon'

gradle.ext.set('versionCode', 7)
gradle.ext.set('versionName', '0.0.7')
gradle.ext.set('versionCode', 8)
gradle.ext.set('versionName', '0.1.0')

gradle.ext.set('minSdk', 15)
gradle.ext.set('targetSdk', 27)
Expand Down

0 comments on commit c4c41fe

Please sign in to comment.