Skip to content

Commit

Permalink
Merge pull request #21233 from wordpress-mobile/roundhill/add-day-one…
Browse files Browse the repository at this point in the history
…-external-link

Link Day One attribution to dayoneapp.com when tapped
  • Loading branch information
roundhill authored Sep 17, 2024
2 parents d91c35c + 5cd49ec commit 80cf2cd
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class MySiteAdapter(
val gravatarLoader: MeGravatarLoader,
val bloggingPromptsCardAnalyticsTracker: BloggingPromptsCardAnalyticsTracker,
val htmlCompatWrapper: HtmlCompatWrapper,
val learnMoreClicked: () -> Unit
val learnMoreClicked: () -> Unit,
val containerClicked: () -> Unit
) : ListAdapter<MySiteCardAndItem, MySiteCardAndItemViewHolder<*>>(MySiteAdapterDiffCallback) {
private var nestedScrollStates = Bundle()

Expand Down Expand Up @@ -108,7 +109,8 @@ class MySiteAdapter(
uiHelpers,
bloggingPromptsCardAnalyticsTracker,
htmlCompatWrapper,
learnMoreClicked
learnMoreClicked,
containerClicked
)

MySiteCardAndItem.Type.BLOGANUARY_NUDGE_CARD.ordinal -> BloganuaryNudgeCardViewHolder(parent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,10 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment),
accountStore,
meGravatarLoader,
bloggingPromptsCardAnalyticsTracker,
htmlCompatWrapper
) { viewModel.onBloggingPromptsLearnMoreClicked() }
htmlCompatWrapper,
{ viewModel.onBloggingPromptsLearnMoreClicked() },
{ viewModel.onBloggingPromptsAttributionClicked() }
)

adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ class MySiteViewModel @Inject constructor(
_onNavigation.postValue(Event(BloggingPromptCardNavigationAction.LearnMore))
}

fun onBloggingPromptsAttributionClicked() {
_onNavigation.value = Event(
SiteNavigationAction.OpenExternalUrl(DAY_ONE_EXTERNAL_URL)
)
}

// FluxC events
@Subscribe(threadMode = MAIN)
Expand Down Expand Up @@ -458,5 +463,6 @@ class MySiteViewModel @Inject constructor(
const val ARG_QUICK_START_TASK = "ARG_QUICK_START_TASK"
const val HIDE_WP_ADMIN_GMT_TIME_ZONE = "GMT"
private const val DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY = 500L
private const val DAY_ONE_EXTERNAL_URL = "https://dayoneapp.com/?utm_source=jetpack&utm_medium=prompts"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ enum class BloggingPromptAttribution(
val value: String,
@StringRes val contentRes: Int,
@DrawableRes val iconRes: Int,
val isContainerClickable: Boolean
) {
NO_ATTRIBUTION("", -1, -1),
NO_ATTRIBUTION("", -1, -1, false),
DAY_ONE(
"dayone",
R.string.my_site_blogging_prompt_card_attribution_day_one,
R.drawable.ic_dayone_24dp,
true
),
BLOGANUARY(
"bloganuary",
R.string.my_site_blogging_prompt_card_attribution_bloganuary,
R.drawable.ic_bloganuary_24dp,
false
);

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import org.wordpress.android.ui.mysite.cards.dashboard.bloggingprompts.BloggingP
import org.wordpress.android.ui.utils.UiHelpers
import org.wordpress.android.util.HtmlCompatWrapper
import org.wordpress.android.util.extensions.getColorStateListFromAttributeOrRes
import org.wordpress.android.util.extensions.setVisible
import org.wordpress.android.util.extensions.viewBinding

class BloggingPromptCardViewHolder(
parent: ViewGroup,
private val uiHelpers: UiHelpers,
private val bloggingPromptsCardAnalyticsTracker: BloggingPromptsCardAnalyticsTracker,
private val htmlCompatWrapper: HtmlCompatWrapper,
private val learnMoreClicked: () -> Unit
private val learnMoreClicked: () -> Unit,
private val containerClicked: () -> Unit,
) : MySiteCardAndItemViewHolder<MySiteBloggingPromptCardBinding>(
parent.viewBinding(MySiteBloggingPromptCardBinding::inflate)
) {
Expand Down Expand Up @@ -74,6 +76,13 @@ class BloggingPromptCardViewHolder(
?.let { iconRes ->
attributionIcon.setImageResource(iconRes)
}

attribution.isContainerClickable
.takeIf { it }
?.let {
attributionContainer.setOnClickListener { containerClicked() }
attributionExternalLinkIcon.setVisible(true)
}
}

@Suppress("NestedBlockDepth")
Expand Down
18 changes: 16 additions & 2 deletions WordPress/src/main/res/layout/my_site_blogging_prompt_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@

<LinearLayout
android:id="@+id/attribution_container"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal"
android:paddingTop="@dimen/margin_medium"
android:paddingBottom="@dimen/margin_medium"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@+id/prompt_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:visibility="visible">

<ImageView
Expand All @@ -77,13 +81,23 @@
android:textAppearance="?attr/textAppearanceCaption"
tools:text="@string/my_site_blogging_prompt_card_attribution_day_one" />

<ImageView
android:id="@+id/attribution_external_link_icon"
style="@style/PluginCardViewSecondaryElement.ExternalLinkImage"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/margin_small"
android:visibility="gone"
android:contentDescription="@string/open_external_link_desc"
android:src="@drawable/ic_external_white_24dp"
app:tint="?attr/colorPrimary" />

</LinearLayout>

<org.wordpress.android.ui.compose.views.TrainOfAvatarsView
android:id="@+id/answered_users_avatars"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_large"
android:layout_marginTop="@dimen/margin_small"
app:iconSize="@dimen/avatar_sz_extra_small"
app:placeholder="@drawable/bg_oval_placeholder_user_32dp"
app:chainUseRtl="true"
Expand Down

0 comments on commit 80cf2cd

Please sign in to comment.