Skip to content

Commit

Permalink
Setup recyclerview and adapter for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
edTheGuy00 committed Feb 17, 2018
1 parent 1ea4409 commit d1e45ce
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 5 deletions.
24 changes: 23 additions & 1 deletion app/src/main/java/com/taskail/mixion/post/EditPostFragment.kt
Expand Up @@ -2,6 +2,8 @@ package com.taskail.mixion.post

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.*
import com.taskail.mixion.R
import com.taskail.mixion.markortexteditor.highlighter.HighlightingEditor
Expand All @@ -25,27 +27,47 @@ class EditPostFragment : Fragment(){
lateinit var textFormat: TextFormat
lateinit var textModuleActionBar: ViewGroup
lateinit var hlEditor: HighlightingEditor
lateinit var tagsAdapter: TagChipsAdapter
lateinit var tagsRecyclerView: RecyclerView

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()

return view
}


override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

textModuleActionBar = edit_post_action_bar
textFormat = TextFormat.getFormat(TextFormat.FORMAT_MARKDOWN, activity)
hlEditor = document__fragment__edit__highlighting_editor
setupHlEditor()
tagsRecyclerView = tag_chip_recyclerView
setupTagsRecycler()

}

private fun setupHlEditor(){
hlEditor.setHighlighter(textFormat.highlighter)
textFormat.textModuleActions
.setHighlightingEditor(hlEditor)
.appendTextModuleActionsToBar(textModuleActionBar)
}

private fun setupTagsRecycler(){
tagsRecyclerView.layoutManager = LinearLayoutManager(context,
LinearLayoutManager.HORIZONTAL, true)

tagsRecyclerView.adapter = tagsAdapter
}

fun getBody(): String{
return hlEditor.text.toString()
}

fun getTags(): Array<String>{
return tagsAdapter.tags.toTypedArray()
}
}
41 changes: 41 additions & 0 deletions app/src/main/java/com/taskail/mixion/post/TagChipsAdapter.kt
@@ -0,0 +1,41 @@
package com.taskail.mixion.post

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.taskail.mixion.R
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>() {

var tags = mutableListOf("Tag")

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

fun setTag(tag: String){
itemView.chip_tag.text = tag
}
}

override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): TagsViewHolder {
val itemView = LayoutInflater.from(parent?.context)
.inflate(R.layout.layout_chip_tags,
parent, false)

return TagsViewHolder(itemView)
}

override fun onBindViewHolder(holder: TagsViewHolder?, position: Int) {
holder?.setTag(tags[position])
}

override fun getItemCount(): Int {
return tags.size
}
}
File renamed without changes.
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/ic_add_12dp.xml
@@ -0,0 +1,4 @@
<vector android:height="12dp" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="12dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFF" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM17,13h-4v4h-2v-4L7,13v-2h4L11,7h2v4h4v2z"/>
</vector>
6 changes: 6 additions & 0 deletions app/src/main/res/layout/fragment_new_post_edit_body.xml
Expand Up @@ -8,6 +8,12 @@
android:orientation="vertical"
tools:showIn="@layout/activity_create_post">

<android.support.v7.widget.RecyclerView
android:id="@+id/tag_chip_recyclerView"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content"/>

<ScrollView
android:id="@+id/edit_body_scrollView"
android:layout_width="match_parent"
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/res/layout/layout_chip_tags.xml
@@ -1,17 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/categoriesChipLayout"
android:clickable="true"
android:focusable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="10dp"
android:background="@drawable/chip_shape"
android:visibility="visible"
xmlns:android="http://schemas.android.com/apk/res/android">
android:visibility="visible">
<TextView
android:id="@+id/categoriesChipText"
android:id="@+id/chip_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
Expand All @@ -23,7 +25,7 @@
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="6dp"
android:src="@drawable/ic_trashcan_delete_12dp"
android:src="@drawable/ic_add_12dp"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/chip_action" />

Expand Down

0 comments on commit d1e45ce

Please sign in to comment.