<commit_before>package com.pr0gramm.app.services

import android.app.Activity
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.net.Uri
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import com.pr0gramm.app.Logger
import com.pr0gramm.app.R
import com.pr0gramm.app.Settings
import com.pr0gramm.app.api.pr0gramm.Api
import com.pr0gramm.app.feed.FeedFilter
import com.pr0gramm.app.feed.FeedType
import com.pr0gramm.app.model.bookmark.Bookmark
import com.pr0gramm.app.model.config.Config
import com.pr0gramm.app.model.user.LoginState
import com.pr0gramm.app.orm.asFeedFilter
import com.pr0gramm.app.services.config.ConfigService
import com.pr0gramm.app.ui.dialogs.ignoreError
import com.pr0gramm.app.util.RxPicasso
import com.squareup.picasso.Picasso
import rx.Observable
import rx.Observable.combineLatest
import rx.subjects.BehaviorSubject
import java.util.concurrent.TimeUnit

/**
 */
class NavigationProvider(
        private val context: Activity,
        private val userService: UserService,
        private val inboxService: InboxService,
        private val bookmarkService: BookmarkService,
        private val configService: ConfigService,
        private val singleShotService: SingleShotService,
        private val picasso: Picasso) {

    private val logger = Logger("NavigationProvider")

    private val iconBookmark = drawable(R.drawable.ic_black_action_bookmark)
    private val iconFavorites = drawable(R.drawable.ic_black_action_favorite)
    private val iconFeedTypeBestOf = drawable(R.drawable.ic_drawer_bestof)
    private val iconFeedTypeControversial = drawable(R.drawable.ic_category_controversial)
    private val iconFeedTypeNew = drawable(R.drawable.ic_black_action_trending)
    private val iconFeedTypePremium = drawable(R.drawable.ic_black_action_stelz)
    private val iconFeedTypePromoted = drawable(R.drawable.ic_black_action_home)
    private val iconFeedTypeRandom = drawable(R.drawable.ic_action_random)
    private val iconInbox = drawable(R.drawable.ic_action_email)
    private val iconUpload = drawable(R.drawable.ic_black_action_upload)

    private val iconSettings = drawable(R.drawable.ic_grey_action_settings)
    private val iconContact = drawable(R.drawable.ic_grey_action_feedback)
    private val iconInvite = drawable(R.drawable.ic_contact_mail_black_24dp)
    private val iconFAQ = drawable(R.drawable.ic_assignment)
    private val iconPremium = drawable(R.drawable.ic_menu_premium)
    private val iconLogin = drawable(R.drawable.ic_grey_action_login)
    private val iconLogout = drawable(R.drawable.ic_black_action_exit)


    private fun drawable(@DrawableRes id: Int): Drawable {
        return ContextCompat.getDrawable(context, id)!!
    }

    private val triggerNavigationUpdate = BehaviorSubject.create<Unit>(Unit)

    val navigationItems: Observable<List<NavigationItem>> = run {
        val loginStates = userService.loginStates

        val rawSources = listOf<Observable<List<NavigationItem>>>(
                loginStates
                        .switchMap { remoteConfigItems(it, upper = true) },

                loginStates
                        .map { categoryNavigationItems(it.name) },

                loginStates
                        .switchMap { remoteConfigItems(it, upper = false) },

                inboxService.unreadMessagesCount()
                        .startWith(Api.InboxCounts())
                        .map { listOf(inboxNavigationItem(it)) },

                Observable.just(listOf(uploadNavigationItem)),<commit_msg>fix missing upload item.<commit_after>package com.pr0gramm.app.services

import android.app.Activity
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.net.Uri
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import com.pr0gramm.app.Logger
import com.pr0gramm.app.R
import com.pr0gramm.app.Settings
import com.pr0gramm.app.api.pr0gramm.Api
import com.pr0gramm.app.feed.FeedFilter
import com.pr0gramm.app.feed.FeedType
import com.pr0gramm.app.model.bookmark.Bookmark
import com.pr0gramm.app.model.config.Config
import com.pr0gramm.app.model.user.LoginState
import com.pr0gramm.app.orm.asFeedFilter
import com.pr0gramm.app.services.config.ConfigService
import com.pr0gramm.app.ui.dialogs.ignoreError
import com.pr0gramm.app.util.RxPicasso
import com.squareup.picasso.Picasso
import rx.Observable
import rx.Observable.combineLatest
import rx.subjects.BehaviorSubject
import java.util.concurrent.TimeUnit

/**
 */
class NavigationProvider(
        private val context: Activity,
        private val userService: UserService,
        private val inboxService: InboxService,
        private val bookmarkService: BookmarkService,
        private val configService: ConfigService,
        private val singleShotService: SingleShotService,
        private val picasso: Picasso) {

    private val logger = Logger("NavigationProvider")

    private val iconBookmark = drawable(R.drawable.ic_black_action_bookmark)
    private val iconFavorites = drawable(R.drawable.ic_black_action_favorite)
    private val iconFeedTypeBestOf = drawable(R.drawable.ic_drawer_bestof)
    private val iconFeedTypeControversial = drawable(R.drawable.ic_category_controversial)
    private val iconFeedTypeNew = drawable(R.drawable.ic_black_action_trending)
    private val iconFeedTypePremium = drawable(R.drawable.ic_black_action_stelz)
    private val iconFeedTypePromoted = drawable(R.drawable.ic_black_action_home)
    private val iconFeedTypeRandom = drawable(R.drawable.ic_action_random)
    private val iconInbox = drawable(R.drawable.ic_action_email)
    private val iconUpload = drawable(R.drawable.ic_black_action_upload)

    private val iconSettings = drawable(R.drawable.ic_grey_action_settings)
    private val iconContact = drawable(R.drawable.ic_grey_action_feedback)
    private val iconInvite = drawable(R.drawable.ic_contact_mail_black_24dp)
    private val iconFAQ = drawable(R.drawable.ic_assignment)
    private val iconPremium = drawable(R.drawable.ic_menu_premium)
    private val iconLogin = drawable(R.drawable.ic_grey_action_login)
    private val iconLogout = drawable(R.drawable.ic_black_action_exit)


    private fun drawable(@DrawableRes id: Int): Drawable {
        return ContextCompat.getDrawable(context, id)!!
    }

    private val triggerNavigationUpdate = BehaviorSubject.create<Unit>(Unit)

    val navigationItems: Observable<List<NavigationItem>> by lazy(LazyThreadSafetyMode.NONE) {
        val loginStates = userService.loginStates

        val rawSources = listOf<Observable<List<NavigationItem>>>(
                loginStates
                        .switchMap { remoteConfigItems(it, upper = true) },

                loginStates
                        .map { categoryNavigationItems(it.name) },

                loginStates
                        .switchMap { remoteConfigItems(it, upper = false) },

                inboxService.unreadMessagesCount()
                        .startWith(Api.InboxCounts())
                        .map { listOf(inboxNavigationItem(it)) },

                Observable.just(listOf(uploadNavigationItem)),
{'fraction_non_alphanumeric': 0.0776766004415011, 'fraction_numerical': 0.004690949227373068, 'mean_word_length': 3.8455882352941178, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '374590', 'n_tokens_mistral': 2185, 'n_tokens_neox': 2085, 'n_words': 389}