-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #777 from StepicOrg/release/1.162
Release/1.162
- Loading branch information
Showing
56 changed files
with
1,335 additions
and
154 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
12 changes: 12 additions & 0 deletions
12
app/src/main/java/org/stepic/droid/storage/migration/MigrationFrom63To64.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,12 @@ | ||
package org.stepic.droid.storage.migration | ||
|
||
import androidx.room.migration.Migration | ||
import androidx.sqlite.db.SupportSQLiteDatabase | ||
import org.stepik.android.cache.course_collection.structure.DbStructureCourseCollection | ||
|
||
object MigrationFrom63To64 : Migration(63, 64) { | ||
override fun migrate(db: SupportSQLiteDatabase) { | ||
db.execSQL("ALTER TABLE ${DbStructureCourseCollection.TABLE_NAME} ADD COLUMN ${DbStructureCourseCollection.Columns.SIMILAR_AUTHORS} TEXT") | ||
db.execSQL("ALTER TABLE ${DbStructureCourseCollection.TABLE_NAME} ADD COLUMN ${DbStructureCourseCollection.Columns.SIMILAR_COURSE_LISTS} TEXT") | ||
} | ||
} |
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
111 changes: 109 additions & 2 deletions
111
...java/org/stepik/android/domain/course_collection/interactor/CourseCollectionInteractor.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 |
---|---|---|
@@ -1,17 +1,124 @@ | ||
package org.stepik.android.domain.course_collection.interactor | ||
|
||
import io.reactivex.Flowable | ||
import io.reactivex.Single | ||
import io.reactivex.rxkotlin.Singles.zip | ||
import org.stepic.droid.util.PagedList | ||
import org.stepik.android.domain.base.DataSourceType | ||
import org.stepik.android.domain.catalog.model.CatalogAuthor | ||
import org.stepik.android.domain.catalog.model.CatalogCourseList | ||
import org.stepik.android.domain.course.analytic.CourseViewSource | ||
import org.stepik.android.domain.course.model.SourceTypeComposition | ||
import org.stepik.android.domain.course_collection.model.CourseCollectionResult | ||
import org.stepik.android.domain.course_collection.repository.CourseCollectionRepository | ||
import org.stepik.android.domain.course_list.interactor.CourseListInteractor | ||
import org.stepik.android.domain.course_list.model.CourseListItem | ||
import org.stepik.android.domain.user.repository.UserRepository | ||
import org.stepik.android.model.CourseCollection | ||
import javax.inject.Inject | ||
|
||
class CourseCollectionInteractor | ||
@Inject | ||
constructor( | ||
private val courseCollectionRepository: CourseCollectionRepository | ||
private val courseListInteractor: CourseListInteractor, | ||
private val courseCollectionRepository: CourseCollectionRepository, | ||
private val userRepository: UserRepository | ||
) { | ||
fun getCourseCollection(id: Long, dataSource: DataSourceType): Single<CourseCollection> = | ||
companion object { | ||
private const val PAGE_SIZE = 20 | ||
} | ||
|
||
fun getCourseCollectionResult(id: Long, viewSource: CourseViewSource): Flowable<CourseCollectionResult> = | ||
Flowable | ||
.fromArray(SourceTypeComposition.CACHE, SourceTypeComposition.REMOTE) | ||
.concatMapSingle { sourceType -> | ||
getCourseCollection(id, sourceType.generalSourceType) | ||
.flatMap { collection -> | ||
if (collection.courses.isEmpty()) { | ||
Single.just( | ||
CourseCollectionResult( | ||
courseCollection = collection, | ||
courseListDataItems = PagedList(emptyList()), | ||
courseListItems = emptyList(), | ||
sourceType = sourceType.generalSourceType | ||
) | ||
) | ||
} else { | ||
resolveCollectionLoading(collection, sourceType, viewSource) | ||
} | ||
} | ||
} | ||
|
||
fun getCourseListItems( | ||
courseId: List<Long>, | ||
courseViewSource: CourseViewSource, | ||
sourceTypeComposition: SourceTypeComposition = SourceTypeComposition.REMOTE | ||
): Single<PagedList<CourseListItem.Data>> = | ||
courseListInteractor.getCourseListItems(courseId, courseViewSource, sourceTypeComposition) | ||
|
||
private fun getCourseCollection(id: Long, dataSource: DataSourceType): Single<CourseCollection> = | ||
courseCollectionRepository | ||
.getCourseCollections(id, dataSource) | ||
|
||
private fun getSimilarCourseLists(ids: List<Long>, dataSource: DataSourceType): Single<List<CatalogCourseList>> = | ||
courseCollectionRepository | ||
.getCourseCollections(ids, dataSource) | ||
.map { it.map { courseCollection -> | ||
CatalogCourseList( | ||
id = courseCollection.id, | ||
title = courseCollection.title, | ||
description = courseCollection.description, | ||
courses = courseCollection.courses, | ||
coursesCount = courseCollection.courses.size | ||
) | ||
} } | ||
|
||
private fun getSimilarAuthorLists(ids: List<Long>, dataSource: DataSourceType): Single<List<CatalogAuthor>> = | ||
userRepository | ||
.getUsers(ids, dataSource) | ||
.map { it.map { user -> | ||
CatalogAuthor( | ||
id = user.id, | ||
isOrganization = user.isOrganization, | ||
fullName = user.fullName ?: "", | ||
alias = null, | ||
avatar = user.avatar ?: "", | ||
createdCoursesCount = user.createdCoursesCount.toInt(), | ||
followersCount = user.followersCount.toInt() | ||
) | ||
} } | ||
|
||
private fun resolveCollectionLoading(collection: CourseCollection, sourceType: SourceTypeComposition, viewSource: CourseViewSource): Single<CourseCollectionResult> = | ||
zip( | ||
courseListInteractor.getCourseListItems( | ||
courseIds = | ||
if (collection.similarCourseLists.isNotEmpty() || collection.similarAuthors.isNotEmpty()) { | ||
collection.courses | ||
} else { | ||
collection.courses.take(PAGE_SIZE) | ||
}, | ||
sourceTypeComposition = sourceType, | ||
courseViewSource = viewSource | ||
), | ||
getSimilarCourseLists(collection.similarCourseLists, dataSource = sourceType.generalSourceType), | ||
getSimilarAuthorLists(collection.similarAuthors, dataSource = sourceType.generalSourceType) | ||
) { items, similarCourses, authors -> | ||
CourseCollectionResult( | ||
courseCollection = collection, | ||
courseListDataItems = items, | ||
courseListItems = items + formHorizontalLists(authors, similarCourses), | ||
sourceType = sourceType.generalSourceType | ||
) | ||
} | ||
|
||
private fun formHorizontalLists(authors: List<CatalogAuthor>, similarCourses: List<CatalogCourseList>): List<CourseListItem> { | ||
val list = mutableListOf<CourseListItem>() | ||
if (authors.isNotEmpty()) { | ||
list += CourseListItem.SimilarAuthors(authors) | ||
} | ||
if (similarCourses.isNotEmpty()) { | ||
list += CourseListItem.SimilarCourses(similarCourses) | ||
} | ||
return list | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...src/main/java/org/stepik/android/domain/course_collection/model/CourseCollectionResult.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,13 @@ | ||
package org.stepik.android.domain.course_collection.model | ||
|
||
import org.stepic.droid.util.PagedList | ||
import org.stepik.android.domain.base.DataSourceType | ||
import org.stepik.android.domain.course_list.model.CourseListItem | ||
import org.stepik.android.model.CourseCollection | ||
|
||
data class CourseCollectionResult( | ||
val courseCollection: CourseCollection, | ||
val courseListDataItems: PagedList<CourseListItem.Data>, | ||
val courseListItems: List<CourseListItem>, | ||
val sourceType: DataSourceType | ||
) |
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
52 changes: 52 additions & 0 deletions
52
app/src/main/java/org/stepik/android/domain/filter/model/SubmissionsFilterQuery.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,52 @@ | ||
package org.stepik.android.domain.filter.model | ||
|
||
import android.os.Parcelable | ||
import com.google.gson.annotations.SerializedName | ||
import kotlinx.android.parcel.Parcelize | ||
import ru.nobird.android.core.model.mapOfNotNull | ||
|
||
@Parcelize | ||
data class SubmissionsFilterQuery( | ||
@SerializedName("user") | ||
val user: Long? = null, | ||
@SerializedName("order") | ||
val order: Order? = null, | ||
@SerializedName("status") | ||
val status: String? = null, | ||
@SerializedName("review_status") | ||
val reviewStatus: ReviewStatus? = null, | ||
@SerializedName("search") | ||
val search: String? = null | ||
) : Parcelable { | ||
companion object { | ||
private const val USER = "user" | ||
private const val ORDER = "order" | ||
private const val STATUS = "status" | ||
private const val REVIEW_STATUS = "review_status" | ||
private const val SEARCH = "search" | ||
|
||
val DEFAULT_QUERY = SubmissionsFilterQuery(order = Order.DESC) | ||
} | ||
enum class Order(val order: String) { | ||
@SerializedName("desc") | ||
DESC("desc"), | ||
@SerializedName("asc") | ||
ASC("asc") | ||
} | ||
|
||
enum class ReviewStatus(val reviewStatus: String) { | ||
@SerializedName("awaiting") | ||
AWAITING("awaiting"), | ||
@SerializedName("done") | ||
DONE("done") | ||
} | ||
|
||
fun toMap(): Map<String, String> = | ||
mapOfNotNull( | ||
USER to user?.toString(), | ||
STATUS to status, | ||
ORDER to order?.order, | ||
REVIEW_STATUS to reviewStatus?.reviewStatus, | ||
SEARCH to search | ||
) | ||
} |
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.