<commit_before>package org.stepic.droid.core.presenters

import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import io.reactivex.Completable
import io.reactivex.Scheduler
import io.reactivex.Single
import io.reactivex.disposables.Disposable
import io.reactivex.rxkotlin.subscribeBy
import org.json.JSONObject
import org.stepic.droid.analytic.AmplitudeAnalytic
import org.stepic.droid.analytic.Analytic
import org.stepic.droid.core.GoogleApiChecker
import org.stepic.droid.core.StepikDevicePoster
import org.stepic.droid.core.presenters.contracts.SplashView
import org.stepic.droid.di.qualifiers.BackgroundScheduler
import org.stepic.droid.di.qualifiers.MainScheduler
import org.stepic.droid.di.splash.SplashScope
import org.stepic.droid.notifications.LocalReminder
import org.stepic.droid.preferences.SharedPreferenceHelper
import org.stepic.droid.storage.operations.DatabaseFacade
import org.stepic.droid.util.AppConstants
import org.stepic.droid.util.emptyOnErrorStub
import org.stepik.android.view.routing.deeplink.BranchDeepLinkParser
import org.stepik.android.view.routing.deeplink.BranchRoute
import java.lang.IllegalArgumentException
import javax.inject.Inject

@SplashScope
class SplashPresenter
@Inject
constructor(
        @MainScheduler
        private val mainScheduler: Scheduler,
        @BackgroundScheduler
        private val backgroundScheduler: Scheduler,
        private val sharedPreferenceHelper: SharedPreferenceHelper,
        private val firebaseRemoteConfig: FirebaseRemoteConfig,
        private val googleApiChecker: GoogleApiChecker,
        private val analytic: Analytic,
        private val stepikDevicePoster: StepikDevicePoster,
        private val databaseFacade: DatabaseFacade,
        private val localReminder: LocalReminder,

        private val branchDeepLinkParsers: Set<@JvmSuppressWildcards BranchDeepLinkParser>
) : PresenterBase<SplashView>() {
    sealed class SplashRoute {
        object Onboarding : SplashRoute()
        object Launch : SplashRoute()
        object Home : SplashRoute()
        class DeepLink(val route: BranchRoute) : SplashRoute()
    }

    private var disposable: Disposable? = null

    fun onSplashCreated(referringParams: JSONObject? = null) {
        disposable = Completable
            .fromCallable {
                countNumberOfLaunches()
                checkRemoteConfigs()
                registerDeviceToPushes()
                executeLegacyOperations()
                localReminder.remindAboutRegistration()
                localReminder.scheduleRetentionNotification(shouldResetCounter = true)
                sharedPreferenceHelper.onNewSession()
            }
            .andThen(resolveSplashRoute(referringParams))
            .subscribeOn(backgroundScheduler)
            .observeOn(mainScheduler)
            .subscribeBy(
                onError = emptyOnErrorStub,
                onSuccess = {
                    when (it) {<commit_msg>replaced localreminder with delegates<commit_after>package org.stepic.droid.core.presenters

import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import io.reactivex.Completable
import io.reactivex.Scheduler
import io.reactivex.Single
import io.reactivex.disposables.Disposable
import io.reactivex.rxkotlin.subscribeBy
import org.json.JSONObject
import org.stepic.droid.analytic.AmplitudeAnalytic
import org.stepic.droid.analytic.Analytic
import org.stepic.droid.core.GoogleApiChecker
import org.stepic.droid.core.StepikDevicePoster
import org.stepic.droid.core.presenters.contracts.SplashView
import org.stepic.droid.di.qualifiers.BackgroundScheduler
import org.stepic.droid.di.qualifiers.MainScheduler
import org.stepic.droid.di.splash.SplashScope
import org.stepic.droid.preferences.SharedPreferenceHelper
import org.stepic.droid.storage.operations.DatabaseFacade
import org.stepic.droid.util.AppConstants
import org.stepic.droid.util.emptyOnErrorStub
import org.stepik.android.view.notification.delegate.RemindRegistrationDelegate
import org.stepik.android.view.notification.delegate.RetentionDelegate
import org.stepik.android.view.routing.deeplink.BranchDeepLinkParser
import org.stepik.android.view.routing.deeplink.BranchRoute
import java.lang.IllegalArgumentException
import javax.inject.Inject

@SplashScope
class SplashPresenter
@Inject
constructor(
        @MainScheduler
        private val mainScheduler: Scheduler,
        @BackgroundScheduler
        private val backgroundScheduler: Scheduler,
        private val sharedPreferenceHelper: SharedPreferenceHelper,
        private val firebaseRemoteConfig: FirebaseRemoteConfig,
        private val googleApiChecker: GoogleApiChecker,
        private val analytic: Analytic,
        private val stepikDevicePoster: StepikDevicePoster,
        private val databaseFacade: DatabaseFacade,
        private val remindRegistrationDelegate: RemindRegistrationDelegate,
        private val retentionDelegate: RetentionDelegate,

        private val branchDeepLinkParsers: Set<@JvmSuppressWildcards BranchDeepLinkParser>
) : PresenterBase<SplashView>() {
    sealed class SplashRoute {
        object Onboarding : SplashRoute()
        object Launch : SplashRoute()
        object Home : SplashRoute()
        class DeepLink(val route: BranchRoute) : SplashRoute()
    }

    private var disposable: Disposable? = null

    fun onSplashCreated(referringParams: JSONObject? = null) {
        disposable = Completable
            .fromCallable {
                countNumberOfLaunches()
                checkRemoteConfigs()
                registerDeviceToPushes()
                executeLegacyOperations()
                remindRegistrationDelegate.scheduleRemindRegistrationNotification()
                retentionDelegate.scheduleRetentionNotification(shouldResetCounter = true)
                sharedPreferenceHelper.onNewSession()
            }
            .andThen(resolveSplashRoute(referringParams))
            .subscribeOn(backgroundScheduler)
            .observeOn(mainScheduler)
            .subscribeBy(
                onError = emptyOnErrorStub,
                onSuccess = {
                    when (it) {
{'fraction_non_alphanumeric': 0.06722140642845488, 'fraction_numerical': 0.0, 'mean_word_length': 3.5474777448071215, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2497900', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1646, 'n_words': 299}