forked from openedx/openedx-app-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added ability to handle course errors
- Integrate and parse CourseEnrollmentDetails API - Handle CourseAccess Errors on course Dashboard - Update UI based on CourseAccess Errors. fix:LEARNER-10019
- Loading branch information
1 parent
12056d2
commit f723215
Showing
50 changed files
with
924 additions
and
277 deletions.
There are no files selected for viewing
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
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
60 changes: 60 additions & 0 deletions
60
core/src/main/java/org/openedx/core/data/model/CourseEnrollmentDetails.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,60 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.Gson | ||
import com.google.gson.JsonDeserializationContext | ||
import com.google.gson.JsonDeserializer | ||
import com.google.gson.JsonElement | ||
import com.google.gson.annotations.SerializedName | ||
import org.openedx.core.data.storage.CorePreferences | ||
import org.openedx.core.extension.takeIfNotEmpty | ||
import java.lang.reflect.Type | ||
import org.openedx.core.domain.model.CourseEnrollmentDetails as DomainCourseEnrollmentDetails | ||
|
||
data class CourseEnrollmentDetails( | ||
@SerializedName("id") | ||
val id: String, | ||
@SerializedName("course_updates") | ||
val courseUpdates: String, | ||
@SerializedName("course_handouts") | ||
val courseHandouts: String, | ||
@SerializedName("discussion_url") | ||
val discussionUrl: String, | ||
@SerializedName("course_access_details") | ||
val courseAccessDetails: CourseAccessDetails, | ||
@SerializedName("certificate") | ||
val certificate: Certificate?, | ||
@SerializedName("enrollment_details") | ||
val enrollmentDetails: EnrollmentDetails, | ||
@SerializedName("course_info_overview") | ||
val courseInfoOverview: CourseInfoOverview, | ||
) { | ||
fun mapToDomain(): DomainCourseEnrollmentDetails { | ||
return DomainCourseEnrollmentDetails( | ||
id = id, | ||
courseUpdates = courseUpdates, | ||
courseHandouts = courseHandouts, | ||
discussionUrl = discussionUrl, | ||
courseAccessDetails = courseAccessDetails.mapToDomain(), | ||
certificate = certificate?.mapToDomain(), | ||
enrollmentDetails = enrollmentDetails.mapToDomain(), | ||
courseInfoOverview = courseInfoOverview.mapToDomain(), | ||
) | ||
} | ||
|
||
class Deserializer(val corePreferences: CorePreferences) : | ||
JsonDeserializer<CourseEnrollmentDetails> { | ||
override fun deserialize( | ||
json: JsonElement?, | ||
typeOfT: Type?, | ||
context: JsonDeserializationContext?, | ||
): CourseEnrollmentDetails { | ||
val courseDetails = Gson().fromJson(json, CourseEnrollmentDetails::class.java) | ||
corePreferences.appConfig.iapConfig.productPrefix?.takeIfNotEmpty()?.let { | ||
courseDetails.courseInfoOverview.courseModes?.forEach { courseModes -> | ||
courseModes.setStoreProductSku(it) | ||
} | ||
} | ||
return courseDetails | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
core/src/main/java/org/openedx/core/data/model/CourseInfoOverview.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,60 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import org.openedx.core.domain.model.iap.ProductInfo | ||
import org.openedx.core.extension.isNotNullOrEmpty | ||
import org.openedx.core.utils.TimeUtils | ||
import org.openedx.core.domain.model.CourseInfoOverview as DomainCourseInfoOverview | ||
|
||
data class CourseInfoOverview( | ||
@SerializedName("name") | ||
val name: String, | ||
@SerializedName("number") | ||
val number: String, | ||
@SerializedName("org") | ||
val org: String, | ||
@SerializedName("start") | ||
val start: String?, | ||
@SerializedName("start_display") | ||
val startDisplay: String, | ||
@SerializedName("start_type") | ||
val startType: String, | ||
@SerializedName("end") | ||
val end: String?, | ||
@SerializedName("is_self_paced") | ||
val isSelfPaced: Boolean, | ||
@SerializedName("media") | ||
var media: Media?, | ||
@SerializedName("course_sharing_utm_parameters") | ||
val courseSharingUtmParameters: CourseSharingUtmParameters, | ||
@SerializedName("course_about") | ||
val courseAbout: String, | ||
@SerializedName("course_modes") | ||
val courseModes: List<CourseMode>?, | ||
) { | ||
fun mapToDomain() = DomainCourseInfoOverview( | ||
name = name, | ||
number = number, | ||
org = org, | ||
start = TimeUtils.iso8601ToDate(start ?: ""), | ||
startDisplay = startDisplay, | ||
startType = startType, | ||
end = TimeUtils.iso8601ToDate(end ?: ""), | ||
isSelfPaced = isSelfPaced, | ||
media = media?.mapToDomain(), | ||
courseSharingUtmParameters = courseSharingUtmParameters.mapToDomain(), | ||
courseAbout = courseAbout, | ||
courseModes = courseModes?.map { it.mapToDomain() }, | ||
productInfo = courseModes?.find { | ||
it.isVerifiedMode() | ||
}?.takeIf { | ||
it.androidSku.isNotNullOrEmpty() && it.storeSku.isNotNullOrEmpty() | ||
}?.run { | ||
ProductInfo( | ||
courseSku = androidSku!!, | ||
storeSku = storeSku!!, | ||
lmsUSDPrice = minPrice ?: 0.0 | ||
) | ||
} | ||
) | ||
} |
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
Oops, something went wrong.