Skip to content

Commit

Permalink
MBL-1071 Add link to Kickstarter campaign from messages (#1950)
Browse files Browse the repository at this point in the history
  • Loading branch information
ycheng-kickstarter authored Feb 14, 2024
1 parent 3b7938e commit fb9e580
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand All @@ -184,6 +190,10 @@ class MessagesActivity : AppCompatActivity() {
viewPledgeButtonClicked()
}

binding.messagesProjectContainerView.setOnClickListener {
projectContainerViewClicked()
}

binding.messageReplyLayout.sendMessageButton.setOnClickListener {
sendMessageButtonClicked()
}
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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)
}
}
18 changes: 18 additions & 0 deletions app/src/main/java/com/kickstarter/viewmodels/MessagesViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -110,6 +113,9 @@ interface MessagesViewModel {
/** Emits when we should start the [BackingActivity]. */
fun startBackingActivity(): Observable<BackingWrapper>

/** Emits when we should start the [ProjectPageActivity]. */
fun startProjectPageActivity(): Observable<Project>

/** Emits when the thread has been marked as read. */
fun successfullyMarkedAsRead(): Observable<Unit>

Expand Down Expand Up @@ -142,6 +148,7 @@ interface MessagesViewModel {
private val messageEditTextChanged = PublishSubject.create<String>()
private val messageEditTextIsFocused = PublishSubject.create<Boolean>()
private val sendMessageButtonClicked = PublishSubject.create<Unit>()
private val projectContainerViewClicked = PublishSubject.create<Unit>()
private val viewPledgeButtonClicked = PublishSubject.create<Unit>()
private val backButtonIsGone: Observable<Boolean>
private val backingAndProject = BehaviorSubject.create<Pair<Backing, Project>>()
Expand All @@ -161,6 +168,7 @@ interface MessagesViewModel {
private val sendMessageButtonIsEnabled: Observable<Boolean>
private val setMessageEditText: Observable<String>
private val startBackingActivity = PublishSubject.create<BackingWrapper>()
private val startProjectPageActivity = PublishSubject.create<Project>()
private val successfullyMarkedAsRead = BehaviorSubject.create<Unit>()
private val toolbarIsExpanded: Observable<Boolean>
private val viewPledgeButtonIsGone = BehaviorSubject.create<Boolean>()
Expand Down Expand Up @@ -192,6 +200,10 @@ interface MessagesViewModel {
viewPledgeButtonClicked.onNext(Unit)
}

override fun projectContainerViewClicked() {
projectContainerViewClicked.onNext(Unit)
}

override fun backButtonIsGone(): Observable<Boolean> = backButtonIsGone
override fun backingAndProject(): Observable<Pair<Backing, Project>> = backingAndProject
override fun backingInfoViewIsGone(): Observable<Boolean> = backingInfoViewIsGone
Expand All @@ -210,6 +222,7 @@ interface MessagesViewModel {
override fun sendMessageButtonIsEnabled(): Observable<Boolean> = sendMessageButtonIsEnabled
override fun setMessageEditText(): Observable<String> = setMessageEditText
override fun startBackingActivity(): Observable<BackingWrapper> = startBackingActivity
override fun startProjectPageActivity(): Observable<Project> = startProjectPageActivity
override fun successfullyMarkedAsRead(): Observable<Unit> = successfullyMarkedAsRead
override fun toolbarIsExpanded(): Observable<Boolean> = toolbarIsExpanded
override fun viewPledgeButtonIsGone(): Observable<Boolean> = viewPledgeButtonIsGone
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/messages_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<LinearLayout
android:id="@+id/messages_project_container_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/grid_8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() {
private val setMessageEditText = TestSubscriber<String>()
private val showMessageErrorToast = TestSubscriber<String>()
private val startBackingActivity = TestSubscriber<BackingWrapper>()
private val startProjectPageActivity = TestSubscriber<Project>()
private val successfullyMarkedAsRead = TestSubscriber<Unit>()
private val toolbarIsExpanded = TestSubscriber<Boolean>()
private val viewPledgeButtonIsGone = TestSubscriber<Boolean>()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<MessageThreadEnvelope> {
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()
Expand Down

0 comments on commit fb9e580

Please sign in to comment.