Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move search to fab #1138

Merged
merged 11 commits into from
Dec 2, 2023
Prev Previous commit
Next Next commit
refactor: rename host screen to search
  • Loading branch information
Chesire committed Dec 2, 2023
commit 30011a490e91ea453579a6373ea1f9183275398e
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import androidx.compose.ui.test.onChild
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import com.chesire.nekome.app.search.host.ui.HostTags
import com.chesire.nekome.app.search.search.ui.SearchTags

/**
* Method to interact with the [HostRobot].
@@ -27,7 +27,7 @@ class HostRobot(private val composeContentTestRule: ComposeContentTestRule) {
*/
fun searchTerm(term: String) {
composeContentTestRule
.onNodeWithTag(HostTags.Input)
.onNodeWithTag(SearchTags.Input)
.performTextInput(term)
}

@@ -36,7 +36,7 @@ class HostRobot(private val composeContentTestRule: ComposeContentTestRule) {
*/
fun selectAnime() {
composeContentTestRule
.onNodeWithTag(HostTags.Anime)
.onNodeWithTag(SearchTags.Anime)
.performClick()
}

@@ -45,7 +45,7 @@ class HostRobot(private val composeContentTestRule: ComposeContentTestRule) {
*/
fun selectManga() {
composeContentTestRule
.onNodeWithTag(HostTags.Manga)
.onNodeWithTag(SearchTags.Manga)
.performClick()
}

@@ -54,7 +54,7 @@ class HostRobot(private val composeContentTestRule: ComposeContentTestRule) {
*/
fun clickSearch() {
composeContentTestRule
.onNodeWithTag(HostTags.Search)
.onNodeWithTag(SearchTags.Search)
.performClick()
}

@@ -75,7 +75,7 @@ class HostResultRobot(private val composeContentTestRule: ComposeContentTestRule
*/
fun isVisible() {
composeContentTestRule
.onNodeWithTag(HostTags.Root)
.onNodeWithTag(SearchTags.Root)
.assertIsDisplayed()
}

@@ -84,7 +84,7 @@ class HostResultRobot(private val composeContentTestRule: ComposeContentTestRule
*/
fun isEmptySearchError() {
composeContentTestRule
.onNodeWithTag(HostTags.Snackbar)
.onNodeWithTag(SearchTags.Snackbar)
.assertIsDisplayed()
.onChild()
.onChild()
@@ -101,7 +101,7 @@ class HostResultRobot(private val composeContentTestRule: ComposeContentTestRule
*/
fun isGenericError() {
composeContentTestRule
.onNodeWithTag(HostTags.Snackbar)
.onNodeWithTag(SearchTags.Snackbar)
.assertIsDisplayed()
.onChild()
.onChild()
@@ -118,7 +118,7 @@ class HostResultRobot(private val composeContentTestRule: ComposeContentTestRule
*/
fun isNoSeriesFoundError() {
composeContentTestRule
.onNodeWithTag(HostTags.Snackbar)
.onNodeWithTag(SearchTags.Snackbar)
.assertIsDisplayed()
.onChild()
.onChild()
10 changes: 5 additions & 5 deletions app/src/main/java/com/chesire/nekome/ui/Routes.kt
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.composable
import com.chesire.nekome.app.login.credentials.ui.CredentialsScreen
import com.chesire.nekome.app.login.syncing.ui.SyncingScreen
import com.chesire.nekome.app.search.host.ui.HostScreen
import com.chesire.nekome.app.search.search.ui.SearchScreen
import com.chesire.nekome.app.series.collection.ui.CollectionScreen
import com.chesire.nekome.app.series.item.ui.ItemScreen
import com.chesire.nekome.app.settings.config.ui.ConfigScreen
@@ -47,7 +47,7 @@ fun NavGraphBuilder.addSeriesRoutes(navController: NavHostController) {
navController.navigate("${Screen.Item.destination}/$seriesId/$seriesTitle")
},
navigateToSearch = {
navController.navigate(Screen.Host.route)
navController.navigate(Screen.Search.route)
}
)
}
@@ -61,7 +61,7 @@ fun NavGraphBuilder.addSeriesRoutes(navController: NavHostController) {
navController.navigate("${Screen.Item.destination}/$seriesId/$seriesTitle")
},
navigateToSearch = {
navController.navigate(Screen.Host.route)
navController.navigate(Screen.Search.route)
}
)
}
@@ -75,8 +75,8 @@ fun NavGraphBuilder.addSeriesRoutes(navController: NavHostController) {
}

fun NavGraphBuilder.addSearchRoutes() {
composable(Screen.Host.route) {
HostScreen()
composable(Screen.Search.route) {
SearchScreen()
}
}

18 changes: 7 additions & 11 deletions app/src/main/java/com/chesire/nekome/ui/Screen.kt
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ package com.chesire.nekome.ui
import androidx.annotation.StringRes
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CollectionsBookmark
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.VideoLibrary
import androidx.compose.ui.graphics.vector.ImageVector
@@ -23,7 +22,7 @@ sealed class Screen {
return when (route) {
Anime.route,
Manga.route,
Host.route,
Search.route,
Config.route -> true

Credentials.route,
@@ -36,19 +35,16 @@ sealed class Screen {
}
}

object Credentials : Screen() {
data object Credentials : Screen() {
override val route = "credentials"
}

object Syncing : Screen() {
data object Syncing : Screen() {
override val route = "syncing"
}

object Host : Screen(), BottomNavTarget {
override val route = "host"
override val title = StringResource.nav_search
override val icon = Icons.Default.Search
override val tag = MainActivityTags.Search
data object Search : Screen() {
override val route = "search"
}

object Anime : Screen(), BottomNavTarget {
@@ -81,7 +77,7 @@ sealed class Screen {
override val tag = MainActivityTags.Manga
}

object Item : Screen() {
data object Item : Screen() {
override val route = "item/{seriesId}/{seriesTitle}"
const val destination = "item"

@@ -98,7 +94,7 @@ sealed class Screen {
override val tag = MainActivityTags.Settings
}

object OSS : Screen() {
data object OSS : Screen() {
override val route = "oss"
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.chesire.nekome.app.search.search.core

import com.chesire.nekome.app.search.search.core.model.SearchGroup
import com.chesire.nekome.app.search.search.data.SearchPreferences
import javax.inject.Inject

class RememberSearchGroupUseCase @Inject constructor(
private val searchPreferences: SearchPreferences
) {

operator fun invoke(newSearchGroup: SearchGroup) {
searchPreferences.lastSearchGroup = newSearchGroup.name
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chesire.nekome.app.search.host.core
package com.chesire.nekome.app.search.search.core

import com.chesire.nekome.datasource.series.SeriesRepository
import javax.inject.Inject
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package com.chesire.nekome.app.search.host.core
package com.chesire.nekome.app.search.search.core

import com.chesire.nekome.app.search.host.core.model.SearchGroup
import com.chesire.nekome.app.search.host.data.HostPreferences
import com.chesire.nekome.app.search.search.core.model.SearchGroup
import com.chesire.nekome.app.search.search.data.SearchPreferences
import javax.inject.Inject
import timber.log.Timber

class HostInitializeUseCase @Inject constructor(private val hostPreferences: HostPreferences) {
class SearchInitializeUseCase @Inject constructor(
private val searchPreferences: SearchPreferences
) {

operator fun invoke() = InitializeArgs(initialGroup = retrieveInitialGroup())

private fun retrieveInitialGroup(): SearchGroup {
val lastGroup = hostPreferences.lastSearchGroup
val lastGroup = searchPreferences.lastSearchGroup

return if (lastGroup.isBlank()) {
SearchGroup.Anime
} else {
try {
SearchGroup.valueOf(hostPreferences.lastSearchGroup)
SearchGroup.valueOf(searchPreferences.lastSearchGroup)
} catch (ex: IllegalArgumentException) {
Timber.w("Failed to parse the search group - [$lastGroup]")
SearchGroup.Anime
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.chesire.nekome.app.search.host.core
package com.chesire.nekome.app.search.search.core

import com.chesire.nekome.app.search.host.core.model.SearchGroup
import com.chesire.nekome.app.search.search.core.model.SearchGroup
import com.chesire.nekome.datasource.search.SearchDomain
import com.chesire.nekome.datasource.search.remote.SearchApi
import com.github.michaelbull.result.Err
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chesire.nekome.app.search.host.core
package com.chesire.nekome.app.search.search.core

import com.chesire.nekome.core.flags.SeriesType
import com.chesire.nekome.core.preferences.ApplicationPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.chesire.nekome.app.search.search.core.model

enum class SearchGroup {
Anime,
Manga
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chesire.nekome.app.search.host.data
package com.chesire.nekome.app.search.search.data

import android.content.SharedPreferences
import androidx.core.content.edit
@@ -7,7 +7,7 @@ import javax.inject.Inject
/**
* Wrapper around [SharedPreferences] to store settings or items related to Search.
*/
data class HostPreferences @Inject constructor(private val sharedPreferences: SharedPreferences) {
data class SearchPreferences @Inject constructor(private val sharedPreferences: SharedPreferences) {

var lastSearchGroup: String
get() = sharedPreferences.getString(LAST_SEARCH_GROUP, "") ?: ""
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chesire.nekome.app.search.host.ui
package com.chesire.nekome.app.search.search.ui

import com.chesire.nekome.core.models.ImageModel
import com.chesire.nekome.core.preferences.SeriesPreferences
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:OptIn(ExperimentalComposeUiApi::class, ExperimentalMaterial3Api::class)

package com.chesire.nekome.app.search.host.ui
package com.chesire.nekome.app.search.search.ui

import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
@@ -65,13 +65,13 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import coil.compose.AsyncImage
import com.chesire.nekome.app.search.host.core.model.SearchGroup
import com.chesire.nekome.app.search.search.core.model.SearchGroup
import com.chesire.nekome.core.compose.theme.NekomeTheme
import com.chesire.nekome.core.flags.SeriesType
import com.chesire.nekome.resources.StringResource

@Composable
fun HostScreen(viewModel: HostViewModel = hiltViewModel()) {
fun SearchScreen(viewModel: SearchViewModel = hiltViewModel()) {
val state = viewModel.uiState.collectAsState()

Render(
@@ -99,10 +99,10 @@ private fun Render(
snackbarHost = {
SnackbarHost(
hostState = snackbarHostState,
modifier = Modifier.semantics { testTag = HostTags.Snackbar }
modifier = Modifier.semantics { testTag = SearchTags.Snackbar }
)
},
modifier = Modifier.semantics { testTag = HostTags.Root }
modifier = Modifier.semantics { testTag = SearchTags.Root }
) { paddingValues ->
Column(
modifier = Modifier
@@ -165,7 +165,7 @@ private fun InputText(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.semantics { testTag = HostTags.Input }
.semantics { testTag = SearchTags.Input }
)
}

@@ -184,7 +184,7 @@ private fun SearchGroup(
label = { Text(text = stringResource(id = StringResource.search_anime)) },
modifier = Modifier
.padding(8.dp, 0.dp, 8.dp, 8.dp)
.semantics { testTag = HostTags.Anime },
.semantics { testTag = SearchTags.Anime },
colors = FilterChipDefaults.filterChipColors(
selectedLabelColor = MaterialTheme.colorScheme.primary
),
@@ -201,7 +201,7 @@ private fun SearchGroup(
label = { Text(text = stringResource(id = StringResource.search_manga)) },
modifier = Modifier
.padding(8.dp, 0.dp, 8.dp, 8.dp)
.semantics { testTag = HostTags.Manga },
.semantics { testTag = SearchTags.Manga },
colors = FilterChipDefaults.filterChipColors(
selectedLabelColor = MaterialTheme.colorScheme.primary
),
@@ -228,7 +228,7 @@ private fun SearchButton(isSearching: Boolean, onSearchPressed: () -> Unit) {
},
modifier = Modifier
.padding(16.dp)
.semantics { testTag = HostTags.Search }
.semantics { testTag = SearchTags.Search }
) {
Text(text = stringResource(id = StringResource.search_search))
}
@@ -399,11 +399,11 @@ private fun PopulatedPreview() {
}
}

object HostTags {
const val Root = "HostRoot"
const val Input = "HostInput"
const val Anime = "HostAnime"
const val Manga = "HostManga"
const val Search = "HostSearch"
const val Snackbar = "HostSnackbar"
object SearchTags {
const val Root = "SearchRoot"
const val Input = "SearchInput"
const val Anime = "SearchAnime"
const val Manga = "SearchManga"
const val Search = "SearchSearch"
const val Snackbar = "SearchSnackbar"
}
Loading