#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