Skip to content

Commit

Permalink
Adding tags into new discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
edTheGuy00 committed Feb 17, 2018
1 parent d1e45ce commit dc53832
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
42 changes: 38 additions & 4 deletions app/src/main/java/com/taskail/mixion/post/TagChipsAdapter.kt
@@ -1,6 +1,7 @@
package com.taskail.mixion.post

import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -14,12 +15,27 @@ import kotlinx.android.synthetic.main.layout_chip_tags.view.*

class TagChipsAdapter : RecyclerView.Adapter<TagsViewHolder>() {

var tags = mutableListOf("Tag")
var tags = mutableListOf<String>()

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

fun setTag(tag: String){
fun setTag(tag: String, position: Int, remove: (Int) -> Unit){
itemView.chip_tag.text = tag
itemView.chip_action.setImageResource(R.drawable.ic_trashcan_delete_12dp)

itemView.setOnClickListener {
Log.d("Chip Adapter", "Delete this tag")
remove(position.minus(1))
}
}

fun setAddNewTag(add: (String) -> Unit) {
itemView.chip_tag.setText(R.string.add_tags)
itemView.chip_action.setImageResource(R.drawable.ic_add_12dp)

itemView.setOnClickListener {
add("steemit")
}
}
}

Expand All @@ -32,10 +48,28 @@ class TagChipsAdapter : RecyclerView.Adapter<TagsViewHolder>() {
}

override fun onBindViewHolder(holder: TagsViewHolder?, position: Int) {
holder?.setTag(tags[position])
when (position){
0 -> holder?.setAddNewTag(
{
if (tags.size < 5){
tags.add(it)
.also { this.notifyDataSetChanged() }
} else {
Log.d("Chip recycler", "reached limit")
}
})
else -> holder?.setTag(tags[position.minus(1)],
position,
{
tags.removeAt(it)
.also { this.notifyDataSetChanged() }
})
}
}

override fun getItemCount(): Int {
return tags.size
var count = 1
count += tags.size
return count
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -38,4 +38,5 @@
<string name="post">Post</string>
<string name="preview">Preview</string>
<string name="chip_action">Chip Action</string>
<string name="add_tags">Add tags</string>
</resources>

0 comments on commit dc53832

Please sign in to comment.