Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBL-1475 Add backing details navigation #2064

Merged
merged 10 commits into from
Jul 1, 2024
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@
<activity
android:name=".ui.activities.MessageThreadsActivity"
android:parentActivityName=".ui.activities.ProfileActivity" />
<activity
android:name=".features.pledgedprojectsoverview.ui.BackingDetailsActivity"
android:parentActivityName=".features.pledgedprojectsoverview.ui.PledgedProjectsOverviewActivity" />
<activity
android:name=".features.pledgedprojectsoverview.ui.PledgedProjectsOverviewActivity"
android:parentActivityName=".ui.activities.DiscoveryActivity" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.kickstarter.features.pledgedprojectsoverview.ui

import android.os.Bundle
import androidx.activity.addCallback
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.kickstarter.databinding.ActivityBackingDetailsBinding
import com.kickstarter.libs.utils.extensions.getEnvironment
import com.kickstarter.ui.extensions.finishWithAnimation
import com.kickstarter.viewmodels.BackingDetailsViewModel
import kotlinx.coroutines.launch

class BackingDetailsActivity : AppCompatActivity() {

private lateinit var binding: ActivityBackingDetailsBinding
private lateinit var viewModelFactory: BackingDetailsViewModel.Factory
private val viewModel: BackingDetailsViewModel by viewModels { viewModelFactory }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityBackingDetailsBinding.inflate(layoutInflater)

this.getEnvironment()?.let { env ->
viewModelFactory = BackingDetailsViewModel.Factory(env, intent = intent)
env
}

setContentView(binding.root)

lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.url.collect { url ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

binding.webView.loadUrl(url)
}
}
}

