<commit_before>package chat.rocket.android.settings.presentation

import android.content.Context
import android.content.Intent
import android.os.Build
import chat.rocket.android.R
import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.db.DatabaseManagerFactory
import chat.rocket.android.dynamiclinks.DynamicLinksForFirebase
import chat.rocket.android.helper.UserHelper
import chat.rocket.android.main.presentation.MainNavigator
import chat.rocket.android.server.domain.AnalyticsTrackingInteractor
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.domain.PermissionsInteractor
import chat.rocket.android.server.domain.RemoveAccountInteractor
import chat.rocket.android.server.domain.SaveCurrentLanguageInteractor
import chat.rocket.android.server.domain.TokenRepository
import chat.rocket.android.server.infrastructure.ConnectionManagerFactory
import chat.rocket.android.server.infrastructure.RocketChatClientFactory
import chat.rocket.android.server.presentation.CheckServerPresenter
import chat.rocket.android.util.extension.HashType
import chat.rocket.android.util.extension.hash
import chat.rocket.android.util.extension.launchUI
import chat.rocket.android.util.extensions.adminPanelUrl
import chat.rocket.android.util.extensions.avatarUrl
import chat.rocket.android.util.retryIO
import chat.rocket.common.util.ifNull
import chat.rocket.core.internal.rest.deleteOwnAccount
import chat.rocket.core.internal.rest.serverInfo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.util.*
import javax.inject.Inject
import javax.inject.Named

