Skip to content

Commit

Permalink
Merge branch 'release/v1.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
master-lzh committed Apr 22, 2024
2 parents d3e8d0f + 293c6e5 commit f31d9f7
Show file tree
Hide file tree
Showing 31 changed files with 490 additions and 16 deletions.
18 changes: 12 additions & 6 deletions api/src/main/java/com/mrl/pixiv/api/UserApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mrl.pixiv.api
import com.mrl.pixiv.common.data.Rlt
import com.mrl.pixiv.data.EmptyResp
import com.mrl.pixiv.data.user.UserDetailResp
import com.mrl.pixiv.data.user.UserHistoryIllustsResp
import com.mrl.pixiv.data.user.UserIllustsResp
import com.mrl.pixiv.data.user.UserNovelsResp
import kotlinx.coroutines.flow.Flow
Expand All @@ -13,35 +14,40 @@ import retrofit2.http.POST
import retrofit2.http.QueryMap

interface UserApi {
@GET("v2/user/detail")
@GET("/v2/user/detail")
suspend fun getUserDetail(
@QueryMap userDetailQuery: Map<String, String>,
): Flow<Rlt<UserDetailResp>>

@GET("v1/user/illusts")
@GET("/v1/user/illusts")
suspend fun getUserIllusts(
@QueryMap userIllustsQuery: Map<String, String>,
): Flow<Rlt<UserIllustsResp>>

@GET("v1/user/bookmarks/illust")
@GET("/v1/user/bookmarks/illust")
suspend fun getUserBookmarksIllust(
@QueryMap userBookmarksIllustQuery: Map<String, String>,
): Flow<Rlt<UserIllustsResp>>

@GET("v1/user/bookmarks/novel")
@GET("/v1/user/bookmarks/novel")
suspend fun getUserBookmarksNovel(
@QueryMap userBookmarksNovelQuery: Map<String, String>,
): Flow<Rlt<UserNovelsResp>>

@POST("v1/user/follow/add")
@POST("/v1/user/follow/add")
@FormUrlEncoded
suspend fun followUser(
@FieldMap followUserField: Map<String, String>,
): Flow<Rlt<EmptyResp>>

@POST("v1/user/follow/delete")
@POST("/v1/user/follow/delete")
@FormUrlEncoded
suspend fun unFollowUser(
@FieldMap unFollowUserField: Map<String, String>,
): Flow<Rlt<EmptyResp>>

@GET("/v1/user/browsing-history/illusts")
suspend fun getUserBrowsingHistoryIllusts(
@QueryMap userBrowsingHistoryIllustsQuery: Map<String, String>,
): Flow<Rlt<UserHistoryIllustsResp>>
}
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {

defaultConfig {
applicationId = "com.mrl.pixiv"
versionCode = 103
versionName = "1.0.3"
versionCode = 104
versionName = "1.0.4"

vectorDrawables {
useSupportLibrary = true
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/mrl/pixiv/di/DiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import com.mrl.pixiv.domain.auth.RefreshUserAccessTokenUseCase
import com.mrl.pixiv.domain.bookmark.BookmarkUseCase
import com.mrl.pixiv.domain.bookmark.UnBookmarkUseCase
import com.mrl.pixiv.domain.setting.GetAppThemeUseCase
import com.mrl.pixiv.history.viewmodel.HistoryMiddleware
import com.mrl.pixiv.history.viewmodel.HistoryReducer
import com.mrl.pixiv.history.viewmodel.HistoryViewModel
import com.mrl.pixiv.home.viewmodel.HomeMiddleware
import com.mrl.pixiv.home.viewmodel.HomeReducer
import com.mrl.pixiv.home.viewmodel.HomeViewModel
Expand All @@ -55,6 +58,7 @@ import com.mrl.pixiv.repository.local.SearchLocalRepository
import com.mrl.pixiv.repository.local.SettingLocalRepository
import com.mrl.pixiv.repository.local.UserLocalRepository
import com.mrl.pixiv.repository.remote.AuthRemoteRepository
import com.mrl.pixiv.repository.remote.HistoryRepository
import com.mrl.pixiv.repository.remote.IllustRemoteRepository
import com.mrl.pixiv.repository.remote.SearchRemoteRepository
import com.mrl.pixiv.repository.remote.TrendingRemoteRepository
Expand Down Expand Up @@ -148,6 +152,8 @@ val viewModelModule = module {
viewModelOf(::SearchPreviewViewModel)

viewModelOf(::SettingViewModel)

viewModelOf(::HistoryViewModel)
}

val repositoryModule = module {
Expand All @@ -161,6 +167,7 @@ val repositoryModule = module {
singleOf(::UserRemoteRepository)
singleOf(::SearchRemoteRepository)
singleOf(::TrendingRemoteRepository)
singleOf(::HistoryRepository)
}

val dataSourceModule = module {
Expand Down Expand Up @@ -209,6 +216,8 @@ val middlewareModule = module {
factoryOf(::SearchPreviewMiddleware)

factoryOf(::SettingMiddleware)

factoryOf(::HistoryMiddleware)
}

val reducerModule = module {
Expand All @@ -223,6 +232,7 @@ val reducerModule = module {
singleOf(::SearchReducer)
singleOf(::SearchPreviewReducer)
singleOf(::SettingReducer)
singleOf(::HistoryReducer)
}

fun provideAuthService(
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/mrl/pixiv/navigation/main/MainGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.mrl.pixiv.common.ui.LocalNavigator
import com.mrl.pixiv.common.ui.currentOrThrow
import com.mrl.pixiv.data.Illust
import com.mrl.pixiv.di.JSON
import com.mrl.pixiv.history.HistoryScreen
import com.mrl.pixiv.home.HomeScreen
import com.mrl.pixiv.home.viewmodel.HomeViewModel
import com.mrl.pixiv.picture.PictureDeeplinkScreen
Expand Down Expand Up @@ -255,6 +256,15 @@ fun MainGraph(
}
}
}

// 历史记录
composable(
route = Destination.HistoryScreen.route,
) {
HistoryScreen(
modifier = modifier,
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.mrl.pixiv.common_ui.illust

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.mrl.pixiv.common.middleware.bookmark.BookmarkAction
import com.mrl.pixiv.common.middleware.bookmark.BookmarkState
import com.mrl.pixiv.common.ui.components.m3.Surface
import com.mrl.pixiv.common_ui.item.SquareIllustItem
import com.mrl.pixiv.data.Illust
import com.mrl.pixiv.util.OnScrollToBottom
import com.mrl.pixiv.util.isEven

@Composable
fun IllustGrid(
modifier: Modifier = Modifier,
lazyGridState: LazyGridState = rememberLazyGridState(),
illusts: List<Illust>,
bookmarkState: BookmarkState,
dispatch: (BookmarkAction) -> Unit,
spanCount: Int,
horizontalPadding: Dp = 0.dp,
paddingValues: PaddingValues = PaddingValues(1.dp),
navToPictureScreen: (Illust) -> Unit,
canLoadMore: Boolean = true,
onLoadMore: () -> Unit,
) {
var currentLoadingItem by rememberSaveable { mutableIntStateOf(0) }
LaunchedEffect(illusts.size) {
currentLoadingItem = if (illusts.size.isEven()) {
4
} else {
5
}
}
LazyVerticalGrid(
state = lazyGridState,
modifier = modifier,
columns = GridCells.Fixed(spanCount),
verticalArrangement = Arrangement.spacedBy(3.dp),
horizontalArrangement = Arrangement.spacedBy(3.dp),
) {
items(illusts, key = { "illust_${it.id}" }) { illust ->
SquareIllustItem(
illust = illust,
bookmarkState = bookmarkState,
dispatch = dispatch,
spanCount = spanCount,
horizontalPadding = horizontalPadding,
paddingValues = paddingValues,
navToPictureScreen = navToPictureScreen,
)
}

if (canLoadMore) {
items(currentLoadingItem, key = { "loading_$it" }) {
Surface(
Modifier
.fillMaxWidth()
.aspectRatio(1f),
shape = MaterialTheme.shapes.medium,
shadowElevation = 4.dp,
propagateMinConstraints = false,
) {

}
}
}
}
lazyGridState.OnScrollToBottom(loadingItemCount = currentLoadingItem) {
onLoadMore()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mrl.pixiv.setting.components
package com.mrl.pixiv.common_ui.item

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ fun NavHostController.navigateToSettingScreen() {

fun NavHostController.navigateToNetworkSettingScreen() {
navigate(route = Destination.NetworkSettingScreen.route)
}

fun NavHostController.navigateToHistoryScreen() {
navigate(route = Destination.HistoryScreen.route)
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ sealed class Destination(
data object SettingScreen : Destination(route = "setting_screen")

data object NetworkSettingScreen : Destination(route = "network_setting_screen")

data object HistoryScreen : Destination(route = "history_screen")
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.Dp

val transparentIndicatorColors
@Composable
get() = TextFieldDefaults.colors(
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent,
errorIndicatorColor = Color.Transparent,
)

@Composable
internal fun TextFieldColors.textColor(
enabled: Boolean,
Expand Down
7 changes: 7 additions & 0 deletions data/src/main/java/com/mrl/pixiv/data/user/UserResp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ data class UserNovelsResp (
val nextUrl: JsonElement? = null
)

@Serializable
data class UserHistoryIllustsResp(
val illusts: List<Illust>,

@SerialName("next_url")
val nextURL: String? = null
)

Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ class UserHttpService(

suspend fun unFollowUser(userFollowDeleteReq: UserFollowDeleteReq) =
userApi.unFollowUser(userFollowDeleteReq.toMap())

suspend fun getUserBrowsingHistoryIllusts() = userApi.getUserBrowsingHistoryIllusts(mapOf())

suspend fun loadMoreUserBrowsingHistoryIllusts(map: Map<String, String>) =
userApi.getUserBrowsingHistoryIllusts(map)
}
1 change: 1 addition & 0 deletions feature/history/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
12 changes: 12 additions & 0 deletions feature/history/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id("pixiv.android.library.compose")
id("pixiv.android.feature")
}

android {
namespace = "com.mrl.pixiv.history"
}

dependencies {
implementation(project(":repository"))
}
Empty file.
21 changes: 21 additions & 0 deletions feature/history/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
4 changes: 4 additions & 0 deletions feature/history/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>

</manifest>
Loading

0 comments on commit f31d9f7

Please sign in to comment.