Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
run detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
matsumo0922 committed Dec 10, 2023
1 parent 6ae3a2b commit e1016ff
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 170 deletions.
2 changes: 0 additions & 2 deletions app/src/main/java/caios/android/fanbox/ui/PixiViewNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ internal fun PixiViewNavHost(

settingTopScreen(
navigateToThemeSetting = { navController.navigateToSettingTheme() },
navigateToAccountSetting = { },
navigateToNotifySetting = { },
navigateToBillingPlus = { navController.navigateToBillingPlus() },
navigateToSettingDeveloper = { navController.navigateToSettingDeveloper() },
navigateToLogoutDialog = { contents, onResult -> navController.navigateToSimpleAlertDialog(contents, onResult) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class AndroidLibraryConventionPlugin: Plugin<Project> {
apply("kotlin-parcelize")
apply("kotlinx-serialization")
apply("project-report")
apply("com.google.gms.google-services")
apply("com.google.devtools.ksp")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class FanboxRepositoryImpl(
withContext(ioDispatcher) {
get(
"post.listComments",
mapOf("postId" to postId.value, "offset" to offset.toString(), "limit" to "10")
mapOf("postId" to postId.value, "offset" to offset.toString(), "limit" to "10"),
).parse<FanboxPostCommentItemsEntity>()!!.translate()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,26 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.InsertDriveFile
import androidx.compose.material.icons.filled.Lock
import androidx.compose.material.icons.filled.NoAdultContent
import androidx.compose.material.icons.filled.RemoveRedEye
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import caios.android.fanbox.core.model.fanbox.FanboxPost
import caios.android.fanbox.core.model.fanbox.id.CreatorId
import caios.android.fanbox.core.model.fanbox.id.PostId
import caios.android.fanbox.core.ui.R
import caios.android.fanbox.core.ui.extensition.SimmerPlaceHolder
import caios.android.fanbox.core.ui.extensition.fanboxHeader
import caios.android.fanbox.core.ui.theme.center
import coil.compose.SubcomposeAsyncImage
import coil.request.ImageRequest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,48 +75,56 @@ import kotlinx.coroutines.flow.collectLatest

fun Modifier.drawHorizontalScrollbar(
state: ScrollState,
reverseScrolling: Boolean = false
reverseScrolling: Boolean = false,
): Modifier = drawScrollbar(state, Orientation.Horizontal, reverseScrolling)

fun Modifier.drawVerticalScrollbar(
state: ScrollState,
reverseScrolling: Boolean = false
reverseScrolling: Boolean = false,
): Modifier = drawScrollbar(state, Orientation.Vertical, reverseScrolling)

private fun Modifier.drawScrollbar(
state: ScrollState,
orientation: Orientation,
reverseScrolling: Boolean
reverseScrolling: Boolean,
): Modifier = drawScrollbar(
orientation, reverseScrolling
orientation,
reverseScrolling,
) { reverseDirection, atEnd, color, alpha ->
if (state.maxValue > 0) {
val canvasSize = if (orientation == Orientation.Horizontal) size.width else size.height
val totalSize = canvasSize + state.maxValue
val thumbSize = canvasSize / totalSize * canvasSize
val startOffset = state.value / totalSize * canvasSize
drawScrollbar(
orientation, reverseDirection, atEnd, color, alpha, thumbSize, startOffset
orientation,
reverseDirection,
atEnd,
color,
alpha,
thumbSize,
startOffset,
)
}
}

fun Modifier.drawHorizontalScrollbar(
state: LazyListState,
reverseScrolling: Boolean = false
reverseScrolling: Boolean = false,
): Modifier = drawScrollbar(state, Orientation.Horizontal, reverseScrolling)

fun Modifier.drawVerticalScrollbar(
state: LazyListState,
reverseScrolling: Boolean = false
reverseScrolling: Boolean = false,
): Modifier = drawScrollbar(state, Orientation.Vertical, reverseScrolling)

private fun Modifier.drawScrollbar(
state: LazyListState,
orientation: Orientation,
reverseScrolling: Boolean
reverseScrolling: Boolean,
): Modifier = drawScrollbar(
orientation, reverseScrolling
orientation,
reverseScrolling,
) { reverseDirection, atEnd, color, alpha ->
val layoutInfo = state.layoutInfo
val viewportSize = layoutInfo.viewportEndOffset - layoutInfo.viewportStartOffset
Expand All @@ -127,21 +135,32 @@ private fun Modifier.drawScrollbar(
val totalSize = estimatedItemSize * layoutInfo.totalItemsCount
val canvasSize = if (orientation == Orientation.Horizontal) size.width else size.height
val thumbSize = viewportSize / totalSize * canvasSize
val startOffset = if (items.isEmpty()) 0f else items.first().run {
(estimatedItemSize * index - offset) / totalSize * canvasSize
val startOffset = if (items.isEmpty()) {
0f
} else {
items.first().run {
(estimatedItemSize * index - offset) / totalSize * canvasSize
}
}
drawScrollbar(
orientation, reverseDirection, atEnd, color, alpha, thumbSize, startOffset
orientation,
reverseDirection,
atEnd,
color,
alpha,
thumbSize,
startOffset,
)
}
}

fun Modifier.drawVerticalScrollbar(
state: LazyGridState,
spanCount: Int,
reverseScrolling: Boolean = false
reverseScrolling: Boolean = false,
): Modifier = drawScrollbar(
Orientation.Vertical, reverseScrolling
Orientation.Vertical,
reverseScrolling,
) { reverseDirection, atEnd, color, alpha ->
val layoutInfo = state.layoutInfo
val viewportSize = layoutInfo.viewportEndOffset - layoutInfo.viewportStartOffset
Expand All @@ -157,12 +176,22 @@ fun Modifier.drawVerticalScrollbar(
val totalSize = estimatedItemSize * totalRow
val canvasSize = size.height
val thumbSize = viewportSize / totalSize * canvasSize
val startOffset = if (rowCount == 0) 0f else items.first().run {
val rowIndex = index / spanCount
(estimatedItemSize * rowIndex - offset.y) / totalSize * canvasSize
val startOffset = if (rowCount == 0) {
0f
} else {
items.first().run {
val rowIndex = index / spanCount
(estimatedItemSize * rowIndex - offset.y) / totalSize * canvasSize
}
}
drawScrollbar(
Orientation.Vertical, reverseDirection, atEnd, color, alpha, thumbSize, startOffset
Orientation.Vertical,
reverseDirection,
atEnd,
color,
alpha,
thumbSize,
startOffset,
)
}
}
Expand All @@ -174,18 +203,18 @@ private fun DrawScope.drawScrollbar(
color: Color,
alpha: () -> Float,
thumbSize: Float,
startOffset: Float
startOffset: Float,
) {
val thicknessPx = Thickness.toPx()
val topLeft = if (orientation == Orientation.Horizontal) {
Offset(
if (reverseDirection) size.width - startOffset - thumbSize else startOffset,
if (atEnd) size.height - thicknessPx else 0f
if (atEnd) size.height - thicknessPx else 0f,
)
} else {
Offset(
if (atEnd) size.width - thicknessPx else 0f,
if (reverseDirection) size.height - startOffset - thumbSize else startOffset
if (reverseDirection) size.height - startOffset - thumbSize else startOffset,
)
}
val size = if (orientation == Orientation.Horizontal) {
Expand All @@ -198,7 +227,7 @@ private fun DrawScope.drawScrollbar(
color = color,
topLeft = topLeft,
size = size,
alpha = alpha()
alpha = alpha(),
)
}

Expand All @@ -209,21 +238,21 @@ private fun Modifier.drawScrollbar(
reverseDirection: Boolean,
atEnd: Boolean,
color: Color,
alpha: () -> Float
) -> Unit
alpha: () -> Float,
) -> Unit,
): Modifier = composed {
val scrolled = remember {
MutableSharedFlow<Unit>(
extraBufferCapacity = 1,
onBufferOverflow = BufferOverflow.DROP_OLDEST
onBufferOverflow = BufferOverflow.DROP_OLDEST,
)
}
val nestedScrollConnection = remember(orientation, scrolled) {
object : NestedScrollConnection {
override fun onPostScroll(
consumed: Offset,
available: Offset,
source: NestedScrollSource
source: NestedScrollSource,
): Offset {
val delta = if (orientation == Orientation.Horizontal) consumed.x else consumed.y
if (delta != 0f) scrolled.tryEmit(Unit)
Expand All @@ -244,7 +273,9 @@ private fun Modifier.drawScrollbar(
val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr
val reverseDirection = if (orientation == Orientation.Horizontal) {
if (isLtr) reverseScrolling else !reverseScrolling
} else reverseScrolling
} else {
reverseScrolling
}
val atEnd = if (orientation == Orientation.Vertical) isLtr else true

val color = BarColor
Expand Down Expand Up @@ -278,7 +309,7 @@ internal fun ScrollbarPreview() {
text = "Item ${it + 1}",
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.padding(16.dp),
)
}
}
Expand All @@ -290,14 +321,14 @@ internal fun LazyListScrollbarPreview() {
val state = rememberLazyListState()
LazyColumn(
modifier = Modifier.drawVerticalScrollbar(state),
state = state
state = state,
) {
items(50) {
Text(
text = "Item ${it + 1}",
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.padding(16.dp),
)
}
}
Expand All @@ -310,13 +341,13 @@ internal fun HorizontalScrollbarPreview() {
Row(
modifier = Modifier
.drawHorizontalScrollbar(state)
.horizontalScroll(state)
.horizontalScroll(state),
) {
repeat(50) {
Text(
text = (it + 1).toString(),
modifier = Modifier
.padding(horizontal = 8.dp, vertical = 16.dp)
.padding(horizontal = 8.dp, vertical = 16.dp),
)
}
}
Expand All @@ -328,13 +359,13 @@ internal fun LazyListHorizontalScrollbarPreview() {
val state = rememberLazyListState()
LazyRow(
modifier = Modifier.drawHorizontalScrollbar(state),
state = state
state = state,
) {
items(50) {
Text(
text = (it + 1).toString(),
modifier = Modifier
.padding(horizontal = 8.dp, vertical = 16.dp)
.padding(horizontal = 8.dp, vertical = 16.dp),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ import caios.android.fanbox.feature.creator.top.items.CreatorTopDescriptionDialo
import caios.android.fanbox.feature.creator.top.items.CreatorTopHeader
import caios.android.fanbox.feature.creator.top.items.CreatorTopPlansScreen
import caios.android.fanbox.feature.creator.top.items.CreatorTopPostsScreen
import com.dokar.pinchzoomgrid.rememberPinchZoomGridState
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.launch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class CreatorTopViewModel @Inject constructor(
creatorDetail = fanboxRepository.getCreator(creatorId),
creatorPlans = fanboxRepository.getCreatorPlans(creatorId),
creatorTags = fanboxRepository.getCreatorTags(creatorId),
creatorPostsPaging = postsPagingCache ?: fanboxRepository.getCreatorPostsPager(creatorId, loadSize).also { postsPagingCache = it },
creatorPostsPaging = postsPagingCache ?: fanboxRepository.getCreatorPostsPager(creatorId, loadSize).also {
postsPagingCache = it
},
)
}.fold(
onSuccess = { ScreenState.Idle(it) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.paging.compose.itemContentType
import androidx.paging.compose.itemKey
import caios.android.fanbox.core.model.ScreenState
import caios.android.fanbox.core.model.UserData
import caios.android.fanbox.core.model.fanbox.FanboxCreatorDetail
import caios.android.fanbox.core.model.fanbox.id.CreatorId
import caios.android.fanbox.core.ui.AsyncLoadContents
Expand All @@ -48,6 +45,8 @@ import caios.android.fanbox.core.ui.component.PixiViewTopBar
import caios.android.fanbox.core.ui.extensition.drawVerticalScrollbar
import caios.android.fanbox.core.ui.theme.bold
import caios.android.fanbox.feature.library.R
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.launch

@Composable
Expand All @@ -74,8 +73,8 @@ internal fun LibraryDiscoveryRoute(
) { uiState ->
LibraryDiscoveryScreen(
modifier = Modifier.fillMaxSize(),
recommendedCreators = uiState.recommendedCreators,
followingPixivCreators = uiState.followingPixivCreators,
recommendedCreators = uiState.recommendedCreators.toImmutableList(),
followingPixivCreators = uiState.followingPixivCreators.toImmutableList(),
openDrawer = openDrawer,
onClickSearch = navigateToPostSearch,
onClickCreator = navigateToCreatorPosts,
Expand All @@ -89,8 +88,8 @@ internal fun LibraryDiscoveryRoute(
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun LibraryDiscoveryScreen(
recommendedCreators: List<FanboxCreatorDetail>,
followingPixivCreators: List<FanboxCreatorDetail>,
recommendedCreators: ImmutableList<FanboxCreatorDetail>,
followingPixivCreators: ImmutableList<FanboxCreatorDetail>,
openDrawer: () -> Unit,
onClickSearch: () -> Unit,
onClickCreator: (CreatorId) -> Unit,
Expand Down
Loading

0 comments on commit e1016ff

Please sign in to comment.