-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10685 from woocommerce/issue/10684-ad-destination…
…-screen Blaze: Ad destination screen
- Loading branch information
Showing
7 changed files
with
234 additions
and
9 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...merce/android/ui/blaze/creation/destination/BlazeCampaignCreationAdDestinationFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.woocommerce.android.ui.blaze.creation.destination | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.viewModels | ||
import androidx.navigation.fragment.findNavController | ||
import com.woocommerce.android.ui.base.BaseFragment | ||
import com.woocommerce.android.ui.compose.composeView | ||
import com.woocommerce.android.ui.main.AppBarStatus | ||
import com.woocommerce.android.viewmodel.MultiLiveEvent | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class BlazeCampaignCreationAdDestinationFragment : BaseFragment() { | ||
private val viewModel: BlazeCampaignCreationAdDestinationViewModel by viewModels() | ||
|
||
override val activityAppBarStatus: AppBarStatus | ||
get() = AppBarStatus.Hidden | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
return composeView { | ||
BlazeCampaignCreationAdDestinationScreen(viewModel) | ||
} | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
handleEvents() | ||
handleResults() | ||
} | ||
|
||
private fun handleEvents() { | ||
viewModel.event.observe(viewLifecycleOwner) { event -> | ||
when (event) { | ||
is MultiLiveEvent.Event.Exit -> findNavController().navigateUp() | ||
} | ||
} | ||
} | ||
|
||
private fun handleResults() { | ||
/* TODO */ | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...ommerce/android/ui/blaze/creation/destination/BlazeCampaignCreationAdDestinationScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package com.woocommerce.android.ui.blaze.creation.destination | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Divider | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.icons.Icons.Filled | ||
import androidx.compose.material.icons.filled.ArrowBack | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.livedata.observeAsState | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.res.dimensionResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import com.woocommerce.android.R | ||
import com.woocommerce.android.ui.blaze.creation.destination.BlazeCampaignCreationAdDestinationViewModel.ViewState | ||
import com.woocommerce.android.ui.compose.component.Toolbar | ||
import com.woocommerce.android.ui.compose.preview.LightDarkThemePreviews | ||
import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground | ||
|
||
@Composable | ||
fun BlazeCampaignCreationAdDestinationScreen(viewModel: BlazeCampaignCreationAdDestinationViewModel) { | ||
viewModel.viewState.observeAsState().value?.let { previewState -> | ||
AdDestinationScreen( | ||
previewState, | ||
viewModel::onBackPressed, | ||
viewModel::onUrlPropertyTapped, | ||
viewModel::onParameterPropertyTapped | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
fun AdDestinationScreen( | ||
viewState: ViewState, | ||
onBackPressed: () -> Unit, | ||
onUrlPropertyTapped: () -> Unit, | ||
onParametersPropertyTapped: () -> Unit | ||
) { | ||
Scaffold( | ||
topBar = { | ||
Toolbar( | ||
title = stringResource(id = R.string.blaze_campaign_preview_details_destination_url), | ||
onNavigationButtonClick = onBackPressed, | ||
navigationIcon = Filled.ArrowBack | ||
) | ||
}, | ||
modifier = Modifier.background(MaterialTheme.colors.surface) | ||
) { paddingValues -> | ||
Column( | ||
Modifier | ||
.background(MaterialTheme.colors.surface) | ||
.padding(paddingValues) | ||
.fillMaxSize() | ||
) { | ||
AdDestinationProperty( | ||
title = stringResource(id = R.string.blaze_campaign_edit_ad_destination_url_property_title), | ||
value = viewState.destinationUrl, | ||
onPropertyTapped = onUrlPropertyTapped | ||
) | ||
Divider() | ||
AdDestinationProperty( | ||
title = stringResource(id = R.string.blaze_campaign_edit_ad_destination_parameters_property_title), | ||
value = viewState.parameters, | ||
onPropertyTapped = onParametersPropertyTapped | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun AdDestinationProperty(title: String, value: String, onPropertyTapped: () -> Unit) { | ||
Column( | ||
modifier = Modifier | ||
.clickable { onPropertyTapped() } | ||
.padding(dimensionResource(id = R.dimen.major_100)) | ||
.fillMaxWidth(1f) | ||
) { | ||
Text( | ||
text = title, | ||
style = MaterialTheme.typography.subtitle1, | ||
color = colorResource(id = R.color.color_on_surface_high) | ||
) | ||
Text( | ||
text = value, | ||
style = MaterialTheme.typography.body2, | ||
color = colorResource(id = R.color.color_on_surface_medium), | ||
maxLines = 3, | ||
overflow = TextOverflow.Ellipsis | ||
) | ||
} | ||
} | ||
|
||
@LightDarkThemePreviews | ||
@Composable | ||
fun PreviewAdDestinationScreen() { | ||
WooThemeWithBackground { | ||
AdDestinationScreen( | ||
viewState = ViewState( | ||
destinationUrl = "https://woocommerce.com", | ||
parameters = "utm_source=woocommerce\nutm_medium=android\nutm_campaign=blaze" | ||
), | ||
onBackPressed = {}, | ||
onUrlPropertyTapped = {}, | ||
onParametersPropertyTapped = {} | ||
) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...erce/android/ui/blaze/creation/destination/BlazeCampaignCreationAdDestinationViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.woocommerce.android.ui.blaze.creation.destination | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.asLiveData | ||
import com.woocommerce.android.R | ||
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.Exit | ||
import com.woocommerce.android.viewmodel.ResourceProvider | ||
import com.woocommerce.android.viewmodel.ScopedViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class BlazeCampaignCreationAdDestinationViewModel @Inject constructor( | ||
savedStateHandle: SavedStateHandle, | ||
resourceProvider: ResourceProvider | ||
) : ScopedViewModel(savedStateHandle) { | ||
private val _viewState = MutableStateFlow( | ||
ViewState( | ||
destinationUrl = resourceProvider.getString(R.string.blaze_campaign_edit_ad_destination_empty_url_message), | ||
parameters = resourceProvider | ||
.getString(R.string.blaze_campaign_edit_ad_destination_empty_parameters_message) | ||
) | ||
) | ||
|
||
val viewState = _viewState.asLiveData() | ||
|
||
fun onBackPressed() { | ||
triggerEvent(Exit) | ||
} | ||
|
||
fun onUrlPropertyTapped() { | ||
/* TODO */ | ||
} | ||
|
||
fun onParameterPropertyTapped() { | ||
/* TODO */ | ||
} | ||
|
||
data class ViewState( | ||
val destinationUrl: String, | ||
val parameters: String | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters