Skip to content

Commit

Permalink
Merge pull request #18306 from wordpress-mobile/issue/activity_card_h…
Browse files Browse the repository at this point in the history
…andle_click_actions

Dashboard Cards: Activity Card implement onclick behavior
  • Loading branch information
zwarm authored Apr 24, 2023
2 parents bd46b53 + a28ed85 commit 40b881a
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
import static org.wordpress.android.ui.stories.StoryComposerActivity.KEY_POST_LOCAL_ID;
import static org.wordpress.android.viewmodel.activitylog.ActivityLogDetailViewModelKt.ACTIVITY_LOG_ARE_BUTTONS_VISIBLE_KEY;
import static org.wordpress.android.viewmodel.activitylog.ActivityLogDetailViewModelKt.ACTIVITY_LOG_ID_KEY;
import static org.wordpress.android.viewmodel.activitylog.ActivityLogDetailViewModelKt.ACTIVITY_LOG_IS_DASHBOARD_CARD_ENTRY_KEY;
import static org.wordpress.android.viewmodel.activitylog.ActivityLogDetailViewModelKt.ACTIVITY_LOG_IS_RESTORE_HIDDEN_KEY;
import static org.wordpress.android.viewmodel.activitylog.ActivityLogViewModelKt.ACTIVITY_LOG_REWINDABLE_ONLY_KEY;

Expand Down Expand Up @@ -821,6 +822,26 @@ public static void viewActivityLogDetailForResult(
activity.startActivityForResult(intent, RequestCodes.ACTIVITY_LOG_DETAIL);
}

public static void viewActivityLogDetailFromDashboardCard(
Activity activity,
SiteModel site,
String activityId,
Boolean isRewindable
) {
Map<String, Object> properties = new HashMap<>();
properties.put(ACTIVITY_LOG_ACTIVITY_ID_KEY, activityId);
properties.put(SOURCE_TRACK_EVENT_PROPERTY_KEY, ACTIVITY_LOG_TRACK_EVENT_PROPERTY_VALUE);
AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.ACTIVITY_LOG_DETAIL_OPENED, site, properties);

Intent intent = new Intent(activity, ActivityLogDetailActivity.class);
intent.putExtra(WordPress.SITE, site);
intent.putExtra(ACTIVITY_LOG_ID_KEY, activityId);
intent.putExtra(ACTIVITY_LOG_IS_DASHBOARD_CARD_ENTRY_KEY, true);
intent.putExtra(ACTIVITY_LOG_ARE_BUTTONS_VISIBLE_KEY, isRewindable);
intent.putExtra(SOURCE_TRACK_EVENT_PROPERTY_KEY, ACTIVITY_LOG_TRACK_EVENT_PROPERTY_VALUE);
activity.startActivity(intent);
}

