Commit 81005547 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Set top decorator for suggestions menu

parent a2ee46cf
package chat.rocket.android.widget.autocompletion.ui package chat.rocket.android.widget.autocompletion.ui
import android.content.Context import android.content.Context
import android.graphics.Canvas
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.support.annotation.DrawableRes
import android.support.transition.Slide import android.support.transition.Slide
import android.support.transition.TransitionManager import android.support.transition.TransitionManager
import android.support.v4.content.ContextCompat
import android.support.v7.widget.DefaultItemAnimator import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
...@@ -14,6 +19,7 @@ import android.view.Gravity ...@@ -14,6 +19,7 @@ import android.view.Gravity
import android.view.View import android.view.View
import android.widget.EditText import android.widget.EditText
import android.widget.FrameLayout import android.widget.FrameLayout
import chat.rocket.android.R
import chat.rocket.android.widget.autocompletion.model.SuggestionModel import chat.rocket.android.widget.autocompletion.model.SuggestionModel
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
...@@ -43,6 +49,7 @@ class SuggestionsView : FrameLayout, TextWatcher { ...@@ -43,6 +49,7 @@ class SuggestionsView : FrameLayout, TextWatcher {
val layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, val layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL,
false) false)
recyclerView.itemAnimator = DefaultItemAnimator() recyclerView.itemAnimator = DefaultItemAnimator()
recyclerView.addItemDecoration(TopItemDecoration(context, R.drawable.suggestions_menu_decorator))
recyclerView.layoutManager = layoutManager recyclerView.layoutManager = layoutManager
recyclerView.visibility = View.GONE recyclerView.visibility = View.GONE
addView(recyclerView) addView(recyclerView)
...@@ -191,4 +198,29 @@ class SuggestionsView : FrameLayout, TextWatcher { ...@@ -191,4 +198,29 @@ class SuggestionsView : FrameLayout, TextWatcher {
TransitionManager.beginDelayedTransition(this, SLIDE_TRANSITION) TransitionManager.beginDelayedTransition(this, SLIDE_TRANSITION)
recyclerView.visibility = View.VISIBLE recyclerView.visibility = View.VISIBLE
} }
private class TopItemDecoration() : RecyclerView.ItemDecoration() {
private lateinit var divider: Drawable
private val padding = Rect()
// Custom divider will be used.
constructor(context: Context, @DrawableRes drawableResId: Int) : this() {
val customDrawable = ContextCompat.getDrawable(context, drawableResId)
if (customDrawable != null) {
divider = customDrawable
}
}
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
val left = parent.paddingLeft
val right = (parent.width - parent.paddingRight)
val parentParams = parent.layoutParams as FrameLayout.LayoutParams
val top = parent.top - parentParams.topMargin - parent.paddingTop
val bottom = top + divider.intrinsicHeight
divider.setBounds(left, top, right, bottom)
divider.draw(c)
}
}
} }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#10000000" />
<corners android:radius="5dp" />
<size android:height="2dp" />
</shape>
\ No newline at end of file
...@@ -4,7 +4,12 @@ ...@@ -4,7 +4,12 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="2dp" android:layout_marginBottom="2dp"
android:layout_marginEnd="2dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"
android:layout_marginStart="4dp"
android:layout_marginTop="2dp"
android:background="@color/suggestion_background_color"> android:background="@color/suggestion_background_color">
<FrameLayout <FrameLayout
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment