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

APPS-3432: Has certificates bug #879

Merged
merged 3 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -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 @@ -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 @@ -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 @@ -157,7 +157,7 @@ class CourseCompleteBottomSheetDialogFragment : BottomSheetDialogFragment(),
val progress = score * 100 / cost

return when {
progress < 20f && !courseCompleteInfo.course.hasCertificate -> {
progress < 20f && !courseCompleteInfo.course.withCertificate -> {
setupCertificateNotIssued(
courseCompleteInfo = courseCompleteInfo,
headerImage = R.drawable.ic_tak_demo_lesson,
Expand All @@ -167,7 +167,7 @@ class CourseCompleteBottomSheetDialogFragment : BottomSheetDialogFragment(),
secondaryActionStringRes = R.string.course_complete_action_back_to_assignments
)
}
progress < 20f && courseCompleteInfo.course.hasCertificate -> {
progress < 20f && courseCompleteInfo.course.withCertificate -> {
val courseScore = score.toLong()
when {
(courseCompleteInfo.course.certificateRegularThreshold != 0L && courseScore < courseCompleteInfo.course.certificateRegularThreshold) ||
Expand Down Expand Up @@ -213,7 +213,7 @@ class CourseCompleteBottomSheetDialogFragment : BottomSheetDialogFragment(),
CourseCompleteDialogViewInfo.EMPTY
}
}
progress >= 20f && progress < 80f && !courseCompleteInfo.course.hasCertificate -> {
progress >= 20f && progress < 80f && !courseCompleteInfo.course.withCertificate -> {
setupCertificateNotIssued(
courseCompleteInfo = courseCompleteInfo,
headerImage = R.drawable.ic_tak_neutral,
Expand All @@ -223,7 +223,7 @@ class CourseCompleteBottomSheetDialogFragment : BottomSheetDialogFragment(),
secondaryActionStringRes = R.string.course_complete_action_back_to_assignments
)
}
progress >= 20f && progress < 80f && courseCompleteInfo.course.hasCertificate -> {
progress >= 20f && progress < 80f && courseCompleteInfo.course.withCertificate -> {
val courseScore = score.toLong()
when {
(courseCompleteInfo.course.certificateRegularThreshold != 0L && courseScore < courseCompleteInfo.course.certificateRegularThreshold) ||
Expand Down Expand Up @@ -269,7 +269,7 @@ class CourseCompleteBottomSheetDialogFragment : BottomSheetDialogFragment(),
CourseCompleteDialogViewInfo.EMPTY
}
}
progress >= 80f && !courseCompleteInfo.course.hasCertificate -> {
progress >= 80f && !courseCompleteInfo.course.withCertificate -> {
val (primaryAction, secondaryAction) = if (courseCompleteInfo.hasReview) {
-1 to R.string.course_complete_action_find_new_course
} else {
Expand All @@ -286,7 +286,7 @@ class CourseCompleteBottomSheetDialogFragment : BottomSheetDialogFragment(),
)
}

progress >= 80f && courseCompleteInfo.course.hasCertificate -> {
progress >= 80f && courseCompleteInfo.course.withCertificate -> {
val courseScore = score.toLong()
when {
(courseCompleteInfo.course.certificateRegularThreshold != 0L && courseScore < courseCompleteInfo.course.certificateRegularThreshold) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class CoursePropertiesDelegate(

private fun setCertificate(course: Course) {
val isEnrolled = course.enrollment > 0L
val needShow = course.hasCertificate && !isEnrolled
val needShow = course.withCertificate && !isEnrolled
courseCertificateImage.isVisible = needShow
courseCertificateText.isVisible = needShow
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ object MigrationWrappers {
object : MigrationWrapper(MigrationFrom66To67) {},
object : MigrationWrapper(MigrationFrom67To68) {},
MigrationWrapperFrom68To69(MigrationFrom68To69),
object : MigrationWrapper(MigrationFrom69To70) {}
object : MigrationWrapper(MigrationFrom69To70) {},
// TODO Multiple tests on a single table fail, must research
object : MigrationWrapper(MigrationFrom70To71) {}
)
}
10 changes: 2 additions & 8 deletions model/src/main/java/org/stepik/android/model/Course.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ data class Course(
val isCertificateAutoIssued: Boolean = false,
@SerializedName("is_certificate_issued")
val isCertificateIssued: Boolean = false,
@SerializedName("with_certificate")
val withCertificate: Boolean = false,

@SerializedName("last_deadline")
val lastDeadline: String? = null,
Expand Down Expand Up @@ -142,14 +144,6 @@ data class Course(
@SerializedName("default_promo_code_expire_date")
val defaultPromoCodeExpireDate: Date? = null
) : Progressable, Parcelable, Identifiable<Long> {

val hasCertificate: Boolean
get() = certificate?.let {
val hasText = it.isNotEmpty()
val anyCertificateThreshold = certificateRegularThreshold > 0 || certificateDistinctionThreshold > 0
anyCertificateThreshold && (hasText || isCertificateAutoIssued || isCertificateIssued)
} ?: false

companion object {
const val SCHEDULE_TYPE_ENDED = "ended"
const val SCHEDULE_TYPE_UPCOMMING = "upcoming"
Expand Down