Skip to content

Commit

Permalink
Create Add tags dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
edTheGuy00 committed Feb 17, 2018
1 parent dc53832 commit 7828db3
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 5 deletions.
37 changes: 37 additions & 0 deletions app/src/main/java/com/taskail/mixion/dialog/EnterTagDialog.kt
@@ -0,0 +1,37 @@
package com.taskail.mixion.dialog

import android.content.Context
import android.os.Bundle
import android.support.v7.app.AppCompatDialog
import com.taskail.mixion.R
import com.taskail.mixion.ui.TextInputValidator
import kotlinx.android.synthetic.main.dialog_enter_tag.*

/**
*Created by ed on 2/17/18.
*/

class EnterTagDialog(context: Context,
private val addTag: (String) -> Unit) : AppCompatDialog(context){

init {
setContentView(R.layout.dialog_enter_tag)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

TextInputValidator({
submitTagBtn.isEnabled = it
}, tag_input)

submitTagBtn.setOnClickListener {
addTag(getTag())
this.dismiss()
}
}

private fun getTag(): String{
return tag_input.editText?.text.toString().toLowerCase()
}
}
Expand Up @@ -33,7 +33,7 @@ class EditPostFragment : Fragment(){
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_new_post_edit_body, container, false)

tagsAdapter = TagChipsAdapter()
tagsAdapter = TagChipsAdapter(context!!)

return view
}
Expand Down
20 changes: 16 additions & 4 deletions app/src/main/java/com/taskail/mixion/post/TagChipsAdapter.kt
@@ -1,23 +1,26 @@
package com.taskail.mixion.post

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import com.taskail.mixion.R
import com.taskail.mixion.dialog.EnterTagDialog
import com.taskail.mixion.post.TagChipsAdapter.TagsViewHolder
import kotlinx.android.synthetic.main.layout_chip_tags.view.*

/**
*Created by ed on 2/16/18.
*/

class TagChipsAdapter : RecyclerView.Adapter<TagsViewHolder>() {
class TagChipsAdapter(private val context: Context) : RecyclerView.Adapter<TagsViewHolder>() {

var tags = mutableListOf<String>()

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

fun setTag(tag: String, position: Int, remove: (Int) -> Unit){
itemView.chip_tag.text = tag
Expand All @@ -29,14 +32,23 @@ class TagChipsAdapter : RecyclerView.Adapter<TagsViewHolder>() {
}
}

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

itemView.setOnClickListener {
add("steemit")
if (tags.size < 5)
showDialog(addTag)
else
Toast.makeText(context, "Only 5 Tags Allowed", Toast.LENGTH_LONG).show()
}
}

}

private fun showDialog(add: (String) -> Unit){
EnterTagDialog(context, add)
.show()
}

override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): TagsViewHolder {
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/res/layout/dialog_enter_tag.xml
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:orientation="vertical"
android:padding="4dp"
android:layout_height="wrap_content">

<android.support.design.widget.TextInputLayout
android:id="@+id/tag_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/enter_tag">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:imeOptions="flagNoExtractUi"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>

<TextView
android:id="@+id/submitTagBtn"
style="@style/App.Button.Login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:text="@string/submit"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"/>

</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -39,4 +39,6 @@
<string name="preview">Preview</string>
<string name="chip_action">Chip Action</string>
<string name="add_tags">Add tags</string>
<string name="enter_tag">Enter Tag</string>
<string name="submit">Submit</string>
</resources>

0 comments on commit 7828db3

Please sign in to comment.