mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 03:37:05 +05:30
refactor(android): resolve Detekt-reported issues
This commit is contained in:
parent
8851071d58
commit
8060c347cc
7 changed files with 30 additions and 25 deletions
|
@ -34,15 +34,20 @@ class ClawApplication : Application(), Configuration.Provider, ImageLoaderFactor
|
|||
|
||||
override fun newImageLoader(): ImageLoader {
|
||||
return ImageLoader.Builder(this)
|
||||
.memoryCache { MemoryCache.Builder(this).maxSizePercent(0.25).build() }
|
||||
.memoryCache { MemoryCache.Builder(this).maxSizePercent(MEMORY_CACHE_RATIO).build() }
|
||||
.diskCache {
|
||||
DiskCache.Builder()
|
||||
.directory(cacheDir.resolve("image_cache"))
|
||||
.maxSizeBytes(25L * 1024 * 1024) // 25 MB
|
||||
.maxSizeBytes(DISK_CACHE_MAX_SIZE)
|
||||
.build()
|
||||
}
|
||||
// Show a short crossfade when loading images asynchronously.
|
||||
.crossfade(true)
|
||||
.build()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private const val MEMORY_CACHE_RATIO = 0.25
|
||||
private const val DISK_CACHE_MAX_SIZE = 25L * 1024 * 1024 // 25 MB
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,10 +30,14 @@ class MainActivity : ComponentActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
installSplashScreen()
|
||||
setContent {
|
||||
LobstersApp(urlLauncher = urlLauncher, htmlConverter = htmlConverter) { url -> webUri = url }
|
||||
LobstersApp(
|
||||
urlLauncher = urlLauncher,
|
||||
htmlConverter = htmlConverter,
|
||||
setWebUri = { url -> webUri = url },
|
||||
)
|
||||
}
|
||||
val postUpdateWorkRequest =
|
||||
PeriodicWorkRequestBuilder<SavedPostUpdaterWorker>(24, TimeUnit.HOURS)
|
||||
PeriodicWorkRequestBuilder<SavedPostUpdaterWorker>(POST_REFRESH_PERIOD, TimeUnit.HOURS)
|
||||
.setConstraints(
|
||||
Constraints.Builder()
|
||||
.setRequiresCharging(false)
|
||||
|
@ -61,4 +65,8 @@ class MainActivity : ComponentActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private const val POST_REFRESH_PERIOD = 24L // 24 hours
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ import kotlinx.coroutines.CoroutineDispatcher
|
|||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
abstract class CoroutineDispatcherModule {
|
||||
interface CoroutineDispatcherModule {
|
||||
|
||||
@Binds abstract fun DefaultDispatcherProvider.bind(): DispatcherProvider
|
||||
@Binds fun DefaultDispatcherProvider.bind(): DispatcherProvider
|
||||
|
||||
companion object {
|
||||
@[Provides IODispatcher]
|
||||
|
|
|
@ -21,24 +21,26 @@ import okhttp3.logging.HttpLoggingInterceptor
|
|||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
abstract class OkHttpModule {
|
||||
interface OkHttpModule {
|
||||
|
||||
@Binds abstract fun NapierLogger.bindLogger(): HttpLoggingInterceptor.Logger
|
||||
@Binds fun NapierLogger.bindLogger(): HttpLoggingInterceptor.Logger
|
||||
|
||||
@Binds @IntoSet abstract fun UserAgentInterceptor.bindUAInterceptor(): Interceptor
|
||||
@Binds @IntoSet fun UserAgentInterceptor.bindUAInterceptor(): Interceptor
|
||||
|
||||
companion object {
|
||||
private const val CACHE_SIZE_MB = 10L * 1024 * 1024
|
||||
private const val THREAD_STATS_TAG = 0x000090000
|
||||
|
||||
@Provides
|
||||
fun provideCache(@ApplicationContext context: Context): Cache {
|
||||
return Cache(context.cacheDir, 10 * 1024 * 1024)
|
||||
return Cache(context.cacheDir, CACHE_SIZE_MB)
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun provideSocketFactory(): SocketFactory {
|
||||
return object : DelegatingSocketFactory(getDefault()) {
|
||||
override fun configureSocket(socket: Socket): Socket {
|
||||
TrafficStats.setThreadStatsTag(0x000090000)
|
||||
TrafficStats.setThreadStatsTag(THREAD_STATS_TAG)
|
||||
return super.configureSocket(socket)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ constructor(
|
|||
@IODispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||
) : PagingSource<Int, LobstersPost>() {
|
||||
|
||||
@Suppress("TooGenericExceptionCaught") // Intentional
|
||||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, LobstersPost> {
|
||||
return try {
|
||||
val page = params.key ?: 1
|
||||
|
|
|
@ -49,13 +49,14 @@ import soup.compose.material.motion.navigation.MaterialMotionNavHost
|
|||
import soup.compose.material.motion.navigation.composable
|
||||
import soup.compose.material.motion.navigation.rememberMaterialMotionNavController
|
||||
|
||||
@Suppress("ModifierMissing") // Top-level composable, will never have a modifier supplied.
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class)
|
||||
@Composable
|
||||
fun LobstersApp(
|
||||
viewModel: ClawViewModel = viewModel(),
|
||||
urlLauncher: UrlLauncher,
|
||||
htmlConverter: HTMLConverter,
|
||||
setWebUri: (String?) -> Unit,
|
||||
viewModel: ClawViewModel = viewModel(),
|
||||
) {
|
||||
val systemUiController = rememberSystemUiController()
|
||||
val hottestListState = rememberLazyListState()
|
||||
|
|
|
@ -2,19 +2,7 @@
|
|||
<SmellBaseline>
|
||||
<ManuallySuppressedIssues></ManuallySuppressedIssues>
|
||||
<CurrentIssues>
|
||||
<ID>ComposableParamOrder:LobstersApp.kt$LobstersApp</ID>
|
||||
<ID>LongMethod:LobstersApp.kt$@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class) @Composable fun LobstersApp( viewModel: ClawViewModel = viewModel(), urlLauncher: UrlLauncher, htmlConverter: HTMLConverter, setWebUri: (String?) -> Unit, )</ID>
|
||||
<ID>LongMethod:LobstersApp.kt$@Suppress("ModifierMissing") // Top-level composable, will never have a modifier supplied. @OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class) @Composable fun LobstersApp( urlLauncher: UrlLauncher, htmlConverter: HTMLConverter, setWebUri: (String?) -> Unit, viewModel: ClawViewModel = viewModel(), )</ID>
|
||||
<ID>LongParameterList:NetworkPosts.kt$( items: LazyPagingItems<LobstersPost>, listState: LazyListState, isPostSaved: suspend (SavedPost) -> Boolean, reloadPosts: () -> Unit, postActions: PostActions, modifier: Modifier = Modifier, )</ID>
|
||||
<ID>MagicNumber:ClawApplication.kt$ClawApplication$0.25</ID>
|
||||
<ID>MagicNumber:ClawApplication.kt$ClawApplication$1024</ID>
|
||||
<ID>MagicNumber:ClawApplication.kt$ClawApplication$25L</ID>
|
||||
<ID>MagicNumber:MainActivity.kt$MainActivity$24</ID>
|
||||
<ID>MagicNumber:OkHttpModule.kt$OkHttpModule.Companion$10</ID>
|
||||
<ID>MagicNumber:OkHttpModule.kt$OkHttpModule.Companion$1024</ID>
|
||||
<ID>MagicNumber:OkHttpModule.kt$OkHttpModule.Companion.<no name provided>$0x000090000</ID>
|
||||
<ID>ModifierMissing:LobstersApp.kt$LobstersApp</ID>
|
||||
<ID>TooGenericExceptionCaught:LobstersPagingSource.kt$LobstersPagingSource$e: Exception</ID>
|
||||
<ID>UnnecessaryAbstractClass:CoroutineDispatcherModule.kt$CoroutineDispatcherModule$CoroutineDispatcherModule</ID>
|
||||
<ID>UnnecessaryAbstractClass:OkHttpModule.kt$OkHttpModule$OkHttpModule</ID>
|
||||
</CurrentIssues>
|
||||
</SmellBaseline>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue