Add compose layout for qk reply

This commit is contained in:
Moez Bhatti
2018-03-28 02:56:02 -04:00
parent 52cfe44497
commit c3b275aba3
3 changed files with 146 additions and 4 deletions
@@ -18,8 +18,10 @@
*/
package feature.qkreply
import android.content.res.ColorStateList
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager
@@ -30,6 +32,7 @@ import common.base.QkThemedActivity
import common.util.extensions.setBackgroundTint
import feature.compose.MessagesAdapter
import injection.appComponent
import io.reactivex.rxkotlin.Observables
import kotlinx.android.synthetic.main.qkreply_activity.*
import javax.inject.Inject
@@ -53,20 +56,61 @@ class QkReplyActivity : QkThemedActivity<QkReplyViewModel>(), QkReplyView {
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewModel.bindView(this)
colors.composeBackground
colors.background
.doOnNext { color -> background.setBackgroundTint(color) }
.doOnNext { color -> composeGradient.setBackgroundTint(color) }
.doOnNext { color -> composeBackground.setBackgroundTint(color) }
.autoDisposable(scope())
.subscribe { color -> background.setBackgroundTint(color) }
.subscribe()
theme
.autoDisposable(scope())
.subscribe { color -> send.setBackgroundTint(color) }
val states = arrayOf(
intArrayOf(android.R.attr.state_enabled),
intArrayOf(-android.R.attr.state_enabled))
val iconEnabled = threadId
.distinctUntilChanged()
.switchMap { threadId -> colors.textPrimaryOnThemeForConversation(threadId) }
val iconDisabled = threadId
.distinctUntilChanged()
.switchMap { threadId -> colors.textTertiaryOnThemeForConversation(threadId) }
Observables
.combineLatest(iconEnabled, iconDisabled, { primary, tertiary ->
ColorStateList(states, intArrayOf(primary, tertiary))
})
.autoDisposable(scope())
.subscribe { tintList -> send.imageTintList = tintList }
toolbar.clipToOutline = true
val layoutManager = LinearLayoutManager(this).apply { stackFromEnd = true }
adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
if (positionStart > 0) {
adapter.notifyItemChanged(positionStart - 1)
}
// If we're at the bottom, scroll down to show new messages
val lastVisiblePosition = layoutManager.findLastCompletelyVisibleItemPosition()
if (positionStart >= adapter.itemCount - 1 && lastVisiblePosition == positionStart - 1) {
messages.scrollToPosition(positionStart)
}
}
})
messages.layoutManager = layoutManager
messages.adapter = adapter
}
override fun render(state: QkReplyState) {
title = state.title
threadId.onNext(state.data?.first?.id ?: 0)
adapter.data = state.data
}
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
~
~ This file is part of QKSMS.
~
~ QKSMS is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ QKSMS is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/white" />
<corners
android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp" />
</shape>
</item>
</layer-list>
@@ -41,10 +41,79 @@
android:paddingBottom="8dp"
android:paddingTop="8dp"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/message"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" />
app:layout_constraintTop_toBottomOf="@id/toolbar"
tools:listitem="@layout/message_list_item_in" />
<View
android:id="@+id/composeBackground"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@drawable/rounded_rectangle_bottom_4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="@id/message"
tools:backgroundTint="@color/white" />
<View
android:id="@+id/composeGradient"
android:layout_width="match_parent"
android:layout_height="8dp"
android:background="@drawable/compose_bar_background"
app:layout_constraintBottom_toTopOf="@id/message"
tools:backgroundTint="@color/white" />
<common.widget.QkEditText
android:id="@+id/message"
style="@style/TextPrimary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:gravity="center_vertical"
android:hint="@string/compose_hint"
android:inputType="textLongMessage|textCapSentences|textMultiLine"
android:maxLines="6"
android:minHeight="44dp"
android:paddingBottom="8dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingTop="8dp"
app:layout_constraintBottom_toBottomOf="@id/send"
app:layout_constraintEnd_toEndOf="@id/messageBackground"
app:layout_constraintEnd_toStartOf="@id/send"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/messages"
app:textColorHint="tertiary" />
<common.widget.QkTextView
android:id="@+id/counter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:gravity="center"
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="@id/send"
app:layout_constraintEnd_toEndOf="@id/send"
app:layout_constraintStart_toStartOf="@id/send"
app:textColor="secondary"
tools:text="108 / 2" />
<ImageView
android:id="@+id/send"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:background="@drawable/circle"
android:elevation="4dp"
android:padding="10dp"
android:src="@drawable/ic_send_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:backgroundTint="@color/tools_theme"
tools:tint="@color/textPrimaryDark" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"