mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added minor fixes to EntriesDialog and passes view
This commit is contained in:
1 parent
213ac7c278
commit
ae53e5dc35
8 files changed
+95
-59
No files matched your search
@@ -24,13 +24,19 @@ android {
|
||||
compose = true
|
||||
}
|
||||
buildTypes {
|
||||
debug {
|
||||
applicationIdSuffix = ".debug"
|
||||
versionNameSuffix = "-debug"
|
||||
}
|
||||
release {
|
||||
isMinifyEnabled = true
|
||||
isShrinkResources = true
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
}
|
||||
}
|
||||
composeOptions { kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get() }
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.rtbishop.look4sat
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.DisplayMetrics
|
||||
import androidx.activity.ComponentActivity
|
||||
@@ -38,9 +37,7 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
override fun attachBaseContext(newBase: Context?) {
|
||||
val newConfig = Configuration(newBase?.resources?.configuration).apply {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
densityDpi = DisplayMetrics.DENSITY_DEVICE_STABLE
|
||||
}
|
||||
densityDpi = DisplayMetrics.DENSITY_DEVICE_STABLE
|
||||
fontScale = 1.0f
|
||||
}
|
||||
applyOverrideConfiguration(newConfig)
|
||||
|
||||
@@ -11,6 +11,7 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavHostController
|
||||
@@ -71,7 +72,7 @@ private fun MainNavGraph(navController: NavHostController) {
|
||||
composable(Screen.Entries.route) {
|
||||
val viewModel = viewModel(EntriesViewModel::class.java, factory = EntriesViewModel.Factory)
|
||||
val navToPasses = { navController.navigate(Screen.Passes.route) }
|
||||
EntriesScreen(viewModel.uiState.value, navToPasses)
|
||||
EntriesScreen(viewModel.uiState.collectAsStateWithLifecycle().value, navToPasses)
|
||||
}
|
||||
composable(Screen.Passes.route) {
|
||||
val viewModel = viewModel(PassesViewModel::class.java, factory = PassesViewModel.Factory)
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.rtbishop.look4sat.presentation
|
||||
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.LocalOverscrollConfiguration
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Shapes
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
@@ -13,6 +16,7 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun MainTheme(
|
||||
// darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
@@ -35,7 +39,9 @@ fun MainTheme(
|
||||
// ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme
|
||||
// }
|
||||
// }
|
||||
MaterialTheme(colorScheme = colors, typography = typography, content = content, shapes = shapes)
|
||||
MaterialTheme(colorScheme = colors, typography = typography, shapes = shapes) {
|
||||
CompositionLocalProvider(LocalOverscrollConfiguration.provides(null), content = content)
|
||||
}
|
||||
}
|
||||
|
||||
private val accentYellow = Color(0xFFFFE082)
|
||||
|
||||
@@ -3,8 +3,9 @@ package com.rtbishop.look4sat.presentation.entries
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
@@ -12,15 +13,17 @@ import androidx.compose.foundation.lazy.grid.itemsIndexed
|
||||
import androidx.compose.material3.ElevatedCard
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import com.rtbishop.look4sat.presentation.MainTheme
|
||||
|
||||
@@ -33,28 +36,35 @@ private fun TypeDialogPreview() {
|
||||
|
||||
@Composable
|
||||
fun TypesDialog(items: List<String>, selected: String, dismiss: () -> Unit, select: (String) -> Unit) {
|
||||
val clickAction = { type: String ->
|
||||
select(type)
|
||||
dismiss()
|
||||
}
|
||||
val height = LocalConfiguration.current.screenHeightDp
|
||||
Dialog(onDismissRequest = { dismiss() }) {
|
||||
ElevatedCard(modifier = Modifier.fillMaxHeight(0.80f)) {
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Adaptive(160.dp),
|
||||
modifier = Modifier.background(MaterialTheme.colorScheme.background),
|
||||
horizontalArrangement = Arrangement.spacedBy(1.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(1.dp)
|
||||
ElevatedCard {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.heightIn(max = height.times(0.80).dp)
|
||||
) {
|
||||
itemsIndexed(items) { index, item ->
|
||||
Surface {
|
||||
Text(
|
||||
text = "Select satellites type",
|
||||
fontSize = 18.sp,
|
||||
textAlign = TextAlign.Center,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(top = 8.dp, bottom = 4.dp)
|
||||
)
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Adaptive(240.dp),
|
||||
modifier = Modifier.background(MaterialTheme.colorScheme.background),
|
||||
horizontalArrangement = Arrangement.spacedBy(1.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(1.dp)
|
||||
) {
|
||||
itemsIndexed(items) { index, item ->
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.clickable { clickAction(item) }) {
|
||||
.clickable { select(item) }) {
|
||||
Text(
|
||||
text = "$index).",
|
||||
modifier = Modifier.padding(start = 12.dp, end = 6.dp),
|
||||
text = "$index - ",
|
||||
modifier = Modifier.padding(start = 12.dp),
|
||||
fontWeight = FontWeight.Normal,
|
||||
color = MaterialTheme.colorScheme.secondary
|
||||
)
|
||||
@@ -65,7 +75,11 @@ fun TypesDialog(items: List<String>, selected: String, dismiss: () -> Unit, sele
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
RadioButton(selected = item == selected, onClick = null, modifier = Modifier.padding(8.dp))
|
||||
RadioButton(
|
||||
selected = item == selected,
|
||||
onClick = null,
|
||||
modifier = Modifier.padding(start = 8.dp, top = 8.dp, end = 12.dp, bottom = 8.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
*/
|
||||
package com.rtbishop.look4sat.presentation.entries
|
||||
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@@ -27,12 +25,14 @@ import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import com.rtbishop.look4sat.MainApplication
|
||||
import com.rtbishop.look4sat.domain.repository.ISelectionRepo
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class EntriesViewModel(private val selectionRepo: ISelectionRepo) : ViewModel() {
|
||||
|
||||
private val defaultType = "All"
|
||||
private val _uiState = mutableStateOf(
|
||||
private val _uiState = MutableStateFlow(
|
||||
EntriesState(
|
||||
isDialogShown = false,
|
||||
isLoading = true,
|
||||
@@ -42,7 +42,7 @@ class EntriesViewModel(private val selectionRepo: ISelectionRepo) : ViewModel()
|
||||
takeAction = ::handleAction
|
||||
)
|
||||
)
|
||||
val uiState: State<EntriesState> = _uiState
|
||||
val uiState: StateFlow<EntriesState> = _uiState
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
@@ -80,7 +80,7 @@ class EntriesViewModel(private val selectionRepo: ISelectionRepo) : ViewModel()
|
||||
|
||||
private fun selectType(type: String) = viewModelScope.launch {
|
||||
selectionRepo.setType(type)
|
||||
_uiState.value = _uiState.value.copy(currentType = type)
|
||||
_uiState.value = _uiState.value.copy(currentType = type, isDialogShown = false)
|
||||
}
|
||||
|
||||
private fun toggleTypesDialog() {
|
||||
|
||||
@@ -32,6 +32,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.domain.predict.DeepSpaceObject
|
||||
import com.rtbishop.look4sat.domain.predict.NearEarthObject
|
||||
import com.rtbishop.look4sat.domain.predict.OrbitalData
|
||||
import com.rtbishop.look4sat.domain.predict.OrbitalPass
|
||||
@@ -53,8 +54,7 @@ fun PassesScreen(uiState: PassesState, navToRadar: (Int, Long) -> Unit) {
|
||||
})
|
||||
val toggleDialog = { uiState.takeAction(PassesAction.ToggleFilterDialog) }
|
||||
if (uiState.isDialogShown) {
|
||||
FilterDialog(uiState.hours, uiState.elevation, uiState.modes, toggleDialog
|
||||
) { hours, elevation, modes ->
|
||||
FilterDialog(uiState.hours, uiState.elevation, uiState.modes, toggleDialog) { hours, elevation, modes ->
|
||||
uiState.takeAction(PassesAction.ApplyFilter(hours, elevation, modes))
|
||||
}
|
||||
}
|
||||
@@ -71,9 +71,20 @@ fun PassesScreen(uiState: PassesState, navToRadar: (Int, Long) -> Unit) {
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
private fun PassPreview() {
|
||||
private fun DeepSpacePassPreview() {
|
||||
val data = OrbitalData(
|
||||
"Satellite", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 45000, 0.0
|
||||
"Satellite", 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 45000, 0.0
|
||||
)
|
||||
val satellite = DeepSpaceObject(data)
|
||||
val pass = OrbitalPass(1L, 0.0, 10L, 180.0, 850, 45.0, satellite, 0.5f)
|
||||
MainTheme { Pass(pass = pass, { _, _ -> }) }
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
private fun NearEarthPassPreview() {
|
||||
val data = OrbitalData(
|
||||
"Satellite", 0.0, 15.0, 0.0, 0.0, 0.0, 0.0, 0.0, 45000, 0.0
|
||||
)
|
||||
val satellite = NearEarthObject(data)
|
||||
val pass = OrbitalPass(1L, 0.0, 10L, 180.0, 850, 45.0, satellite, 0.5f)
|
||||
@@ -146,27 +157,28 @@ private fun Pass(
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
}
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
val deepTime = stringResource(id = R.string.pass_placeholder)
|
||||
Text(
|
||||
text = if (pass.isDeepSpace) deepTime else sdf.format(Date(pass.aosTime)),
|
||||
fontSize = 15.sp
|
||||
)
|
||||
LinearProgressIndicator(
|
||||
progress = if (pass.isDeepSpace) 1f else pass.progress,
|
||||
modifier = modifier
|
||||
.fillMaxWidth(0.75f)
|
||||
.padding(top = 3.dp),
|
||||
trackColor = MaterialTheme.colorScheme.inverseSurface
|
||||
)
|
||||
Text(
|
||||
text = if (pass.isDeepSpace) deepTime else sdf.format(Date(pass.losTime)),
|
||||
fontSize = 15.sp
|
||||
)
|
||||
if (!pass.isDeepSpace) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
text = sdf.format(Date(pass.aosTime)),
|
||||
fontSize = 15.sp
|
||||
)
|
||||
LinearProgressIndicator(
|
||||
progress = pass.progress,
|
||||
modifier = modifier
|
||||
.fillMaxWidth(0.75f)
|
||||
.padding(top = 3.dp),
|
||||
trackColor = MaterialTheme.colorScheme.inverseSurface
|
||||
)
|
||||
Text(
|
||||
text = sdf.format(Date(pass.losTime)),
|
||||
fontSize = 15.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user