Skip to content

Commit

Permalink
feat: applied ktlint to all files
Browse files Browse the repository at this point in the history
  • Loading branch information
Malopieds committed Jul 6, 2024
1 parent 4ac918a commit f0c5fd1
Show file tree
Hide file tree
Showing 190 changed files with 10,833 additions and 7,916 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import com.malopieds.innertune.db.entities.LyricsEntity

object TranslationHelper {
suspend fun translate(lyrics: LyricsEntity): LyricsEntity = lyrics

suspend fun clearModels() {}
}
}
77 changes: 48 additions & 29 deletions app/src/main/java/com/malopieds/innertune/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ import coil.ImageLoaderFactory
import coil.disk.DiskCache
import com.malopieds.innertube.YouTube
import com.malopieds.innertube.models.YouTubeLocale
import com.malopieds.innertune.constants.*
import com.malopieds.innertune.extensions.*
import com.malopieds.innertune.constants.ContentCountryKey
import com.malopieds.innertune.constants.ContentLanguageKey
import com.malopieds.innertune.constants.CountryCodeToName
import com.malopieds.innertune.constants.InnerTubeCookieKey
import com.malopieds.innertune.constants.LanguageCodeToName
import com.malopieds.innertune.constants.MaxImageCacheSizeKey
import com.malopieds.innertune.constants.ProxyEnabledKey
import com.malopieds.innertune.constants.ProxyTypeKey
import com.malopieds.innertune.constants.ProxyUrlKey
import com.malopieds.innertune.constants.SYSTEM_DEFAULT
import com.malopieds.innertune.constants.VisitorDataKey
import com.malopieds.innertune.extensions.toEnum
import com.malopieds.innertune.extensions.toInetSocketAddress
import com.malopieds.innertune.utils.dataStore
import com.malopieds.innertune.utils.get
import com.malopieds.innertune.utils.reportException
Expand All @@ -23,33 +34,39 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import timber.log.Timber
import java.net.Proxy
import java.util.*
import java.util.Locale

@HiltAndroidApp
class App : Application(), ImageLoaderFactory {
class App :
Application(),
ImageLoaderFactory {
@OptIn(DelicateCoroutinesApi::class)
override fun onCreate() {
super.onCreate()
Timber.plant(Timber.DebugTree())

val locale = Locale.getDefault()
val languageTag = locale.toLanguageTag().replace("-Hant", "") // replace zh-Hant-* to zh-*
YouTube.locale = YouTubeLocale(
gl = dataStore[ContentCountryKey]?.takeIf { it != SYSTEM_DEFAULT }
?: locale.country.takeIf { it in CountryCodeToName }
?: "US",
hl = dataStore[ContentLanguageKey]?.takeIf { it != SYSTEM_DEFAULT }
?: locale.language.takeIf { it in LanguageCodeToName }
?: languageTag.takeIf { it in LanguageCodeToName }
?: "en"
)
YouTube.locale =
YouTubeLocale(
gl =
dataStore[ContentCountryKey]?.takeIf { it != SYSTEM_DEFAULT }
?: locale.country.takeIf { it in CountryCodeToName }
?: "US",
hl =
dataStore[ContentLanguageKey]?.takeIf { it != SYSTEM_DEFAULT }
?: locale.language.takeIf { it in LanguageCodeToName }
?: languageTag.takeIf { it in LanguageCodeToName }
?: "en",
)

if (dataStore[ProxyEnabledKey] == true) {
try {
YouTube.proxy = Proxy(
dataStore[ProxyTypeKey].toEnum(defaultValue = Proxy.Type.HTTP),
dataStore[ProxyUrlKey]!!.toInetSocketAddress()
)
YouTube.proxy =
Proxy(
dataStore[ProxyTypeKey].toEnum(defaultValue = Proxy.Type.HTTP),
dataStore[ProxyUrlKey]!!.toInetSocketAddress(),
)
} catch (e: Exception) {
Toast.makeText(this, "Failed to parse proxy url.", LENGTH_SHORT).show()
reportException(e)
Expand Down Expand Up @@ -80,15 +97,17 @@ class App : Application(), ImageLoaderFactory {
}
}

override fun newImageLoader() = ImageLoader.Builder(this)
.crossfade(true)
.respectCacheHeaders(false)
.allowHardware(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
.diskCache(
DiskCache.Builder()
.directory(cacheDir.resolve("coil"))
.maxSizeBytes((dataStore[MaxImageCacheSizeKey] ?: 512) * 1024 * 1024L)
.build()
)
.build()
}
override fun newImageLoader() =
ImageLoader
.Builder(this)
.crossfade(true)
.respectCacheHeaders(false)
.allowHardware(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
.diskCache(
DiskCache
.Builder()
.directory(cacheDir.resolve("coil"))
.maxSizeBytes((dataStore[MaxImageCacheSizeKey] ?: 512) * 1024 * 1024L)
.build(),
).build()
}
Loading

0 comments on commit f0c5fd1

Please sign in to comment.