Tiny code clean up

This commit is contained in:
Sad Ellie 2022-07-22 21:21:36 +03:00
parent 12c5f312e6
commit c7ed540c2e
22 changed files with 17 additions and 49 deletions

View File

@ -26,6 +26,7 @@ import androidx.compose.animation.core.tween
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
@ -54,19 +55,15 @@ import io.github.sadellie.themmo.Themmo
import io.github.sadellie.themmo.ThemmoController
import io.github.sadellie.themmo.rememberThemmoController
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
private val mainViewModel: MainViewModel by viewModels()
private val secondViewModel: SecondViewModel by viewModels()
private val themesViewModel: ThemesViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
themesViewModel.collectThemeOptions()
val themmoController = rememberThemmoController(
lightColorScheme = LightThemeColors,
darkColorScheme = DarkThemeColors,
@ -88,14 +85,12 @@ class MainActivity : ComponentActivity() {
UnittoApp(
navController = navController,
mainViewModel = mainViewModel,
secondViewModel = secondViewModel,
themesViewModel = themesViewModel,
themmoController = it
)
SideEffect { sysUiController.setSystemBarsColor(backgroundColor) }
}
}
}
@ -109,15 +104,14 @@ class MainActivity : ComponentActivity() {
fun UnittoApp(
navController: NavHostController,
mainViewModel: MainViewModel,
secondViewModel: SecondViewModel,
themesViewModel: ThemesViewModel,
themmoController: ThemmoController
) {
val secondViewModel: SecondViewModel = hiltViewModel()
NavHost(
navController = navController,
startDestination = MAIN_SCREEN
) {
composable(MAIN_SCREEN) {
MainScreen(
navControllerAction = { route -> navController.navigate(route) },

View File

@ -18,7 +18,6 @@
package com.sadellie.unitto.data
data class AppLibrary(
val name: String,
val dev: String?,
@ -27,7 +26,6 @@ data class AppLibrary(
val description: String?
)
val ALL_LIBRARIES = lazy {
listOf(
AppLibrary(

View File

@ -41,7 +41,6 @@ private const val USER_PREFERENCES = "settings"
@InstallIn(SingletonComponent::class)
@Module
class DataStoreModule {
/**
* Tells Hilt to use this method to get [DataStore]
*

View File

@ -63,7 +63,6 @@ data class UserPreferences(
* Repository that works with DataStore
*/
class UserPreferencesRepository @Inject constructor(private val dataStore: DataStore<Preferences>) {
/**
* Keys for DataStore
*/

View File

@ -24,7 +24,6 @@ package com.sadellie.unitto.data.units
* NEVER CHANGE IDS THAT ARE ALREADY HERE, THESE IDS ARE USED IN DATABASE
*/
object MyUnitIDS {
// LENGTH
const val attometer = "attometer"
const val nanometer = "nanometer"

View File

@ -27,7 +27,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
/**
* Module for database. Used to access same instance of database
*
@ -35,7 +34,6 @@ import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
@Module
class BasedUnitDatabaseModule {
/**
* Tells Hilt to use this method to get [MyBasedUnitDao]
*

View File

@ -21,7 +21,6 @@ package com.sadellie.unitto.data.units.database
import javax.inject.Inject
class MyBasedUnitsRepository @Inject constructor (private val myBasedUnitDao: MyBasedUnitDao) {
/**
* Method to insert units. Will rewrite row if unit's id is already in database
*

View File

@ -49,7 +49,6 @@ import java.math.BigDecimal
import java.math.RoundingMode
import javax.inject.Inject
@HiltViewModel
class MainViewModel @Inject constructor(
private val userPrefsRepository: UserPreferencesRepository,
@ -57,7 +56,6 @@ class MainViewModel @Inject constructor(
private val application: Application,
private val allUnitsRepository: AllUnitsRepository
) : ViewModel() {
var precision: Int by mutableStateOf(3)
private set
var separator: Int by mutableStateOf(Separator.SPACES)

View File

@ -36,7 +36,6 @@ import kotlin.math.floor
import kotlin.math.log10
import kotlin.math.max
object Formatter {
private var nf: NumberFormat = NumberFormat.getInstance(Locale.GERMANY)
@ -222,4 +221,4 @@ fun Sequence<AbstractUnit>.sortByLev(stringA: String): Sequence<AbstractUnit> {
.sortedBy { it.second }
.map { it.first }
.asSequence()
}
}

View File

@ -41,7 +41,6 @@ import com.sadellie.unitto.data.ALL_LIBRARIES
import com.sadellie.unitto.screens.common.UnittoLargeTopAppBar
import com.sadellie.unitto.screens.openLink
/**
* Screen with used third party libraries
*

View File

@ -55,4 +55,4 @@ fun AnimatedTopBarText(showAppName: Boolean) {
style = MaterialTheme.typography.headlineSmall.copy(fontWeight = FontWeight.W600)
)
}
}
}

View File

@ -18,7 +18,6 @@
package com.sadellie.unitto.screens.main
import android.content.res.Configuration
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
@ -54,7 +53,6 @@ import com.sadellie.unitto.screens.main.components.Keyboard
import com.sadellie.unitto.screens.main.components.TopScreenPart
import kotlinx.coroutines.delay
@Composable
fun MainScreen(
navControllerAction: (String) -> Unit = {},

View File

@ -41,7 +41,6 @@ import com.sadellie.unitto.data.KEY_DOT
import com.sadellie.unitto.data.KEY_NEGATE
import com.sadellie.unitto.screens.Formatter
/**
* Keyboard with button that looks like a calculator
*

View File

@ -29,7 +29,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.sadellie.unitto.ui.theme.NumbersTextStyleTitleLarge
/**
* Button for keyboard
*

View File

@ -48,7 +48,6 @@ import com.sadellie.unitto.R
import com.sadellie.unitto.screens.Formatter
import com.sadellie.unitto.ui.theme.NumbersTextStyleDisplayLarge
/**
* Component for input and output
*

View File

@ -37,7 +37,6 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.sadellie.unitto.R
/**
* Button to select a unit
*

View File

@ -27,7 +27,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
/**
* Unit group header.
*

View File

@ -36,7 +36,6 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.sadellie.unitto.R
/**
* Placeholder that can be seen when there are no units found
*

View File

@ -151,7 +151,6 @@ fun SettingsScreen(
}
}
/**
* Function to reset currently displayed dialog.
*/

View File

@ -40,7 +40,6 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.sadellie.unitto.R
/**
* Alert dialog that has a list of options in it
*
@ -59,12 +58,12 @@ fun AlertDialogWithList(
selectAction: (Int) -> Unit = {},
dismissAction: () -> Unit,
supportText: String? = null,
dismissButtonLabel: String = stringResource(id = R.string.cancel_label)
dismissButtonLabel: String = stringResource(R.string.cancel_label)
) {
AlertDialog(
onDismissRequest = dismissAction,
title = {
Text(text = title)
Text(title)
},
text = {
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
@ -93,7 +92,6 @@ fun AlertDialogWithList(
)
}
/**
* An item that represents one option item
*
@ -117,12 +115,7 @@ private fun CustomDialogContentListItem(
),
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(
selected = selected,
onClick = onClick
)
Text(
text = label
)
RadioButton(selected, onClick)
Text(label)
}
}

View File

@ -34,6 +34,9 @@ import javax.inject.Inject
class ThemesViewModel @Inject constructor(
private val userPrefsRepository: UserPreferencesRepository
) : ViewModel() {
var themingMode: ThemingMode? by mutableStateOf(null)
var enableDynamic by mutableStateOf(false)
var enableAmoled by mutableStateOf(false)
/**
* @see [UserPreferencesRepository.updateThemingMode]
@ -62,14 +65,10 @@ class ThemesViewModel @Inject constructor(
}
}
var themingMode: ThemingMode? by mutableStateOf(null)
var enableDynamic by mutableStateOf(false)
var enableAmoled by mutableStateOf(false)
/**
* Collect saved theming options. Used on app launch.
*/
fun collectThemeOptions() {
private fun collectThemeOptions() {
viewModelScope.launch {
val userPref = userPrefsRepository.userPreferencesFlow.first()
themingMode = userPref.themingMode
@ -77,4 +76,8 @@ class ThemesViewModel @Inject constructor(
enableAmoled = userPref.enableAmoledTheme
}
}
}
init {
collectThemeOptions()
}
}

View File

@ -20,7 +20,6 @@ package com.sadellie.unitto.ui.theme
import androidx.compose.ui.graphics.Color
val md_theme_light_primary = Color(0xFF186c31)
val md_theme_light_onPrimary = Color(0xFFffffff)
val md_theme_light_primaryContainer = Color(0xFFa3f6ab)