diff --git a/app/src/main/java/com/kickstarter/ui/activities/MessagesActivity.kt b/app/src/main/java/com/kickstarter/ui/activities/MessagesActivity.kt index dfd28b61ea..6649efcb4a 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/MessagesActivity.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/MessagesActivity.kt @@ -21,6 +21,7 @@ import com.kickstarter.libs.utils.DateTimeUtils import com.kickstarter.libs.utils.ViewUtils import com.kickstarter.libs.utils.extensions.addToDisposable import com.kickstarter.libs.utils.extensions.getEnvironment +import com.kickstarter.libs.utils.extensions.getProjectIntent import com.kickstarter.models.Backing import com.kickstarter.models.BackingWrapper import com.kickstarter.models.Project @@ -170,6 +171,11 @@ class MessagesActivity : AppCompatActivity() { .subscribe { startBackingActivity(it) } .addToDisposable(disposables) + viewModel.outputs.startProjectPageActivity() + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { startProjectPageActivity(it) } + .addToDisposable(disposables) + viewModel.outputs.toolbarIsExpanded() .observeOn(AndroidSchedulers.mainThread()) .subscribe { binding.messagesAppBarLayout.setExpanded(it) } @@ -184,6 +190,10 @@ class MessagesActivity : AppCompatActivity() { viewPledgeButtonClicked() } + binding.messagesProjectContainerView.setOnClickListener { + projectContainerViewClicked() + } + binding.messageReplyLayout.sendMessageButton.setOnClickListener { sendMessageButtonClicked() } @@ -211,6 +221,9 @@ class MessagesActivity : AppCompatActivity() { private fun viewPledgeButtonClicked() = viewModel.inputs.viewPledgeButtonClicked() + private fun projectContainerViewClicked() = + viewModel.inputs.projectContainerViewClicked() + private fun onMessageEditTextChanged(message: CharSequence) = viewModel.inputs.messageEditTextChanged(message.toString()) @@ -274,4 +287,10 @@ class MessagesActivity : AppCompatActivity() { .putExtra(IntentKey.IS_FROM_MESSAGES_ACTIVITY, true) startActivityWithTransition(intent, R.anim.slide_in_right, R.anim.fade_out_slide_out_left) } + + private fun startProjectPageActivity(project: Project) { + val intent = Intent().getProjectIntent(this) + .putExtra(IntentKey.PROJECT, project) + startActivityWithTransition(intent, R.anim.slide_in_right, R.anim.fade_out_slide_out_left) + } } diff --git a/app/src/main/java/com/kickstarter/viewmodels/MessagesViewModel.kt b/app/src/main/java/com/kickstarter/viewmodels/MessagesViewModel.kt index c9a0226798..b05b65ff2f 100644 --- a/app/src/main/java/com/kickstarter/viewmodels/MessagesViewModel.kt +++ b/app/src/main/java/com/kickstarter/viewmodels/MessagesViewModel.kt @@ -53,6 +53,9 @@ interface MessagesViewModel { /** Call when the view pledge button is clicked. */ fun viewPledgeButtonClicked() + + /** Call when the project container view is clicked. */ + fun projectContainerViewClicked() } interface Outputs { @@ -110,6 +113,9 @@ interface MessagesViewModel { /** Emits when we should start the [BackingActivity]. */ fun startBackingActivity(): Observable + /** Emits when we should start the [ProjectPageActivity]. */ + fun startProjectPageActivity(): Observable + /** Emits when the thread has been marked as read. */ fun successfullyMarkedAsRead(): Observable @@ -142,6 +148,7 @@ interface MessagesViewModel { private val messageEditTextChanged = PublishSubject.create() private val messageEditTextIsFocused = PublishSubject.create() private val sendMessageButtonClicked = PublishSubject.create() + private val projectContainerViewClicked = PublishSubject.create() private val viewPledgeButtonClicked = PublishSubject.create() private val backButtonIsGone: Observable private val backingAndProject = BehaviorSubject.create>() @@ -161,6 +168,7 @@ interface MessagesViewModel { private val sendMessageButtonIsEnabled: Observable private val setMessageEditText: Observable private val startBackingActivity = PublishSubject.create() + private val startProjectPageActivity = PublishSubject.create() private val successfullyMarkedAsRead = BehaviorSubject.create() private val toolbarIsExpanded: Observable private val viewPledgeButtonIsGone = BehaviorSubject.create() @@ -192,6 +200,10 @@ interface MessagesViewModel { viewPledgeButtonClicked.onNext(Unit) } + override fun projectContainerViewClicked() { + projectContainerViewClicked.onNext(Unit) + } + override fun backButtonIsGone(): Observable = backButtonIsGone override fun backingAndProject(): Observable> = backingAndProject override fun backingInfoViewIsGone(): Observable = backingInfoViewIsGone @@ -210,6 +222,7 @@ interface MessagesViewModel { override fun sendMessageButtonIsEnabled(): Observable = sendMessageButtonIsEnabled override fun setMessageEditText(): Observable = setMessageEditText override fun startBackingActivity(): Observable = startBackingActivity + override fun startProjectPageActivity(): Observable = startProjectPageActivity override fun successfullyMarkedAsRead(): Observable = successfullyMarkedAsRead override fun toolbarIsExpanded(): Observable = toolbarIsExpanded override fun viewPledgeButtonIsGone(): Observable = viewPledgeButtonIsGone @@ -543,6 +556,11 @@ interface MessagesViewModel { .subscribe { projectNameTextViewText.onNext(it) } .addToDisposable(disposables) + project + .compose(Transformers.takeWhenV2(projectContainerViewClicked)) + .subscribe { startProjectPageActivity.onNext(it) } + .addToDisposable(disposables) + messageThreadEnvelope .compose(Transformers.combineLatestPair(messagesData)) .compose(Transformers.takeWhenV2(viewPledgeButtonClicked)) diff --git a/app/src/main/res/layout/messages_layout.xml b/app/src/main/res/layout/messages_layout.xml index 7b153cd140..d2c41f23bb 100644 --- a/app/src/main/res/layout/messages_layout.xml +++ b/app/src/main/res/layout/messages_layout.xml @@ -20,6 +20,7 @@ app:layout_scrollFlags="scroll|exitUntilCollapsed"> () private val showMessageErrorToast = TestSubscriber() private val startBackingActivity = TestSubscriber() + private val startProjectPageActivity = TestSubscriber() private val successfullyMarkedAsRead = TestSubscriber() private val toolbarIsExpanded = TestSubscriber() private val viewPledgeButtonIsGone = TestSubscriber() @@ -85,6 +86,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { vm.outputs.setMessageEditText().subscribe { setMessageEditText.onNext(it) }.addToDisposable(disposables) vm.outputs.showMessageErrorToast().subscribe { showMessageErrorToast.onNext(it) }.addToDisposable(disposables) vm.outputs.startBackingActivity().subscribe { startBackingActivity.onNext(it) }.addToDisposable(disposables) + vm.outputs.startProjectPageActivity().subscribe { startProjectPageActivity.onNext(it) }.addToDisposable(disposables) vm.outputs.successfullyMarkedAsRead().subscribe { successfullyMarkedAsRead.onNext(it) }.addToDisposable(disposables) vm.outputs.toolbarIsExpanded().subscribe { toolbarIsExpanded.onNext(it) }.addToDisposable(disposables) vm.outputs.viewPledgeButtonIsGone().subscribe { viewPledgeButtonIsGone.onNext(it) }.addToDisposable(disposables) @@ -536,6 +538,32 @@ class MessagesViewModelTest : KSRobolectricTestCase() { ) } + @Test + fun testStartProjectPageActivity() { + val project = project().toBuilder().isBacking(true).build() + val messageThread = messageThread() + .toBuilder() + .project(project) + .build() + val messageThreadEnvelope = messageThreadEnvelope() + .toBuilder() + .messageThread(messageThread) + .build() + val apiClient: MockApiClientV2 = object : MockApiClientV2() { + override fun fetchMessagesForBacking(backing: Backing): Observable { + return Observable.just(messageThreadEnvelope) + } + } + setUpEnvironment( + environment().toBuilder().currentUserV2(MockCurrentUserV2(user())).apiClientV2(apiClient) + .build(), + messagesContextIntent(messageThread) + ) + + vm.inputs.projectContainerViewClicked() + startProjectPageActivity.assertValues(project) + } + @Test fun testSuccessfullyMarkedAsRead() { val messageThread = messageThread()