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

PWN-8905 - UiKit. Informer view #1874

Merged
merged 5 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.annotation.StringRes
import android.os.Bundle
import android.view.View
import org.koin.android.ext.android.inject
import org.p2p.core.network.environment.NetworkEnvironment
import org.p2p.uikit.utils.attachAdapter
import org.p2p.wallet.R
import org.p2p.wallet.common.mvp.BaseMvpFragment
Expand All @@ -23,7 +24,7 @@ import org.p2p.wallet.debug.settings.adapter.settingsRowSectionItemDelegate
import org.p2p.wallet.debug.settings.adapter.settingsRowSwtichItemDelegate
import org.p2p.wallet.debug.settings.adapter.settingsRowTitleItemDelegate
import org.p2p.wallet.debug.torus.DebugTorusFragment
import org.p2p.core.network.environment.NetworkEnvironment
import org.p2p.wallet.debug.uikit.DebugUiKitFragmentFragment
import org.p2p.wallet.settings.model.SettingsRow
import org.p2p.wallet.settings.ui.network.SettingsNetworkBottomSheet
import org.p2p.wallet.utils.getSerializableOrNull
Expand Down Expand Up @@ -115,6 +116,9 @@ class DebugSettingsFragment :
R.string.debug_settings_striga_detach_user_id_title -> {
presenter.onClickDetachStrigaUser()
}
R.string.debug_settings_ui_kit -> {
replaceFragment(DebugUiKitFragmentFragment())
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class DebugSettingsMapper(
}

this += createStrigaSettings()

this += SettingsRow.Section(
titleResId = R.string.debug_settings_ui_kit,
iconRes = R.drawable.ic_settings_cloud
)
}

