-
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 #796 from StepicOrg/release/1.166
Release/1.166
- Loading branch information
Showing
66 changed files
with
928 additions
and
152 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
12 changes: 12 additions & 0 deletions
12
app/src/main/java/org/stepic/droid/storage/migration/MigrationFrom65To66.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.step.structure.DbStructureStep | ||
|
||
object MigrationFrom65To66 : Migration(65, 66) { | ||
override fun migrate(db: SupportSQLiteDatabase) { | ||
db.execSQL("ALTER TABLE ${DbStructureStep.TABLE_NAME} ADD COLUMN ${DbStructureStep.Column.NEEDS_PLAN} TEXT") | ||
db.execSQL("CREATE TABLE IF NOT EXISTS `CourseRecommendation` (`id` INTEGER NOT NULL, `courses` TEXT NOT NULL, PRIMARY KEY (`id`))") | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...g/stepik/android/cache/course_recommendations/CourseRecommendationsCacheDataSourceImpl.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,22 @@ | ||
package org.stepik.android.cache.course_recommendations | ||
|
||
import io.reactivex.Completable | ||
import io.reactivex.Maybe | ||
import org.stepik.android.cache.course_recommendations.dao.CourseRecommendationsDao | ||
import org.stepik.android.data.course_recommendations.source.CourseRecommendationsCacheDataSource | ||
import org.stepik.android.domain.course_recommendations.model.CourseRecommendation | ||
import javax.inject.Inject | ||
|
||
class CourseRecommendationsCacheDataSourceImpl | ||
@Inject | ||
constructor( | ||
private val courseRecommendationsDao: CourseRecommendationsDao | ||
) : CourseRecommendationsCacheDataSource { | ||
override fun getCourseRecommendations(): Maybe<List<CourseRecommendation>> = | ||
courseRecommendationsDao.getCourseRecommendations() | ||
|
||
override fun saveCourseRecommendations(courseRecommendations: List<CourseRecommendation>): Completable = | ||
courseRecommendationsDao | ||
.clearCourseRecommendations() | ||
.andThen(courseRecommendationsDao.insertCourseRecommendations(courseRecommendations)) | ||
} |
21 changes: 21 additions & 0 deletions
21
...main/java/org/stepik/android/cache/course_recommendations/dao/CourseRecommendationsDao.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,21 @@ | ||
package org.stepik.android.cache.course_recommendations.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import io.reactivex.Completable | ||
import io.reactivex.Maybe | ||
import org.stepik.android.domain.course_recommendations.model.CourseRecommendation | ||
|
||
@Dao | ||
interface CourseRecommendationsDao { | ||
@Query("SELECT * FROM CourseRecommendation") | ||
fun getCourseRecommendations(): Maybe<List<CourseRecommendation>> | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
fun insertCourseRecommendations(courseRecommendations: List<CourseRecommendation>): Completable | ||
|
||
@Query("DELETE FROM CourseRecommendation") | ||
fun clearCourseRecommendations(): Completable | ||
} |
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
39 changes: 39 additions & 0 deletions
39
...pik/android/data/course_recommendations/repository/CourseRecommendationsRepositoryImpl.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,39 @@ | ||
package org.stepik.android.data.course_recommendations.repository | ||
|
||
import io.reactivex.Maybe | ||
import org.stepik.android.data.course_recommendations.source.CourseRecommendationsCacheDataSource | ||
import org.stepik.android.data.course_recommendations.source.CourseRecommendationsRemoteDataSource | ||
import org.stepik.android.domain.base.DataSourceType | ||
import org.stepik.android.domain.course_recommendations.model.CourseRecommendation | ||
import org.stepik.android.domain.course_recommendations.repository.CourseRecommendationsRepository | ||
import ru.nobird.android.domain.rx.doCompletableOnSuccess | ||
import javax.inject.Inject | ||
|
||
class CourseRecommendationsRepositoryImpl | ||
@Inject | ||
constructor( | ||
private val courseRecommendationsRemoteDataSource: CourseRecommendationsRemoteDataSource, | ||
private val courseRecommendationsCacheDataSource: CourseRecommendationsCacheDataSource | ||
) : CourseRecommendationsRepository { | ||
override fun getCourseRecommendations(language: String, primarySourceType: DataSourceType): Maybe<List<CourseRecommendation>> { | ||
val remoteSource = courseRecommendationsRemoteDataSource | ||
.getCourseRecommendations(language) | ||
.doCompletableOnSuccess { courseRecommendationsCacheDataSource.saveCourseRecommendations(it) } | ||
|
||
val cacheDataSource = courseRecommendationsCacheDataSource | ||
.getCourseRecommendations() | ||
|
||
return when (primarySourceType) { | ||
DataSourceType.REMOTE -> | ||
remoteSource | ||
.onErrorResumeNext(cacheDataSource) | ||
|
||
DataSourceType.CACHE -> | ||
cacheDataSource | ||
.switchIfEmpty(remoteSource) | ||
|
||
else -> | ||
throw IllegalArgumentException("Unsupported source type = $primarySourceType") | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...stepik/android/data/course_recommendations/source/CourseRecommendationsCacheDataSource.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,10 @@ | ||
package org.stepik.android.data.course_recommendations.source | ||
|
||
import io.reactivex.Completable | ||
import io.reactivex.Maybe | ||
import org.stepik.android.domain.course_recommendations.model.CourseRecommendation | ||
|
||
interface CourseRecommendationsCacheDataSource { | ||
fun getCourseRecommendations(): Maybe<List<CourseRecommendation>> | ||
fun saveCourseRecommendations(courseRecommendations: List<CourseRecommendation>): Completable | ||
} |
8 changes: 8 additions & 0 deletions
8
...tepik/android/data/course_recommendations/source/CourseRecommendationsRemoteDataSource.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,8 @@ | ||
package org.stepik.android.data.course_recommendations.source | ||
|
||
import io.reactivex.Maybe | ||
import org.stepik.android.domain.course_recommendations.model.CourseRecommendation | ||
|
||
interface CourseRecommendationsRemoteDataSource { | ||
fun getCourseRecommendations(language: String): Maybe<List<CourseRecommendation>> | ||
} |
19 changes: 19 additions & 0 deletions
19
...tepik/android/domain/course_recommendations/interactor/CourseRecommendationsInteractor.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,19 @@ | ||
package org.stepik.android.domain.course_recommendations.interactor | ||
|
||
import io.reactivex.Maybe | ||
import org.stepic.droid.preferences.SharedPreferenceHelper | ||
import org.stepik.android.domain.base.DataSourceType | ||
import org.stepik.android.domain.course_recommendations.model.CourseRecommendation | ||
import org.stepik.android.domain.course_recommendations.repository.CourseRecommendationsRepository | ||
import javax.inject.Inject | ||
|
||
class CourseRecommendationsInteractor | ||
@Inject | ||
constructor( | ||
private val sharedPreferenceHelper: SharedPreferenceHelper, | ||
private val courseRecommendationsRepository: CourseRecommendationsRepository | ||
) { | ||
fun fetchCourseRecommendations(): Maybe<List<CourseRecommendation>> = | ||
courseRecommendationsRepository | ||
.getCourseRecommendations(language = sharedPreferenceHelper.languageForFeatured, primarySourceType = DataSourceType.REMOTE) | ||
} |
14 changes: 14 additions & 0 deletions
14
.../main/java/org/stepik/android/domain/course_recommendations/model/CourseRecommendation.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,14 @@ | ||
package org.stepik.android.domain.course_recommendations.model | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.google.gson.annotations.SerializedName | ||
|
||
@Entity | ||
data class CourseRecommendation( | ||
@PrimaryKey | ||
@SerializedName("id") | ||
val id: Long, | ||
@SerializedName("courses") | ||
val courses: List<Long> | ||
) |
Oops, something went wrong.