mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 02:57:04 +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 {
|
override fun newImageLoader(): ImageLoader {
|
||||||
return ImageLoader.Builder(this)
|
return ImageLoader.Builder(this)
|
||||||
.memoryCache { MemoryCache.Builder(this).maxSizePercent(0.25).build() }
|
.memoryCache { MemoryCache.Builder(this).maxSizePercent(MEMORY_CACHE_RATIO).build() }
|
||||||
.diskCache {
|
.diskCache {
|
||||||
DiskCache.Builder()
|
DiskCache.Builder()
|
||||||
.directory(cacheDir.resolve("image_cache"))
|
.directory(cacheDir.resolve("image_cache"))
|
||||||
.maxSizeBytes(25L * 1024 * 1024) // 25 MB
|
.maxSizeBytes(DISK_CACHE_MAX_SIZE)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
// Show a short crossfade when loading images asynchronously.
|
// Show a short crossfade when loading images asynchronously.
|
||||||
.crossfade(true)
|
.crossfade(true)
|
||||||
.build()
|
.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)
|
super.onCreate(savedInstanceState)
|
||||||
installSplashScreen()
|
installSplashScreen()
|
||||||
setContent {
|
setContent {
|
||||||
LobstersApp(urlLauncher = urlLauncher, htmlConverter = htmlConverter) { url -> webUri = url }
|
LobstersApp(
|
||||||
|
urlLauncher = urlLauncher,
|
||||||
|
htmlConverter = htmlConverter,
|
||||||
|
setWebUri = { url -> webUri = url },
|
||||||
|
)
|
||||||
}
|
}
|
||||||
val postUpdateWorkRequest =
|
val postUpdateWorkRequest =
|
||||||
PeriodicWorkRequestBuilder<SavedPostUpdaterWorker>(24, TimeUnit.HOURS)
|
PeriodicWorkRequestBuilder<SavedPostUpdaterWorker>(POST_REFRESH_PERIOD, TimeUnit.HOURS)
|
||||||
.setConstraints(
|
.setConstraints(
|
||||||
Constraints.Builder()
|
Constraints.Builder()
|
||||||
.setRequiresCharging(false)
|
.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
|
@Module
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
abstract class CoroutineDispatcherModule {
|
interface CoroutineDispatcherModule {
|
||||||
|
|
||||||
@Binds abstract fun DefaultDispatcherProvider.bind(): DispatcherProvider
|
@Binds fun DefaultDispatcherProvider.bind(): DispatcherProvider
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@[Provides IODispatcher]
|
@[Provides IODispatcher]
|
||||||
|
|
|
@ -21,24 +21,26 @@ import okhttp3.logging.HttpLoggingInterceptor
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@InstallIn(SingletonComponent::class)
|
@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 {
|
companion object {
|
||||||
|
private const val CACHE_SIZE_MB = 10L * 1024 * 1024
|
||||||
|
private const val THREAD_STATS_TAG = 0x000090000
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideCache(@ApplicationContext context: Context): Cache {
|
fun provideCache(@ApplicationContext context: Context): Cache {
|
||||||
return Cache(context.cacheDir, 10 * 1024 * 1024)
|
return Cache(context.cacheDir, CACHE_SIZE_MB)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideSocketFactory(): SocketFactory {
|
fun provideSocketFactory(): SocketFactory {
|
||||||
return object : DelegatingSocketFactory(getDefault()) {
|
return object : DelegatingSocketFactory(getDefault()) {
|
||||||
override fun configureSocket(socket: Socket): Socket {
|
override fun configureSocket(socket: Socket): Socket {
|
||||||
TrafficStats.setThreadStatsTag(0x000090000)
|
TrafficStats.setThreadStatsTag(THREAD_STATS_TAG)
|
||||||
return super.configureSocket(socket)
|
return super.configureSocket(socket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ constructor(
|
||||||
@IODispatcher private val ioDispatcher: CoroutineDispatcher,
|
@IODispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
) : PagingSource<Int, LobstersPost>() {
|
) : PagingSource<Int, LobstersPost>() {
|
||||||
|
|
||||||
|
@Suppress("TooGenericExceptionCaught") // Intentional
|
||||||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, LobstersPost> {
|
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, LobstersPost> {
|
||||||
return try {
|
return try {
|
||||||
val page = params.key ?: 1
|
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.composable
|
||||||
import soup.compose.material.motion.navigation.rememberMaterialMotionNavController
|
import soup.compose.material.motion.navigation.rememberMaterialMotionNavController
|
||||||
|
|
||||||
|
@Suppress("ModifierMissing") // Top-level composable, will never have a modifier supplied.
|
||||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class)
|
@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun LobstersApp(
|
fun LobstersApp(
|
||||||
viewModel: ClawViewModel = viewModel(),
|
|
||||||
urlLauncher: UrlLauncher,
|
urlLauncher: UrlLauncher,
|
||||||
htmlConverter: HTMLConverter,
|
htmlConverter: HTMLConverter,
|
||||||
setWebUri: (String?) -> Unit,
|
setWebUri: (String?) -> Unit,
|
||||||
|
viewModel: ClawViewModel = viewModel(),
|
||||||
) {
|
) {
|
||||||
val systemUiController = rememberSystemUiController()
|
val systemUiController = rememberSystemUiController()
|
||||||
val hottestListState = rememberLazyListState()
|
val hottestListState = rememberLazyListState()
|
||||||
|
|
|
@ -2,19 +2,7 @@
|
||||||
<SmellBaseline>
|
<SmellBaseline>
|
||||||
<ManuallySuppressedIssues></ManuallySuppressedIssues>
|
<ManuallySuppressedIssues></ManuallySuppressedIssues>
|
||||||
<CurrentIssues>
|
<CurrentIssues>
|
||||||
<ID>ComposableParamOrder:LobstersApp.kt$LobstersApp</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>LongMethod:LobstersApp.kt$@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class) @Composable fun LobstersApp( viewModel: ClawViewModel = viewModel(), urlLauncher: UrlLauncher, htmlConverter: HTMLConverter, setWebUri: (String?) -> Unit, )</ID>
|
|
||||||
<ID>LongParameterList:NetworkPosts.kt$( items: LazyPagingItems<LobstersPost>, listState: LazyListState, isPostSaved: suspend (SavedPost) -> Boolean, reloadPosts: () -> Unit, postActions: PostActions, modifier: Modifier = Modifier, )</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>
|
</CurrentIssues>
|
||||||
</SmellBaseline>
|
</SmellBaseline>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue