Skip to content

Commit

Permalink
Merge branch 'release/v1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
master-lzh committed Apr 11, 2024
2 parents 79e639a + 46db197 commit 2b6a483
Show file tree
Hide file tree
Showing 27 changed files with 835 additions and 436 deletions.
12 changes: 12 additions & 0 deletions api/src/main/java/com/mrl/pixiv/api/TrendingApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mrl.pixiv.api

import com.mrl.pixiv.common.data.Rlt
import com.mrl.pixiv.data.search.TrendingTagsResp
import kotlinx.coroutines.flow.Flow
import retrofit2.http.GET
import retrofit2.http.Query

interface TrendingApi {
@GET("v1/trending-tags/illust")
suspend fun trendingTags(@Query("filter") filter: String): Flow<Rlt<TrendingTagsResp>>
}
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 = 1
versionName = "1.0"
versionCode = 101
versionName = "1.0.1"

vectorDrawables {
useSupportLibrary = true
Expand Down
96 changes: 55 additions & 41 deletions app/src/main/java/com/mrl/pixiv/di/DiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mrl.pixiv.di

import com.mrl.pixiv.api.IllustApi
import com.mrl.pixiv.api.SearchApi
import com.mrl.pixiv.api.TrendingApi
import com.mrl.pixiv.api.UserApi
import com.mrl.pixiv.api.UserAuthApi
import com.mrl.pixiv.common.coroutine.CloseableCoroutineScope
Expand All @@ -14,14 +15,14 @@ import com.mrl.pixiv.common.middleware.bookmark.BookmarkViewModel
import com.mrl.pixiv.common.middleware.follow.FollowMiddleware
import com.mrl.pixiv.common.middleware.follow.FollowReducer
import com.mrl.pixiv.common.middleware.follow.FollowViewModel
import com.mrl.pixiv.data.Illust
import com.mrl.pixiv.data.search.searchDataStore
import com.mrl.pixiv.data.user.userInfoDataStore
import com.mrl.pixiv.datasource.local.SearchDataSource
import com.mrl.pixiv.datasource.local.UserAuthDataSource
import com.mrl.pixiv.datasource.local.UserInfoDataSource
import com.mrl.pixiv.datasource.remote.IllustHttpService
import com.mrl.pixiv.datasource.remote.SearchHttpService
import com.mrl.pixiv.datasource.remote.TrendingHttpService
import com.mrl.pixiv.datasource.remote.UserAuthHttpService
import com.mrl.pixiv.datasource.remote.UserHttpService
import com.mrl.pixiv.domain.GetLocalUserInfoUseCase
Expand All @@ -48,7 +49,11 @@ import com.mrl.pixiv.repository.local.UserLocalRepository
import com.mrl.pixiv.repository.remote.AuthRemoteRepository
import com.mrl.pixiv.repository.remote.IllustRemoteRepository
import com.mrl.pixiv.repository.remote.SearchRemoteRepository
import com.mrl.pixiv.repository.remote.TrendingRemoteRepository
import com.mrl.pixiv.repository.remote.UserRemoteRepository
import com.mrl.pixiv.search.preview.viewmodel.SearchPreviewMiddleware
import com.mrl.pixiv.search.preview.viewmodel.SearchPreviewReducer
import com.mrl.pixiv.search.preview.viewmodel.SearchPreviewViewModel
import com.mrl.pixiv.search.viewmodel.SearchMiddleware
import com.mrl.pixiv.search.viewmodel.SearchReducer
import com.mrl.pixiv.search.viewmodel.SearchViewModel
Expand All @@ -62,7 +67,9 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import org.koin.android.ext.koin.androidContext
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.core.module.dsl.factoryOf
import org.koin.core.module.dsl.singleOf
import org.koin.core.qualifier.named
import org.koin.dsl.module

Expand Down Expand Up @@ -90,46 +97,49 @@ val appModule = module {
JSON.asConverterFactory("application/json".toMediaType())
}

single { HttpManager(get(), get()) }
singleOf(::HttpManager)

single(named(DispatcherEnum.IO)) { Dispatchers.IO }

single(named(DispatcherEnum.MAIN)) { Dispatchers.Main.immediate }

single { JSON }
singleOf(::JSON)

factory {
CloseableCoroutineScope(SupervisorJob() + get<MainCoroutineDispatcher>(named(DispatcherEnum.MAIN)))
}
}

