mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-23 10:40:31 +02:00
Tiny code clean up
This commit is contained in:
parent
12c5f312e6
commit
c7ed540c2e
@ -26,6 +26,7 @@ import androidx.compose.animation.core.tween
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.SideEffect
|
import androidx.compose.runtime.SideEffect
|
||||||
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
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.ThemmoController
|
||||||
import io.github.sadellie.themmo.rememberThemmoController
|
import io.github.sadellie.themmo.rememberThemmoController
|
||||||
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
private val mainViewModel: MainViewModel by viewModels()
|
private val mainViewModel: MainViewModel by viewModels()
|
||||||
private val secondViewModel: SecondViewModel by viewModels()
|
|
||||||
private val themesViewModel: ThemesViewModel by viewModels()
|
private val themesViewModel: ThemesViewModel by viewModels()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
themesViewModel.collectThemeOptions()
|
|
||||||
|
|
||||||
val themmoController = rememberThemmoController(
|
val themmoController = rememberThemmoController(
|
||||||
lightColorScheme = LightThemeColors,
|
lightColorScheme = LightThemeColors,
|
||||||
darkColorScheme = DarkThemeColors,
|
darkColorScheme = DarkThemeColors,
|
||||||
@ -88,14 +85,12 @@ class MainActivity : ComponentActivity() {
|
|||||||
UnittoApp(
|
UnittoApp(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
mainViewModel = mainViewModel,
|
mainViewModel = mainViewModel,
|
||||||
secondViewModel = secondViewModel,
|
|
||||||
themesViewModel = themesViewModel,
|
themesViewModel = themesViewModel,
|
||||||
themmoController = it
|
themmoController = it
|
||||||
)
|
)
|
||||||
|
|
||||||
SideEffect { sysUiController.setSystemBarsColor(backgroundColor) }
|
SideEffect { sysUiController.setSystemBarsColor(backgroundColor) }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,15 +104,14 @@ class MainActivity : ComponentActivity() {
|
|||||||
fun UnittoApp(
|
fun UnittoApp(
|
||||||
navController: NavHostController,
|
navController: NavHostController,
|
||||||
mainViewModel: MainViewModel,
|
mainViewModel: MainViewModel,
|
||||||
secondViewModel: SecondViewModel,
|
|
||||||
themesViewModel: ThemesViewModel,
|
themesViewModel: ThemesViewModel,
|
||||||
themmoController: ThemmoController
|
themmoController: ThemmoController
|
||||||
) {
|
) {
|
||||||
|
val secondViewModel: SecondViewModel = hiltViewModel()
|
||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
startDestination = MAIN_SCREEN
|
startDestination = MAIN_SCREEN
|
||||||
) {
|
) {
|
||||||
|
|
||||||
composable(MAIN_SCREEN) {
|
composable(MAIN_SCREEN) {
|
||||||
MainScreen(
|
MainScreen(
|
||||||
navControllerAction = { route -> navController.navigate(route) },
|
navControllerAction = { route -> navController.navigate(route) },
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
package com.sadellie.unitto.data
|
package com.sadellie.unitto.data
|
||||||
|
|
||||||
|
|
||||||
data class AppLibrary(
|
data class AppLibrary(
|
||||||
val name: String,
|
val name: String,
|
||||||
val dev: String?,
|
val dev: String?,
|
||||||
@ -27,7 +26,6 @@ data class AppLibrary(
|
|||||||
val description: String?
|
val description: String?
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
val ALL_LIBRARIES = lazy {
|
val ALL_LIBRARIES = lazy {
|
||||||
listOf(
|
listOf(
|
||||||
AppLibrary(
|
AppLibrary(
|
||||||
|
@ -41,7 +41,6 @@ private const val USER_PREFERENCES = "settings"
|
|||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
@Module
|
@Module
|
||||||
class DataStoreModule {
|
class DataStoreModule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells Hilt to use this method to get [DataStore]
|
* Tells Hilt to use this method to get [DataStore]
|
||||||
*
|
*
|
||||||
|
@ -63,7 +63,6 @@ data class UserPreferences(
|
|||||||
* Repository that works with DataStore
|
* Repository that works with DataStore
|
||||||
*/
|
*/
|
||||||
class UserPreferencesRepository @Inject constructor(private val dataStore: DataStore<Preferences>) {
|
class UserPreferencesRepository @Inject constructor(private val dataStore: DataStore<Preferences>) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keys for DataStore
|
* Keys for DataStore
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +24,6 @@ package com.sadellie.unitto.data.units
|
|||||||
* NEVER CHANGE IDS THAT ARE ALREADY HERE, THESE IDS ARE USED IN DATABASE
|
* NEVER CHANGE IDS THAT ARE ALREADY HERE, THESE IDS ARE USED IN DATABASE
|
||||||
*/
|
*/
|
||||||
object MyUnitIDS {
|
object MyUnitIDS {
|
||||||
|
|
||||||
// LENGTH
|
// LENGTH
|
||||||
const val attometer = "attometer"
|
const val attometer = "attometer"
|
||||||
const val nanometer = "nanometer"
|
const val nanometer = "nanometer"
|
||||||
|
@ -27,7 +27,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
|||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module for database. Used to access same instance of database
|
* Module for database. Used to access same instance of database
|
||||||
*
|
*
|
||||||
@ -35,7 +34,6 @@ import javax.inject.Singleton
|
|||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
@Module
|
@Module
|
||||||
class BasedUnitDatabaseModule {
|
class BasedUnitDatabaseModule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells Hilt to use this method to get [MyBasedUnitDao]
|
* Tells Hilt to use this method to get [MyBasedUnitDao]
|
||||||
*
|
*
|
||||||
|
@ -21,7 +21,6 @@ package com.sadellie.unitto.data.units.database
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MyBasedUnitsRepository @Inject constructor (private val myBasedUnitDao: MyBasedUnitDao) {
|
class MyBasedUnitsRepository @Inject constructor (private val myBasedUnitDao: MyBasedUnitDao) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to insert units. Will rewrite row if unit's id is already in database
|
* Method to insert units. Will rewrite row if unit's id is already in database
|
||||||
*
|
*
|
||||||
|
@ -49,7 +49,6 @@ import java.math.BigDecimal
|
|||||||
import java.math.RoundingMode
|
import java.math.RoundingMode
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class MainViewModel @Inject constructor(
|
class MainViewModel @Inject constructor(
|
||||||
private val userPrefsRepository: UserPreferencesRepository,
|
private val userPrefsRepository: UserPreferencesRepository,
|
||||||
@ -57,7 +56,6 @@ class MainViewModel @Inject constructor(
|
|||||||
private val application: Application,
|
private val application: Application,
|
||||||
private val allUnitsRepository: AllUnitsRepository
|
private val allUnitsRepository: AllUnitsRepository
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
var precision: Int by mutableStateOf(3)
|
var precision: Int by mutableStateOf(3)
|
||||||
private set
|
private set
|
||||||
var separator: Int by mutableStateOf(Separator.SPACES)
|
var separator: Int by mutableStateOf(Separator.SPACES)
|
||||||
|
@ -36,7 +36,6 @@ import kotlin.math.floor
|
|||||||
import kotlin.math.log10
|
import kotlin.math.log10
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
|
|
||||||
object Formatter {
|
object Formatter {
|
||||||
private var nf: NumberFormat = NumberFormat.getInstance(Locale.GERMANY)
|
private var nf: NumberFormat = NumberFormat.getInstance(Locale.GERMANY)
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ import com.sadellie.unitto.data.ALL_LIBRARIES
|
|||||||
import com.sadellie.unitto.screens.common.UnittoLargeTopAppBar
|
import com.sadellie.unitto.screens.common.UnittoLargeTopAppBar
|
||||||
import com.sadellie.unitto.screens.openLink
|
import com.sadellie.unitto.screens.openLink
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Screen with used third party libraries
|
* Screen with used third party libraries
|
||||||
*
|
*
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
package com.sadellie.unitto.screens.main
|
package com.sadellie.unitto.screens.main
|
||||||
|
|
||||||
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
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 com.sadellie.unitto.screens.main.components.TopScreenPart
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(
|
fun MainScreen(
|
||||||
navControllerAction: (String) -> Unit = {},
|
navControllerAction: (String) -> Unit = {},
|
||||||
|
@ -41,7 +41,6 @@ import com.sadellie.unitto.data.KEY_DOT
|
|||||||
import com.sadellie.unitto.data.KEY_NEGATE
|
import com.sadellie.unitto.data.KEY_NEGATE
|
||||||
import com.sadellie.unitto.screens.Formatter
|
import com.sadellie.unitto.screens.Formatter
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keyboard with button that looks like a calculator
|
* Keyboard with button that looks like a calculator
|
||||||
*
|
*
|
||||||
|
@ -29,7 +29,6 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.sadellie.unitto.ui.theme.NumbersTextStyleTitleLarge
|
import com.sadellie.unitto.ui.theme.NumbersTextStyleTitleLarge
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Button for keyboard
|
* Button for keyboard
|
||||||
*
|
*
|
||||||
|
@ -48,7 +48,6 @@ import com.sadellie.unitto.R
|
|||||||
import com.sadellie.unitto.screens.Formatter
|
import com.sadellie.unitto.screens.Formatter
|
||||||
import com.sadellie.unitto.ui.theme.NumbersTextStyleDisplayLarge
|
import com.sadellie.unitto.ui.theme.NumbersTextStyleDisplayLarge
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component for input and output
|
* Component for input and output
|
||||||
*
|
*
|
||||||
|
@ -37,7 +37,6 @@ import androidx.compose.ui.text.style.TextOverflow
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.sadellie.unitto.R
|
import com.sadellie.unitto.R
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Button to select a unit
|
* Button to select a unit
|
||||||
*
|
*
|
||||||
|
@ -27,7 +27,6 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit group header.
|
* Unit group header.
|
||||||
*
|
*
|
||||||
|
@ -36,7 +36,6 @@ import androidx.compose.ui.text.style.TextAlign
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.sadellie.unitto.R
|
import com.sadellie.unitto.R
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholder that can be seen when there are no units found
|
* Placeholder that can be seen when there are no units found
|
||||||
*
|
*
|
||||||
|
@ -151,7 +151,6 @@ fun SettingsScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to reset currently displayed dialog.
|
* Function to reset currently displayed dialog.
|
||||||
*/
|
*/
|
||||||
|
@ -40,7 +40,6 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.sadellie.unitto.R
|
import com.sadellie.unitto.R
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alert dialog that has a list of options in it
|
* Alert dialog that has a list of options in it
|
||||||
*
|
*
|
||||||
@ -59,12 +58,12 @@ fun AlertDialogWithList(
|
|||||||
selectAction: (Int) -> Unit = {},
|
selectAction: (Int) -> Unit = {},
|
||||||
dismissAction: () -> Unit,
|
dismissAction: () -> Unit,
|
||||||
supportText: String? = null,
|
supportText: String? = null,
|
||||||
dismissButtonLabel: String = stringResource(id = R.string.cancel_label)
|
dismissButtonLabel: String = stringResource(R.string.cancel_label)
|
||||||
) {
|
) {
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = dismissAction,
|
onDismissRequest = dismissAction,
|
||||||
title = {
|
title = {
|
||||||
Text(text = title)
|
Text(title)
|
||||||
},
|
},
|
||||||
text = {
|
text = {
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
|
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||||
@ -93,7 +92,6 @@ fun AlertDialogWithList(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An item that represents one option item
|
* An item that represents one option item
|
||||||
*
|
*
|
||||||
@ -117,12 +115,7 @@ private fun CustomDialogContentListItem(
|
|||||||
),
|
),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
RadioButton(
|
RadioButton(selected, onClick)
|
||||||
selected = selected,
|
Text(label)
|
||||||
onClick = onClick
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = label
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,9 @@ import javax.inject.Inject
|
|||||||
class ThemesViewModel @Inject constructor(
|
class ThemesViewModel @Inject constructor(
|
||||||
private val userPrefsRepository: UserPreferencesRepository
|
private val userPrefsRepository: UserPreferencesRepository
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
var themingMode: ThemingMode? by mutableStateOf(null)
|
||||||
|
var enableDynamic by mutableStateOf(false)
|
||||||
|
var enableAmoled by mutableStateOf(false)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see [UserPreferencesRepository.updateThemingMode]
|
* @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.
|
* Collect saved theming options. Used on app launch.
|
||||||
*/
|
*/
|
||||||
fun collectThemeOptions() {
|
private fun collectThemeOptions() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val userPref = userPrefsRepository.userPreferencesFlow.first()
|
val userPref = userPrefsRepository.userPreferencesFlow.first()
|
||||||
themingMode = userPref.themingMode
|
themingMode = userPref.themingMode
|
||||||
@ -77,4 +76,8 @@ class ThemesViewModel @Inject constructor(
|
|||||||
enableAmoled = userPref.enableAmoledTheme
|
enableAmoled = userPref.enableAmoledTheme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
collectThemeOptions()
|
||||||
|
}
|
||||||
}
|
}
|
@ -20,7 +20,6 @@ package com.sadellie.unitto.ui.theme
|
|||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
|
|
||||||
val md_theme_light_primary = Color(0xFF186c31)
|
val md_theme_light_primary = Color(0xFF186c31)
|
||||||
val md_theme_light_onPrimary = Color(0xFFffffff)
|
val md_theme_light_onPrimary = Color(0xFFffffff)
|
||||||
val md_theme_light_primaryContainer = Color(0xFFa3f6ab)
|
val md_theme_light_primaryContainer = Color(0xFFa3f6ab)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user