Skip to content

Commit

Permalink
[1.227.*] Pre-release merge (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
tramline-github[bot] authored Aug 8, 2024
2 parents b01f1cd + ae10f1d commit 3b53e70
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@

package dev.sasikanth.rss.reader.app

data class AppInfo(val versionCode: Int, val versionName: String, val isDebugBuild: Boolean)
data class AppInfo(
val versionCode: Int,
val versionName: String,
val isDebugBuild: Boolean,
val cachePath: () -> String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ abstract class ApplicationComponent(@get:Provides val context: Context) :
return AppInfo(
versionName = packageInfo.versionName,
versionCode = versionCode,
isDebugBuild = (applicationInfo.flags and FLAG_DEBUGGABLE) != 0
isDebugBuild = (applicationInfo.flags and FLAG_DEBUGGABLE) != 0,
cachePath = { context.cacheDir.absolutePath }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ package dev.sasikanth.rss.reader.di
import android.content.Context
import coil3.PlatformContext
import me.tatarka.inject.annotations.Provides
import okio.Path
import okio.Path.Companion.toPath

actual interface ImageLoaderPlatformComponent {

@Provides fun providePlatformContext(context: Context): PlatformContext = context

@Provides
fun diskCache(application: Context): Path =
application.cacheDir.absolutePath.toPath().resolve("dev_sasikanth_rss_reader_images_cache")
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import coil3.ImageLoader
import coil3.PlatformContext
import coil3.disk.DiskCache
import coil3.memory.MemoryCache
import dev.sasikanth.rss.reader.app.AppInfo
import me.tatarka.inject.annotations.Provides
import okio.Path
import okio.Path.Companion.toPath

expect interface ImageLoaderPlatformComponent

Expand All @@ -32,11 +33,15 @@ interface ImageLoaderComponent : ImageLoaderPlatformComponent {
@Provides
fun imageLoader(
platformContext: PlatformContext,
cachePath: Path,
appInfo: AppInfo,
): ImageLoader {
return ImageLoader.Builder(platformContext)
.memoryCache { MemoryCache.Builder().maxSizePercent(platformContext, percent = 0.25).build() }
.diskCache { DiskCache.Builder().directory(cachePath).build() }
.diskCache {
DiskCache.Builder()
.directory(appInfo.cachePath().toPath().resolve("dev_sasikanth_rss_reader_images_cache"))
.build()
}
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal fun FeaturedSection(
systemBarsEndPadding
}

LaunchedEffect(pagerState) {
LaunchedEffect(pagerState, featuredPosts) {
snapshotFlow {
val settledPage = pagerState.settledPage
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ import dev.sasikanth.rss.reader.data.repository.RssRepository
import dev.sasikanth.rss.reader.data.repository.SettingsRepository
import dev.sasikanth.rss.reader.di.scopes.AppScope
import kotlin.experimental.ExperimentalNativeApi
import kotlinx.cinterop.ExperimentalForeignApi
import me.tatarka.inject.annotations.Component
import me.tatarka.inject.annotations.Provides
import platform.Foundation.NSBundle
import platform.Foundation.NSCachesDirectory
import platform.Foundation.NSFileManager
import platform.Foundation.NSUserDomainMask
import platform.UIKit.UIViewController

@AppScope
Expand All @@ -45,5 +49,19 @@ abstract class ApplicationComponent(
versionName = NSBundle.mainBundle.infoDictionary?.get("CFBundleShortVersionString") as? String
?: "",
isDebugBuild = Platform.isDebugBinary,
cachePath = { NSFileManager.defaultManager.cacheDir }
)

@OptIn(ExperimentalForeignApi::class)
private val NSFileManager.cacheDir: String
get() =
URLForDirectory(
directory = NSCachesDirectory,
inDomain = NSUserDomainMask,
appropriateForURL = null,
create = true,
error = null,
)
?.path
.orEmpty()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,9 @@
package dev.sasikanth.rss.reader.di

import coil3.PlatformContext
import kotlinx.cinterop.ExperimentalForeignApi
import me.tatarka.inject.annotations.Provides
import okio.Path
import okio.Path.Companion.toPath
import platform.Foundation.NSCachesDirectory
import platform.Foundation.NSFileManager
import platform.Foundation.NSUserDomainMask

actual interface ImageLoaderPlatformComponent {

@Provides fun providePlatformContext(): PlatformContext = PlatformContext.INSTANCE

@Provides
fun diskCache(): Path =
NSFileManager.defaultManager.cacheDir.toPath().resolve("dev_sasikanth_rss_reader_images_cache")

@OptIn(ExperimentalForeignApi::class)
private val NSFileManager.cacheDir: String
get() =
URLForDirectory(
directory = NSCachesDirectory,
inDomain = NSUserDomainMask,
appropriateForURL = null,
create = true,
error = null,
)
?.path
.orEmpty()
}

0 comments on commit 3b53e70

Please sign in to comment.