<commit_before>package host.exp.exponent.experience.splashscreen

import android.content.Context
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.AlphaAnimation
import android.widget.ImageView
import com.squareup.picasso.Callback
import com.squareup.picasso.Picasso
import expo.modules.splashscreen.SplashScreenImageResizeMode
import expo.modules.splashscreen.SplashScreenView
import expo.modules.splashscreen.SplashScreenViewProvider
import host.exp.exponent.analytics.EXL
import org.json.JSONObject

/**
 * SplashScreenView provider that parses manifest and extracts splash configuration.
 * It allows reconfiguration of the SplashScreenImage.
 */
class ManagedAppSplashScreenViewProvider(
  private var config: ManagedAppSplashScreenConfiguration
) : SplashScreenViewProvider {
  private lateinit var splashScreenView: SplashScreenView

  companion object {
    private const val TAG: String = "ExperienceSplashScreenManifestBasedResourceProvider"
  }

  override fun createSplashScreenView(context: Context): View {
    splashScreenView = SplashScreenView(context)
    configureSplashScreenView(context, config)
    return splashScreenView
  }

  fun updateSplashScreenViewWithManifest(context: Context, manifest: JSONObject) {
    config = ManagedAppSplashScreenConfiguration.parseManifest(manifest)
    configureSplashScreenView(context, config)
  }

  private fun configureSplashScreenView(context: Context, config: ManagedAppSplashScreenConfiguration) {
    splashScreenView.setBackgroundColor(config.backgroundColor)
    splashScreenView.configureImageViewResizeMode(config.resizeMode)
    configureSplashScreenImageView(context, config)
  }

  private fun configureSplashScreenImageView(context: Context, config: ManagedAppSplashScreenConfiguration) {
    splashScreenView.imageView.visibility = View.GONE
    if (config.imageUrl == null) {
      return
    }
    Picasso.with(context).load(config.imageUrl).into(splashScreenView.imageView, object : Callback {
      override fun onSuccess() {
        splashScreenView.imageView.visibility = View.VISIBLE<commit_msg>[android] only update splash screen image when configuration values are updated (#10522)<commit_after>package host.exp.exponent.experience.splashscreen

import android.content.Context
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.AlphaAnimation
import android.widget.ImageView
import com.squareup.picasso.Callback
import com.squareup.picasso.Picasso
import expo.modules.splashscreen.SplashScreenImageResizeMode
import expo.modules.splashscreen.SplashScreenView
import expo.modules.splashscreen.SplashScreenViewProvider
import host.exp.exponent.analytics.EXL
import org.json.JSONObject

/**
 * SplashScreenView provider that parses manifest and extracts splash configuration.
 * It allows reconfiguration of the SplashScreenImage.
 */
class ManagedAppSplashScreenViewProvider(
  private var config: ManagedAppSplashScreenConfiguration
) : SplashScreenViewProvider {
  private lateinit var splashScreenView: SplashScreenView

  companion object {
    private const val TAG: String = "ExperienceSplashScreenManifestBasedResourceProvider"
  }

  override fun createSplashScreenView(context: Context): View {
    splashScreenView = SplashScreenView(context)
    configureSplashScreenView(context, config, null)
    return splashScreenView
  }

  fun updateSplashScreenViewWithManifest(context: Context, manifest: JSONObject) {
    val previousConfig = config;
    config = ManagedAppSplashScreenConfiguration.parseManifest(manifest)
    configureSplashScreenView(context, config, previousConfig)
  }

  private fun configureSplashScreenView(
    context: Context,
    config: ManagedAppSplashScreenConfiguration,
    previousConfig: ManagedAppSplashScreenConfiguration?
  ) {
    splashScreenView.setBackgroundColor(config.backgroundColor)
    // Only re-create the image view when the imageUrl or resizeMode changes
    if (previousConfig == null ||
      config.resizeMode != previousConfig.resizeMode ||
      !config.imageUrl.equals(previousConfig.imageUrl)
    ) {
      splashScreenView.configureImageViewResizeMode(config.resizeMode)
      configureSplashScreenImageView(context, config)
    }
  }

  private fun configureSplashScreenImageView(context: Context, config: ManagedAppSplashScreenConfiguration) {
    splashScreenView.imageView.visibility = View.GONE
    if (config.imageUrl == null) {
      return
    }
    Picasso.with(context).load(config.imageUrl).into(splashScreenView.imageView, object : Callback {
      override fun onSuccess() {
        splashScreenView.imageView.visibility = View.VISIBLE
{'fraction_non_alphanumeric': 0.06744186046511629, 'fraction_numerical': 0.0010570824524312897, 'mean_word_length': 5.72972972972973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5049670', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1248, 'n_words': 257}