Skip to content

Commit

Permalink
Merge pull request #880 from StepicOrg/release/1.190
Browse files Browse the repository at this point in the history
Release/1.190
  • Loading branch information
rostikjoystick authored Sep 15, 2021
2 parents 88e80d9 + 9d8caca commit f5de1b2
Show file tree
Hide file tree
Showing 49 changed files with 728 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ app/src/envDev/assets/configs/config.json filter=git-crypt diff=git-crypt
app/src/debug/assets/configs/config_dev.json filter=git-crypt diff=git-crypt
app/src/debug/assets/configs/config_production.json filter=git-crypt diff=git-crypt
app/src/debug/assets/configs/config_release.json filter=git-crypt diff=git-crypt
app/src/stageDebuggable/assets/configs/config_dev.json filter=git-crypt diff=git-crypt
app/src/stageDebuggable/assets/configs/config_production.json filter=git-crypt diff=git-crypt
app/src/stageDebuggable/assets/configs/config_release.json filter=git-crypt diff=git-crypt
buildsystem/cert/** filter=git-crypt diff=git-crypt
buildsystem/secret.gradle filter=git-crypt diff=git-crypt
fastlane/Fastfile filter=git-crypt diff=git-crypt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ constructor(
certificateLink = cursor.getString(DbStructureCourse.Columns.CERTIFICATE_LINK),
isCertificateAutoIssued = cursor.getBoolean(DbStructureCourse.Columns.IS_CERTIFICATE_AUTO_ISSUED),
isCertificateIssued = cursor.getBoolean(DbStructureCourse.Columns.IS_CERTIFICATE_ISSUED),
withCertificate = cursor.getBoolean(DbStructureCourse.Columns.WITH_CERTIFICATE),
lastDeadline = cursor.getString(DbStructureCourse.Columns.LAST_DEADLINE),
beginDate = cursor.getString(DbStructureCourse.Columns.BEGIN_DATE),
endDate = cursor.getString(DbStructureCourse.Columns.END_DATE),
Expand Down Expand Up @@ -126,6 +127,7 @@ constructor(
values.put(DbStructureCourse.Columns.CERTIFICATE_LINK, course.certificateLink)
values.put(DbStructureCourse.Columns.IS_CERTIFICATE_AUTO_ISSUED, course.isCertificateAutoIssued)
values.put(DbStructureCourse.Columns.IS_CERTIFICATE_ISSUED, course.isCertificateIssued)
values.put(DbStructureCourse.Columns.WITH_CERTIFICATE, course.withCertificate)
values.put(DbStructureCourse.Columns.LAST_DEADLINE, course.lastDeadline)
values.put(DbStructureCourse.Columns.BEGIN_DATE, course.beginDate)
values.put(DbStructureCourse.Columns.END_DATE, course.endDate)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.stepic.droid.storage.migration

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import org.stepic.droid.storage.structure.DbStructureCourse

object MigrationFrom70To71 : Migration(70, 71) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE ${DbStructureCourse.TABLE_NAME} ADD COLUMN ${DbStructureCourse.Columns.WITH_CERTIFICATE} INTEGER")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ object Migrations {
MigrationFrom66To67,
MigrationFrom67To68,
MigrationFrom68To69,
MigrationFrom69To70
MigrationFrom69To70,
MigrationFrom70To71
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ object DbStructureCourse {
const val CERTIFICATE_LINK = "certificate_link"
const val IS_CERTIFICATE_AUTO_ISSUED = "is_certificate_auto_issued"
const val IS_CERTIFICATE_ISSUED = "is_certificate_issued"
const val WITH_CERTIFICATE = "with_certificate"

const val LAST_DEADLINE = "last_deadline"
const val BEGIN_DATE = "begin_date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class MainFeedActivity : BackToExitActivityWithSmartLockBase(),
private const val NOTIFICATIONS_DEEPLINK = "notifications"

private const val DEBUG_BUILD_TYPE = "debug"
private const val STAGE_DEBUGGABLE_BUILD_TYPE = "stageDebuggable"

const val HOME_INDEX: Int = 1
const val CATALOG_INDEX: Int = 2
Expand Down Expand Up @@ -289,7 +290,7 @@ class MainFeedActivity : BackToExitActivityWithSmartLockBase(),
private fun initNavigation() {
navigationView.setOnNavigationItemSelectedListener(::onNavigationItemSelected)
navigationView.setOnNavigationItemReselectedListener(::onNavigationItemReselected)
navigationView.menu.findItem(R.id.debug).isVisible = BuildConfig.BUILD_TYPE == DEBUG_BUILD_TYPE
navigationView.menu.findItem(R.id.debug).isVisible = BuildConfig.BUILD_TYPE == DEBUG_BUILD_TYPE || BuildConfig.BUILD_TYPE == STAGE_DEBUGGABLE_BUILD_TYPE
}

private fun showCurrentFragment(@IdRes id: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import org.stepik.android.domain.visited_courses.model.VisitedCourse
)
abstract class AppDatabase : RoomDatabase() {
companion object {
const val VERSION = 70
const val VERSION = 71
const val NAME = "stepic_database.db"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,8 +36,8 @@ constructor(
throw IllegalArgumentException("Unsupported source type = $sourceType")
}

override fun checkPromoCodeValidity(courseId: Long, name: String): Single<PromoCode> =
override fun checkDeeplinkPromoCodeValidity(courseId: Long, name: String): Single<DeeplinkPromoCode> =
coursePaymentsRemoteDataSource
.checkPromoCodeValidity(courseId, name)
.onErrorReturnItem(PromoCode.EMPTY)
.checkDeeplinkPromoCodeValidity(courseId, name)
.onErrorReturnItem(DeeplinkPromoCode.EMPTY)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -17,5 +17,5 @@ interface CoursePaymentsRemoteDataSource {
*/
fun getCoursePaymentsByCourseId(courseId: Long, coursePaymentStatus: CoursePayment.Status? = null): Single<List<CoursePayment>>

