Skip to content

Commit

Permalink
Merge branch 'release/1.87'
Browse files Browse the repository at this point in the history
  • Loading branch information
eadm committed Jul 15, 2019
2 parents 1a493bb + 26e8363 commit 5e10192
Show file tree
Hide file tree
Showing 170 changed files with 3,246 additions and 653 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ dependencies {

implementation libraries.shortcutBadger
implementation libraries.StoriesKit
implementation libraries.AdapterDelegates
implementation libraries.Adapters

debugImplementation libraries.leakCanary
releaseImplementation libraries.leakCanaryNoOp
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@
android:windowSoftInputMode="adjustResize" />

<activity
android:name="org.stepik.android.view.lesson.ui.activity.LessonActivity">
android:name="org.stepik.android.view.lesson.ui.activity.LessonActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter
android:autoVerify="true"
tools:ignore="UnusedAttribute">
Expand Down
Binary file added app/src/main/assets/fonts/PT-Mono.ttf
Binary file not shown.
13 changes: 0 additions & 13 deletions app/src/main/java/org/stepic/droid/base/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,6 @@ class App : MultiDexApplication() {
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())

StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectAll()
.penaltyLog()
.build())
StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build())

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WebView.setDataDirectorySuffix("web")
Expand Down
86 changes: 45 additions & 41 deletions app/src/main/java/org/stepic/droid/core/CommentManager.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
package org.stepic.droid.core

import io.reactivex.Scheduler
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.subscribeBy
import org.stepic.droid.core.comments.contract.CommentsPoster
import org.stepic.droid.di.comment.CommentsScope
import org.stepic.droid.di.qualifiers.BackgroundScheduler
import org.stepic.droid.di.qualifiers.MainScheduler
import org.stepic.droid.model.CommentAdapterItem
import org.stepik.android.model.comments.Comment
import org.stepik.android.model.comments.DiscussionProxy
import org.stepik.android.model.comments.Vote
import org.stepic.droid.preferences.SharedPreferenceHelper
import org.stepic.droid.web.Api
import org.stepic.droid.web.CommentsResponse
import org.stepik.android.domain.comment.interactor.CommentInteractor
import org.stepik.android.domain.comment.model.CommentsData
import org.stepik.android.model.user.User
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.util.*
import javax.inject.Inject