val viewModelModule = module {
viewModel { SplashViewModel(get(), get()) }
viewModelOf(::SplashViewModel)

viewModel { LoginViewModel(get(), get()) }
viewModelOf(::LoginViewModel)

viewModel { HomeViewModel(get(), get()) }
viewModelOf(::HomeViewModel)

viewModel { ProfileViewModel(get(), get()) }
viewModelOf(::ProfileViewModel)

viewModel { (illust: Illust) -> PictureViewModel(illust, get(), get()) }
viewModelOf(::PictureViewModel)

viewModel { BookmarkViewModel(get(), get()) }
viewModelOf(::BookmarkViewModel)

viewModel { FollowViewModel(get(), get()) }
viewModelOf(::FollowViewModel)

viewModel { SearchViewModel(get(), get()) }
viewModelOf(::SearchViewModel)

viewModelOf(::SearchPreviewViewModel)
}

val repositoryModule = module {
single { UserLocalRepository(get(), get()) }
single { SearchLocalRepository(get()) }
singleOf(::UserLocalRepository)
singleOf(::SearchLocalRepository)


single { AuthRemoteRepository(get(), get(named(DispatcherEnum.IO))) }
single { IllustRemoteRepository(get(), get(named(DispatcherEnum.IO))) }
single { UserRemoteRepository(get(), get(named(DispatcherEnum.IO))) }
single { SearchRemoteRepository(get(), get(named(DispatcherEnum.IO))) }
singleOf(::AuthRemoteRepository)
singleOf(::IllustRemoteRepository)
singleOf(::UserRemoteRepository)
singleOf(::SearchRemoteRepository)
singleOf(::TrendingRemoteRepository)
}

