#1069 - Add ability to take photo from app

This commit is contained in:
Moez Bhatti
2018-04-23 00:26:54 -04:00
parent d48a759ef8
commit e8c8b0aaee
7 changed files with 104 additions and 5 deletions
@@ -67,6 +67,8 @@ class ComposeActivity : QkThemedActivity<ComposeViewModel>(), ComposeView {
override val attachmentDeletedIntent: Subject<Uri> by lazy { attachmentAdapter.attachmentDeleted }
override val textChangedIntent by lazy { message.textChanges() }
override val attachIntent by lazy { attach.clicks() }
override val cameraIntent by lazy { camera.clicks() }
override val galleryIntent by lazy { gallery.clicks() }
override val sendIntent by lazy { send.clicks() }
@Inject lateinit var chipsAdapter: ChipsAdapter
@@ -129,7 +131,11 @@ class ComposeActivity : QkThemedActivity<ComposeViewModel>(), ComposeView {
colors.textSecondary
.autoDisposable(scope())
.subscribe { color -> attach.setTint(color) }
.subscribe { color ->
attach.setTint(color)
camera.setTint(color)
gallery.setTint(color)
}
colors.bubble
.autoDisposable(scope())
@@ -189,6 +195,10 @@ class ComposeActivity : QkThemedActivity<ComposeViewModel>(), ComposeView {
attachments.setVisible(state.attachments.isNotEmpty())
attachmentAdapter.data = state.attachments
attach.animate().rotation(if (state.attaching) 45f else 0f).start()
camera.setVisible(state.attaching)
gallery.setVisible(state.attaching)
if (title != state.title) title = state.title
counter.text = state.remaining
@@ -34,6 +34,7 @@ data class ComposeState(
val title: String = "",
val messages: Pair<Conversation, RealmResults<Message>>? = null,
val attachments: List<Uri> = ArrayList(),
val attaching: Boolean = false,
val remaining: String = "",
val canSend: Boolean = false
)
@@ -44,6 +44,8 @@ interface ComposeView : QkView<ComposeState> {
val attachmentDeletedIntent: Subject<Uri>
val textChangedIntent: Observable<CharSequence>
val attachIntent: Observable<Unit>
val cameraIntent: Observable<*>
val galleryIntent: Observable<*>
val sendIntent: Observable<Unit>
fun showMenu(menuItems: List<MenuItem>)
@@ -352,12 +352,26 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
.autoDisposable(view.scope())
.subscribe { threadId -> markRead.execute(threadId) }
// Attach a photo
// Open the attachment options
view.attachIntent
.autoDisposable(view.scope())
.subscribe { newState { it.copy(attaching = !it.attaching) } }
// Attach a photo from camera
view.cameraIntent
.flatMap { RxImagePicker.with(context).requestImage(Sources.CAMERA) }
.withLatestFrom(attachments, { attachment, attachments -> attachments + attachment })
.doOnNext { attachments.onNext(it) }
.autoDisposable(view.scope())
.subscribe { newState { it.copy(attaching = false) } }
// Attach a photo from gallery
view.galleryIntent
.flatMap { RxImagePicker.with(context).requestImage(Sources.GALLERY) }
.withLatestFrom(attachments, { attachment, attachments -> attachments + attachment })
.doOnNext { attachments.onNext(it) }
.autoDisposable(view.scope())
.subscribe { attachments.onNext(it) }
.subscribe { newState { it.copy(attaching = false) } }
// Detach a photo
view.attachmentDeletedIntent
@@ -0,0 +1,23 @@
<!--
~ 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/>.
-->
<vector android:height="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" 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>
@@ -0,0 +1,24 @@
<!--
~ 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/>.
-->
<vector android:height="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
<path android:fillColor="#FF000000" android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
</vector>
@@ -121,11 +121,36 @@
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_marginStart="8dp"
android:padding="10dp"
android:src="@drawable/ic_add_circle_black_24dp"
app:layout_constraintBottom_toBottomOf="@id/message"
app:layout_constraintStart_toStartOf="@id/messageBackground"
tools:tint="@color/textSecondary" />
<ImageView
android:id="@+id/camera"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_marginStart="8dp"
android:background="@drawable/ripple"
android:padding="10dp"
android:src="@drawable/ic_camera_alt_black_24dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/message"
app:layout_constraintStart_toEndOf="@id/attach"
tools:tint="@color/textSecondary" />
<ImageView
android:id="@+id/gallery"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_marginStart="8dp"
android:background="@drawable/ripple"
android:padding="10dp"
android:src="@drawable/ic_insert_photo_black_24dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/message"
app:layout_constraintStart_toStartOf="@id/messageBackground"
app:layout_constraintStart_toEndOf="@id/camera"
tools:tint="@color/textSecondary" />
<common.widget.Separator
@@ -135,7 +160,7 @@
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="@id/message"
app:layout_constraintStart_toEndOf="@id/attach"
app:layout_constraintStart_toEndOf="@id/gallery"
app:layout_constraintTop_toBottomOf="@id/attachments" />
<common.widget.QkEditText