@CommentsScope
class CommentManager @Inject constructor(
private val api: Api,
private val commentsPoster: CommentsPoster,
private val sharedPrefs: SharedPreferenceHelper
class CommentManager
@Inject
constructor(
private val commentInteractor: CommentInteractor,
private val commentsPoster: CommentsPoster,
private val sharedPrefs: SharedPreferenceHelper,

@BackgroundScheduler
private val backgroundScheduler: Scheduler,
@MainScheduler
private val mainScheduler: Scheduler
) {

private var discussionProxy: DiscussionProxy? = null
private val discussionOrderList: MutableList<Long> = ArrayList()

Expand All @@ -40,6 +49,8 @@ class CommentManager @Inject constructor(
private val commentIdIsLoading: MutableSet<Long> = HashSet() //can be reply or comment (with 0 replies) for load more comments).
private val voteMap: MutableMap<String, Vote> = HashMap()

private val compositeDisposable = CompositeDisposable()

fun loadComments() {
val orderOfComments = discussionOrderList
orderOfComments.let {
Expand Down Expand Up @@ -73,18 +84,19 @@ class CommentManager @Inject constructor(
}
}

private fun addComments(stepicResponse: CommentsResponse, fromReply: Boolean = false) {
updateOnlyCommentsIfCachedSilent(stepicResponse.comments)
stepicResponse.users
?.forEach {
if (it.id !in userSetMap) {
userSetMap[it.id] = it
}
private fun addComments(commentsData: CommentsData, fromReply: Boolean = false) {
updateOnlyCommentsIfCachedSilent(commentsData.comments)
commentsData.users
.forEach {
if (it.id !in userSetMap) {
userSetMap[it.id] = it
}
stepicResponse.votes?.forEach {
//updating info
voteMap[it.id] = it
}
}
commentsData.votes
.forEach {
//updating info
voteMap[it.id] = it
}
//commentIdIsLoading = commentIdIsLoading.filterNot { cachedCommentsSetMap.containsKey(it) }.toHashSet()
if (fromReply) {
repliesIdIsLoading.clear()
Expand Down Expand Up @@ -148,26 +160,14 @@ class CommentManager @Inject constructor(
}

fun loadCommentsByIds(idsForLoading: LongArray, fromReply: Boolean = false) {
api.getCommentsByIds(idsForLoading).enqueue(object : Callback<CommentsResponse> {

override fun onResponse(call: Call<CommentsResponse>?, response: Response<CommentsResponse>?) {

if (response != null && response.isSuccessful) {
val stepicResponse = response.body()
if (stepicResponse != null) {
addComments(stepicResponse, fromReply)
} else {
commentsPoster.connectionProblem()
}
} else {
commentsPoster.connectionProblem()
}
}

override fun onFailure(call: Call<CommentsResponse>?, t: Throwable?) {
commentsPoster.connectionProblem()
}
})
compositeDisposable += commentInteractor
.getComments(*idsForLoading)
.subscribeOn(backgroundScheduler)
.observeOn(mainScheduler)
.subscribeBy(
onSuccess = { addComments(it, fromReply) },
onError = { commentsPoster.connectionProblem() }
)
}

fun getSize() = cachedCommentsList.size
Expand Down Expand Up @@ -254,6 +254,8 @@ class CommentManager @Inject constructor(
fun getVoteByVoteId(voteId: String): Vote? = voteMap[voteId]

fun resetAll(dP: DiscussionProxy? = null) {
compositeDisposable.clear()

parentIdToPositionInDiscussionMap.clear()
if (dP != null) {
setDiscussionProxy(dP)
Expand All @@ -274,6 +276,8 @@ class CommentManager @Inject constructor(
fun clearAllLoadings() {
commentIdIsLoading.clear()
repliesIdIsLoading.clear()

compositeDisposable.clear()
}

fun isDiscussionProxyNull() = (discussionProxyId == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.stepic.droid.di.qualifiers.BackgroundScheduler
import org.stepic.droid.di.qualifiers.MainScheduler
import org.stepic.droid.util.getStepType
import org.stepic.droid.web.Api
import org.stepic.droid.web.SubmissionResponse
import org.stepik.android.remote.submission.model.SubmissionResponse
import retrofit2.HttpException
import java.util.concurrent.TimeUnit
import javax.inject.Inject
Expand Down Expand Up @@ -114,6 +114,7 @@ class CardPresenter(
reply = view?.getQuizViewDelegate()?.createReply(),
attempt = card.attempt?.id ?: 0)
disposable = api.createNewSubmissionReactive(submission)
.ignoreElement()
.andThen(api.getSubmissionsReactive(submission.attempt))
.subscribeOn(backgroundScheduler)
.observeOn(mainScheduler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import org.stepic.droid.core.presenters.contracts.CommentsView
import org.stepic.droid.di.qualifiers.BackgroundScheduler
import org.stepic.droid.di.qualifiers.MainScheduler
import org.stepic.droid.util.emptyOnErrorStub
import org.stepik.android.domain.comments.interactor.CommentsInteractor
import org.stepik.android.domain.comment_banner.interactor.CommentBannerInteractor
import timber.log.Timber
import javax.inject.Inject

class CommentsBannerPresenter
@Inject
constructor(
private val commentsBannerInteractor: CommentsInteractor,
private val commentsBannerInteractor: CommentBannerInteractor,
private val commentsTooltipSplitTest: CommentsTooltipSplitTest,

@BackgroundScheduler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
package org.stepic.droid.core.presenters

import org.stepic.droid.concurrency.MainHandler
import io.reactivex.Scheduler
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.subscribeBy
import org.stepic.droid.core.presenters.contracts.DiscussionView
import org.stepic.droid.di.comment.CommentsScope
import org.stepic.droid.web.Api
import java.util.concurrent.ThreadPoolExecutor
import org.stepic.droid.di.qualifiers.BackgroundScheduler
import org.stepic.droid.di.qualifiers.MainScheduler
import org.stepik.android.domain.discussion_proxy.interactor.DiscussionProxyInteractor
import javax.inject.Inject

@CommentsScope
class DiscussionPresenter
@Inject constructor(
private val threadPoolExecutor: ThreadPoolExecutor,
private val mainHandler: MainHandler,
private val api: Api) : PresenterBase<DiscussionView>() {
@Inject
constructor(
private val discussionProxyInteractor: DiscussionProxyInteractor,

@BackgroundScheduler
private val backgroundScheduler: Scheduler,
@MainScheduler
private val mainScheduler: Scheduler
) : PresenterBase<DiscussionView>() {
private val compositeDisposable = CompositeDisposable()

fun loadDiscussion(discussionId: String) {
threadPoolExecutor.execute {
try {
val discussionProxy = api
.getDiscussionProxies(discussionId)
.execute()
.body()
?.discussionProxies!!
.first()
if (discussionProxy.discussions.isEmpty()) {
mainHandler.post {
compositeDisposable.clear()
compositeDisposable += discussionProxyInteractor
.getDiscussionProxy(discussionId)
.subscribeOn(backgroundScheduler)
.observeOn(mainScheduler)
.subscribeBy(
onSuccess = { discussionProxy ->
if (discussionProxy.discussions.isEmpty()) {
view?.onEmptyComments(discussionProxy)
}
} else {
mainHandler.post {
} else {
view?.onLoaded(discussionProxy)
}
}
} catch (exception: Exception) {
mainHandler.post {
view?.onInternetProblemInComments()
}
}
}

},
onError = { view?.onInternetProblemInComments() }
)
}

}
2 changes: 2 additions & 0 deletions app/src/main/java/org/stepic/droid/di/AppCoreComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import org.stepik.android.view.injection.progress.ProgressBusModule
import org.stepik.android.view.injection.step.StepComponent
import org.stepik.android.view.injection.step.StepDiscussionBusModule
import org.stepik.android.view.injection.step_content_video.VideoStepContentComponent
import org.stepik.android.view.injection.step_quiz.StepQuizBusModule
import org.stepik.android.view.injection.video_player.VideoPlayerComponent
import org.stepik.android.view.notification.service.BootCompleteService
import org.stepik.android.view.notification.service.NotificationAlarmService
Expand Down Expand Up @@ -92,6 +93,7 @@ import org.stepik.android.view.injection.view_assignment.ViewAssignmentComponent
ProgressBusModule::class,
ViewAssignmentBusModule::class,
StepDiscussionBusModule::class,
StepQuizBusModule::class,
PersonalDeadlinesDataModule::class,

CourseRoutingModule::class, // todo unite it in RoutingModule::class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ package org.stepic.droid.di.comment

import dagger.Subcomponent
import org.stepic.droid.ui.fragments.CommentsFragment
import org.stepik.android.view.injection.comment.CommentDataModule
import org.stepik.android.view.injection.discussion_proxy.DiscussionProxyDataModule

@CommentsScope
@Subcomponent(modules = arrayOf(CommentsModule::class))
@Subcomponent(modules = [
CommentsModule::class,
CommentDataModule::class,
DiscussionProxyDataModule::class
])
interface CommentsComponent {

@Subcomponent.Builder
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/stepic/droid/di/step/StepComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import org.stepic.droid.di.comment.CommentsComponent
import org.stepic.droid.di.step.code.CodeComponent
import org.stepic.droid.di.streak.StreakModule
import org.stepic.droid.ui.fragments.StepAttemptFragment
import org.stepik.android.view.injection.comments.CommentsBannerDataModule
import org.stepik.android.view.injection.comment_banner.CommentBannerDataModule
import org.stepik.android.view.injection.feedback.FeedbackDataModule

@StepScope
@Subcomponent(modules = arrayOf(StreakModule::class, CommentCountModule::class, CommentsBannerDataModule::class, FeedbackDataModule::class))
@Subcomponent(modules = arrayOf(StreakModule::class, CommentCountModule::class, CommentBannerDataModule::class, FeedbackDataModule::class))
interface StepComponent {
@Subcomponent.Builder
interface Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.stepic.droid.persistence.storage.dao.PersistentItemDao
import org.stepic.droid.persistence.storage.dao.PersistentStateDao
import org.stepic.droid.storage.dao.IDao
import org.stepic.droid.storage.operations.DatabaseFacade
import org.stepik.android.cache.comments.dao.CommentsBannerDao
import org.stepik.android.cache.comment_banner.dao.CommentBannerDao
import org.stepik.android.cache.personal_deadlines.dao.PersonalDeadlinesDao
import org.stepik.android.domain.course_reviews.model.CourseReview
import org.stepik.android.model.CourseReviewSummary
Expand All @@ -31,7 +31,7 @@ interface StorageComponent {

val deadlinesDao: PersonalDeadlinesDao
val deadlinesBannerDao: DeadlinesBannerDao
val commentsBannerDao: CommentsBannerDao
val commentBannerDao: CommentBannerDao
val persistentItemDao: PersistentItemDao
val persistentStateDao: PersistentStateDao

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import org.stepic.droid.storage.DatabaseHelper
import org.stepic.droid.storage.dao.*
import org.stepic.droid.storage.operations.*
import org.stepik.android.model.ViewAssignment
import org.stepik.android.cache.comments.dao.CommentsBannerDao
import org.stepik.android.cache.comments.dao.CommentsBannerDaoImpl
import org.stepik.android.cache.comment_banner.dao.CommentBannerDao
import org.stepik.android.cache.comment_banner.dao.CommentBannerDaoImpl
import org.stepik.android.cache.user.dao.UserDaoImpl
import org.stepik.android.cache.video.dao.VideoEntityDaoImpl
import org.stepik.android.cache.video.dao.VideoDao
Expand Down Expand Up @@ -173,7 +173,7 @@ abstract class StorageModule {

@StorageSingleton
@Binds
internal abstract fun provideCommentsBannerDao(commentsBannerDaoImpl: CommentsBannerDaoImpl): CommentsBannerDao
internal abstract fun provideCommentsBannerDao(commentsBannerDaoImpl: CommentBannerDaoImpl): CommentBannerDao

@StorageSingleton
@Binds
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/org/stepic/droid/fonts/FontType.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.stepic.droid.fonts

enum class FontType {
regular, italic, bold, boldItalic, medium, light
regular, italic, bold, boldItalic, medium, light,

mono
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ class FontsProviderImpl @Inject constructor() : FontsProvider {
FontType.boldItalic -> "fonts/Roboto-BoldItalic.ttf"
FontType.medium -> "fonts/Roboto-Medium.ttf"
FontType.light -> "fonts/Roboto-Light.ttf"
FontType.mono -> "fonts/PT-Mono.ttf"
}
}
Loading

0 comments on commit 5e10192

Please sign in to comment.