Skip to content

Commit

Permalink
Finished implementing new opponent selection dialog. Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
acristescu committed Oct 29, 2024
1 parent 3a06039 commit e5a09f5
Show file tree
Hide file tree
Showing 26 changed files with 70 additions and 722 deletions.
26 changes: 13 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ android {

dependencies {
def koin_version = '3.5.0'
def play_services_version = '21.1.1'
def play_services_version = '21.2.0'
def accompanist_version = '0.34.0'
def room_version = '2.5.2'
def firebase_version = '33.0.0'
def compose_version = "1.6.7"
def work_manager_version = "2.9.0"
def work_manager_version = "2.9.1"
// def composeBom = platform('androidx.compose:compose-bom:2023.01.00')

implementation fileTree(dir: 'libs', include: ['*.jar'])
Expand All @@ -112,7 +112,7 @@ dependencies {
implementation "com.google.accompanist:accompanist-placeholder-material:$accompanist_version"
implementation "com.google.accompanist:accompanist-pager-indicators:$accompanist_version"

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat:1.7.0'

implementation platform("com.google.firebase:firebase-bom:$firebase_version")
// retrofit
Expand All @@ -122,17 +122,17 @@ dependencies {

implementation "com.google.android.gms:play-services-auth:$play_services_version"
implementation "org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.7"
implementation "androidx.compose.material3:material3:1.2.1"
implementation "androidx.compose.material3:material3:1.3.0"

implementation "io.coil-kt:coil-compose:2.4.0"
implementation 'com.squareup.okhttp3:logging-interceptor:4.11.0'
implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1'

implementation 'com.squareup.moshi:moshi-kotlin:1.15.0'
implementation 'com.squareup.moshi:moshi-kotlin:1.15.1'
implementation 'com.squareup.moshi:moshi-adapters:1.15.0'

implementation "androidx.navigation:navigation-fragment-ktx:2.7.7"
implementation "androidx.navigation:navigation-ui-ktx:2.7.7"
implementation "androidx.navigation:navigation-fragment-ktx:2.8.3"
implementation "androidx.navigation:navigation-ui-ktx:2.8.3"
implementation "androidx.core:core-ktx:1.13.1"

implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
Expand All @@ -157,7 +157,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation "androidx.activity:activity-compose:1.9.0"
implementation "androidx.activity:activity-compose:1.9.3"

implementation 'me.zhanghai.android.materialprogressbar:library:1.6.1'

Expand All @@ -176,32 +176,32 @@ dependencies {
implementation 'org.jsoup:jsoup:1.16.1'

implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.6'
ksp 'com.github.bumptech.glide:compiler:4.12.0'

implementation "io.insert-koin:koin-android:$koin_version"
implementation "io.insert-koin:koin-androidx-compose:$koin_version"

implementation "com.android.billingclient:billing-ktx:7.0.0"
implementation "com.android.billingclient:billing-ktx:7.1.1"

implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
implementation "androidx.room:room-ktx:$room_version"

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.2'

implementation 'com.github.cpiz:BubbleView:1.0.3'

ksp "androidx.room:room-compiler:$room_version"

implementation 'androidx.test.espresso:espresso-idling-resource:3.5.1'
implementation 'androidx.test.espresso:espresso-idling-resource:3.6.1'

implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

testImplementation 'com.nhaarman:mockito-kotlin-kt1.1:1.6.0'
testImplementation 'junit:junit:4.13.2'
testImplementation "io.insert-koin:koin-test-junit4:$koin_version"
testImplementation "org.mockito:mockito-inline:4.8.0"
testImplementation "org.mockito:mockito-inline:5.2.0"
testImplementation "androidx.arch.core:core-testing:2.2.0"
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3'
testImplementation 'app.cash.turbine:turbine:1.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ interface OGSRestAPI {
fun challengePlayer(@Path("id") id: Long, @Body request: OGSChallengeRequest): Completable

@GET("/api/v1/ui/omniSearch")
fun omniSearch(@Query("q") q: String): Single<OmniSearchResponse>
suspend fun omniSearch(@Query("q") q: String): OmniSearchResponse

@Headers("x-godojo-auth-token: foofer")
@GET("/oje/positions?mode=0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ class OGSRestService(
restApi.fetchPlayerFinishedAfterGames(userSessionRepository.userId!!, 10, afterDate.microsToISODateTime(), 1)
}.map { it.results }

fun searchPlayers(query: String): Single<List<OGSPlayer>> =
restApi.omniSearch(query).map { it.players }
suspend fun searchPlayers(query: String): List<OGSPlayer> =
restApi.omniSearch(query).players


fun getJosekiPositions(id: Long?): Single<List<JosekiPosition>> =
restApi.getJosekiPositions(id?.toString() ?: "root")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PlayersRepository(
.getRecentOpponents(userSessionRepository.userId)
.distinctBy { it.id }

fun searchPlayers(query: String): Single<List<Player>> {
return restService.searchPlayers(query).map { it.map(Player.Companion::fromOGSPlayer) }
suspend fun searchPlayers(query: String): List<Player> {
return restService.searchPlayers(query).map (Player.Companion::fromOGSPlayer)
}
}
14 changes: 0 additions & 14 deletions app/src/main/java/io/zenandroid/onlinego/di/Modules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ import io.zenandroid.onlinego.ui.screens.localai.middlewares.UserMoveMiddleware
import io.zenandroid.onlinego.ui.screens.mygames.MyGamesViewModel
import io.zenandroid.onlinego.ui.screens.newchallenge.NewChallengeViewModel
import io.zenandroid.onlinego.ui.screens.newchallenge.SelectOpponentViewModel
import io.zenandroid.onlinego.ui.screens.newchallenge.selectopponent.searchplayer.SearchMiddleware
import io.zenandroid.onlinego.ui.screens.newchallenge.selectopponent.searchplayer.SearchPlayerReducer
import io.zenandroid.onlinego.ui.screens.newchallenge.selectopponent.searchplayer.SearchPlayerState
import io.zenandroid.onlinego.ui.screens.newchallenge.selectopponent.searchplayer.SearchPlayerViewModel
import io.zenandroid.onlinego.ui.screens.onboarding.OnboardingViewModel
import io.zenandroid.onlinego.ui.screens.puzzle.directory.PuzzleDirectoryViewModel
import io.zenandroid.onlinego.ui.screens.puzzle.tsumego.TsumegoViewModel
Expand Down Expand Up @@ -160,16 +156,6 @@ private val useCasesModule = module {
}

private val viewModelsModule = module {
viewModel {
SearchPlayerViewModel(
Store(
SearchPlayerReducer(),
listOf(SearchMiddleware(get())),
SearchPlayerState()
)
)
}

viewModel {
JosekiExplorerViewModel(
Store(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,7 @@ class NewChallengeBottomSheet : BottomSheetDialogFragment() {
NewChallengeBottomSheetContent(
state = state,
onEvent = {
// if (it is NewChallengeViewModel.Event.OpponentClicked) {
// fragmentManager?.let {
// SelectOpponentDialog().apply {
// setTargetFragment(this@NewChallengeBottomSheet, 1)
// show(it, "SELECT_OPPONENT")
// }
// }
// } else {
viewModel.onEvent(it)
// }
}
)
if(state.selectOpponentDialogShowing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import coil.request.ImageRequest
import com.google.accompanist.pager.pagerTabIndicatorOffset
import io.zenandroid.onlinego.R
import io.zenandroid.onlinego.data.model.local.Player
import io.zenandroid.onlinego.ui.composables.SearchTextField
import io.zenandroid.onlinego.utils.PreviewBackground
import io.zenandroid.onlinego.utils.egfToRank
import io.zenandroid.onlinego.utils.formatRank
Expand Down Expand Up @@ -158,7 +159,11 @@ private fun SelectOpponentDialogContent(
state = state,
onOpponentSelected = { onEvent(Event.OpponentSelected(it)) }
)
2 -> Search()
2 -> Search(
state = state,
onOpponentSelected = { onEvent(Event.OpponentSelected(it)) },
onSearchTermChanged = { onEvent(Event.SearchTermChanged(it)) },
)
}
}
}
Expand Down Expand Up @@ -266,14 +271,31 @@ private fun RecentList(state: SelectOpponentState, onOpponentSelected: (Player)
}

@Composable
private fun Search() {
private fun Search(state: SelectOpponentState, onOpponentSelected: (Player) -> Unit, onSearchTermChanged: (String) -> Unit) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.fillMaxSize()
.padding(top = 16.dp)
.padding(16.dp)
) {
Text(text = "Search")
SearchTextField(
value = state.searchTerm,
onValueChange = onSearchTermChanged,
hint = "Search by username",
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
)
LazyColumn {
items(items = state.searchResults) {
OpponentItem(
opponent = it,
modifier = Modifier
.clickable { onOpponentSelected(it) }
.padding(vertical = 8.dp)
)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import io.zenandroid.onlinego.data.model.local.Player
import io.zenandroid.onlinego.data.repositories.BotsRepository
import io.zenandroid.onlinego.data.repositories.PlayersRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
Expand All @@ -22,6 +24,8 @@ class SelectOpponentViewModel(
.sortedBy { it.rating }
))

private var currentSearch: Job? = null

init {
viewModelScope.launch {
val recentOpponents = playersRepository.getRecentOpponents()
Expand All @@ -42,6 +46,20 @@ class SelectOpponentViewModel(
it.copy(selectedTab = event.tab)
}
}

is Event.SearchTermChanged -> {
state.update {
it.copy(searchTerm = event.query)
}
currentSearch?.cancel()
currentSearch = viewModelScope.launch {
delay(100)
val searchResults = playersRepository.searchPlayers(event.query)
state.update {
it.copy(searchResults = searchResults )
}
}
}
}
}
}
Expand All @@ -51,6 +69,8 @@ data class SelectOpponentState(
val selectedTab: Tab = Tab.BOT,
val bots: List<Player> = emptyList(),
val recentOpponents: List<Player> = emptyList(),
val searchTerm: String = "",
val searchResults: List<Player> = emptyList(),
)

enum class Tab {
Expand All @@ -62,4 +82,5 @@ enum class Tab {
sealed interface Event {
data class TabSelected(val tab: Tab) : Event
data class OpponentSelected(val opponent: Player) : Event
data class SearchTermChanged(val query: String) : Event
}

This file was deleted.

Loading

0 comments on commit e5a09f5

Please sign in to comment.