Display attachments that will be sent in scheduled message

This commit is contained in:
Moez Bhatti
2018-06-30 17:11:39 -04:00
parent 45745339b9
commit e4bb5b3190
7 changed files with 100 additions and 8 deletions
@@ -29,6 +29,7 @@ class ScheduledActivity : QkThemedActivity(), ScheduledView {
showBackButton(true)
viewModel.bindView(this)
dialog.title = getString(R.string.scheduled_options_title)
dialog.adapter.setData(R.array.scheduled_options)
messageAdapter.emptyView = empty
@@ -1,8 +1,11 @@
package com.moez.QKSMS.feature.scheduled
import android.net.Uri
import android.telephony.PhoneNumberUtils
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkRealmAdapter
import com.moez.QKSMS.common.base.QkViewHolder
@@ -25,11 +28,17 @@ class ScheduledMessageAdapter @Inject constructor(
private val contacts by lazy { contactRepo.getContacts() }
private val contactMap: HashMap<String, Contact> = hashMapOf()
private val imagesViewPool = RecyclerView.RecycledViewPool()
val clicks: Subject<Long> = PublishSubject.create()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
return QkViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.scheduled_message_list_item, parent, false))
val view = LayoutInflater.from(parent.context).inflate(R.layout.scheduled_message_list_item, parent, false)
view.attachments.adapter = ScheduledMessageAttachmentAdapter()
view.attachments.setRecycledViewPool(imagesViewPool)
return QkViewHolder(view)
}
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
@@ -55,6 +64,10 @@ class ScheduledMessageAdapter @Inject constructor(
view.date.text = dateFormatter.getScheduledTimestamp(message.date)
view.body.text = message.body
val adapter = view.attachments.adapter as ScheduledMessageAttachmentAdapter
adapter.data = message.attachments.map(Uri::parse)
view.attachments.isVisible = message.attachments.isNotEmpty()
}
}
@@ -0,0 +1,29 @@
package com.moez.QKSMS.feature.scheduled
import android.net.Uri
import android.view.LayoutInflater
import android.view.ViewGroup
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkAdapter
import com.moez.QKSMS.common.base.QkViewHolder
import com.moez.QKSMS.common.util.GlideApp
import kotlinx.android.synthetic.main.attachment_list_item.view.*
import javax.inject.Inject
class ScheduledMessageAttachmentAdapter @Inject constructor() : QkAdapter<Uri>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.scheduled_message_image_list_item, parent, false)
view.thumbnail.clipToOutline = true
return QkViewHolder(view)
}
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
val attachment = getItem(position)
val view = holder.itemView
GlideApp.with(view).load(attachment).into(view.thumbnail)
}
}
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?><!--
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
~
~ This file is part of QKSMS.
@@ -51,7 +52,7 @@
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar"
tools:listitem="@layout/blocked_list_item" />
tools:listitem="@layout/scheduled_message_list_item" />
<View
android:layout_width="match_parent"
@@ -0,0 +1,36 @@
<?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/>.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginEnd="8dp">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="@drawable/rounded_rectangle_4dp"
android:backgroundTint="?android:attr/divider"
android:scaleType="centerCrop"
tools:src="@tools:sample/backgrounds/scenic" />
</FrameLayout>
@@ -25,10 +25,7 @@
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="12dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingTop="12dp">
android:padding="16dp">
<com.moez.QKSMS.common.widget.GroupAvatarView
android:id="@+id/avatars"
@@ -70,10 +67,24 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/recipients"
app:layout_constraintTop_toBottomOf="@id/date"
tools:text="@tools:sample/lorem/random" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/attachments"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:nestedScrollingEnabled="false"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="@id/recipients"
app:layout_constraintTop_toBottomOf="@id/body"
tools:listitem="@layout/scheduled_message_image_list_item" />
</androidx.constraintlayout.widget.ConstraintLayout>
@@ -137,6 +137,7 @@
<string name="scheduled_title">Scheduled</string>
<string name="scheduled_empty_text">Your scheduled messages will appear here</string>
<string name="scheduled_options_title">Scheduled message</string>
<string-array name="scheduled_options">
<item>Send now</item>
<item>Delete</item>