diff --git a/app/src/main/java/org/stepik/android/data/course_payments/repository/CoursePaymentsRepositoryImpl.kt b/app/src/main/java/org/stepik/android/data/course_payments/repository/CoursePaymentsRepositoryImpl.kt index c5abf77baf..97bf469a76 100644 --- a/app/src/main/java/org/stepik/android/data/course_payments/repository/CoursePaymentsRepositoryImpl.kt +++ b/app/src/main/java/org/stepik/android/data/course_payments/repository/CoursePaymentsRepositoryImpl.kt @@ -7,7 +7,7 @@ import org.stepik.android.data.course_payments.source.CoursePaymentsCacheDataSou import org.stepik.android.data.course_payments.source.CoursePaymentsRemoteDataSource import org.stepik.android.domain.base.DataSourceType import org.stepik.android.domain.course_payments.model.CoursePayment -import org.stepik.android.domain.course_payments.model.PromoCode +import org.stepik.android.domain.course_payments.model.DeeplinkPromoCode import org.stepik.android.domain.course_payments.repository.CoursePaymentsRepository import ru.nobird.android.domain.rx.doCompletableOnSuccess import javax.inject.Inject @@ -36,8 +36,8 @@ constructor( throw IllegalArgumentException("Unsupported source type = $sourceType") } - override fun checkPromoCodeValidity(courseId: Long, name: String): Single = + override fun checkDeeplinkPromoCodeValidity(courseId: Long, name: String): Single = coursePaymentsRemoteDataSource - .checkPromoCodeValidity(courseId, name) - .onErrorReturnItem(PromoCode.EMPTY) + .checkDeeplinkPromoCodeValidity(courseId, name) + .onErrorReturnItem(DeeplinkPromoCode.EMPTY) } \ No newline at end of file diff --git a/app/src/main/java/org/stepik/android/data/course_payments/source/CoursePaymentsRemoteDataSource.kt b/app/src/main/java/org/stepik/android/data/course_payments/source/CoursePaymentsRemoteDataSource.kt index 21a3c3e788..e77537f70f 100644 --- a/app/src/main/java/org/stepik/android/data/course_payments/source/CoursePaymentsRemoteDataSource.kt +++ b/app/src/main/java/org/stepik/android/data/course_payments/source/CoursePaymentsRemoteDataSource.kt @@ -4,7 +4,7 @@ import io.reactivex.Single import org.solovyev.android.checkout.Purchase import org.solovyev.android.checkout.Sku import org.stepik.android.domain.course_payments.model.CoursePayment -import org.stepik.android.domain.course_payments.model.PromoCode +import org.stepik.android.domain.course_payments.model.DeeplinkPromoCode interface CoursePaymentsRemoteDataSource { @@ -17,5 +17,5 @@ interface CoursePaymentsRemoteDataSource { */ fun getCoursePaymentsByCourseId(courseId: Long, coursePaymentStatus: CoursePayment.Status? = null): Single> - fun checkPromoCodeValidity(courseId: Long, name: String): Single + fun checkDeeplinkPromoCodeValidity(courseId: Long, name: String): Single } \ No newline at end of file diff --git a/app/src/main/java/org/stepik/android/domain/course/interactor/CourseInteractor.kt b/app/src/main/java/org/stepik/android/domain/course/interactor/CourseInteractor.kt index b83063c4b4..8bd974f56f 100644 --- a/app/src/main/java/org/stepik/android/domain/course/interactor/CourseInteractor.kt +++ b/app/src/main/java/org/stepik/android/domain/course/interactor/CourseInteractor.kt @@ -12,7 +12,7 @@ import org.stepik.android.domain.base.DataSourceType import org.stepik.android.domain.course.model.CourseHeaderData import org.stepik.android.domain.course.repository.CourseRepository import org.stepik.android.domain.course_payments.mapper.DefaultPromoCodeMapper -import org.stepik.android.domain.course_payments.model.PromoCode +import org.stepik.android.domain.course_payments.model.DeeplinkPromoCode import org.stepik.android.domain.solutions.interactor.SolutionsInteractor import org.stepik.android.domain.solutions.model.SolutionItem import org.stepik.android.domain.wishlist.model.WishlistEntity @@ -62,9 +62,8 @@ constructor( zip( courseStatsInteractor.getCourseStats(listOf(course)), solutionsInteractor.fetchAttemptCacheItems(course.id, localOnly = true), - if (promo == null) Single.just(PromoCode.EMPTY) else courseStatsInteractor.checkPromoCodeValidity(course.id, promo), + if (promo == null) Single.just(DeeplinkPromoCode.EMPTY) else courseStatsInteractor.checkDeeplinkPromoCodeValidity(course.id, promo), (requireAuthorization() then wishlistRepository.getWishlistRecord(DataSourceType.CACHE)).onErrorReturnItem(WishlistEntity.EMPTY) -// if (sharedPreferenceHelper.authResponseFromStore != null) wishlistRepository.getWishlistRecord(DataSourceType.CACHE) else Single.just(WishlistEntity.EMPTY) ) { courseStats, localSubmissions, promoCode, wishlistEntity -> CourseHeaderData( courseId = course.id, @@ -74,7 +73,7 @@ constructor( stats = courseStats.first(), localSubmissionsCount = localSubmissions.count { it is SolutionItem.SubmissionItem }, - promoCode = promoCode, + deeplinkPromoCode = promoCode, defaultPromoCode = defaultPromoCodeMapper.mapToDefaultPromoCode(course), isWishlistUpdating = false, wishlistEntity = wishlistEntity diff --git a/app/src/main/java/org/stepik/android/domain/course/interactor/CourseStatsInteractor.kt b/app/src/main/java/org/stepik/android/domain/course/interactor/CourseStatsInteractor.kt index d9620221ce..3f14d0aba7 100644 --- a/app/src/main/java/org/stepik/android/domain/course/interactor/CourseStatsInteractor.kt +++ b/app/src/main/java/org/stepik/android/domain/course/interactor/CourseStatsInteractor.kt @@ -14,7 +14,7 @@ import org.stepik.android.domain.course.model.EnrollmentState import org.stepik.android.domain.course.model.SourceTypeComposition import org.stepik.android.domain.course.repository.CourseReviewSummaryRepository import org.stepik.android.domain.course_payments.model.CoursePayment -import org.stepik.android.domain.course_payments.model.PromoCode +import org.stepik.android.domain.course_payments.model.DeeplinkPromoCode import org.stepik.android.domain.course_payments.repository.CoursePaymentsRepository import org.stepik.android.domain.progress.mapper.getProgresses import org.stepik.android.domain.profile.repository.ProfileRepository @@ -70,9 +70,9 @@ constructor( } } - fun checkPromoCodeValidity(courseId: Long, promo: String): Single = + fun checkDeeplinkPromoCodeValidity(courseId: Long, promo: String): Single = coursePaymentsRepository - .checkPromoCodeValidity(courseId, promo) + .checkDeeplinkPromoCodeValidity(courseId, promo) /** * Load course reviews for not enrolled [courses] diff --git a/app/src/main/java/org/stepik/android/domain/course/model/CourseHeaderData.kt b/app/src/main/java/org/stepik/android/domain/course/model/CourseHeaderData.kt index d4e3fa4e41..91a92a6445 100644 --- a/app/src/main/java/org/stepik/android/domain/course/model/CourseHeaderData.kt +++ b/app/src/main/java/org/stepik/android/domain/course/model/CourseHeaderData.kt @@ -4,7 +4,7 @@ import android.os.Parcelable import kotlinx.android.parcel.Parcelize import org.stepik.android.domain.wishlist.model.WishlistEntity import org.stepik.android.domain.course_payments.model.DefaultPromoCode -import org.stepik.android.domain.course_payments.model.PromoCode +import org.stepik.android.domain.course_payments.model.DeeplinkPromoCode import org.stepik.android.model.Course @Parcelize @@ -16,7 +16,7 @@ data class CourseHeaderData( val stats: CourseStats, val localSubmissionsCount: Int, - val promoCode: PromoCode, + val deeplinkPromoCode: DeeplinkPromoCode, val defaultPromoCode: DefaultPromoCode, val isWishlistUpdating: Boolean, val wishlistEntity: WishlistEntity diff --git a/app/src/main/java/org/stepik/android/domain/course_payments/model/PromoCode.kt b/app/src/main/java/org/stepik/android/domain/course_payments/model/DeeplinkPromoCode.kt similarity index 82% rename from app/src/main/java/org/stepik/android/domain/course_payments/model/PromoCode.kt rename to app/src/main/java/org/stepik/android/domain/course_payments/model/DeeplinkPromoCode.kt index 1162d97b8e..171939a9a3 100644 --- a/app/src/main/java/org/stepik/android/domain/course_payments/model/PromoCode.kt +++ b/app/src/main/java/org/stepik/android/domain/course_payments/model/DeeplinkPromoCode.kt @@ -5,13 +5,13 @@ import com.google.gson.annotations.SerializedName import kotlinx.android.parcel.Parcelize @Parcelize -data class PromoCode( +data class DeeplinkPromoCode( @SerializedName("price") val price: String, @SerializedName("currency_code") val currencyCode: String ) : Parcelable { companion object { - val EMPTY = PromoCode("", "") + val EMPTY = DeeplinkPromoCode("", "") } } \ No newline at end of file diff --git a/app/src/main/java/org/stepik/android/domain/course_payments/repository/CoursePaymentsRepository.kt b/app/src/main/java/org/stepik/android/domain/course_payments/repository/CoursePaymentsRepository.kt index a9a5b7a458..dc8785e1e6 100644 --- a/app/src/main/java/org/stepik/android/domain/course_payments/repository/CoursePaymentsRepository.kt +++ b/app/src/main/java/org/stepik/android/domain/course_payments/repository/CoursePaymentsRepository.kt @@ -5,7 +5,7 @@ import org.solovyev.android.checkout.Purchase import org.solovyev.android.checkout.Sku import org.stepik.android.domain.base.DataSourceType import org.stepik.android.domain.course_payments.model.CoursePayment -import org.stepik.android.domain.course_payments.model.PromoCode +import org.stepik.android.domain.course_payments.model.DeeplinkPromoCode interface CoursePaymentsRepository { fun createCoursePayment(courseId: Long, sku: Sku, purchase: Purchase): Single @@ -17,5 +17,5 @@ interface CoursePaymentsRepository { */ fun getCoursePaymentsByCourseId(courseId: Long, coursePaymentStatus: CoursePayment.Status? = null, sourceType: DataSourceType = DataSourceType.CACHE): Single> - fun checkPromoCodeValidity(courseId: Long, name: String): Single + fun checkDeeplinkPromoCodeValidity(courseId: Long, name: String): Single } \ No newline at end of file diff --git a/app/src/main/java/org/stepik/android/remote/course_payments/CoursePaymentsRemoteDataSourceImpl.kt b/app/src/main/java/org/stepik/android/remote/course_payments/CoursePaymentsRemoteDataSourceImpl.kt index b3b37e3418..8a989004b1 100644 --- a/app/src/main/java/org/stepik/android/remote/course_payments/CoursePaymentsRemoteDataSourceImpl.kt +++ b/app/src/main/java/org/stepik/android/remote/course_payments/CoursePaymentsRemoteDataSourceImpl.kt @@ -5,7 +5,7 @@ import org.solovyev.android.checkout.Purchase import org.solovyev.android.checkout.Sku import org.stepik.android.data.course_payments.source.CoursePaymentsRemoteDataSource import org.stepik.android.domain.course_payments.model.CoursePayment -import org.stepik.android.domain.course_payments.model.PromoCode +import org.stepik.android.domain.course_payments.model.DeeplinkPromoCode import org.stepik.android.remote.course_payments.model.CoursePaymentRequest import org.stepik.android.remote.course_payments.model.CoursePaymentsResponse import org.stepik.android.remote.course_payments.model.PromoCodeRequest @@ -47,9 +47,9 @@ constructor( } } - override fun checkPromoCodeValidity(courseId: Long, name: String): Single = + override fun checkDeeplinkPromoCodeValidity(courseId: Long, name: String): Single = coursePaymentService - .checkPromoCodeValidity(PromoCodeRequest( + .checkDeeplinkPromoCodeValidity(PromoCodeRequest( course = courseId, name = name )) diff --git a/app/src/main/java/org/stepik/android/remote/course_payments/service/CoursePaymentService.kt b/app/src/main/java/org/stepik/android/remote/course_payments/service/CoursePaymentService.kt index c7dcbfe88d..75bea40656 100644 --- a/app/src/main/java/org/stepik/android/remote/course_payments/service/CoursePaymentService.kt +++ b/app/src/main/java/org/stepik/android/remote/course_payments/service/CoursePaymentService.kt @@ -1,7 +1,7 @@ package org.stepik.android.remote.course_payments.service import io.reactivex.Single -import org.stepik.android.domain.course_payments.model.PromoCode +import org.stepik.android.domain.course_payments.model.DeeplinkPromoCode import org.stepik.android.remote.course_payments.model.CoursePaymentRequest import org.stepik.android.remote.course_payments.model.CoursePaymentsResponse import org.stepik.android.remote.course_payments.model.PromoCodeRequest @@ -22,7 +22,7 @@ interface CoursePaymentService { ): Single @POST("api/promo-codes/check") - fun checkPromoCodeValidity( + fun checkDeeplinkPromoCodeValidity( @Body promoCodeRequest: PromoCodeRequest - ): Single + ): Single } \ No newline at end of file diff --git a/app/src/main/java/org/stepik/android/view/course/mapper/DisplayPriceMapper.kt b/app/src/main/java/org/stepik/android/view/course/mapper/DisplayPriceMapper.kt index 9de7381ed5..98006fc5e2 100644 --- a/app/src/main/java/org/stepik/android/view/course/mapper/DisplayPriceMapper.kt +++ b/app/src/main/java/org/stepik/android/view/course/mapper/DisplayPriceMapper.kt @@ -1,6 +1,10 @@ package org.stepik.android.view.course.mapper import android.content.Context +import android.text.SpannedString +import androidx.core.text.buildSpannedString +import androidx.core.text.scale +import androidx.core.text.strikeThrough import org.stepic.droid.R import javax.inject.Inject @@ -22,4 +26,18 @@ constructor( else -> "$price $currencyCode" } + + fun mapToDiscountedDisplayPriceSpannedString(originalDisplayPrice: String, currencyCode: String, promoPrice: String): SpannedString { + val promoDisplayPrice = mapToDisplayPrice(currencyCode, promoPrice) + return buildSpannedString { + append(context.getString(R.string.course_payments_purchase_in_web_with_price_promo)) + append(promoDisplayPrice) + append(" ") + scale(0.9f) { + strikeThrough { + append(originalDisplayPrice) + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/org/stepik/android/view/course/model/CoursePromoCodeInfo.kt b/app/src/main/java/org/stepik/android/view/course/model/CoursePromoCodeInfo.kt new file mode 100644 index 0000000000..fd1a5ef1d7 --- /dev/null +++ b/app/src/main/java/org/stepik/android/view/course/model/CoursePromoCodeInfo.kt @@ -0,0 +1,7 @@ +package org.stepik.android.view.course.model + +data class CoursePromoCodeInfo( + val currencyCode: String, + val price: String, + val hasPromo: Boolean +) \ No newline at end of file diff --git a/app/src/main/java/org/stepik/android/view/course/resolver/CoursePromoCodeResolver.kt b/app/src/main/java/org/stepik/android/view/course/resolver/CoursePromoCodeResolver.kt new file mode 100644 index 0000000000..32372d1f67 --- /dev/null +++ b/app/src/main/java/org/stepik/android/view/course/resolver/CoursePromoCodeResolver.kt @@ -0,0 +1,25 @@ +package org.stepik.android.view.course.resolver + +import org.stepic.droid.util.DateTimeHelper +import org.stepik.android.domain.course_payments.model.DeeplinkPromoCode +import org.stepik.android.domain.course_payments.model.DefaultPromoCode +import org.stepik.android.model.Course +import org.stepik.android.view.course.model.CoursePromoCodeInfo +import javax.inject.Inject + +class CoursePromoCodeResolver +@Inject +constructor() { + fun resolvePromoCodeInfo(deeplinkPromoCode: DeeplinkPromoCode, defaultPromoCode: DefaultPromoCode, course: Course): CoursePromoCodeInfo = + when { + deeplinkPromoCode != DeeplinkPromoCode.EMPTY -> + CoursePromoCodeInfo(deeplinkPromoCode.currencyCode, deeplinkPromoCode.price, true) + + defaultPromoCode != DefaultPromoCode.EMPTY && + (defaultPromoCode.defaultPromoCodeExpireDate == null || defaultPromoCode.defaultPromoCodeExpireDate.time > DateTimeHelper.nowUtc()) && course.currencyCode != null -> + CoursePromoCodeInfo(course.currencyCode!!, defaultPromoCode.defaultPromoCodePrice, true) + + else -> + CoursePromoCodeInfo("", "", false) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/stepik/android/view/course/ui/delegates/CourseHeaderDelegate.kt b/app/src/main/java/org/stepik/android/view/course/ui/delegates/CourseHeaderDelegate.kt index db102de141..d2aef97a60 100644 --- a/app/src/main/java/org/stepik/android/view/course/ui/delegates/CourseHeaderDelegate.kt +++ b/app/src/main/java/org/stepik/android/view/course/ui/delegates/CourseHeaderDelegate.kt @@ -2,7 +2,6 @@ package org.stepik.android.view.course.ui.delegates import android.app.Activity import android.text.SpannableString -import android.text.SpannedString import android.text.style.ForegroundColorSpan import android.view.Menu import android.view.MenuItem @@ -10,7 +9,6 @@ import android.view.View import androidx.appcompat.content.res.AppCompatResources import androidx.core.content.ContextCompat import androidx.core.text.buildSpannedString -import androidx.core.text.scale import androidx.core.text.strikeThrough import androidx.core.view.ViewCompat import androidx.core.view.isVisible @@ -39,14 +37,13 @@ import org.stepik.android.domain.course.analytic.batch.BuyCoursePressedAnalyticB import org.stepik.android.domain.course.model.CourseHeaderData import org.stepik.android.domain.course.model.EnrollmentState import org.stepik.android.domain.course_continue.analytic.CourseContinuePressedEvent -import org.stepik.android.domain.course_payments.model.DefaultPromoCode -import org.stepik.android.domain.course_payments.model.PromoCode import org.stepik.android.presentation.course.CoursePresenter import org.stepik.android.presentation.course_continue.model.CourseContinueInteractionSource import org.stepik.android.presentation.user_courses.model.UserCourseAction import org.stepik.android.presentation.wishlist.model.WishlistAction import org.stepik.android.view.base.ui.extension.ColorExtensions import org.stepik.android.view.course.mapper.DisplayPriceMapper +import org.stepik.android.view.course.resolver.CoursePromoCodeResolver import org.stepik.android.view.ui.delegate.ViewStateDelegate import ru.nobird.android.core.model.safeCast import ru.nobird.android.view.base.ui.extension.getAllQueryParameters @@ -61,6 +58,7 @@ constructor( @Assisted private val coursePresenter: CoursePresenter, private val discountButtonAppearanceSplitTest: DiscountButtonAppearanceSplitTest, private val displayPriceMapper: DisplayPriceMapper, + private val coursePromoCodeResolver: CoursePromoCodeResolver, @Assisted private val courseViewSource: CourseViewSource, @Assisted private val isAuthorized: Boolean, @Assisted private val mustShowCourseBenefits: Boolean, @@ -206,25 +204,18 @@ constructor( courseStatsDelegate.setStats(courseHeaderData.stats) } - val (currencyCode, promoPrice, hasPromo) = when { - courseHeaderData.promoCode != PromoCode.EMPTY -> - Triple(courseHeaderData.promoCode.currencyCode, courseHeaderData.promoCode.price, true) - - courseHeaderData.defaultPromoCode != DefaultPromoCode.EMPTY && - (courseHeaderData.defaultPromoCode.defaultPromoCodeExpireDate == null || courseHeaderData.defaultPromoCode.defaultPromoCodeExpireDate.time > DateTimeHelper.nowUtc()) && - courseHeaderData.course.currencyCode != null -> - Triple(courseHeaderData.course.currencyCode!!, courseHeaderData.defaultPromoCode.defaultPromoCodePrice, true) - - else -> - Triple("", "", false) - } + val (currencyCode, promoPrice, hasPromo) = coursePromoCodeResolver.resolvePromoCodeInfo( + courseHeaderData.deeplinkPromoCode, + courseHeaderData.defaultPromoCode, + courseHeaderData.course + ) val courseDisplayPrice = courseHeaderData.course.displayPrice courseBuyInWebAction.text = if (courseDisplayPrice != null) { if (hasPromo) { - getPurchaseButtonText(courseDisplayPrice, currencyCode, promoPrice) + displayPriceMapper.mapToDiscountedDisplayPriceSpannedString(courseDisplayPrice, currencyCode, promoPrice) } else { getString(R.string.course_payments_purchase_in_web_with_price, courseDisplayPrice) } @@ -293,20 +284,6 @@ constructor( shareCourseMenuItem?.isVisible = true } - private fun getPurchaseButtonText(originalDisplayPrice: String, currencyCode: String, promoPrice: String): SpannedString { - val promoDisplayPrice = displayPriceMapper.mapToDisplayPrice(currencyCode, promoPrice) - return buildSpannedString { - append(courseActivity.getString(R.string.course_payments_purchase_in_web_with_price_promo)) - append(promoDisplayPrice) - append(" ") - scale(0.9f) { - strikeThrough { - append(originalDisplayPrice) - } - } - } - } - fun showCourseShareTooltip() { val menuItemView = courseActivity .courseToolbar diff --git a/app/src/main/java/org/stepik/android/view/download/ui/activity/DownloadActivity.kt b/app/src/main/java/org/stepik/android/view/download/ui/activity/DownloadActivity.kt index f48f009ba9..ec61379d56 100644 --- a/app/src/main/java/org/stepik/android/view/download/ui/activity/DownloadActivity.kt +++ b/app/src/main/java/org/stepik/android/view/download/ui/activity/DownloadActivity.kt @@ -86,9 +86,9 @@ class DownloadActivity : FragmentActivityBase(), DownloadView, RemoveCachedConte downloadPresenter.fetchStorage() downloadPresenter.fetchDownloadedCourses() - TextViewCompat.setCompoundDrawableTintList(downloadsOtherApps, ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_on_surface_alpha_12))) + TextViewCompat.setCompoundDrawableTintList(downloadsOtherApps, ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_overlay_yellow))) TextViewCompat.setCompoundDrawableTintList(downloadsStepik, ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_overlay_green))) - TextViewCompat.setCompoundDrawableTintList(downloadsFree, ColorStateList.valueOf(ContextCompat.getColor(this, R.color.grey04))) + TextViewCompat.setCompoundDrawableTintList(downloadsFree, ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_elevation_overlay_2dp))) } private fun injectComponent() { diff --git a/app/src/main/java/org/stepik/android/view/lesson/ui/dialog/LessonDemoCompleteBottomSheetDialogFragment.kt b/app/src/main/java/org/stepik/android/view/lesson/ui/dialog/LessonDemoCompleteBottomSheetDialogFragment.kt index 98be19951d..b8795920ef 100644 --- a/app/src/main/java/org/stepik/android/view/lesson/ui/dialog/LessonDemoCompleteBottomSheetDialogFragment.kt +++ b/app/src/main/java/org/stepik/android/view/lesson/ui/dialog/LessonDemoCompleteBottomSheetDialogFragment.kt @@ -13,7 +13,11 @@ import org.stepic.droid.R import org.stepic.droid.base.App import org.stepic.droid.core.ScreenManager import org.stepik.android.domain.course.analytic.CourseViewSource +import org.stepik.android.domain.course_payments.model.DeeplinkPromoCode +import org.stepik.android.domain.course_payments.model.DefaultPromoCode import org.stepik.android.model.Course +import org.stepik.android.view.course.mapper.DisplayPriceMapper +import org.stepik.android.view.course.resolver.CoursePromoCodeResolver import org.stepik.android.view.course.routing.CourseScreenTab import ru.nobird.android.view.base.ui.extension.argument import javax.inject.Inject @@ -22,8 +26,6 @@ class LessonDemoCompleteBottomSheetDialogFragment : BottomSheetDialogFragment() companion object { const val TAG = "LessonDemoCompleteBottomSheetDialog" - const val ARG_COURSE = "course" - fun newInstance(course: Course): DialogFragment = LessonDemoCompleteBottomSheetDialogFragment().apply { this.course = course @@ -35,6 +37,12 @@ class LessonDemoCompleteBottomSheetDialogFragment : BottomSheetDialogFragment() @Inject lateinit var screenManager: ScreenManager + @Inject + lateinit var displayPriceMapper: DisplayPriceMapper + + @Inject + lateinit var coursePromoCodeResolver: CoursePromoCodeResolver + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) App.component().inject(this) @@ -52,7 +60,30 @@ class LessonDemoCompleteBottomSheetDialogFragment : BottomSheetDialogFragment() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) demoCompleteTitle.text = getString(R.string.demo_complete_title, course.title) - demoCompleteAction.text = getString(R.string.demo_complete_purchase_action, course.displayPrice) + + val courseDisplayPrice = course.displayPrice + val (currencyCode, promoPrice, hasPromo) = coursePromoCodeResolver.resolvePromoCodeInfo( + DeeplinkPromoCode.EMPTY, // TODO Deeplink promo code will be passed as a parameter to newInstance + DefaultPromoCode( + course.defaultPromoCodeName ?: "", + course.defaultPromoCodePrice ?: "", + course.defaultPromoCodeDiscount ?: "", + course.defaultPromoCodeExpireDate + ), + course + ) + + demoCompleteAction.text = + if (courseDisplayPrice != null) { + if (hasPromo) { + displayPriceMapper.mapToDiscountedDisplayPriceSpannedString(courseDisplayPrice, currencyCode, promoPrice) + } else { + getString(R.string.course_payments_purchase_in_web_with_price, courseDisplayPrice) + } + } else { + getString(R.string.course_payments_purchase_in_web) + } + demoCompleteAction.setOnClickListener { screenManager.showCourseFromNavigationDialog(requireContext(), course.id, CourseViewSource.LessonDemoDialog, CourseScreenTab.INFO, true) } diff --git a/app/src/main/java/org/stepik/android/view/user_reviews/ui/fragment/UserReviewsFragment.kt b/app/src/main/java/org/stepik/android/view/user_reviews/ui/fragment/UserReviewsFragment.kt index 01d9089d37..d710708850 100644 --- a/app/src/main/java/org/stepik/android/view/user_reviews/ui/fragment/UserReviewsFragment.kt +++ b/app/src/main/java/org/stepik/android/view/user_reviews/ui/fragment/UserReviewsFragment.kt @@ -86,7 +86,7 @@ class UserReviewsFragment : Fragment(R.layout.fragment_user_reviews), ReduxView< screenManager.showCourseDescription(requireContext(), course, CourseViewSource.UserReviews) }, onEditReviewClicked = { courseReview, course -> - analytic.report(EditCourseReviewPressedAnalyticEvent(course.id, course.title.toString(), CourseReviewViewSource.COURSE_REVIEWS_SOURCE)) + analytic.report(EditCourseReviewPressedAnalyticEvent(course.id, course.title.toString(), CourseReviewViewSource.USER_REVIEWS_SOURCE)) showCourseReviewEditDialog(courseReview.course, courseReview, -1f) }, onRemoveReviewClicked = { courseReview -> userReviewsViewModel.onNewMessage(UserReviewsFeature.Message.DeletedReviewUserReviews(courseReview)) } diff --git a/app/src/main/res/drawable/downloads_progress.xml b/app/src/main/res/drawable/downloads_progress.xml index a45f3697d3..5016bc3872 100644 --- a/app/src/main/res/drawable/downloads_progress.xml +++ b/app/src/main/res/drawable/downloads_progress.xml @@ -25,8 +25,8 @@ diff --git a/app/src/test/java/org/stepik/android/domain/course/model/CourseHeaderDataTest.kt b/app/src/test/java/org/stepik/android/domain/course/model/CourseHeaderDataTest.kt index 027a061ba4..96370411d8 100644 --- a/app/src/test/java/org/stepik/android/domain/course/model/CourseHeaderDataTest.kt +++ b/app/src/test/java/org/stepik/android/domain/course/model/CourseHeaderDataTest.kt @@ -5,7 +5,7 @@ import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.stepic.droid.testUtils.assertThatObjectParcelable import org.stepik.android.domain.course_payments.model.DefaultPromoCode -import org.stepik.android.domain.course_payments.model.PromoCode +import org.stepik.android.domain.course_payments.model.DeeplinkPromoCode import org.stepik.android.domain.wishlist.model.WishlistEntity import org.stepik.android.model.Course import org.stepik.android.model.Progress @@ -37,7 +37,7 @@ class CourseHeaderDataTest { isWishlisted = false ), localSubmissionsCount = 5, - promoCode = PromoCode("200", "RUB"), + deeplinkPromoCode = DeeplinkPromoCode("200", "RUB"), defaultPromoCode = DefaultPromoCode.EMPTY, isWishlistUpdating = false, wishlistEntity = WishlistEntity(-1, emptyList())