this.onBackPressedDispatcher.addCallback {
finishWithAnimation()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fun PPOCardPreview() {
showBadge = true,
onActionButtonClicked = {},
onSecondaryActionButtonClicked = {},
onProjectPledgeSummaryClick = {},
timeNumberForAction = 5
)

Expand All @@ -84,6 +85,7 @@ fun PPOCardPreview() {
showBadge = true,
onActionButtonClicked = {},
onSecondaryActionButtonClicked = {},
onProjectPledgeSummaryClick = {},
timeNumberForAction = 6
)

Expand All @@ -101,6 +103,7 @@ fun PPOCardPreview() {
showBadge = false,
onActionButtonClicked = {},
onSecondaryActionButtonClicked = {},
onProjectPledgeSummaryClick = {},
timeNumberForAction = 6
)

Expand All @@ -118,6 +121,7 @@ fun PPOCardPreview() {
showBadge = true,
onActionButtonClicked = {},
onSecondaryActionButtonClicked = {},
onProjectPledgeSummaryClick = {},
timeNumberForAction = 7
)

Expand All @@ -135,6 +139,7 @@ fun PPOCardPreview() {
showBadge = false,
onActionButtonClicked = {},
onSecondaryActionButtonClicked = {},
onProjectPledgeSummaryClick = {},
timeNumberForAction = 7
)

Expand All @@ -152,6 +157,7 @@ fun PPOCardPreview() {
showBadge = true,
onActionButtonClicked = {},
onSecondaryActionButtonClicked = {},
onProjectPledgeSummaryClick = {},
timeNumberForAction = 8
)

Expand All @@ -169,6 +175,7 @@ fun PPOCardPreview() {
showBadge = false,
onActionButtonClicked = {},
onSecondaryActionButtonClicked = {},
onProjectPledgeSummaryClick = {},
timeNumberForAction = 8
)

Expand Down Expand Up @@ -198,6 +205,7 @@ enum class PPOCardViewTestTag {
fun PPOCardView(
viewType: PPOCardViewType,
onCardClick: () -> Unit,
onProjectPledgeSummaryClick: () -> Unit,
projectName: String? = null,
pledgeAmount: String? = null,
imageUrl: String? = null,
Expand Down Expand Up @@ -240,7 +248,8 @@ fun PPOCardView(
projectName = projectName,
pledgeAmount = pledgeAmount,
imageUrl = imageUrl,
imageContentDescription = imageContentDescription
imageContentDescription = imageContentDescription,
onProjectPledgeSummaryClick = onProjectPledgeSummaryClick
)

CreatorNameSendMessageView(
Expand Down Expand Up @@ -280,9 +289,11 @@ fun ProjectPledgeSummaryView(
pledgeAmount: String? = null,
imageUrl: String? = null,
imageContentDescription: String? = null,
onProjectPledgeSummaryClick: () -> Unit
) {
Row(
modifier = Modifier
.clickable { onProjectPledgeSummaryClick.invoke() }
.fillMaxWidth()
.padding(all = dimensions.paddingMediumSmall)
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kickstarter.features.pledgedprojectsoverview.ui

import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
Expand All @@ -20,6 +21,7 @@ import com.kickstarter.libs.MessagePreviousScreenType
import com.kickstarter.libs.utils.TransitionUtils
import com.kickstarter.libs.utils.extensions.getEnvironment
import com.kickstarter.libs.utils.extensions.isDarkModeEnabled
import com.kickstarter.ui.IntentKey
import com.kickstarter.ui.SharedPreferenceKey
import com.kickstarter.ui.activities.AppThemes
import com.kickstarter.ui.compose.designsystem.KickstarterApp
Expand Down Expand Up @@ -72,6 +74,8 @@ class PledgedProjectsOverviewActivity : AppCompatActivity() {
ppoCards = ppoCardPagingSource,
totalAlerts = totalAlerts.value,
onAddressConfirmed = { viewModel.showSnackbarAndRefreshCardsList() },
onCardClick = { },
onProjectPledgeSummaryClick = { url -> openBackingDetailsWebView(url) },
onSendMessageClick = { projectName -> viewModel.onMessageCreatorClicked(projectName) }
)
}
Expand All @@ -98,4 +102,10 @@ class PledgedProjectsOverviewActivity : AppCompatActivity() {
}
}
}

private fun openBackingDetailsWebView(url: String) {
val intent = Intent(this, BackingDetailsActivity::class.java)
.putExtra(IntentKey.URL, url)
startActivity(intent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ private fun PledgedProjectsOverviewScreenPreview() {
totalAlerts = 10,
onBackPressed = {},
onAddressConfirmed = {},
onCardClick = {},
onProjectPledgeSummaryClick = {},
onSendMessageClick = {},
errorSnackBarHostState = SnackbarHostState()
)
Expand All @@ -72,6 +74,8 @@ fun PledgedProjectsOverviewScreen(
errorSnackBarHostState: SnackbarHostState,
ppoCards: LazyPagingItems<PPOCardDataMock>,
totalAlerts: Int = 0,
onCardClick: () -> Unit,
onProjectPledgeSummaryClick: (backingDetailsUrl: String) -> Unit,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new onProjectPledgeSummaryClick lambda for just the pledge summary tap area per the ticket AC. The onCardClick lambda is for the tap area of the entire card, not sure if it's going to end up being used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The onCardClick i believe was meant to be used for this part of the feature, but it's fine. i'll just remove it at some point in a subsequent PR

onSendMessageClick: (projectName: String) -> Unit
) {
val openConfirmAddressAlertDialog = remember { mutableStateOf(false) }
Expand Down Expand Up @@ -129,6 +133,7 @@ fun PledgedProjectsOverviewScreen(
PPOCardView(
viewType = it.viewType,
onCardClick = { },
onProjectPledgeSummaryClick = { onProjectPledgeSummaryClick(it.backingDetailsUrl) },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leighdouglas Here's where we pass the backingDetailsUrl from the PPO card when user clicks on the tap area.

projectName = it.projectName,
pledgeAmount = it.pledgeAmount,
imageUrl = it.imageUrl,
Expand Down Expand Up @@ -196,5 +201,6 @@ data class PPOCardDataMock(
val showBadge: Boolean = true,
val onActionButtonClicked: () -> Unit = {},
val onSecondaryActionButtonClicked: () -> Unit = {},
val timeNumberForAction: Int = 25
val timeNumberForAction: Int = 25,
val backingDetailsUrl: String = "https://www.kickstarter.com/projects/thehoneycouple/the-honey-couples-building-expansion"
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PledgedProjectsOverviewViewModel(environment: Environment) : ViewModel() {
val totalAlertsState: StateFlow<Int> = totalAlerts.asStateFlow()

fun showSnackbarAndRefreshCardsList() {
snackbarMessage.invoke(R.string.address_confirmed_snackbar_text)
snackbarMessage.invoke(R.string.address_confirmed_snackbar_text_fpo)

// TODO: MBL-1556 refresh the PPO list (i.e. requery the PPO list).
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.kickstarter.viewmodels

import android.content.Intent
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.kickstarter.libs.Environment
import com.kickstarter.ui.IntentKey
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

class BackingDetailsViewModel(environment: Environment, private val intent: Intent? = null) : ViewModel() {

private var mutableUrl = MutableStateFlow<String>("")
val url: StateFlow<String>
get() = mutableUrl.asStateFlow()
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(),
initialValue = ""
)
init {
viewModelScope.launch {
intent?.getStringExtra(IntentKey.URL)?.let { url ->
mutableUrl.emit(url)
}
}
}

class Factory(private val environment: Environment, private val intent: Intent? = null) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return BackingDetailsViewModel(environment, intent) as T
}
}
}
45 changes: 45 additions & 0 deletions app/src/main/res/layout/activity_backing_details.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.kickstarter.ui.toolbars.KSToolbar
android:id="@+id/web_view_toolbar"
style="@style/Toolbar"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal">

<com.kickstarter.ui.views.IconButton
android:id="@+id/back_button"
style="@style/ToolbarIconBackButton" />

<TextView
android:id="@+id/title_text_view"
style="@style/ToolbarTitle"
android:text="@string/backing_details_fpo" />

</RelativeLayout>

</com.kickstarter.ui.toolbars.KSToolbar>

</com.google.android.material.appbar.AppBarLayout>

<com.kickstarter.ui.views.KSWebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<!-- PPO Mock Strings -->
<string name="project_alerts_fpo">Project Alerts</string>
<string name="alerts_fpo">Alerts (%1$s)</string>
<string name="address_confirmed_snackbar_text">Address confirmed! Need to change your address before it locks? Visit your backing details on our website.</string>
<string name="address_confirmed_snackbar_text_fpo">Address confirmed! Need to change your address before it locks? Visit your backing details on our website.</string>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I snuck in this tiny string name change unrelated to this ticket because I realized I forgot to add "fpo" to the end of it

<string name="backing_details_fpo">Backing details</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class PledgedProjectsOverviewScreenTest : KSRobolectricTestCase() {
ppoCards = ppoCardList,
errorSnackBarHostState = SnackbarHostState(),
onSendMessageClick = {},
onAddressConfirmed = {}
onAddressConfirmed = {},
onCardClick = {},
onProjectPledgeSummaryClick = {}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PledgedProjectsOverviewViewModelTest : KSRobolectricTestCase() {
// Should equal address confirmed string id
assertEquals(
snackbarAction,
R.string.address_confirmed_snackbar_text
R.string.address_confirmed_snackbar_text_fpo
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PPOCardViewKtTest : KSRobolectricTestCase() {
PPOCardView(
viewType = PPOCardViewType.CONFIRM_ADDRESS,
onCardClick = {},
onProjectPledgeSummaryClick = {},
projectName = "Sugardew Island - Your cozy farm shop let’s pretend this is a longer title let’s pretend this is a longer title",
pledgeAmount = "$50.00",
creatorName = "Some really really really really really really really long name",
Expand Down Expand Up @@ -53,6 +54,7 @@ class PPOCardViewKtTest : KSRobolectricTestCase() {
PPOCardView(
viewType = PPOCardViewType.ADDRESS_CONFIRMED,
onCardClick = {},
onProjectPledgeSummaryClick = {},
projectName = "Sugardew Island - Your cozy farm shop let’s pretend this is a longer title let’s pretend this is a longer title",
pledgeAmount = "$50.00",
creatorName = "Some really really really really really really really long name",
Expand Down Expand Up @@ -83,6 +85,7 @@ class PPOCardViewKtTest : KSRobolectricTestCase() {
PPOCardView(
viewType = PPOCardViewType.FIX_PAYMENT,
onCardClick = {},
onProjectPledgeSummaryClick = {},
projectName = "Sugardew Island - Your cozy farm shop let’s pretend this is a longer title let’s pretend this is a longer title",
pledgeAmount = "$50.00",
creatorName = "Some really really really really really really really long name",
Expand Down Expand Up @@ -113,6 +116,7 @@ class PPOCardViewKtTest : KSRobolectricTestCase() {
PPOCardView(
viewType = PPOCardViewType.PAYMENT_FIXED,
onCardClick = {},
onProjectPledgeSummaryClick = {},
projectName = "Sugardew Island - Your cozy farm shop let’s pretend this is a longer title let’s pretend this is a longer title",
pledgeAmount = "$50.00",
creatorName = "Some really really really really really really really long name",
Expand Down Expand Up @@ -141,6 +145,7 @@ class PPOCardViewKtTest : KSRobolectricTestCase() {
PPOCardView(
viewType = PPOCardViewType.AUTHENTICATE_CARD,
onCardClick = {},
onProjectPledgeSummaryClick = {},
projectName = "Sugardew Island - Your cozy farm shop let’s pretend this is a longer title let’s pretend this is a longer title",
pledgeAmount = "$60.00",
creatorName = "Some really really really really really really really long name",
Expand Down Expand Up @@ -171,6 +176,7 @@ class PPOCardViewKtTest : KSRobolectricTestCase() {
PPOCardView(
viewType = PPOCardViewType.CARD_AUTHENTICATED,
onCardClick = {},
onProjectPledgeSummaryClick = {},
projectName = "Sugardew Island - Your cozy farm shop let’s pretend this is a longer title let’s pretend this is a longer title",
pledgeAmount = "$60.00",
creatorName = "Some really really really really really really really long name",
Expand Down Expand Up @@ -199,6 +205,7 @@ class PPOCardViewKtTest : KSRobolectricTestCase() {
PPOCardView(
viewType = PPOCardViewType.TAKE_SURVEY,
onCardClick = {},
onProjectPledgeSummaryClick = {},
projectName = "Sugardew Island - Your cozy farm shop let’s pretend this is a longer title let’s pretend this is a longer title",
pledgeAmount = "$70.00",
creatorName = "Some really really really really really really really long name",
Expand Down Expand Up @@ -228,6 +235,7 @@ class PPOCardViewKtTest : KSRobolectricTestCase() {
PPOCardView(
viewType = PPOCardViewType.SURVEY_SUBMITTED,
onCardClick = {},
onProjectPledgeSummaryClick = {},
projectName = "Sugardew Island - Your cozy farm shop let’s pretend this is a longer title let’s pretend this is a longer title",
pledgeAmount = "$70.00",
creatorName = "Some really really really really really really really long name",
Expand Down
Loading