From b1ff0921c38180c11dadeb6e595a6face485c6a9 Mon Sep 17 00:00:00 2001 From: Arty Bishop Date: Sun, 5 Feb 2023 11:39:32 +0000 Subject: [PATCH] Switched to using Material3 components --- app/build.gradle | 29 ++- .../look4sat/presentation/MainActivity.kt | 25 ++- .../look4sat/presentation/MainTheme.kt | 17 +- .../presentation/aboutScreen/AboutFragment.kt | 165 ----------------- .../presentation/aboutScreen/AboutScreen.kt | 157 ++++++++++++++++ .../presentation/bottomNav/BottomNavBar.kt | 6 +- .../bottomNav/BottomNavScreens.kt | 40 +---- .../entriesScreen/EntriesFragmentCompose.kt | 169 ------------------ .../entriesScreen/EntriesScreen.kt | 145 +++++++++++++++ .../look4sat/presentation/theme/Color.kt | 12 -- .../look4sat/presentation/theme/Shape.kt | 11 -- .../look4sat/presentation/theme/Theme.kt | 37 ---- .../look4sat/presentation/theme/Type.kt | 23 --- app/src/main/res/values/styles.xml | 12 +- build.gradle | 9 +- 15 files changed, 348 insertions(+), 509 deletions(-) delete mode 100644 app/src/main/java/com/rtbishop/look4sat/presentation/aboutScreen/AboutFragment.kt create mode 100644 app/src/main/java/com/rtbishop/look4sat/presentation/aboutScreen/AboutScreen.kt delete mode 100644 app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesFragmentCompose.kt create mode 100644 app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesScreen.kt delete mode 100644 app/src/main/java/com/rtbishop/look4sat/presentation/theme/Color.kt delete mode 100644 app/src/main/java/com/rtbishop/look4sat/presentation/theme/Shape.kt delete mode 100644 app/src/main/java/com/rtbishop/look4sat/presentation/theme/Theme.kt delete mode 100644 app/src/main/java/com/rtbishop/look4sat/presentation/theme/Type.kt diff --git a/app/build.gradle b/app/build.gradle index d3e0c663..beb16d28 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -84,39 +84,32 @@ dependencies { implementation "com.squareup.okhttp3:okhttp:$okhttp_version" implementation "org.osmdroid:osmdroid-android:$osmdroid_version" - implementation "androidx.compose.ui:ui:$compose_version" - implementation "androidx.compose.ui:ui-tooling:$compose_version" + implementation "androidx.activity:activity-compose:$activity_compose_version" + implementation "androidx.compose.animation:animation:$compose_version" + implementation "androidx.compose.compiler:compiler:$compose_compiler_version" + implementation "androidx.compose.material3:material3:$material3_version" implementation "androidx.compose.runtime:runtime:$compose_version" implementation "androidx.compose.runtime:runtime-livedata:$compose_version" - implementation "androidx.compose.compiler:compiler:$compose_compiler_version" - implementation "androidx.compose.animation:animation:$compose_version" - implementation "androidx.compose.foundation:foundation:$compose_foundation_version" - implementation "androidx.navigation:navigation-compose:$navigation_version" - implementation "androidx.activity:activity-compose:$activity_compose_version" + implementation "androidx.compose.ui:ui:$compose_version" + implementation "androidx.compose.ui:ui-tooling:$compose_version" + implementation "androidx.hilt:hilt-navigation-compose:$hilt_compose_version" implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version" - implementation "androidx.compose.material:material:$compose_material_version" - implementation "androidx.compose.material:material-icons-extended:$compose_material_version" - implementation "androidx.compose.material3:material3:$material3_version" - implementation "androidx.compose.material3:material3-window-size-class:$material3_version" - implementation "com.google.android.material:compose-theme-adapter:$material_adapter_version" + implementation "androidx.navigation:navigation-compose:$navigation_version" debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version" - debugImplementation "androidx.fragment:fragment-testing:$fragment_test_version" debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version" testImplementation "junit:junit:$junit_version" testImplementation "org.mockito:mockito-core:$mockito_version" - testImplementation "org.robolectric:robolectric:$robolectric_version" testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_test_version" + androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" androidTestImplementation "androidx.test:core:$androidx_test_version" - androidTestImplementation "androidx.test:runner:$androidx_test_version" androidTestImplementation "androidx.test:rules:$androidx_test_version" + androidTestImplementation "androidx.test:runner:$androidx_test_version" androidTestImplementation "androidx.test.ext:junit:$androidx_junit_version" androidTestImplementation "androidx.test.ext:truth:$androidx_test_version" - androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version" - androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" - androidTestImplementation "org.mockito:mockito-android:$mockito_version" androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_test_version" + androidTestImplementation "org.mockito:mockito-android:$mockito_version" } diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/MainActivity.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/MainActivity.kt index c1240113..0ada24ff 100644 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/MainActivity.kt +++ b/app/src/main/java/com/rtbishop/look4sat/presentation/MainActivity.kt @@ -24,36 +24,31 @@ import android.content.res.Configuration import android.os.Bundle import android.os.SystemClock import android.view.View +import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.annotation.IdRes -import androidx.appcompat.app.AppCompatActivity +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.composed import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.fragment.app.Fragment import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver -import androidx.navigation.fragment.NavHostFragment import androidx.navigation.fragment.findNavController -import androidx.navigation.ui.NavigationUI -import androidx.navigation.ui.NavigationUiSaveStateControl -import com.rtbishop.look4sat.R -import com.rtbishop.look4sat.databinding.ActivityMainBinding import com.rtbishop.look4sat.presentation.bottomNav.MainScreenView import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint -class MainActivity : AppCompatActivity() { +class MainActivity : ComponentActivity() { - @OptIn(NavigationUiSaveStateControl::class) @SuppressLint("SourceLockedOrientationActivity") override fun onCreate(savedInstanceState: Bundle?) { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT installSplashScreen() super.onCreate(savedInstanceState) - val binding = ActivityMainBinding.inflate(layoutInflater) - val host = supportFragmentManager.findFragmentById(R.id.nav_host) as NavHostFragment - NavigationUI.setupWithNavController(binding.navBar, host.navController, false) - setContentView(binding.root) -// setContent { MainTheme { MainScreenView() } } + setContent { MainTheme { MainScreenView() } } } override fun attachBaseContext(newBase: Context?) { @@ -64,6 +59,10 @@ class MainActivity : AppCompatActivity() { } } +fun Modifier.onClick(onClick: () -> Unit): Modifier = composed { + clickable(remember { MutableInteractionSource() }, null) { onClick() } +} + fun Fragment.getNavResult(@IdRes id: Int, key: String, onResult: (result: T) -> Unit) { val backStackEntry = findNavController().getBackStackEntry(id) val observer = LifecycleEventObserver { _, event -> diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/MainTheme.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/MainTheme.kt index 682f1589..b0522183 100644 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/MainTheme.kt +++ b/app/src/main/java/com/rtbishop/look4sat/presentation/MainTheme.kt @@ -1,8 +1,6 @@ package com.rtbishop.look4sat.presentation -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Typography -import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle @@ -19,7 +17,7 @@ private val SurfaceGrey = Color(0xFF1C1C1C) private val Background = Color(0xFF121212) private val Transparent = Color(0x00000000) -private val DarkColorScheme = darkColorScheme( +private val DarkColors = lightColorScheme( primary = SurfaceGrey, secondary = Yellow, tertiary = ButtonGrey, @@ -29,7 +27,8 @@ private val DarkColorScheme = darkColorScheme( onSecondary = TextBlack, onTertiary = TextWhite, onBackground = TextWhite, - onSurface = TextWhite + onSurface = TextWhite, + surfaceTint = SurfaceGrey ) private val Typography = Typography( @@ -54,6 +53,10 @@ private val Typography = Typography( ) ) +val Shapes = Shapes( + +) + @Composable fun MainTheme( // darkTheme: Boolean = isSystemInDarkTheme(), @@ -68,7 +71,7 @@ fun MainTheme( // darkTheme -> DarkColorScheme // else -> LightColorScheme // } - val colorScheme = DarkColorScheme + val colors = DarkColors // val view = LocalView.current // if (!view.isInEditMode) { // SideEffect { @@ -76,5 +79,5 @@ fun MainTheme( // ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme // } // } - MaterialTheme(colorScheme = colorScheme, typography = Typography, content = content) + MaterialTheme(colorScheme = colors, typography = Typography, content = content, shapes = Shapes) } diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/aboutScreen/AboutFragment.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/aboutScreen/AboutFragment.kt deleted file mode 100644 index 7b5a2746..00000000 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/aboutScreen/AboutFragment.kt +++ /dev/null @@ -1,165 +0,0 @@ -package com.rtbishop.look4sat.presentation.aboutScreen - -import android.content.Intent -import android.net.Uri -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material.* -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.font.FontWeight -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 -import androidx.fragment.app.Fragment -import com.rtbishop.look4sat.BuildConfig -import com.rtbishop.look4sat.R -import com.rtbishop.look4sat.presentation.theme.Look4SatTheme -import dagger.hilt.android.AndroidEntryPoint - -@AndroidEntryPoint -class AboutFragment : Fragment() { - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View { - return ComposeView(requireContext()).apply { - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) - setContent { AboutScreen() } - } - } - - @Preview(showBackground = true, widthDp = 400, heightDp = 720, showSystemUi = true) - @Composable - private fun AboutScreen() { - Look4SatTheme { - LazyColumn( - contentPadding = PaddingValues(6.dp), - verticalArrangement = Arrangement.spacedBy(6.dp), - modifier = Modifier.fillMaxSize() - ) { - item { CardAbout(BuildConfig.VERSION_NAME) } - item { CardCredits() } - } - } - } - - @Composable - private fun CardAbout(version: String, modifier: Modifier = Modifier) { - Card(modifier = modifier.fillMaxWidth()) { - Column(horizontalAlignment = Alignment.CenterHorizontally) { - Row(horizontalArrangement = Arrangement.Center) { - Icon( - painter = painterResource(id = R.drawable.ic_satellite), - tint = MaterialTheme.colors.secondary, - contentDescription = null, - modifier = Modifier - .size(96.dp) - .padding(top = 8.dp, end = 8.dp) - ) - Column { - Text( - text = stringResource(id = R.string.app_name), - fontSize = 48.sp, - color = MaterialTheme.colors.secondary - ) - Text( - text = stringResource(id = R.string.app_version, version), - fontSize = 21.sp - ) - } - } - Text( - text = stringResource(id = R.string.app_subtitle), - fontSize = 21.sp, - modifier = modifier.padding(top = 4.dp) - ) - Row( - horizontalArrangement = Arrangement.SpaceEvenly, - modifier = Modifier.padding(start = 4.dp, end = 4.dp) - ) { - LinkButton( - onClick = { gotoUrl("https://sites.google.com/view/look4sat-privacy-policy/home") }, - text = stringResource(id = R.string.btn_privacy), - modifier = Modifier.weight(1f) - ) - LinkButton( - onClick = { gotoUrl("https://www.gnu.org/licenses/gpl-3.0.html") }, - text = stringResource(id = R.string.btn_license), - modifier = Modifier.weight(1f) - ) - } - } - } - } - - @Composable - private fun CardCredits(modifier: Modifier = Modifier) { - Card(modifier = modifier.fillMaxWidth()) { - Column(horizontalAlignment = Alignment.CenterHorizontally) { - Text( - text = stringResource(id = R.string.outro_title), - fontSize = 18.sp, - color = MaterialTheme.colors.secondary, - modifier = modifier.padding(8.dp) - ) - Text( - text = stringResource(id = R.string.outro_thanks), - fontSize = 16.sp, - textAlign = TextAlign.Center, - modifier = modifier.padding(start = 8.dp, end = 8.dp) - ) - Text( - text = stringResource(id = R.string.outro_license), - fontSize = 18.sp, - color = MaterialTheme.colors.secondary, - modifier = modifier.padding(start = 8.dp, end = 8.dp, top = 8.dp, bottom = 4.dp) - ) - Row( - horizontalArrangement = Arrangement.SpaceEvenly, - modifier = Modifier.padding(start = 4.dp, end = 4.dp) - ) { - LinkButton( - onClick = { gotoUrl("https://github.com/rt-bishop/Look4Sat/") }, - text = stringResource(id = R.string.btn_github), - modifier = Modifier.weight(1f) - ) - LinkButton( - onClick = { gotoUrl("https://ko-fi.com/rt_bishop") }, - text = stringResource(id = R.string.btn_support), - modifier = Modifier.weight(1f) - ) - LinkButton( - onClick = { gotoUrl("https://f-droid.org/en/packages/com.rtbishop.look4sat/") }, - text = stringResource(id = R.string.btn_fdroid), - modifier = Modifier.weight(1f) - ) - } - } - } - } - - @Composable - private fun LinkButton(onClick: () -> Unit, text: String, modifier: Modifier = Modifier) { - Button( - onClick = { onClick() }, - colors = ButtonDefaults.buttonColors(backgroundColor = MaterialTheme.colors.primaryVariant), - modifier = modifier.padding(4.dp) - ) { - Text(text = text, style = TextStyle(fontWeight = FontWeight.Bold), fontSize = 18.sp) - } - } - - private fun gotoUrl(url: String) = startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) -} diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/aboutScreen/AboutScreen.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/aboutScreen/AboutScreen.kt new file mode 100644 index 00000000..c7b363be --- /dev/null +++ b/app/src/main/java/com/rtbishop/look4sat/presentation/aboutScreen/AboutScreen.kt @@ -0,0 +1,157 @@ +package com.rtbishop.look4sat.presentation.aboutScreen + +import android.content.Context +import android.content.Intent +import android.net.Uri +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.material3.* +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight +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 +import com.rtbishop.look4sat.BuildConfig +import com.rtbishop.look4sat.R +import com.rtbishop.look4sat.presentation.MainTheme + +@Preview(showBackground = true, widthDp = 400, heightDp = 720, showSystemUi = true) +@Composable +fun AboutScreen() { + MainTheme { + LazyColumn( + contentPadding = PaddingValues(6.dp), + verticalArrangement = Arrangement.spacedBy(6.dp), + modifier = Modifier.fillMaxSize() + ) { + item { CardAbout(BuildConfig.VERSION_NAME) } + item { CardCredits() } + } + } +} + +@Composable +private fun CardAbout(version: String, modifier: Modifier = Modifier) { + val context = LocalContext.current + ElevatedCard(modifier = modifier.fillMaxWidth()) { + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Row(horizontalArrangement = Arrangement.Center) { + Icon( + painter = painterResource(id = R.drawable.ic_satellite), + tint = MaterialTheme.colorScheme.secondary, + contentDescription = null, + modifier = Modifier + .size(96.dp) + .padding(top = 8.dp, end = 8.dp) + ) + Column { + Text( + text = stringResource(id = R.string.app_name), + fontSize = 48.sp, + color = MaterialTheme.colorScheme.secondary + ) + Text( + text = stringResource(id = R.string.app_version, version), fontSize = 21.sp + ) + } + } + Text( + text = stringResource(id = R.string.app_subtitle), + fontSize = 21.sp, + modifier = modifier.padding(top = 4.dp) + ) + Row( + horizontalArrangement = Arrangement.SpaceEvenly, + modifier = Modifier.padding(start = 4.dp, end = 4.dp) + ) { + LinkButton( + onClick = { + gotoUrl( + context, "https://sites.google.com/view/look4sat-privacy-policy/home" + ) + }, + text = stringResource(id = R.string.btn_privacy), + modifier = Modifier.weight(1f) + ) + LinkButton( + onClick = { gotoUrl(context, "https://www.gnu.org/licenses/gpl-3.0.html") }, + text = stringResource(id = R.string.btn_license), + modifier = Modifier.weight(1f) + ) + } + } + } +} + +@Composable +private fun CardCredits(modifier: Modifier = Modifier) { + val context = LocalContext.current + ElevatedCard(modifier = modifier.fillMaxWidth()) { + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Text( + text = stringResource(id = R.string.outro_title), + fontSize = 18.sp, + color = MaterialTheme.colorScheme.secondary, + modifier = modifier.padding(8.dp) + ) + Text( + text = stringResource(id = R.string.outro_thanks), + fontSize = 16.sp, + textAlign = TextAlign.Center, + modifier = modifier.padding(start = 8.dp, end = 8.dp) + ) + Text( + text = stringResource(id = R.string.outro_license), + fontSize = 18.sp, + color = MaterialTheme.colorScheme.secondary, + modifier = modifier.padding(start = 8.dp, end = 8.dp, top = 8.dp, bottom = 4.dp) + ) + Row( + horizontalArrangement = Arrangement.SpaceEvenly, + modifier = Modifier.padding(start = 4.dp, end = 4.dp) + ) { + LinkButton( + onClick = { gotoUrl(context, "https://github.com/rt-bishop/Look4Sat/") }, + text = stringResource(id = R.string.btn_github), + modifier = Modifier.weight(1f) + ) + LinkButton( + onClick = { gotoUrl(context, "https://ko-fi.com/rt_bishop") }, + text = stringResource(id = R.string.btn_support), + modifier = Modifier.weight(1f) + ) + LinkButton( + onClick = { + gotoUrl( + context, "https://f-droid.org/en/packages/com.rtbishop.look4sat/" + ) + }, + text = stringResource(id = R.string.btn_fdroid), + modifier = Modifier.weight(1f) + ) + } + } + } +} + +@Composable +private fun LinkButton(onClick: () -> Unit, text: String, modifier: Modifier = Modifier) { + Button( + onClick = { onClick() }, + colors = ButtonDefaults.buttonColors(MaterialTheme.colorScheme.tertiary), + modifier = modifier.padding(4.dp) + ) { + Text(text = text, style = TextStyle(fontWeight = FontWeight.Bold), fontSize = 18.sp) + } +} + +private fun gotoUrl(context: Context, url: String) { + context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) +} diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/bottomNav/BottomNavBar.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/bottomNav/BottomNavBar.kt index 4dcc8a2c..a430c72f 100644 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/bottomNav/BottomNavBar.kt +++ b/app/src/main/java/com/rtbishop/look4sat/presentation/bottomNav/BottomNavBar.kt @@ -15,6 +15,8 @@ import androidx.navigation.compose.composable import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import com.rtbishop.look4sat.presentation.MainTheme +import com.rtbishop.look4sat.presentation.aboutScreen.AboutScreen +import com.rtbishop.look4sat.presentation.entriesScreen.EntriesScreenView @Composable fun BottomNavBar(navController: NavController) { @@ -44,8 +46,8 @@ fun BottomNavBar(navController: NavController) { @Composable fun NavigationGraph(navController: NavHostController) { - NavHost(navController, startDestination = BottomNavItem.Satellites.screen_route) { - composable(BottomNavItem.Satellites.screen_route) { SatellitesScreen() } + NavHost(navController, startDestination = BottomNavItem.Passes.screen_route) { + composable(BottomNavItem.Satellites.screen_route) { EntriesScreenView() } composable(BottomNavItem.Passes.screen_route) { PassesScreen() } composable(BottomNavItem.WorldMap.screen_route) { WorldMapScreen() } composable(BottomNavItem.Settings.screen_route) { SettingsScreen() } diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/bottomNav/BottomNavScreens.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/bottomNav/BottomNavScreens.kt index 7422f66f..3a4ee9ba 100644 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/bottomNav/BottomNavScreens.kt +++ b/app/src/main/java/com/rtbishop/look4sat/presentation/bottomNav/BottomNavScreens.kt @@ -4,7 +4,7 @@ import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.wrapContentSize -import androidx.compose.material.Text +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -15,25 +15,6 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.sp import com.rtbishop.look4sat.R -@Composable -fun SatellitesScreen() { - Column( - modifier = Modifier - .fillMaxSize() - .background(colorResource(id = R.color.background)) - .wrapContentSize(Alignment.Center) - ) { - Text( - text = "Satellites", - fontWeight = FontWeight.Bold, - color = Color.White, - modifier = Modifier.align(Alignment.CenterHorizontally), - textAlign = TextAlign.Center, - fontSize = 20.sp - ) - } -} - @Composable fun PassesScreen() { Column( @@ -90,22 +71,3 @@ fun SettingsScreen() { ) } } - -@Composable -fun AboutScreen() { - Column( - modifier = Modifier - .fillMaxSize() - .background(colorResource(id = R.color.background)) - .wrapContentSize(Alignment.Center) - ) { - Text( - text = "About", - fontWeight = FontWeight.Bold, - color = Color.White, - modifier = Modifier.align(Alignment.CenterHorizontally), - textAlign = TextAlign.Center, - fontSize = 20.sp - ) - } -} diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesFragmentCompose.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesFragmentCompose.kt deleted file mode 100644 index 9c5f3b10..00000000 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesFragmentCompose.kt +++ /dev/null @@ -1,169 +0,0 @@ -package com.rtbishop.look4sat.presentation.entriesScreen - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.grid.GridCells -import androidx.compose.foundation.lazy.grid.LazyVerticalGrid -import androidx.compose.foundation.lazy.grid.items -import androidx.compose.material.* -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.ArrowRight -import androidx.compose.material.icons.outlined.Close -import androidx.compose.material.icons.outlined.Search -import androidx.compose.runtime.Composable -import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.composed -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.dp -import androidx.fragment.app.Fragment -import androidx.lifecycle.viewmodel.compose.viewModel -import com.rtbishop.look4sat.R -import com.rtbishop.look4sat.domain.model.DataState -import com.rtbishop.look4sat.domain.model.SatItem -import com.rtbishop.look4sat.presentation.theme.Look4SatTheme -import dagger.hilt.android.AndroidEntryPoint - -@AndroidEntryPoint -class EntriesFragmentCompose : Fragment() { - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View { - return ComposeView(requireContext()).apply { - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) - setContent { Look4SatTheme { EntriesScreenView() } } - } - } - - @Composable - fun EntriesScreenView(viewModel: EntriesViewModel = viewModel()) { - val dataState = viewModel.satData.observeAsState(DataState.Loading) - Column(modifier = Modifier.padding(6.dp)) { - Card { SearchBar(setQuery = { newQuery -> viewModel.setQuery(newQuery) }) } - - Spacer(modifier = Modifier.height(6.dp)) - Card( - modifier = Modifier - .fillMaxWidth() - .weight(1f) - ) { - LoadingOrList(state = dataState.value) { list, value -> - viewModel.updateSelection(list, value) - } - } - Spacer(modifier = Modifier.height(6.dp)) - EntryTypeBar(entryType = "All") - - } - } - - @Composable - fun EntryTypeBar(entryType: String, modifier: Modifier = Modifier) { - val icon = Icons.Outlined.ArrowRight - val text = "Selected type: $entryType" - Card { - Row(verticalAlignment = Alignment.CenterVertically) { -// Icon(painter = painterResource(id = R.drawable.ic_next), contentDescription = null) - Icon(imageVector = icon, contentDescription = null, modifier = modifier.size(48.dp)) - Text(text = text, maxLines = 1, modifier = modifier.fillMaxWidth()) - } - } - } - - @Composable - fun LoadingOrList(state: DataState>, onSelected: (List, Boolean) -> Unit) { - when (state) { - is DataState.Loading -> { - LoadingProgress() - } - is DataState.Success -> { - EntriesList(entries = state.data) { list, value -> onSelected(list, value) } - } - else -> { - LoadingProgress() - } - } - } - - @Composable - fun LoadingProgress() { - Row( - horizontalArrangement = Arrangement.Center, - verticalAlignment = Alignment.CenterVertically - ) { CircularProgressIndicator(modifier = Modifier.size(64.dp)) } - } - - @OptIn(ExperimentalFoundationApi::class) - @Composable - fun EntriesList(entries: List, onSelected: (List, Boolean) -> Unit) { - LazyVerticalGrid(columns = GridCells.Adaptive(200.dp)) { - items(items = entries, key = { item -> item.catnum }) { entry -> - EntryItem(entry, onSelected, Modifier.animateItemPlacement()) - } - } - } - - @Composable - fun EntryItem(entry: SatItem, onSelected: (List, Boolean) -> Unit, modifier: Modifier) { - Surface(color = MaterialTheme.colors.background, modifier = modifier) { - Surface(modifier = modifier.padding(bottom = 1.dp)) { - Row(verticalAlignment = Alignment.CenterVertically, - modifier = modifier - .background(MaterialTheme.colors.surface) - .onClick { onSelected(listOf(entry.catnum), entry.isSelected.not()) }) { - Checkbox( - checked = entry.isSelected, onCheckedChange = null, Modifier.padding(6.dp) - ) - Text(text = entry.name, maxLines = 1, overflow = TextOverflow.Ellipsis) - } - } - } - } - - @Composable - fun SearchBar(setQuery: (String) -> Unit) { - val currentQuery = rememberSaveable { mutableStateOf("") } - OutlinedTextField(value = currentQuery.value, onValueChange = { newValue -> - currentQuery.value = newValue - setQuery(newValue) - }, maxLines = 1, -// label = { Text(text = stringResource(id = R.string.entries_search_hint)) }, - placeholder = { Text(text = stringResource(id = R.string.entries_search_hint)) }, - leadingIcon = { - Icon(imageVector = Icons.Outlined.Search, contentDescription = null) - }, trailingIcon = { - Icon(imageVector = Icons.Outlined.Close, - contentDescription = null, - modifier = Modifier.onClick { - currentQuery.value = "" - setQuery("") - }) - }, - colors = TextFieldDefaults.outlinedTextFieldColors( - focusedBorderColor = MaterialTheme.colors.onBackground, - unfocusedBorderColor = MaterialTheme.colors.onBackground), - modifier = Modifier - .fillMaxWidth() - .background(MaterialTheme.colors.surface) - ) - } - - private fun Modifier.onClick(onClick: () -> Unit): Modifier = composed { - clickable(remember { MutableInteractionSource() }, null) { onClick() } - } -} diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesScreen.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesScreen.kt new file mode 100644 index 00000000..90bf89fa --- /dev/null +++ b/app/src/main/java/com/rtbishop/look4sat/presentation/entriesScreen/EntriesScreen.kt @@ -0,0 +1,145 @@ +package com.rtbishop.look4sat.presentation.entriesScreen + +import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.LazyVerticalGrid +import androidx.compose.foundation.lazy.grid.items +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.ArrowForward +import androidx.compose.material.icons.outlined.Close +import androidx.compose.material.icons.outlined.Search +import androidx.compose.material3.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.livedata.observeAsState +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import com.rtbishop.look4sat.R +import com.rtbishop.look4sat.domain.model.DataState +import com.rtbishop.look4sat.domain.model.SatItem +import com.rtbishop.look4sat.presentation.onClick + +@Composable +fun EntriesScreenView() { + val viewModel = hiltViewModel() + val dataState = viewModel.satData.observeAsState(DataState.Loading) + Column(modifier = Modifier.padding(6.dp)) { + Card { SearchBar(setQuery = { newQuery -> viewModel.setQuery(newQuery) }) } + Spacer(modifier = Modifier.height(6.dp)) + Card( + modifier = Modifier + .fillMaxWidth() + .weight(1f) + ) { + LoadingOrList(state = dataState.value) { list, value -> + viewModel.updateSelection(list, value) + } + } + Spacer(modifier = Modifier.height(6.dp)) + EntryTypeBar(entryType = "All") + + } +} + +@Composable +fun EntryTypeBar(entryType: String, modifier: Modifier = Modifier) { + val icon = Icons.Outlined.ArrowForward + val text = "Selected type: $entryType" + Card { + Row(verticalAlignment = Alignment.CenterVertically) { +// Icon(painter = painterResource(id = R.drawable.ic_next), contentDescription = null) + Icon(imageVector = icon, contentDescription = null, modifier = modifier.size(48.dp)) + Text(text = text, maxLines = 1, modifier = modifier.fillMaxWidth()) + } + } +} + +@Composable +fun LoadingOrList(state: DataState>, onSelected: (List, Boolean) -> Unit) { + when (state) { + is DataState.Loading -> { + LoadingProgress() + } + is DataState.Success -> { + EntriesList(entries = state.data) { list, value -> onSelected(list, value) } + } + else -> { + LoadingProgress() + } + } +} + +@Composable +fun LoadingProgress() { + Row( + horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically + ) { CircularProgressIndicator(modifier = Modifier.size(64.dp)) } +} + +@OptIn(ExperimentalFoundationApi::class) +@Composable +fun EntriesList(entries: List, onSelected: (List, Boolean) -> Unit) { + LazyVerticalGrid(columns = GridCells.Adaptive(200.dp)) { + items(items = entries, key = { item -> item.catnum }) { entry -> + EntryItem(entry, onSelected, Modifier.animateItemPlacement()) + } + } +} + +@Composable +fun EntryItem(entry: SatItem, onSelected: (List, Boolean) -> Unit, modifier: Modifier) { + Surface(color = MaterialTheme.colorScheme.background, modifier = modifier) { + Surface(modifier = modifier.padding(bottom = 1.dp)) { + Row(verticalAlignment = Alignment.CenterVertically, + modifier = modifier + .background(MaterialTheme.colorScheme.surface) + .onClick { onSelected(listOf(entry.catnum), entry.isSelected.not()) }) { + Checkbox( + checked = entry.isSelected, onCheckedChange = null, Modifier.padding(6.dp) + ) + Text(text = entry.name, maxLines = 1, overflow = TextOverflow.Ellipsis) + } + } + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun SearchBar(setQuery: (String) -> Unit) { + val currentQuery = rememberSaveable { mutableStateOf("") } + OutlinedTextField( + value = currentQuery.value, + onValueChange = { newValue -> + currentQuery.value = newValue + setQuery(newValue) + }, + maxLines = 1, +// label = { Text(text = stringResource(id = R.string.entries_search_hint)) }, + placeholder = { Text(text = stringResource(id = R.string.entries_search_hint)) }, + leadingIcon = { + Icon(imageVector = Icons.Outlined.Search, contentDescription = null) + }, + trailingIcon = { + Icon(imageVector = Icons.Outlined.Close, + contentDescription = null, + modifier = Modifier.onClick { + currentQuery.value = "" + setQuery("") + }) + }, +// colors = TextFieldDefaults.outlinedTextFieldColors( +// focusedBorderColor = MaterialTheme.colorScheme.onBackground, +// unfocusedBorderColor = MaterialTheme.colorScheme.onBackground +// ), + modifier = Modifier + .fillMaxWidth() + .background(MaterialTheme.colorScheme.surface) + ) +} diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/theme/Color.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/theme/Color.kt deleted file mode 100644 index 8aa20283..00000000 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/theme/Color.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.rtbishop.look4sat.presentation.theme - -import androidx.compose.ui.graphics.Color - -val Yellow = Color(0xFFFFE082) -val TextWhite = Color(0xCCFFFFFF) -val TextGrey = Color(0x66FFFFFF) -val TextBlack = Color(0xFF000000) -val ButtonGrey = Color(0xFF2A2A2A) -val SurfaceGrey = Color(0xFF1C1C1C) -val Background = Color(0xFF121212) -val Transparent = Color(0x00000000) diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/theme/Shape.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/theme/Shape.kt deleted file mode 100644 index 1078280d..00000000 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/theme/Shape.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.rtbishop.look4sat.presentation.theme - -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Shapes -import androidx.compose.ui.unit.dp - -val Shapes = Shapes( - small = RoundedCornerShape(12.dp), - medium = RoundedCornerShape(12.dp), - large = RoundedCornerShape(12.dp) -) diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/theme/Theme.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/theme/Theme.kt deleted file mode 100644 index c33f5c69..00000000 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/theme/Theme.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.rtbishop.look4sat.presentation.theme - -import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.material.MaterialTheme -import androidx.compose.material.darkColors -import androidx.compose.material.lightColors -import androidx.compose.runtime.Composable - -@Composable -fun Look4SatTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) { - val colors = if (darkTheme) DarkColors else LightColors - MaterialTheme(colors = colors, typography = Typography, shapes = Shapes, content = content) -} - -private val LightColors = lightColors( - primary = SurfaceGrey, - primaryVariant = ButtonGrey, - secondary = Yellow, - background = Background, - surface = SurfaceGrey, - onPrimary = TextWhite, - onSecondary = TextBlack, - onBackground = TextGrey, - onSurface = TextWhite -) - -private val DarkColors = darkColors( - primary = SurfaceGrey, - primaryVariant = ButtonGrey, - secondary = Yellow, - background = Background, - surface = SurfaceGrey, - onPrimary = TextWhite, - onSecondary = TextBlack, - onBackground = TextGrey, - onSurface = TextWhite -) diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/theme/Type.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/theme/Type.kt deleted file mode 100644 index 0a861c54..00000000 --- a/app/src/main/java/com/rtbishop/look4sat/presentation/theme/Type.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.rtbishop.look4sat.presentation.theme - -import androidx.compose.material.Typography -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.font.FontFamily -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.unit.sp - -val Typography = Typography( - body1 = TextStyle( - fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 16.sp - ) -// button = TextStyle( -// fontFamily = FontFamily.Default, -// fontWeight = FontWeight.W500, -// fontSize = 14.sp -// ), -// caption = TextStyle( -// fontFamily = FontFamily.Default, -// fontWeight = FontWeight.Normal, -// fontSize = 12.sp -// ) -) diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 1310c990..f7195619 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -7,16 +7,16 @@ @drawable/ic_splash - -