package com.swoosh.microblog

import android.app.Application
import coil.ImageLoader
import coil.ImageLoaderFactory
import coil.disk.DiskCache
import coil.memory.MemoryCache
import com.swoosh.microblog.worker.PostUploadWorker

class SwooshApp : Application(), ImageLoaderFactory {
    override fun onCreate() {
        super.onCreate()
        // Schedule periodic connectivity check for queued posts
        PostUploadWorker.enqueuePeriodicCheck(this)
    }

    override fun newImageLoader(): ImageLoader {
        return ImageLoader.Builder(this)
            .crossfade(150) // Short crossfade for smooth image loading
            .memoryCache {
                MemoryCache.Builder(this)
                    .maxSizePercent(0.25) // Use 25% of available memory
                    .build()
            }
            .diskCache {
                DiskCache.Builder()
                    .directory(cacheDir.resolve("image_cache"))
                    .maxSizePercent(0.05) // 5% of disk
                    .build()
            }
            .build()
    }
}
