Skip to content

Commit

Permalink
Merge branch 'release/0.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
sangcomz committed Mar 28, 2018
2 parents 5180933 + 8b8ed79 commit 2a1426e
Show file tree
Hide file tree
Showing 65 changed files with 1,405 additions and 128 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
/build
/captures
.externalNativeBuild
/.idea/
/release/

/app/release/
33 changes: 0 additions & 33 deletions .idea/misc.xml

This file was deleted.

136 changes: 136 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@

# Chameleoen


<img src="/pic/logo.png" width = 20%>

[![](https://jitpack.io/v/sangcomz/chameleon.svg)](https://jitpack.io/#sangcomz/chameleon)

Chameleoen deals with the Status of RecyclerView.

## How to Use

### Gradle
```groovy
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
compile 'com.github.sangcomz:Chameleon:v0.0.1'
}
```
### Usage
```xml
<xyz.sangcomz.chameleon.Chameleon xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
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: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"
tools:context="xyz.sangcomz.chameleonsample.MainActivity">

<android.support.v7.widget.RecyclerView
android:id="@+id/rv_main_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</xyz.sangcomz.chameleon.Chameleon>
```

#### STATUS
| Status | Description |
|:--------:|------------------|
| CONTENT | show content |
| LOADING | show progress  |
| EMPTY | show empty view |
| ERROR | show error view |

##### usage
```kotlin
chameleon.showState(Chameleon.STATE.CONTENT)
chameleon.showState(Chameleon.STATE.LOADING)
chameleon.showState(Chameleon.STATE.EMPTY)
chameleon.showState(Chameleon.STATE.ERROR)

chameleon.setEmptyButtonClickListener { Toast.makeText(this, "Empty Button!", Toast.LENGTH_LONG).show() }
chameleon.setErrorButtonClickListener { Toast.makeText(this, "Error Button!", Toast.LENGTH_LONG).show() }
```

#### attribute

|      Attribute Name       | Description                               |   Default Value   |
|:--------------------------:|-------------------------------------------|:-------------------:|
| emptyText | empty view Change text | "empty" |
| emptyTextColor | empty view Change text color | #808080 |
| emptyTextSize | empty view Change text size | 24sp |
| emptySubText | empty view Change sub text | "empty content" |
| emptySubTextColor | empty view Change sub text color | #b7b7b7 |
| emptySubTextSize | empty view Change sub text size | 16sp |
| emptyDrawable | empty view Change drawable | R.drawable.ic_empty |
| emptyButtonText | empty view Change button text | "retry" |
| emptyButtonTextColor | empty view Change button text color | #808080 |
| emptyButtonTextSize | empty view Change button text size | 24sp |
| emptyButtonBackgroundColor | empty view Change button background color | #b7b7b7 |
| useEmptyButton | Change whether to use empty view Button | false |
| errorText | error view Change text | "error" |
| errorTextColor | error view Change text color | #808080 |
| errorTextSize | error view Change text size | 24sp |
| errorSubText | error view Change sub text | "error content" |
| errorSubTextColor | error view Change sub text color | #b7b7b7 |
| errorSubTextSize | error view Change sub text size | 16sp |
| errorDrawable | error view Change drawable | R.drawable.ic_error |
| errorButtonText | error view Change button text | "retry" |
| errorButtonTextColor | error view Change button text color | #808080 |
| errorButtonTextSize | error view Change button text size | 24sp |
| errorButtonBackgroundColor | error view Change button background color | #808080 |
| useErrorButton | Change whether to use error view Button | false |
| progressDrawable | progress drawable setting | - |
| isLargeProgress | Whether to use large progress | false |


## Result Screen

| Project Name | Result Screen |
|:---------:|---|
| Sample <p style="float:left;"> <a href="https://play.google.com/store/apps/details?id=xyz.sangcomz.chameleonsample"> <img HEIGHT="40" WIDTH="135" alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/images/apps/en-play-badge.png" /></a></p> | <img src="/pic/sample.gif"> |

# Contribute
We welcome any contributions.

# Inspired by
* [Kennyc1012/MultiStateView](https://github.com/Kennyc1012/MultiStateView), I was inspired by his code.

# License

Copyright 2018 Jeong Seok-Won

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
41 changes: 31 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
signingConfigs {
if (project.rootProject.file('release/sign.properties').exists()) {
Properties signProp = new Properties()
signProp.load(project.rootProject.file('release/sign.properties').newDataInputStream())
config {
keyAlias signProp.get("alias") ? signProp.get("alias") : ""
keyPassword signProp.get("alias_password") ? signProp.get("alias_password") : ""
storeFile rootProject.file("release/key.jks")
storePassword signProp.get("password") ? signProp.get("password") : ""
v2SigningEnabled true
}
}
}

compileSdkVersion gradle.compileSdk
defaultConfig {
applicationId "xyz.sangcomz.chameleonsample"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
minSdkVersion gradle.minSdk
targetSdkVersion gradle.targetSdk
versionName gradle.versionName
versionCode gradle.versionCode

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (project.rootProject.file('release/sign.properties').exists()) {
signingConfig signingConfigs.config
}
}

debug {
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support.constraint:constraint-layout:$constraint_version"
project (':chameleon')
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'xyz.sangcomz:dalcomz:0.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation project(':chameleon')
}
Binary file modified app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/src/main/java/xyz/sangcomz/chameleonsample/Chameleon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package xyz.sangcomz.chameleonsample

/**
* Created by sangcomz on 27/03/2018.
*/
data class Chameleon(val petName: String,
val drawableId: Int)
50 changes: 50 additions & 0 deletions app/src/main/java/xyz/sangcomz/chameleonsample/ChameleonAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package xyz.sangcomz.chameleonsample

import android.support.v7.widget.AppCompatImageView
import android.support.v7.widget.AppCompatTextView
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.squareup.picasso.Picasso

/**
* Created by sangcomz on 27/03/2018.
*/
class ChameleonAdapter : RecyclerView.Adapter<ChameleonAdapter.ViewHolder>() {
private var chameleonList: List<Chameleon> = arrayListOf()

fun setChameleonList(chameleonList: List<Chameleon>) {
this.chameleonList = chameleonList
notifyDataSetChanged()
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_chamelon, parent, false)
)
}

override fun getItemCount(): Int = chameleonList.size

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.setItem(chameleonList[position])
}


class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

private val ivItemChameleon = itemView.findViewById<AppCompatImageView>(R.id.iv_item_chameleon)
private val tvItemChameleon = itemView.findViewById<AppCompatTextView>(R.id.tv_item_chameleon)

fun setItem(chameleon: Chameleon) {
Picasso.get()
.load(chameleon.drawableId)
.fit()
.centerCrop()
.into(ivItemChameleon)
tvItemChameleon.text = chameleon.petName
}

}
}
55 changes: 55 additions & 0 deletions app/src/main/java/xyz/sangcomz/chameleonsample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,66 @@ package xyz.sangcomz.chameleonsample

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.DividerItemDecoration
import android.support.v7.widget.LinearLayoutManager
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import io.reactivex.android.schedulers.AndroidSchedulers
import kotlinx.android.synthetic.main.activity_main.*
import xyz.sangcomz.chameleon.Chameleon
import java.util.concurrent.TimeUnit

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
root.setEmptyButtonClickListener { Toast.makeText(this, "Empty Button!", Toast.LENGTH_LONG).show() }
root.setErrorButtonClickListener { Toast.makeText(this, "Error Button!", Toast.LENGTH_LONG).show() }
setChameleonList()
}

private fun setChameleonList() {
root.showState(Chameleon.STATE.LOADING)
rv_main_list.adapter = ChameleonAdapter()
rv_main_list.layoutManager = LinearLayoutManager(this)
rv_main_list.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
getChameleons()
.delay(3000, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
(rv_main_list.adapter as? ChameleonAdapter)?.setChameleonList(it)
root.showState(Chameleon.STATE.CONTENT)
},
{
root.showState(Chameleon.STATE.ERROR)
})


}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.main_menu, menu)
return super.onCreateOptionsMenu(menu)
}

override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.menu_content -> {
root.showState(Chameleon.STATE.CONTENT)
}
R.id.menu_loading -> {
root.showState(Chameleon.STATE.LOADING)
}
R.id.menu_empty -> {
root.showState(Chameleon.STATE.EMPTY)
}
R.id.menu_error -> {
root.showState(Chameleon.STATE.ERROR)
}
}
return super.onOptionsItemSelected(item)
}
}
Loading

0 comments on commit 2a1426e

Please sign in to comment.