class SettingsPresenter @Inject constructor(
    private val view: SettingsView,
    private val strategy: CancelStrategy,
    private val navigator: MainNavigator,
    @Named("currentServer") private val currentServer: String?,
    private val userHelper: UserHelper,
    private val analyticsTrackingInteractor: AnalyticsTrackingInteractor,
    private val tokenRepository: TokenRepository,
    private val permissions: PermissionsInteractor,
    private val rocketChatClientFactory: RocketChatClientFactory,
    private val dynamicLinksManager: DynamicLinksForFirebase,
    private val saveLanguageInteractor: SaveCurrentLanguageInteractor,
    getCurrentServerInteractor: GetCurrentServerInteractor,
    removeAccountInteractor: RemoveAccountInteractor,
    databaseManagerFactory: DatabaseManagerFactory?,
    connectionManagerFactory: ConnectionManagerFactory
) : CheckServerPresenter(
    strategy = strategy,
    factory = rocketChatClientFactory,
    currentSavedServer = currentServer,
    serverInteractor = getCurrentServerInteractor,
    removeAccountInteractor = removeAccountInteractor,
    tokenRepository = tokenRepository,
    dbManagerFactory = databaseManagerFactory,
    managerFactory = connectionManagerFactory,
    tokenView = view,
    navigator = navigator
) {
    private val token = currentServer?.let { tokenRepository.get(it) }

    fun setupView() {
        launchUI(strategy) {
            try {
                currentServer?.let {
                    val serverInfo = retryIO(description = "serverInfo", times = 5) {
                        rocketChatClientFactory.get(it).serverInfo()
                    }

                    userHelper.user()?.let { user ->
                        view.setupSettingsView(
                            it.avatarUrl(user.username!!, token?.userId, token?.authToken),
                            userHelper.displayName(user) ?: user.username ?: "",
                            user.status.toString(),
                            permissions.isAdministrationEnabled(),
                            analyticsTrackingInteractor.get(),
                            true,
                            serverInfo.version
                        )
                    }
                }
            } catch (exception: Exception) {
                Timber.d(exception, "Error getting server info")
                exception.message?.let {
                    view.showMessage(it)
                }.ifNull {
                    view.showGenericErrorMessage()
                }
            }
        }
    }

    fun enableAnalyticsTracking(isEnabled: Boolean) {
        analyticsTrackingInteractor.save(isEnabled)
    }

    fun deleteAccount(password: String) {
        launchUI(strategy) {<commit_msg>add loading bar when loading avatar image and other info in settings<commit_after>package chat.rocket.android.settings.presentation

import android.content.Context
import android.content.Intent
import android.os.Build
import chat.rocket.android.R
import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.db.DatabaseManagerFactory
import chat.rocket.android.dynamiclinks.DynamicLinksForFirebase
import chat.rocket.android.helper.UserHelper
import chat.rocket.android.main.presentation.MainNavigator
import chat.rocket.android.server.domain.AnalyticsTrackingInteractor
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.domain.PermissionsInteractor
import chat.rocket.android.server.domain.RemoveAccountInteractor
import chat.rocket.android.server.domain.SaveCurrentLanguageInteractor
import chat.rocket.android.server.domain.TokenRepository
import chat.rocket.android.server.infrastructure.ConnectionManagerFactory
import chat.rocket.android.server.infrastructure.RocketChatClientFactory
import chat.rocket.android.server.presentation.CheckServerPresenter
import chat.rocket.android.util.extension.HashType
import chat.rocket.android.util.extension.hash
import chat.rocket.android.util.extension.launchUI
import chat.rocket.android.util.extensions.adminPanelUrl
import chat.rocket.android.util.extensions.avatarUrl
import chat.rocket.android.util.retryIO
import chat.rocket.common.util.ifNull
import chat.rocket.core.internal.rest.deleteOwnAccount
import chat.rocket.core.internal.rest.serverInfo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.util.*
import javax.inject.Inject
import javax.inject.Named

class SettingsPresenter @Inject constructor(
    private val view: SettingsView,
    private val strategy: CancelStrategy,
    private val navigator: MainNavigator,
    @Named("currentServer") private val currentServer: String?,
    private val userHelper: UserHelper,
    private val analyticsTrackingInteractor: AnalyticsTrackingInteractor,
    private val tokenRepository: TokenRepository,
    private val permissions: PermissionsInteractor,
    private val rocketChatClientFactory: RocketChatClientFactory,
    private val dynamicLinksManager: DynamicLinksForFirebase,
    private val saveLanguageInteractor: SaveCurrentLanguageInteractor,
    getCurrentServerInteractor: GetCurrentServerInteractor,
    removeAccountInteractor: RemoveAccountInteractor,
    databaseManagerFactory: DatabaseManagerFactory?,
    connectionManagerFactory: ConnectionManagerFactory
) : CheckServerPresenter(
    strategy = strategy,
    factory = rocketChatClientFactory,
    currentSavedServer = currentServer,
    serverInteractor = getCurrentServerInteractor,
    removeAccountInteractor = removeAccountInteractor,
    tokenRepository = tokenRepository,
    dbManagerFactory = databaseManagerFactory,
    managerFactory = connectionManagerFactory,
    tokenView = view,
    navigator = navigator
) {
    private val token = currentServer?.let { tokenRepository.get(it) }

    fun setupView() {
        launchUI(strategy) {
            try {
                view.showLoading()
                currentServer?.let {
                    val serverInfo = retryIO(description = "serverInfo", times = 5) {
                        rocketChatClientFactory.get(it).serverInfo()
                    }

                    userHelper.user()?.let { user ->
                        view.setupSettingsView(
                            it.avatarUrl(user.username!!, token?.userId, token?.authToken),
                            userHelper.displayName(user) ?: user.username ?: "",
                            user.status.toString(),
                            permissions.isAdministrationEnabled(),
                            analyticsTrackingInteractor.get(),
                            true,
                            serverInfo.version
                        )
                    }
                }
                view.hideLoading()
            } catch (exception: Exception) {
                Timber.d(exception, "Error getting server info")
                exception.message?.let {
                    view.showMessage(it)
                }.ifNull {
                    view.showGenericErrorMessage()
                }
                view.hideLoading()
            }
        }
    }

    fun enableAnalyticsTracking(isEnabled: Boolean) {
        analyticsTrackingInteractor.save(isEnabled)
    }

    fun deleteAccount(password: String) {
        launchUI(strategy) {
{'fraction_non_alphanumeric': 0.07398805573988056, 'fraction_numerical': 0.00022119000221190003, 'mean_word_length': 3.0442754919499104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7324150', 'n_tokens_mistral': 2257, 'n_tokens_neox': 2210, 'n_words': 406}