mirror of
https://github.com/owenlejeune/TVTime.git
synced 2025-11-14 07:42:43 -05:00
some searching refactoring
This commit is contained in:
@@ -352,7 +352,8 @@ class MainActivity : MonetCompatActivity() {
|
||||
const val ID_KEY = "id_key"
|
||||
const val TYPE_KEY = "type_key"
|
||||
const val SETTINGS_KEY = "settings_key"
|
||||
const val SEARCH_KEY = "search_key"
|
||||
const val SEARCH_ID_KEY = "search_key"
|
||||
const val SEARCH_TITLE_KEY = "search_title_key"
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -360,6 +361,7 @@ class MainActivity : MonetCompatActivity() {
|
||||
startDestination: String = MainNavItem.MainView.route,
|
||||
mainNavStartRoute: String = MainNavItem.Items[0].route,
|
||||
appNavController: NavHostController,
|
||||
preferences: AppPreferences = get(AppPreferences::class.java)
|
||||
) {
|
||||
NavHost(navController = appNavController, startDestination = startDestination) {
|
||||
composable(MainNavItem.MainView.route) {
|
||||
@@ -404,12 +406,26 @@ class MainActivity : MonetCompatActivity() {
|
||||
SettingsTab(appNavController = appNavController, activity = this@MainActivity)
|
||||
}
|
||||
composable(
|
||||
route = MainNavItem.SearchView.route.plus("/{${NavConstants.SEARCH_KEY}}"),
|
||||
route = MainNavItem.SearchView.route.plus("/{${NavConstants.SEARCH_ID_KEY}}/{${NavConstants.SEARCH_TITLE_KEY}}"),
|
||||
arguments = listOf(
|
||||
navArgument(NavConstants.SEARCH_KEY) { type = NavType.IntType }
|
||||
navArgument(NavConstants.SEARCH_ID_KEY) { type = NavType.IntType },
|
||||
navArgument(NavConstants.SEARCH_TITLE_KEY) { type = NavType.StringType }
|
||||
)
|
||||
) {
|
||||
SearchScreen(appNavController = appNavController)
|
||||
it.arguments?.let { arguments ->
|
||||
val title = arguments.getString(NavConstants.SEARCH_TITLE_KEY) ?: ""
|
||||
val type = if (preferences.multiSearch) {
|
||||
MediaViewType.MIXED
|
||||
} else {
|
||||
MediaViewType[arguments.getInt(NavConstants.SEARCH_ID_KEY)]
|
||||
}
|
||||
|
||||
SearchScreen(
|
||||
appNavController = appNavController,
|
||||
title = title,
|
||||
mediaViewType = type
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.google.gson.Gson
|
||||
import com.kieronquinn.monetcompat.core.MonetCompat
|
||||
import com.owenlejeune.tvtime.BuildConfig
|
||||
import com.owenlejeune.tvtime.utils.SessionManager
|
||||
import java.util.function.BiPredicate
|
||||
|
||||
class AppPreferences(context: Context) {
|
||||
|
||||
@@ -27,6 +26,7 @@ class AppPreferences(context: Context) {
|
||||
private val SHOW_BACKDROP_GALLERY = "show_backdrop_gallery"
|
||||
private val USE_WALLPAPER_COLORS = "use_wallpaper_colors"
|
||||
private val DARK_THEME = "dark_theme"
|
||||
private val MULTI_SEARCH = "multi_search"
|
||||
}
|
||||
|
||||
private val preferences: SharedPreferences = context.getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE)
|
||||
@@ -36,12 +36,15 @@ class AppPreferences(context: Context) {
|
||||
get() = preferences.getBoolean(PERSISTENT_SEARCH, true)
|
||||
set(value) { preferences.put(PERSISTENT_SEARCH, value) }
|
||||
|
||||
var multiSearch: Boolean
|
||||
get() = preferences.getBoolean(MULTI_SEARCH, false)
|
||||
set(value) { preferences.put(MULTI_SEARCH, value) }
|
||||
|
||||
/******* Design Preferences ********/
|
||||
var useWallpaperColors: Boolean
|
||||
get() = preferences.getBoolean(USE_WALLPAPER_COLORS, true)
|
||||
set(value) { preferences.put(USE_WALLPAPER_COLORS, value) }
|
||||
|
||||
|
||||
/******* Design Preferences ********/
|
||||
var darkTheme: Int
|
||||
get() = preferences.getInt(DARK_THEME, 0)
|
||||
set(value) { preferences.put(DARK_THEME, value) }
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.owenlejeune.tvtime.ui.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.material3.*
|
||||
@@ -10,10 +9,6 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.role
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
@@ -47,7 +42,7 @@ fun SwitchPreference(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.padding(start = 8.dp, top = 8.dp, bottom = 8.dp, end = 8.dp)
|
||||
.padding(all = 8.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@@ -61,6 +56,8 @@ fun SwitchPreference(
|
||||
Text(text = subtitleText, style = MaterialTheme.typography.bodyMedium, color = subtitleColor)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(32.dp))
|
||||
|
||||
CustomSwitch(
|
||||
modifier = Modifier
|
||||
@@ -127,12 +124,6 @@ fun RadioButtonPreference(
|
||||
disabledTextColor: Color = MaterialTheme.colorScheme.outline
|
||||
) {
|
||||
Row(
|
||||
// modifier = modifier
|
||||
// .clickable(
|
||||
// enabled = enabled,
|
||||
// onClick = onClick
|
||||
// )
|
||||
// .semantics { role = Role.RadioButton }
|
||||
modifier = modifier
|
||||
.padding(all = 8.dp)
|
||||
.selectable(
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.owenlejeune.tvtime.ui.components
|
||||
|
||||
import android.content.res.Configuration.UI_MODE_NIGHT_YES
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
@@ -20,7 +18,10 @@ import androidx.compose.material.Card
|
||||
import androidx.compose.material.OutlinedTextField
|
||||
import androidx.compose.material.TextFieldDefaults
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.*
|
||||
import androidx.compose.material.icons.filled.Error
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material.icons.filled.Visibility
|
||||
import androidx.compose.material.icons.filled.VisibilityOff
|
||||
import androidx.compose.material.icons.outlined.ArrowDropDown
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
@@ -55,7 +56,6 @@ import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextDecoration
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.*
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.compose.ui.window.Dialog
|
||||
@@ -65,13 +65,11 @@ import androidx.navigation.NavHostController
|
||||
import coil.compose.AsyncImage
|
||||
import coil.compose.rememberAsyncImagePainter
|
||||
import com.google.accompanist.flowlayout.FlowRow
|
||||
import com.kieronquinn.monetcompat.core.MonetCompat
|
||||
import com.owenlejeune.tvtime.R
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.AuthorDetails
|
||||
import com.owenlejeune.tvtime.preferences.AppPreferences
|
||||
import com.owenlejeune.tvtime.ui.navigation.MainNavItem
|
||||
import com.owenlejeune.tvtime.ui.screens.main.MediaViewType
|
||||
import com.owenlejeune.tvtime.ui.theme.RatingSelected
|
||||
import com.owenlejeune.tvtime.utils.TmdbUtils
|
||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer
|
||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener
|
||||
@@ -82,7 +80,6 @@ import org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor
|
||||
import org.intellij.markdown.html.HtmlGenerator
|
||||
import org.intellij.markdown.parser.MarkdownParser
|
||||
import org.koin.java.KoinJavaComponent
|
||||
import kotlin.math.exp
|
||||
|
||||
@Composable
|
||||
fun TopLevelSwitch(
|
||||
@@ -212,7 +209,7 @@ fun SearchView(
|
||||
fab: MutableState<@Composable () -> Unit>,
|
||||
preferences: AppPreferences = KoinJavaComponent.get(AppPreferences::class.java)
|
||||
) {
|
||||
val route = "${MainNavItem.SearchView.route}/${mediaType.ordinal}"
|
||||
val route = "${MainNavItem.SearchView.route}/${mediaType.ordinal}/$title"
|
||||
if (preferences.showSearchBar) {
|
||||
SearchBar(
|
||||
placeholder = title
|
||||
|
||||
@@ -1,33 +1,62 @@
|
||||
package com.owenlejeune.tvtime.ui.screens
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.navigation.NavHostController
|
||||
import com.owenlejeune.tvtime.R
|
||||
import com.owenlejeune.tvtime.ui.screens.main.MediaViewType
|
||||
|
||||
@Composable
|
||||
fun SearchScreen(
|
||||
appNavController: NavHostController
|
||||
appNavController: NavHostController,
|
||||
title: String,
|
||||
mediaViewType: MediaViewType
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.clickable(
|
||||
onClick = {
|
||||
appNavController.popBackStack()
|
||||
}
|
||||
)
|
||||
.fillMaxSize()
|
||||
.background(color = MaterialTheme.colorScheme.background)
|
||||
) {
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
Text(
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||
text = "Search"
|
||||
var searchValue by remember { mutableStateOf("") }
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
|
||||
SmallTopAppBar(
|
||||
modifier = Modifier,
|
||||
title = {
|
||||
TextField(
|
||||
value = searchValue,
|
||||
onValueChange = { searchValue = it },
|
||||
placeholder = { Text(text = stringResource(id = R.string.search_placeholder, title)) },
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
focusedIndicatorColor = MaterialTheme.colorScheme.surface,
|
||||
unfocusedIndicatorColor = MaterialTheme.colorScheme.surface
|
||||
),
|
||||
modifier = Modifier
|
||||
.focusRequester(focusRequester)
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(onClick = { appNavController.popBackStack() }) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.content_description_back_button)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
LaunchedEffect(key1 = "") {
|
||||
focusRequester.requestFocus()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,5 +8,12 @@ enum class MediaViewType {
|
||||
@SerializedName("tv")
|
||||
TV,
|
||||
PERSON,
|
||||
EPISODE
|
||||
EPISODE,
|
||||
MIXED;
|
||||
|
||||
companion object {
|
||||
operator fun get(oridinal: Int): MediaViewType {
|
||||
return values()[oridinal]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,9 @@
|
||||
package com.owenlejeune.tvtime.ui.screens.main
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavHostController
|
||||
import com.owenlejeune.tvtime.R
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.PeopleService
|
||||
@@ -38,13 +33,6 @@ fun PeopleTab(
|
||||
fab = fab
|
||||
)
|
||||
|
||||
Text(
|
||||
modifier = Modifier.padding(start = 16.dp),
|
||||
text = stringResource(id = R.string.nav_popular_people_title),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
style = MaterialTheme.typography.headlineLarge
|
||||
)
|
||||
|
||||
PeoplePosterGrid(
|
||||
fetchPeople = { peopleList ->
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
|
||||
@@ -6,17 +6,13 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.compose.animation.rememberSplineBasedDecay
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.material.IconButton
|
||||
import androidx.compose.material.TextButton
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.*
|
||||
import androidx.compose.material.icons.outlined.DarkMode
|
||||
import androidx.compose.material.icons.outlined.LightMode
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -197,6 +193,17 @@ private fun SearchPreferences(
|
||||
preferences.showSearchBar = isChecked
|
||||
}
|
||||
)
|
||||
|
||||
val multiSearch = remember { mutableStateOf(preferences.multiSearch) }
|
||||
SwitchPreference(
|
||||
titleText = "Multi Search",
|
||||
subtitleText = "Search across movies, TV, and people at the same time",
|
||||
checkState = multiSearch.value,
|
||||
onCheckedChange = { isChecked ->
|
||||
multiSearch.value = isChecked
|
||||
preferences.multiSearch = isChecked
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
Reference in New Issue
Block a user