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

Fix nits problems #4

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PixiViewPreferencesDataStore(
else -> ThemeConfig.System
},
themeColorConfig = when (it.themeColorConfig) {
ThemeColorConfigProto.THEME_COLOR_CONFIG_RED -> ThemeColorConfig.Red
ThemeColorConfigProto.THEME_COLOR_CONFIG_BLUE -> ThemeColorConfig.Blue
ThemeColorConfigProto.THEME_COLOR_CONFIG_BROWN -> ThemeColorConfig.Brown
ThemeColorConfigProto.THEME_COLOR_CONFIG_GREEN -> ThemeColorConfig.Green
Expand Down Expand Up @@ -99,8 +100,7 @@ class PixiViewPreferencesDataStore(
ThemeColorConfig.Green -> ThemeColorConfigProto.THEME_COLOR_CONFIG_GREEN
ThemeColorConfig.Pink -> ThemeColorConfigProto.THEME_COLOR_CONFIG_PINK
ThemeColorConfig.Purple -> ThemeColorConfigProto.THEME_COLOR_CONFIG_PURPLE
ThemeColorConfig.Default -> ThemeColorConfigProto.THEME_COLOR_CONFIG_DEFAULT
else -> ThemeColorConfigProto.THEME_COLOR_CONFIG_BLUE
ThemeColorConfig.Red -> ThemeColorConfigProto.THEME_COLOR_CONFIG_RED
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class PreferenceVersion @Inject constructor(
message = if (Locale.getDefault() == Locale.JAPAN) it.logJp else it.logEn,
)
}
.sortedByDescending { it.date }
.also {
data = it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ option java_multiple_files = true;

enum ThemeColorConfigProto {
THEME_COLOR_CONFIG_UNSPECIFIED = 0;
THEME_COLOR_CONFIG_DEFAULT = 1;
THEME_COLOR_CONFIG_RED = 1;
THEME_COLOR_CONFIG_BLUE = 2;
THEME_COLOR_CONFIG_BROWN = 3;
THEME_COLOR_CONFIG_GREEN = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import androidx.compose.runtime.Stable

@Stable
enum class ThemeColorConfig {
Default, Blue, Brown, Green, Pink, Purple
Red, Blue, Brown, Green, Pink, Purple
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class UserData(
return UserData(
pixiViewId = "",
themeConfig = ThemeConfig.System,
themeColorConfig = ThemeColorConfig.Default,
themeColorConfig = ThemeColorConfig.Red,
isAgreedPrivacyPolicy = false,
isAgreedTermsOfService = false,
isAppLock = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.webkit.MimeTypeMap
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import caios.android.fanbox.core.datastore.PreferenceBookmarkedPosts
import caios.android.fanbox.core.datastore.PreferenceFanboxCookie
import caios.android.fanbox.core.model.FanboxTag
Expand Down Expand Up @@ -72,6 +73,7 @@ import io.ktor.utils.io.jvm.javaio.copyTo
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -170,6 +172,8 @@ class FanboxRepositoryImpl(
private val ioDispatcher: CoroutineDispatcher,
) : FanboxRepository {

private val scope = CoroutineScope(SupervisorJob() + ioDispatcher)

private val creatorCache = mutableMapOf<CreatorId, FanboxCreatorDetail>()
private val postCache = mutableMapOf<PostId, FanboxPostDetail>()
private var homePostsPager: Flow<PagingData<FanboxPost>>? = null
Expand Down Expand Up @@ -322,7 +326,10 @@ class FanboxRepositoryImpl(
pagingSourceFactory = {
HomePostsPagingSource(this, isHideRestricted)
},
).flow.also { homePostsPager = it }
)
.flow
.cachedIn(scope)
.also { homePostsPager = it }
}

override fun getHomePostsPagerCache(loadSize: Int, isHideRestricted: Boolean): Flow<PagingData<FanboxPost>> {
Expand All @@ -336,7 +343,10 @@ class FanboxRepositoryImpl(
pagingSourceFactory = {
HomePostsPagingSource(this, isHideRestricted)
},
).flow.also { supportedPostsPager = it }
)
.flow
.cachedIn(scope)
.also { supportedPostsPager = it }
}

override fun getSupportedPostsPagerCache(loadSize: Int, isHideRestricted: Boolean): Flow<PagingData<FanboxPost>> {
Expand All @@ -350,7 +360,10 @@ class FanboxRepositoryImpl(
pagingSourceFactory = {
CreatorPostsPagingSource(creatorId, this)
},
).flow.also { creatorPostsPager = it }
)
.flow
.cachedIn(scope)
.also { creatorPostsPager = it }
}

override fun getCreatorPostsPagerCache(): Flow<PagingData<FanboxPost>>? {
Expand All @@ -364,7 +377,10 @@ class FanboxRepositoryImpl(
pagingSourceFactory = {
SearchPostsPagingSource(this, creatorId, query)
},
).flow.also { searchPostsPager = it }
)
.flow
.cachedIn(scope)
.also { searchPostsPager = it }
}

override fun getPostsFromQueryPagerCache(): Flow<PagingData<FanboxPost>>? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ val DarkDefaultColorScheme = darkColorScheme(
fun PixiViewTheme(
fanboxCookie: String = "",
fanboxMetadata: FanboxMetaData = FanboxMetaData.dummy(),
themeColorConfig: ThemeColorConfig = ThemeColorConfig.Default,
themeColorConfig: ThemeColorConfig = ThemeColorConfig.Red,
shouldUseDarkTheme: Boolean = isSystemInDarkTheme(),
enableDynamicTheme: Boolean = false,
content: @Composable () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -19,10 +18,7 @@ import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.InsertDriveFile
import androidx.compose.material.icons.filled.Bookmark
import androidx.compose.material.icons.outlined.BookmarkBorder
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.surfaceColorAtElevation
Expand All @@ -31,6 +27,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -62,10 +59,13 @@ import caios.android.fanbox.core.ui.component.RestrictCardItem
import caios.android.fanbox.core.ui.component.TagItems
import caios.android.fanbox.core.ui.extensition.FadePlaceHolder
import caios.android.fanbox.core.ui.extensition.fanboxHeader
import caios.android.fanbox.core.ui.extensition.isNullOrEmpty
import caios.android.fanbox.core.ui.extensition.marquee
import caios.android.fanbox.core.ui.theme.bold
import caios.android.fanbox.core.ui.theme.center
import caios.android.fanbox.core.ui.view.ErrorView
import caios.android.fanbox.core.ui.view.SimpleAlertContents
import caios.android.fanbox.feature.post.R
import caios.android.fanbox.feature.post.detail.items.PostDetailArticleHeader
import caios.android.fanbox.feature.post.detail.items.PostDetailCommentLikeButton
import caios.android.fanbox.feature.post.detail.items.PostDetailCommentSection
Expand Down Expand Up @@ -103,10 +103,10 @@ internal fun PostDetailRoute(
}
}

if (paging != null) {
if (!paging.isNullOrEmpty()) {
LazyPagingItemsLoadContents(
modifier = modifier,
lazyPagingItems = paging,
lazyPagingItems = paging!!,
) {
val initIndex = remember { paging.itemSnapshotList.indexOfFirst { it?.id == postId } }
val pagerState = rememberPagerState(if (initIndex != -1) initIndex else 0) { paging.itemCount }
Expand All @@ -130,7 +130,7 @@ internal fun PostDetailRoute(
}
}
}
} else {
} else if (paging != null) {
PostDetailView(
modifier = modifier,
postId = postId,
Expand All @@ -142,6 +142,12 @@ internal fun PostDetailRoute(
navigateToCommentDeleteDialog = navigateToCommentDeleteDialog,
terminate = terminate,
)
} else {
ErrorView(
modifier = Modifier.fillMaxSize(),
errorState = ScreenState.Error(R.string.error_network),
retryAction = { terminate.invoke() },
)
}
}

Expand Down Expand Up @@ -241,6 +247,7 @@ private fun PostDetailScreen(
modifier: Modifier = Modifier,
) {
var isShowMenu by remember { mutableStateOf(false) }
var isPostLiked by rememberSaveable(postDetail.isLiked) { mutableStateOf(postDetail.isLiked) }
var isBookmarked by remember(postDetail.isBookmarked) { mutableStateOf(postDetail.isBookmarked) }

val isShowCoordinateHeader = when (val content = postDetail.body) {
Expand Down Expand Up @@ -307,32 +314,23 @@ private fun PostDetailScreen(
}

item {
Row(
PostDetailCommentLikeButton(
modifier = Modifier
.padding(horizontal = 16.dp)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(16.dp),
) {
PostDetailCommentLikeButton(
modifier = Modifier.weight(1f),
likeCount = postDetail.likeCount,
commentCount = postDetail.commentCount,
)

IconButton(
onClick = {
isBookmarked = !isBookmarked
onClickPostBookmark.invoke(postDetail.asPost(), isBookmarked)
},
) {
Icon(
imageVector = if (isBookmarked) Icons.Default.Bookmark else Icons.Outlined.BookmarkBorder,
tint = if (isBookmarked) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurface,
contentDescription = null,
)
}
}
isLiked = isPostLiked,
isBookmarked = isBookmarked,
likeCount = postDetail.likeCount,
commentCount = postDetail.commentCount,
onClickLike = {
isPostLiked = true
onClickPostLike.invoke(postDetail.id)
},
onClickBookmark = {
isBookmarked = it
onClickPostBookmark.invoke(postDetail.asPost(), isBookmarked)
},
)
}

if (postDetail.isRestricted) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,100 @@
package caios.android.fanbox.feature.post.detail.items

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.Comment
import androidx.compose.material.icons.filled.Bookmark
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.outlined.BookmarkBorder
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.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

@Composable
internal fun PostDetailCommentLikeButton(
commentCount: Int,
likeCount: Int,
isBookmarked: Boolean,
isLiked: Boolean,
onClickLike: () -> Unit,
onClickBookmark: (Boolean) -> Unit,
modifier: Modifier = Modifier,
) {
val likeColor = if (isLiked) Color(0xffe0405e) else MaterialTheme.colorScheme.onSurfaceVariant
val bookmarkColor = if (isBookmarked) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurfaceVariant

Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(6.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Icon(
modifier = Modifier.size(18.dp),
modifier = Modifier.size(20.dp),
imageVector = Icons.AutoMirrored.Filled.Comment,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
contentDescription = null,
)

Text(
text = commentCount.toString(),
style = MaterialTheme.typography.bodyMedium,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}

Row(
modifier = Modifier
.clip(CircleShape)
.clickable {
if (!isLiked) {
onClickLike.invoke()
}
onClickBookmark.invoke(true)
}
.padding(4.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(6.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Icon(
modifier = Modifier.size(18.dp),
modifier = Modifier.size(20.dp),
imageVector = Icons.Default.Favorite,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
tint = likeColor,
contentDescription = null,
)

Text(
text = likeCount.toString(),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall,
color = likeColor,
)
}

Spacer(modifier = Modifier.weight(1f))

IconButton(
onClick = { onClickBookmark.invoke(!isBookmarked) },
) {
Icon(
imageVector = if (isBookmarked) Icons.Default.Bookmark else Icons.Outlined.BookmarkBorder,
tint = bookmarkColor,
contentDescription = null,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ internal fun SettingThemeColorSection(
key = { it.name },
) {
val color = when (it) {
ThemeColorConfig.Red -> if (isDarkMode) DarkDefaultColorScheme else LightDefaultColorScheme
ThemeColorConfig.Blue -> if (isDarkMode) DarkBlueColorScheme else LightBlueColorScheme
ThemeColorConfig.Brown -> if (isDarkMode) DarkBrownColorScheme else LightBrownColorScheme
ThemeColorConfig.Green -> if (isDarkMode) DarkGreenColorScheme else LightGreenColorScheme
ThemeColorConfig.Purple -> if (isDarkMode) DarkPurpleColorScheme else LightPurpleColorScheme
ThemeColorConfig.Pink -> if (isDarkMode) DarkPinkColorScheme else LightPinckColorScheme
else -> if (isDarkMode) DarkDefaultColorScheme else LightDefaultColorScheme
}

SettingThemeColorItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ internal fun LoginScreen(
cookieManager.acceptCookie()
cookieManager.acceptThirdPartyCookies(it)

it.settings.loadWithOverviewMode = true
it.settings.domStorageEnabled = true
it.settings.javaScriptEnabled = true
it.settings.javaScriptCanOpenWindowsAutomatically = true
},
client = object : AccompanistWebViewClient() {
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
Expand Down
Loading