diff --git a/presentation/src/main/java/feature/compose/ComposeActivity.kt b/presentation/src/main/java/feature/compose/ComposeActivity.kt index b333ae4e..f1194a2d 100644 --- a/presentation/src/main/java/feature/compose/ComposeActivity.kt +++ b/presentation/src/main/java/feature/compose/ComposeActivity.kt @@ -67,6 +67,8 @@ class ComposeActivity : QkThemedActivity(), ComposeView { override val attachmentDeletedIntent: Subject 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(), 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(), 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 diff --git a/presentation/src/main/java/feature/compose/ComposeState.kt b/presentation/src/main/java/feature/compose/ComposeState.kt index cdc0141b..698a2872 100644 --- a/presentation/src/main/java/feature/compose/ComposeState.kt +++ b/presentation/src/main/java/feature/compose/ComposeState.kt @@ -34,6 +34,7 @@ data class ComposeState( val title: String = "", val messages: Pair>? = null, val attachments: List = ArrayList(), + val attaching: Boolean = false, val remaining: String = "", val canSend: Boolean = false ) \ No newline at end of file diff --git a/presentation/src/main/java/feature/compose/ComposeView.kt b/presentation/src/main/java/feature/compose/ComposeView.kt index 5e2f9beb..a974d587 100644 --- a/presentation/src/main/java/feature/compose/ComposeView.kt +++ b/presentation/src/main/java/feature/compose/ComposeView.kt @@ -44,6 +44,8 @@ interface ComposeView : QkView { val attachmentDeletedIntent: Subject val textChangedIntent: Observable val attachIntent: Observable + val cameraIntent: Observable<*> + val galleryIntent: Observable<*> val sendIntent: Observable fun showMenu(menuItems: List) diff --git a/presentation/src/main/java/feature/compose/ComposeViewModel.kt b/presentation/src/main/java/feature/compose/ComposeViewModel.kt index dc03a473..e1628775 100644 --- a/presentation/src/main/java/feature/compose/ComposeViewModel.kt +++ b/presentation/src/main/java/feature/compose/ComposeViewModel.kt @@ -352,12 +352,26 @@ class ComposeViewModel(intent: Intent) : QkViewModel( .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 diff --git a/presentation/src/main/res/drawable/ic_add_circle_black_24dp.xml b/presentation/src/main/res/drawable/ic_add_circle_black_24dp.xml new file mode 100644 index 00000000..1eea2a0f --- /dev/null +++ b/presentation/src/main/res/drawable/ic_add_circle_black_24dp.xml @@ -0,0 +1,23 @@ + + + + diff --git a/presentation/src/main/res/drawable/ic_camera_alt_black_24dp.xml b/presentation/src/main/res/drawable/ic_camera_alt_black_24dp.xml new file mode 100644 index 00000000..5809569a --- /dev/null +++ b/presentation/src/main/res/drawable/ic_camera_alt_black_24dp.xml @@ -0,0 +1,24 @@ + + + + + diff --git a/presentation/src/main/res/layout/compose_activity.xml b/presentation/src/main/res/layout/compose_activity.xml index b62d8599..a610c200 100644 --- a/presentation/src/main/res/layout/compose_activity.xml +++ b/presentation/src/main/res/layout/compose_activity.xml @@ -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" /> + + + +