private fun createEnvironmentSettings(): List<SettingsRow> = buildList {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package org.p2p.wallet.debug.uikit

import androidx.annotation.DrawableRes
import org.p2p.core.common.DrawableContainer
import org.p2p.core.common.TextContainer
import org.p2p.uikit.components.InformerViewCellModel
import org.p2p.uikit.model.AnyCellItem
import org.p2p.uikit.organisms.sectionheader.SectionHeaderCellModel
import org.p2p.wallet.R

class DebugInformerViewBuilder {
fun build(
onInfoLineClicked: () -> Unit
): List<AnyCellItem> = listOf(
SectionHeaderCellModel(
sectionTitle = TextContainer("Informer view row 1"),
isShevronVisible = false
),
InformerViewCellModel(
leftIcon = InformerViewCellModel.LeftIconParams(
icon = R.drawable.ic_checkbox_checked.wrap(),
iconTint = R.color.icons_night
),
title = InformerViewCellModel.TitleParams(
value = "Account creation fee".wrap(),
titleIcon = R.drawable.ic_info_solid.wrap()
),
caption = "0.028813 USDC".wrap(),
infoLine = InformerViewCellModel.InfoLineParams(
value = "Info line".wrap(),
position = InformerViewCellModel.InfoLineParams.InfoLinePosition.BOTTOM,
onInfoLineClicked = { onInfoLineClicked() }
),
),
InformerViewCellModel(
leftIcon = InformerViewCellModel.LeftIconParams(
R.drawable.ic_checkbox_checked.wrap(),
iconTint = R.color.icons_night
),
title = InformerViewCellModel.TitleParams(
"Account creation fee".wrap(),
R.drawable.ic_info_solid.wrap()
),
caption = "0.028813 USDC".wrap(),
infoLine = InformerViewCellModel.InfoLineParams(
value = "(\$0.03)".wrap(),
position = InformerViewCellModel.InfoLineParams.InfoLinePosition.CAPTION_LINE,
textColorRes = R.color.text_sky,
onInfoLineClicked = { onInfoLineClicked() }
)
),
InformerViewCellModel(
leftIcon = InformerViewCellModel.LeftIconParams(
R.drawable.ic_checkbox_checked.wrap(),
iconTint = R.color.icons_night
),
title = InformerViewCellModel.TitleParams(
"Account creation fee".wrap(),
R.drawable.ic_info_solid.wrap()
),
caption = "0.028813 USDC".wrap(),
)
) +

listOf(
SectionHeaderCellModel(
sectionTitle = TextContainer("Informer view row 2"),
isShevronVisible = false
),
InformerViewCellModel(
leftIcon = InformerViewCellModel.LeftIconParams(
icon = R.drawable.ic_checkbox_checked.wrap(),
iconTint = R.color.icons_night
),
title = InformerViewCellModel.TitleParams(
value = "Account creation fee".wrap(),
),
caption = "0.028813 USDC".wrap(),
infoLine = InformerViewCellModel.InfoLineParams(
value = "Info line".wrap(),
position = InformerViewCellModel.InfoLineParams.InfoLinePosition.BOTTOM,
onInfoLineClicked = { onInfoLineClicked() }
),
),
InformerViewCellModel(
leftIcon = InformerViewCellModel.LeftIconParams(
icon = R.drawable.ic_checkbox_checked.wrap(),
iconTint = R.color.icons_night
),
title = InformerViewCellModel.TitleParams(
value = "Account creation fee".wrap(),
),
caption = "0.028813 USDC".wrap(),
infoLine = InformerViewCellModel.InfoLineParams(
value = "(\$0.03)".wrap(),
position = InformerViewCellModel.InfoLineParams.InfoLinePosition.CAPTION_LINE,
textColorRes = R.color.text_sky,
onInfoLineClicked = { onInfoLineClicked() }
)
),
InformerViewCellModel(
leftIcon = InformerViewCellModel.LeftIconParams(
icon = R.drawable.ic_checkbox_checked.wrap(),
iconTint = R.color.icons_night
),
title = InformerViewCellModel.TitleParams(
value = "Account creation fee".wrap(),
),
caption = "0.028813 USDC".wrap(),
),
) +

listOf(
SectionHeaderCellModel(
sectionTitle = TextContainer("Informer view row 3"),
isShevronVisible = false
),
InformerViewCellModel(
leftIcon = InformerViewCellModel.LeftIconParams(
icon = R.drawable.ic_checkbox_checked.wrap(),
iconTint = R.color.icons_night
),
caption = "0.028813 USDC".wrap(),
infoLine = InformerViewCellModel.InfoLineParams(
value = "Info line".wrap(),
position = InformerViewCellModel.InfoLineParams.InfoLinePosition.BOTTOM,
onInfoLineClicked = { onInfoLineClicked() }
),
),
InformerViewCellModel(
leftIcon = InformerViewCellModel.LeftIconParams(
icon = R.drawable.ic_checkbox_checked.wrap(),
iconTint = R.color.icons_night
),
caption = "The minimum amount you will receive. If the price slips any further ".wrap(),
infoLine = InformerViewCellModel.InfoLineParams(
value = "(\$0.03)".wrap(),
position = InformerViewCellModel.InfoLineParams.InfoLinePosition.CAPTION_LINE,
textColorRes = R.color.text_sky,
onInfoLineClicked = { onInfoLineClicked() }
)
),
InformerViewCellModel(
leftIcon = InformerViewCellModel.LeftIconParams(
icon = R.drawable.ic_checkbox_checked.wrap(),
iconTint = R.color.icons_night
),
caption = buildString {
append("The minimum amount you will receive. ")
append("If the price slips any further, your transaction will revert.")
}.wrap(),
),
)

private fun @receiver:DrawableRes Int.wrap(): DrawableContainer.Res =
DrawableContainer.invoke(this)

private fun String.wrap(): TextContainer.Raw =
TextContainer.Raw(this)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.p2p.wallet.debug.uikit

import org.p2p.uikit.model.AnyCellItem
import org.p2p.wallet.common.mvp.MvpPresenter
import org.p2p.wallet.common.mvp.MvpView

interface DebugUiKitFragmentContract {
interface View : MvpView {
fun showViews(items: List<AnyCellItem>)
}

interface Presenter : MvpPresenter<View> {
fun buildInformerViews()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.p2p.wallet.debug.uikit

import android.os.Bundle
import android.view.View
import org.p2p.uikit.components.informerViewDelegate
import org.p2p.uikit.model.AnyCellItem
import org.p2p.uikit.organisms.sectionheader.sectionHeaderCellDelegate
import org.p2p.uikit.utils.attachAdapter
import org.p2p.wallet.R
import org.p2p.wallet.common.adapter.CommonAnyCellAdapter
import org.p2p.wallet.common.mvp.BaseMvpFragment
import org.p2p.wallet.databinding.FragmentDebugUiKitBinding
import org.p2p.wallet.utils.viewbinding.viewBinding

class DebugUiKitFragmentFragment :
BaseMvpFragment<DebugUiKitFragmentContract.View, DebugUiKitFragmentContract.Presenter>(
R.layout.fragment_debug_ui_kit
),
DebugUiKitFragmentContract.View {

override val presenter: DebugUiKitFragmentContract.Presenter = DebugUiKitFragmentPresenter()

private val binding: FragmentDebugUiKitBinding by viewBinding()
private val adapter = CommonAnyCellAdapter(
sectionHeaderCellDelegate(),
informerViewDelegate()
)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.recyclerViewUiKitViews.attachAdapter(adapter)

presenter.buildInformerViews()
}

override fun showViews(items: List<AnyCellItem>) {
adapter.items = items
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.p2p.wallet.debug.uikit

import org.p2p.wallet.common.mvp.BasePresenter

class DebugUiKitFragmentPresenter :
BasePresenter<DebugUiKitFragmentContract.View>(),
DebugUiKitFragmentContract.Presenter {
private val informerViewBuilder = DebugInformerViewBuilder()

override fun buildInformerViews() {
view?.showViews(
informerViewBuilder.build(
onInfoLineClicked = { view?.showUiKitSnackBar("informer view clicked") }
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class HistorySendLinkDetailsBottomSheet :
financeBlockLinkValue.rightSideView.setOnClickListener {
historyAnalytics.logUserSendLinkCopyClicked()
requireContext().copyToClipBoard(state.link)
showUiKitSnackBar(messageResId = R.string.send_via_link_generation_copied)
showUiKitSnackBar(messageResId = R.string.general_copied)
}
buttonShare.setOnClickListener {
historyAnalytics.logUserSendLinkShareClicked()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ class StrigaOnboardingFragment :
val helpHighlightText = getString(R.string.striga_onboarding_help_highlight_text)
val helpCommonText = getString(R.string.striga_onboarding_help_common_text, helpHighlightText)
val helpTextSpannable = SpanUtils.highlightLinkNoUnderline(
text = helpCommonText,
linkToHighlight = helpHighlightText,
linkColor = getColor(R.color.sky),
commonText = helpCommonText,
highlightedText = helpHighlightText,
color = getColor(R.color.sky),
onClick = { presenter.onClickHelp() }
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class SendLinkGenerationResultFragment : BaseFragment(R.layout.fragment_send_lin
imageViewCopy.setOnClickListener {
svlAnalytics.logLinkCopyIconClicked()
requireContext().copyToClipBoard(state.formattedLink)
showUiKitSnackBar(messageResId = R.string.send_via_link_generation_copied)
showUiKitSnackBar(messageResId = R.string.general_copied)
}
}
is LinkGenerationState.Error -> {
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/res/layout/fragment_debug_ui_kit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewUiKitViews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bg_smoke"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_informer_view" />

</ScrollView>
2 changes: 1 addition & 1 deletion app/src/main/res/values/send_via_link_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<string name="send_via_link_ready">Share your link to send money</string>
<string name="send_via_link_return_back">If you want to get your money back just open the link by yourself</string>
<string name="send_via_link_limit_exceeded">You have reached the daily limit of sending free links. Try tomorrow</string>
<string name="send_via_link_generation_copied">✅ Copied</string>
<string name="general_copied">✅ Copied</string>
<string name="send_via_link_share_message">Hey, I\'ve sent you %1s! Get it here: \n%2s</string>
<string name="send_dont_need_the_address">Without account details</string>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/settings_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="debug_settings_kyc_mock_title">KYC Banner mock</string>
<string name="debug_settings_kyc_set_rejected_title">KYC Simulate rejected</string>
<string name="debug_settings_striga_detach_user_id_title">Detach striga from web3 user</string>
<string name="debug_settings_ui_kit">UiKit examples</string>

<!-- Debug Settings -> Notifications -->
<string name="debug_notifications_title">Debug Notifications</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sealed class DrawableContainer : Parcelable {
abstract fun applyTo(imageView: ImageView)

@Parcelize
class Res(@DrawableRes private val drawableRes: Int) : DrawableContainer() {
class Res(@DrawableRes val drawableRes: Int) : DrawableContainer() {
override fun applyTo(imageView: ImageView) {
imageView.setImageResource(drawableRes)
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/p2p/core/common/TextContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sealed class TextContainer {
operator fun invoke(@StringRes textRes: Int, vararg args: Any) =
ResParams(textRes, args.toList())

operator fun invoke(text: String) =
operator fun invoke(text: CharSequence) =
Raw(text)
}

Expand Down
Loading
Loading