val dataSourceModule = module {
Expand All @@ -141,45 +151,49 @@ val dataSourceModule = module {
single { UserAuthHttpService(provideAuthService(get())) }
single { UserHttpService(provideCommonService(get(), UserApi::class.java)) }
single { SearchHttpService(provideCommonService(get(), SearchApi::class.java)) }
single { TrendingHttpService(provideCommonService(get(), TrendingApi::class.java)) }
}

val useCaseModule = module {
single { SetUserRefreshTokenUseCase(get()) }
single { SetUserAccessTokenUseCase(get()) }
single { GetLocalUserInfoUseCase(get()) }
single { SetLocalUserInfoUseCase(get()) }
single { RefreshUserAccessTokenUseCase(get(), get(), get(), get(), get()) }
single { BookmarkUseCase(get()) }
single { UnBookmarkUseCase(get()) }
singleOf(::SetUserRefreshTokenUseCase)
singleOf(::SetUserAccessTokenUseCase)
singleOf(::GetLocalUserInfoUseCase)
singleOf(::SetLocalUserInfoUseCase)
singleOf(::RefreshUserAccessTokenUseCase)
singleOf(::BookmarkUseCase)
singleOf(::UnBookmarkUseCase)
}

val middlewareModule = module {
factory { SplashMiddleware(get(), get(), get(), get(), get()) }
factoryOf(::SplashMiddleware)

factoryOf(::HomeMiddleware)

factory { HomeMiddleware(get(), get()) }
factoryOf(::BookmarkMiddleware)

factory { BookmarkMiddleware(get()) }
factoryOf(::AuthMiddleware)

factory { AuthMiddleware(get(), get(), get(), get(), get(), get()) }
factoryOf(::ProfileMiddleware)

factory { ProfileMiddleware(get(), get()) }
factoryOf(::PictureMiddleware)

factory { PictureMiddleware(get(), get()) }
factoryOf(::FollowMiddleware)

factory { FollowMiddleware(get()) }
factoryOf(::SearchMiddleware)

factory { SearchMiddleware(get(), get()) }
factoryOf(::SearchPreviewMiddleware)
}

val reducerModule = module {
single { SplashReducer() }
single { HomeReducer() }
single { BookmarkReducer() }
single { AuthReducer() }
single { ProfileReducer() }
single { PictureReducer() }
single { FollowReducer() }
single { SearchReducer() }
singleOf(::SplashReducer)
singleOf(::HomeReducer)
singleOf(::BookmarkReducer)
singleOf(::AuthReducer)
singleOf(::ProfileReducer)
singleOf(::PictureReducer)
singleOf(::FollowReducer)
singleOf(::SearchReducer)
singleOf(::SearchPreviewReducer)
}

fun provideAuthService(
Expand Down
37 changes: 30 additions & 7 deletions app/src/main/java/com/mrl/pixiv/navigation/main/MainGraph.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mrl.pixiv.navigation.main

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand All @@ -19,8 +20,9 @@ import com.mrl.pixiv.home.viewmodel.HomeViewModel
import com.mrl.pixiv.picture.PictureScreen
import com.mrl.pixiv.profile.ProfileScreen
import com.mrl.pixiv.search.OutsideSearchResultsScreen
import com.mrl.pixiv.search.SearchResultScreen1
import com.mrl.pixiv.search.SearchScreen1
import com.mrl.pixiv.search.SearchResultScreen
import com.mrl.pixiv.search.SearchScreen
import com.mrl.pixiv.search.preview.SearchPreviewScreen
import com.mrl.pixiv.search.viewmodel.SearchViewModel
import org.koin.androidx.compose.koinViewModel
import kotlin.io.encoding.Base64
Expand All @@ -29,6 +31,7 @@ import kotlin.io.encoding.ExperimentalEncodingApi
@OptIn(ExperimentalEncodingApi::class)
@Composable
fun MainGraph(
modifier: Modifier = Modifier,
navHostController: NavHostController,
) {
val homeViewModel: HomeViewModel = koinViewModel()
Expand All @@ -39,21 +42,34 @@ fun MainGraph(
route = Graph.MAIN,
startDestination = Destination.HomeScreen.route,
) {
// 首页
composable(
route = Destination.HomeScreen.route,
deepLinks = listOf(
navDeepLink {
uriPattern = DestinationsDeepLink.HomePattern
}
),

) {
) {
HomeScreen(
modifier = modifier,
navHostController = navHostController,
homeViewModel = homeViewModel,
bookmarkViewModel = bookmarkViewModel
)
}

// 搜索预览页
composable(
route = Destination.SearchPreviewScreen.route,
) {
SearchPreviewScreen(
modifier = modifier,
navHostController = navHostController,
)
}

// 个人主页
composable(
route = Destination.ProfileScreen.route,
deepLinks = listOf(
Expand All @@ -63,10 +79,13 @@ fun MainGraph(
),
) {
ProfileScreen(
modifier = modifier,
navHostController = navHostController,
bookmarkViewModel = bookmarkViewModel
)
}

// 作品详情页
composable(
route = "${Destination.PictureScreen.route}/{${Destination.PictureScreen.illustParams}}",
arguments = listOf(
Expand All @@ -91,8 +110,10 @@ fun MainGraph(
followViewModel = followViewModel,
)
}

// 搜索页
composable(
route = Graph.SEARCH,
route = Destination.SearchScreen.route,
) {
val searchViewModel: SearchViewModel = koinViewModel(viewModelStoreOwner = it)
val searchNavHostController = rememberNavController()
Expand All @@ -104,7 +125,7 @@ fun MainGraph(
composable(
route = Destination.SearchScreen.route,
) {
SearchScreen1(
SearchScreen(
searchNavHostController = searchNavHostController,
navHostController = navHostController,
searchViewModel = searchViewModel
Expand All @@ -113,7 +134,7 @@ fun MainGraph(
composable(
route = Destination.SearchResultsScreen.route,
) {
SearchResultScreen1(
SearchResultScreen(
searchNavHostController = searchNavHostController,
bookmarkViewModel = bookmarkViewModel,
searchViewModel = searchViewModel,
Expand All @@ -122,6 +143,8 @@ fun MainGraph(
}
}
}

// 外部搜索结果页
composable(
route = "${Destination.SearchResultsScreen.route}/{${Destination.SearchResultsScreen.searchWord}}",
arguments = listOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.mrl.pixiv.navigation.main

import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
Expand All @@ -25,7 +27,10 @@ fun MainScreen(
)
},
) {
MainGraph(navHostController = navHostController)
MainGraph(
modifier = Modifier.padding(bottom = it.calculateBottomPadding()),
navHostController = navHostController
)
}
}

Expand All @@ -38,6 +43,7 @@ fun bottomBarVisibility(
val navBackStackEntry by navController.currentBackStackEntryAsState()
when (navBackStackEntry?.destination?.route) {
Destination.HomeScreen.route -> bottomBarState.value = true
Destination.SearchPreviewScreen.route -> bottomBarState.value = true
Destination.ProfileScreen.route -> bottomBarState.value = true
else -> bottomBarState.value = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fun NavHostController.navigateToPictureScreen(illust: Illust) {
}

fun NavHostController.navigateToSearchScreen() {
navigate(route = Graph.SEARCH) {
navigate(route = Destination.SearchScreen.route) {
launchSingleTop = true
}
}
Expand Down
12 changes: 12 additions & 0 deletions common/src/main/java/com/mrl/pixiv/common/router/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mrl.pixiv.common.router
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.AccountCircle
import androidx.compose.material.icons.rounded.Home
import androidx.compose.material.icons.rounded.Search
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable

Expand Down Expand Up @@ -39,6 +40,17 @@ sealed class Destination(
const val illustParams = "illust"
}

data object SearchPreviewScreen : Destination(
route = "search_preview_screen",
title = "搜索",
icon = {
Icon(
imageVector = Icons.Rounded.Search,
contentDescription = null,
)
}
)

data object SearchScreen : Destination(route = "search_screen")

data object SearchResultsScreen : Destination(route = "search_results_screen") {
Expand Down
Loading

0 comments on commit 2b6a483

Please sign in to comment.