fun checkPromoCodeValidity(courseId: Long, name: String): Single<PromoCode>
fun checkDeeplinkPromoCodeValidity(courseId: Long, name: String): Single<DeeplinkPromoCode>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,9 +70,9 @@ constructor(
}
}

fun checkPromoCodeValidity(courseId: Long, promo: String): Single<PromoCode> =
fun checkDeeplinkPromoCodeValidity(courseId: Long, promo: String): Single<DeeplinkPromoCode> =
coursePaymentsRepository
.checkPromoCodeValidity(courseId, promo)
.checkDeeplinkPromoCodeValidity(courseId, promo)

/**
* Load course reviews for not enrolled [courses]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ constructor(
instructors = (instructors ?: course.instructors?.map { null })?.takeIf { it.isNotEmpty() },
language = course.language,
certificate = course.certificate
?.takeIf { course.hasCertificate }
?.takeIf { course.withCertificate }
?.let {
CourseInfoData.Certificate(
title = it,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("", "")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoursePayment>
Expand All @@ -17,5 +17,5 @@ interface CoursePaymentsRepository {
*/
fun getCoursePaymentsByCourseId(courseId: Long, coursePaymentStatus: CoursePayment.Status? = null, sourceType: DataSourceType = DataSourceType.CACHE): Single<List<CoursePayment>>

fun checkPromoCodeValidity(courseId: Long, name: String): Single<PromoCode>
fun checkDeeplinkPromoCodeValidity(courseId: Long, name: String): Single<DeeplinkPromoCode>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,9 +47,9 @@ constructor(
}
}

override fun checkPromoCodeValidity(courseId: Long, name: String): Single<PromoCode> =
override fun checkDeeplinkPromoCodeValidity(courseId: Long, name: String): Single<DeeplinkPromoCode> =
coursePaymentService
.checkPromoCodeValidity(PromoCodeRequest(
.checkDeeplinkPromoCodeValidity(PromoCodeRequest(
course = courseId,
name = name
))
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,7 +22,7 @@ interface CoursePaymentService {
): Single<CoursePaymentsResponse>

@POST("api/promo-codes/check")
fun checkPromoCodeValidity(
fun checkDeeplinkPromoCodeValidity(
@Body promoCodeRequest: PromoCodeRequest
): Single<PromoCode>
): Single<DeeplinkPromoCode>
}
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.stepik.android.view.course.model

data class CoursePromoCodeInfo(
val currencyCode: String,
val price: String,
val hasPromo: Boolean
)
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading

0 comments on commit f5de1b2

Please sign in to comment.