public static void viewScan(Activity activity, SiteModel site) {
if (site == null) {
ToastUtils.showToast(activity, R.string.blog_not_found, ToastUtils.Duration.SHORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.wordpress.android.util.image.ImageManager
import org.wordpress.android.util.image.ImageType.AVATAR_WITH_BACKGROUND
import org.wordpress.android.viewmodel.activitylog.ACTIVITY_LOG_ARE_BUTTONS_VISIBLE_KEY
import org.wordpress.android.viewmodel.activitylog.ACTIVITY_LOG_ID_KEY
import org.wordpress.android.viewmodel.activitylog.ACTIVITY_LOG_IS_DASHBOARD_CARD_ENTRY_KEY
import org.wordpress.android.viewmodel.activitylog.ACTIVITY_LOG_IS_RESTORE_HIDDEN_KEY
import org.wordpress.android.viewmodel.activitylog.ActivityLogDetailViewModel
import org.wordpress.android.viewmodel.observeEvent
Expand Down Expand Up @@ -85,8 +86,9 @@ class ActivityLogDetailFragment : Fragment(R.layout.activity_log_item_detail) {
val (site, activityLogId) = sideAndActivityId(savedInstanceState, activity.intent)
val areButtonsVisible = areButtonsVisible(savedInstanceState, activity.intent)
val isRestoreHidden = isRestoreHidden(savedInstanceState, activity.intent)
val isDashboardCardEntry = isDashboardCardEntry(savedInstanceState, activity.intent)

viewModel.start(site, activityLogId, areButtonsVisible, isRestoreHidden)
viewModel.start(site, activityLogId, areButtonsVisible, isRestoreHidden, isDashboardCardEntry)
}

if (jetpackBrandingUtils.shouldShowJetpackBranding()) {
Expand All @@ -111,21 +113,21 @@ class ActivityLogDetailFragment : Fragment(R.layout.activity_log_item_detail) {
}

private fun ActivityLogItemDetailBinding.setupObservers() {
viewModel.activityLogItem.observe(viewLifecycleOwner, { activityLogModel ->
viewModel.activityLogItem.observe(viewLifecycleOwner) { activityLogModel ->
loadLogItem(activityLogModel, requireActivity())
})
}

viewModel.restoreVisible.observe(viewLifecycleOwner, { available ->
viewModel.restoreVisible.observe(viewLifecycleOwner) { available ->
activityRestoreButton.visibility = if (available == true) View.VISIBLE else View.GONE
})
viewModel.downloadBackupVisible.observe(viewLifecycleOwner, { available ->
}
viewModel.downloadBackupVisible.observe(viewLifecycleOwner) { available ->
activityDownloadBackupButton.visibility = if (available == true) View.VISIBLE else View.GONE
})
viewModel.multisiteVisible.observe(viewLifecycleOwner, { available ->
}
viewModel.multisiteVisible.observe(viewLifecycleOwner) { available ->
checkAndShowMultisiteMessage(available)
})
}

viewModel.navigationEvents.observeEvent(viewLifecycleOwner, {
viewModel.navigationEvents.observeEvent(viewLifecycleOwner) {
when (it) {
is ShowBackupDownload -> ActivityLauncher.showBackupDownloadForResult(
requireActivity(),
Expand All @@ -143,17 +145,17 @@ class ActivityLogDetailFragment : Fragment(R.layout.activity_log_item_detail) {
)
is ShowDocumentationPage -> ActivityLauncher.openUrlExternal(requireContext(), it.url)
}
})
}

viewModel.handleFormattableRangeClick.observe(viewLifecycleOwner, { range ->
viewModel.handleFormattableRangeClick.observe(viewLifecycleOwner) { range ->
if (range != null) {
formattableContentClickHandler.onClick(
requireActivity(),
range,
ReaderTracker.SOURCE_ACTIVITY_LOG_DETAIL
)
}
})
}

viewModel.showJetpackPoweredBottomSheet.observeEvent(viewLifecycleOwner) {
JetpackPoweredBottomSheetFragment
Expand Down Expand Up @@ -259,12 +261,21 @@ class ActivityLogDetailFragment : Fragment(R.layout.activity_log_item_detail) {
else -> throw Throwable("Couldn't initialize Activity Log view model")
}

private fun isDashboardCardEntry(savedInstanceState: Bundle?, intent: Intent?) = when {
savedInstanceState != null ->
requireNotNull(savedInstanceState.getBoolean(ACTIVITY_LOG_IS_DASHBOARD_CARD_ENTRY_KEY, false))
intent != null ->
intent.getBooleanExtra(ACTIVITY_LOG_IS_DASHBOARD_CARD_ENTRY_KEY, false)
else -> throw Throwable("Couldn't initialize Activity Log view model")
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putSerializable(WordPress.SITE, viewModel.site)
outState.putString(ACTIVITY_LOG_ID_KEY, viewModel.activityLogId)
outState.putBoolean(ACTIVITY_LOG_ARE_BUTTONS_VISIBLE_KEY, viewModel.areButtonsVisible)
outState.putBoolean(ACTIVITY_LOG_IS_RESTORE_HIDDEN_KEY, viewModel.isRestoreHidden)
outState.putBoolean(ACTIVITY_LOG_IS_DASHBOARD_CARD_ENTRY_KEY, viewModel.isDashboardCardEntry)
}

private fun ActivityLogItemDetailBinding.setActorIcon(actorIcon: String?, showJetpackIcon: Boolean?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,14 @@ sealed class MySiteCardAndItemBuilderParams {
data class ActivityCardBuilderParams(
val site: SiteModel,
val activityCardModel: CardModel.ActivityCardModel?,
val onActivityItemClick: (activityId: String) -> Unit,
val onActivityItemClick: (activityCardItemClickParams: ActivityCardItemClickParams) -> Unit,
val onFooterLinkClick: () -> Unit
) : MySiteCardAndItemBuilderParams()
) : MySiteCardAndItemBuilderParams() {
data class ActivityCardItemClickParams(
val activityId: String,
val isRewindable: Boolean
)
}

data class SiteItemsBuilderParams(
val site: SiteModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import org.wordpress.android.ui.mysite.MySiteCardAndItem.JetpackBadge
import org.wordpress.android.ui.mysite.MySiteCardAndItem.SiteInfoHeaderCard
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Type
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.ActivityCardBuilderParams
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.ActivityCardBuilderParams.ActivityCardItemClickParams
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.BloggingPromptCardBuilderParams
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.DashboardCardDomainBuilderParams
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.DashboardCardsBuilderParams
Expand Down Expand Up @@ -620,7 +621,7 @@ class MySiteViewModel @Inject constructor(
activityCardModel = cardsUpdate?.cards?.firstOrNull {
it is ActivityCardModel
} as? ActivityCardModel,
onActivityItemClick = this::onActivityItemClick,
onActivityItemClick = this::onActivityCardItemClick,
onFooterLinkClick = this::onActivityCardFooterLinkClick
),
),
Expand Down Expand Up @@ -716,14 +717,22 @@ class MySiteViewModel @Inject constructor(
// implement navigation logic for create page
}

@Suppress("UNUSED_PARAMETER")
private fun onActivityItemClick(activityId: String) {
// implement navigation logic for activity item
private fun onActivityCardItemClick(activityCardItemClickParams: ActivityCardItemClickParams) {
// implement track event for activity item click
_onNavigation.value =
Event(
SiteNavigationAction.OpenActivityLogDetail(
requireNotNull(selectedSiteRepository.getSelectedSite()),
activityCardItemClickParams.activityId,
activityCardItemClickParams.isRewindable
)
)
}

@Suppress("UNUSED_PARAMETER")
private fun onActivityCardFooterLinkClick() {
// implement navigation logic for activity card footer link
// implement track event for activity card footer link
_onNavigation.value =
Event(SiteNavigationAction.OpenActivityLog(requireNotNull(selectedSiteRepository.getSelectedSite())))
}

private fun buildJetpackBadgeIfEnabled(): JetpackBadge? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ sealed class SiteNavigationAction {
data class OpenJetpackFeatureOverlay(val source: JetpackFeatureCollectionOverlaySource) : SiteNavigationAction()
data class OpenPromoteWithBlazeOverlay(val source: BlazeFlowSource) : SiteNavigationAction()
object ShowJetpackRemovalStaticPostersView : SiteNavigationAction()
data class OpenActivityLogDetail(val site: SiteModel, val activityId: String, val isRewindable: Boolean) :
SiteNavigationAction()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.Das
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.ActivityCard.ActivityCardWithItems
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.ActivityCard.ActivityCardWithItems.ActivityItem
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.ActivityCardBuilderParams
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.ActivityCardBuilderParams.ActivityCardItemClickParams
import org.wordpress.android.ui.utils.ListItemInteraction
import org.wordpress.android.ui.utils.UiString
import org.wordpress.android.ui.utils.UiString.UiStringRes
Expand Down Expand Up @@ -40,17 +41,21 @@ class ActivityCardBuilder @Inject constructor(
)
}

private fun List<ActivityLogModel>.mapToActivityItems(onClick: (activityId: String) -> Unit) =
map {
ActivityItem(
label = UiString.UiStringText(it.content?.text?:""),
subLabel = it.summary,
displayDate = buildDateLine(it.published),
icon = ActivityLogListItem.Icon.fromValue(it.gridicon).drawable,
iconBackgroundColor = ActivityLogListItem.Status.fromValue(it.status).color,
onClick = ListItemInteraction.create(it.activityID, onClick),
private fun List<ActivityLogModel>.mapToActivityItems(
onClick: (activityCardItemClickParams: ActivityCardItemClickParams) -> Unit
) = map {
ActivityItem(
label = UiString.UiStringText(it.content?.text ?: ""),
subLabel = it.summary,
displayDate = buildDateLine(it.published),
icon = ActivityLogListItem.Icon.fromValue(it.gridicon).drawable,
iconBackgroundColor = ActivityLogListItem.Status.fromValue(it.status).color,
onClick = ListItemInteraction.create(
ActivityCardItemClickParams(it.activityID, it.rewindable ?: false),
onClick
)
}
)
}

private fun buildDateLine(published: Date) = dateTimeUtilsWrapper.javaDateToTimeSpan(published)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ class MySiteTabFragment : Fragment(R.layout.my_site_tab_fragment),
is SiteNavigationAction.ShowJetpackRemovalStaticPostersView -> {
ActivityLauncher.showJetpackStaticPoster(requireActivity())
}
is SiteNavigationAction.OpenActivityLogDetail -> ActivityLauncher.viewActivityLogDetailFromDashboardCard(
activity,
action.site,
action.activityId,
action.isRewindable
)
}

private fun showJetpackPoweredBottomSheet() {
Expand Down
Loading

0 comments on commit 40b881a

Please sign in to comment.