Skip to content

Commit

Permalink
Merge pull request #10 from groupeminaste/feature/search
Browse files Browse the repository at this point in the history
feat: search
  • Loading branch information
nathanfallet authored Mar 12, 2024
2 parents 624c093 + d78e2d5 commit d98ba5b
Show file tree
Hide file tree
Showing 31 changed files with 254 additions and 143 deletions.
20 changes: 10 additions & 10 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId = "me.nathanfallet.extopy"
minSdk = 21
targetSdk = 34
versionCode = 4
versionName = "0.1.0"
versionCode = 5
versionName = "0.1.1"
}
buildFeatures {
buildConfig = true
Expand Down Expand Up @@ -53,26 +53,26 @@ android {

dependencies {
implementation(project(":shared"))
implementation("androidx.compose.ui:ui:1.5.4")
implementation("androidx.compose.ui:ui-tooling:1.5.4")
implementation("androidx.compose.ui:ui-tooling-preview:1.5.4")
implementation("androidx.compose.foundation:foundation:1.5.4")
implementation("androidx.compose.material3:material3:1.1.2")
implementation("androidx.compose.runtime:runtime-livedata:1.5.4")
implementation("androidx.compose.ui:ui:1.6.2")
implementation("androidx.compose.ui:ui-tooling:1.6.2")
implementation("androidx.compose.ui:ui-tooling-preview:1.6.2")
implementation("androidx.compose.foundation:foundation:1.6.2")
implementation("androidx.compose.material3:material3:1.2.0")
implementation("androidx.compose.runtime:runtime-livedata:1.6.2")

implementation("io.insert-koin:koin-core:3.5.3")
implementation("io.insert-koin:koin-android:3.5.3")
implementation("io.insert-koin:koin-androidx-compose:3.5.0")

implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0")
implementation("androidx.activity:activity-compose:1.8.2")
implementation("androidx.navigation:navigation-compose:2.7.6")
implementation("androidx.navigation:navigation-compose:2.7.7")
implementation("androidx.datastore:datastore-preferences:1.0.0")

implementation("com.google.android.material:material:1.11.0")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0")
implementation("io.coil-kt:coil-compose:2.4.0")
implementation("com.github.JamalMulla:ComposePrefs:1.0.6")
implementation("com.github.JamalMulla:ComposePrefs3:1.0.4")

coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ enum class NavigationItem(
val title: Int,
) {

TIMELINE("timeline", R.drawable.ic_baseline_menu_24, R.string.timeline_title),
TIMELINE("timelines", R.drawable.ic_baseline_menu_24, R.string.timeline_title),
DIRECT_MESSAGE(
"direct_message",
R.drawable.ic_baseline_message_24,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package me.nathanfallet.extopy.features.settings

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.jamal.composeprefs.ui.prefs.TextPref
import com.jamal.composeprefs3.ui.prefs.TextPref
import me.nathanfallet.extopy.models.users.User

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.core.content.ContextCompat.startActivity
import androidx.lifecycle.viewmodel.compose.viewModel
import com.jamal.composeprefs.ui.GroupHeader
import com.jamal.composeprefs.ui.PrefsScreen
import com.jamal.composeprefs.ui.prefs.TextPref
import com.jamal.composeprefs3.ui.GroupHeader
import com.jamal.composeprefs3.ui.PrefsScreen
import com.jamal.composeprefs3.ui.prefs.TextPref
import me.nathanfallet.extopy.R
import me.nathanfallet.extopy.extensions.dataStore

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package me.nathanfallet.extopy.features.timelines

import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
Expand All @@ -23,6 +24,7 @@ import me.nathanfallet.extopy.R
import me.nathanfallet.extopy.models.users.User
import me.nathanfallet.extopy.ui.components.posts.PostCard
import me.nathanfallet.extopy.ui.components.users.UserCard
import me.nathanfallet.extopy.viewmodels.timelines.SearchViewModel
import me.nathanfallet.extopy.viewmodels.timelines.TimelineViewModel
import org.koin.androidx.compose.koinViewModel
import org.koin.core.parameter.parametersOf
Expand All @@ -39,6 +41,7 @@ fun TimelineView(
val viewModel = koinViewModel<TimelineViewModel>(
parameters = { parametersOf(id) }
)
val searchViewModel = koinViewModel<SearchViewModel>()

LaunchedEffect(id) {
viewModel.fetchTimeline()
Expand All @@ -47,69 +50,24 @@ fun TimelineView(
val timeline by viewModel.timeline.collectAsState()
val users by viewModel.users.collectAsState()
val posts by viewModel.posts.collectAsState()
val search by viewModel.search.collectAsState()

val search by searchViewModel.search.collectAsState()
val searchUsers by searchViewModel.users.collectAsState()
val searchPosts by searchViewModel.posts.collectAsState()

LazyColumn(
modifier
) {
item {
TopAppBar(
title = {
search?.let { search ->
TextField(
value = search,
onValueChange = viewModel::updateSearch,
placeholder = {
Text(
text = stringResource(id = R.string.timeline_search_field),
color = Color.LightGray
)
},
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Search
),
keyboardActions = KeyboardActions(
onSearch = {
viewModel.viewModelScope.coroutineScope.launch {
viewModel.doSearch()
}
}
)
)
} ?: run {
Text(stringResource(R.string.timeline_title))
}
},
title = { Text(stringResource(R.string.timeline_title)) },
actions = {
if (search != null) {
IconButton(
onClick = { viewModel.updateSearch(null) }
) {
Icon(
painter = painterResource(id = R.drawable.ic_baseline_close_24),
contentDescription = stringResource(id = R.string.timeline_search_cancel)
)
}
} else {
IconButton(
onClick = { navigate("timelines/compose") }
) {
Icon(
painter = painterResource(id = R.drawable.ic_baseline_create_24),
contentDescription = stringResource(id = R.string.timeline_compose_title)
)
}
}
IconButton(
onClick = {
viewModel.viewModelScope.coroutineScope.launch {
viewModel.doSearch()
}
}
onClick = { navigate("timelines/compose") }
) {
Icon(
painter = painterResource(id = R.drawable.ic_baseline_search_24),
contentDescription = stringResource(id = R.string.timeline_search_title)
painter = painterResource(id = R.drawable.ic_baseline_create_24),
contentDescription = stringResource(id = R.string.timeline_compose_title)
)
}
}
Expand All @@ -118,7 +76,25 @@ fun TimelineView(
item {
Spacer(modifier = Modifier.height(12.dp))
}
items(users ?: listOf()) {
item {
TextField(
value = search,
onValueChange = searchViewModel::updateSearch,
placeholder = {
Text(
text = stringResource(id = R.string.timeline_search_field),
color = Color.LightGray
)
},
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Search
),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
)
}
items(searchUsers?.takeIf { it.isNotEmpty() } ?: users ?: listOf()) {
UserCard(
user = it,
viewedBy = viewedBy,
Expand Down Expand Up @@ -148,7 +124,7 @@ fun TimelineView(
}
)
}
items(posts ?: listOf()) {
items(searchPosts?.takeIf { it.isNotEmpty() } ?: posts ?: listOf()) {
PostCard(
post = it,
navigate = navigate,
Expand Down
10 changes: 5 additions & 5 deletions ios/Extopy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
6A996E58291EB51300F36B8C /* TimelineSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineSheet.swift; sourceTree = "<group>"; };
6AB01ADD2B3602C5001AF7FF /* TokenRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenRepository.swift; sourceTree = "<group>"; };
6AB01AE32B3605A1001AF7FF /* AuthView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthView.swift; sourceTree = "<group>"; };
6AC04BB02B35A804009938B9 /* KoinExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KoinExtension.swift; sourceTree = SOURCE_ROOT; };
6AC04BB02B35A804009938B9 /* KoinExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = KoinExtension.swift; path = Extopy/DI/KoinExtension.swift; sourceTree = SOURCE_ROOT; };
6AC04BB22B35A897009938B9 /* InjectStateViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectStateViewModel.swift; sourceTree = "<group>"; };
6AC04BB62B35A983009938B9 /* KMMViewModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMMViewModelExtension.swift; sourceTree = "<group>"; };
6AC04BBF2B35F46F009938B9 /* UserHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserHeaderView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -493,7 +493,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
KOTLIN_FRAMEWORK_BUILD_TYPE = Debug;
LD_RUNPATH_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 0.1.0;
MARKETING_VERSION = 0.1.1;
OTHER_LDFLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = me.nathanfallet.Extopy;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -528,7 +528,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
KOTLIN_FRAMEWORK_BUILD_TYPE = Release;
LD_RUNPATH_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 0.1.0;
MARKETING_VERSION = 0.1.1;
OTHER_LDFLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = me.nathanfallet.Extopy;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -637,7 +637,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
KOTLIN_FRAMEWORK_BUILD_TYPE = Debug;
LD_RUNPATH_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 0.1.0;
MARKETING_VERSION = 0.1.1;
OTHER_LDFLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = me.nathanfallet.Extopy.dev;
PRODUCT_NAME = "$(TARGET_NAME) Dev";
Expand Down Expand Up @@ -739,7 +739,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
KOTLIN_FRAMEWORK_BUILD_TYPE = Release;
LD_RUNPATH_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 0.1.0;
MARKETING_VERSION = 0.1.1;
OTHER_LDFLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = me.nathanfallet.Extopy.dev;
PRODUCT_NAME = "$(TARGET_NAME) Dev";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extension KoinApplication {

private static let keyPaths: [PartialKeyPath<Koin>] = [
\.rootViewModel,
\.searchViewModel,
\.authViewModel
]

Expand Down
22 changes: 4 additions & 18 deletions ios/Extopy/Features/Timelines/TimelineView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,17 @@ import KMPNativeCoroutinesAsync
struct TimelineView: View {

@StateViewModel var viewModel: TimelineViewModel
@InjectStateViewModel var searchViewModel: SearchViewModel

@State var sheet: TimelineSheet?

let viewedBy: Extopy_commonsUser

var body: some View {
ZStack {
/*
NavigationLink(
destination: TimelineView(viewModel: TimelineViewModel(
type: .search(search: viewModel.searchText)
)),
isActive: $viewModel.searchShown
) {
EmptyView()
}
*/
ScrollView {
LazyVStack(spacing: 8) {
ForEach(viewModel.users ?? [], id: \.namespacedId) { user in
ForEach(searchViewModel.users ?? viewModel.users ?? [], id: \.namespacedId) { user in
NavigationLink(destination: ProfileView(
viewModel: KoinApplication.shared.koin.profileViewModel(id: user.id),
viewedBy: viewedBy
Expand All @@ -56,7 +47,7 @@ struct TimelineView: View {
)
}
}
ForEach(viewModel.posts ?? [], id: \.namespacedId) { post in
ForEach(searchViewModel.posts ?? viewModel.posts ?? [], id: \.namespacedId) { post in
NavigationLink(destination: PostView(
viewModel: KoinApplication.shared.koin.postViewModel(id: post.id),
viewedBy: viewedBy
Expand Down Expand Up @@ -96,12 +87,7 @@ struct TimelineView: View {
}
}
}
/*
.searchable(text: $viewModel.searchText) {
EmptyView()
}
.onSubmit(of: .search, viewModel.submitSearch)
*/
.searchable(text: Binding(get: { searchViewModel.search }, set: searchViewModel.updateSearch))
.sheet(item: $sheet) { sheet in
switch (sheet) {
case .compose(let repliedToId, let repostOfId):
Expand Down
1 change: 1 addition & 0 deletions ios/Extopy/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"timeline_user_title" = "User profile";
"timeline_post_title" = "Post details";
"timeline_search_title" = "Search results";
"timeline_search_field" = "Search…";
"timeline_compose_title" = "Compose a post";
"timeline_compose_reply_title" = "Reply to a post";
"timeline_compose_repost_title" = "Repost a post";
Expand Down
4 changes: 2 additions & 2 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ kotlin {

api("com.rickclephas.kmm:kmm-viewmodel-core:1.0.0-ALPHA-16")
api("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0")
api("me.nathanfallet.usecases:usecases:1.5.5")
api("me.nathanfallet.extopy:extopy-commons:0.1.0")
api("me.nathanfallet.usecases:usecases:1.6.0")
api("me.nathanfallet.extopy:extopy-commons:0.1.1")
}
}
val commonTest by getting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import me.nathanfallet.extopy.viewmodels.auth.AuthViewModel
import me.nathanfallet.extopy.viewmodels.notifications.NotificationsViewModel
import me.nathanfallet.extopy.viewmodels.posts.PostViewModel
import me.nathanfallet.extopy.viewmodels.root.RootViewModel
import me.nathanfallet.extopy.viewmodels.timelines.SearchViewModel
import me.nathanfallet.extopy.viewmodels.timelines.TimelineComposeViewModel
import me.nathanfallet.extopy.viewmodels.timelines.TimelineViewModel
import me.nathanfallet.extopy.viewmodels.users.ProfileViewModel
Expand Down Expand Up @@ -50,13 +51,15 @@ val useCaseModule = module {
single<IFetchTimelinePostsUseCase> { FetchTimelinePostsUseCase(get()) }

// Users
single<IFetchUsersUseCase> { FetchUsersUseCase(get()) }
single<IFetchUserUseCase> { FetchUserUseCase(get(), get()) }
single<IUpdateFollowInUserUseCase> { UpdateFollowInUserUseCase(get(), get()) }
single<IFetchUserPostsUseCase> { FetchUserPostsUseCase(get(), get()) }

// Posts
single<ICreatePostUseCase> { CreatePostUseCase(get(), get()) }
single<IUpdateLikeInPostUseCase> { UpdateLikeInPostUseCase(get(), get()) }
single<IFetchPostsUseCase> { FetchPostsUseCase(get()) }
single<IFetchPostUseCase> { FetchPostUseCase(get(), get()) }
single<IFetchPostRepliesUseCase> { FetchPostRepliesUseCase(get(), get()) }
}
Expand All @@ -66,6 +69,7 @@ val viewModelModule = module {
factory { AuthViewModel(get(), get(), get(), get(), get()) }
factory { TimelineViewModel(it[0], get(), get(), get(), get()) }
factory { TimelineComposeViewModel(it[0], it[1], it[2], get()) }
factory { SearchViewModel(get(), get()) }
factory { PostViewModel(it[0], get(), get(), get()) }
factory { ProfileViewModel(it[0], get(), get(), get(), get()) }
factory { NotificationsViewModel() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ class CreatePostUseCase(
private val postsRepository: IPostsRepository,
) : ICreatePostUseCase {

override suspend fun invoke(input: PostPayload): Post? {
return client.posts.create(input)?.also {
override suspend fun invoke(input: PostPayload): Post? =
client.posts.create(input)?.also {
postsRepository.save(
it,
Clock.System.now().plus(60, DateTimeUnit.SECOND, TimeZone.currentSystemDefault())
)
}
}

}
Loading

0 comments on commit d98ba5b

Please sign in to comment.