mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
Enable Time Zones
This commit is contained in:
parent
fbe980ca94
commit
1279a8acad
@ -47,10 +47,10 @@ import com.sadellie.unitto.core.ui.common.open
|
|||||||
import com.sadellie.unitto.core.ui.common.rememberUnittoDrawerState
|
import com.sadellie.unitto.core.ui.common.rememberUnittoDrawerState
|
||||||
import com.sadellie.unitto.core.ui.model.DrawerItems
|
import com.sadellie.unitto.core.ui.model.DrawerItems
|
||||||
import com.sadellie.unitto.core.ui.pushDynamicShortcut
|
import com.sadellie.unitto.core.ui.pushDynamicShortcut
|
||||||
import com.sadellie.unitto.core.ui.theme.TypographySystem
|
|
||||||
import com.sadellie.unitto.core.ui.theme.TypographyUnitto
|
|
||||||
import com.sadellie.unitto.core.ui.theme.DarkThemeColors
|
import com.sadellie.unitto.core.ui.theme.DarkThemeColors
|
||||||
import com.sadellie.unitto.core.ui.theme.LightThemeColors
|
import com.sadellie.unitto.core.ui.theme.LightThemeColors
|
||||||
|
import com.sadellie.unitto.core.ui.theme.TypographySystem
|
||||||
|
import com.sadellie.unitto.core.ui.theme.TypographyUnitto
|
||||||
import com.sadellie.unitto.data.userprefs.AppPreferences
|
import com.sadellie.unitto.data.userprefs.AppPreferences
|
||||||
import io.github.sadellie.themmo.Themmo
|
import io.github.sadellie.themmo.Themmo
|
||||||
import io.github.sadellie.themmo.rememberThemmoController
|
import io.github.sadellie.themmo.rememberThemmoController
|
||||||
@ -79,23 +79,15 @@ internal fun UnittoApp(prefs: AppPreferences) {
|
|||||||
|
|
||||||
val shortcutsScope = rememberCoroutineScope()
|
val shortcutsScope = rememberCoroutineScope()
|
||||||
|
|
||||||
val tabs by remember(prefs.enableToolsExperiment) {
|
val tabs by remember {
|
||||||
derivedStateOf {
|
mutableStateOf(
|
||||||
if (prefs.enableToolsExperiment) {
|
listOf(
|
||||||
listOf(
|
DrawerItems.Calculator,
|
||||||
DrawerItems.Calculator,
|
DrawerItems.Converter,
|
||||||
DrawerItems.Converter,
|
DrawerItems.DateDifference,
|
||||||
DrawerItems.DateDifference,
|
DrawerItems.TimeZones
|
||||||
DrawerItems.TimeZones,
|
)
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
listOf(
|
|
||||||
DrawerItems.Calculator,
|
|
||||||
DrawerItems.Converter,
|
|
||||||
DrawerItems.DateDifference,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||||
|
@ -106,15 +106,15 @@ val TOP_LEVEL_DESTINATIONS by lazy {
|
|||||||
TopLevelDestinations.Calculator,
|
TopLevelDestinations.Calculator,
|
||||||
TopLevelDestinations.Converter,
|
TopLevelDestinations.Converter,
|
||||||
TopLevelDestinations.DateCalculator,
|
TopLevelDestinations.DateCalculator,
|
||||||
// TopLevelDestinations.TimeZone,
|
TopLevelDestinations.TimeZone,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only routes, not graphs!
|
// Only routes, not graphs!
|
||||||
val TOP_LEVEL_START_ROUTES by lazy {
|
val TOP_LEVEL_START_ROUTES by lazy {
|
||||||
listOf(
|
listOf(
|
||||||
CONVERTER_START,
|
|
||||||
CALCULATOR_START,
|
CALCULATOR_START,
|
||||||
|
CONVERTER_START,
|
||||||
DATE_CALCULATOR_START,
|
DATE_CALCULATOR_START,
|
||||||
TIME_ZONE_START,
|
TIME_ZONE_START,
|
||||||
)
|
)
|
||||||
|
@ -45,17 +45,16 @@ class UnittoDatabaseModule {
|
|||||||
return unittoDatabase.calculatorHistoryDao()
|
return unittoDatabase.calculatorHistoryDao()
|
||||||
}
|
}
|
||||||
|
|
||||||
// For some reason this fucks up the migration
|
/**
|
||||||
// /**
|
* Tells Hilt to use this method to get [TimeZoneDao]
|
||||||
// * Tells Hilt to use this method to get [TimeZoneDao]
|
*
|
||||||
// *
|
* @param unittoDatabase Database for which we need DAO
|
||||||
// * @param unittoDatabase Database for which we need DAO
|
* @return Singleton of [TimeZoneDao]
|
||||||
// * @return Singleton of [TimeZoneDao]
|
*/
|
||||||
// */
|
@Provides
|
||||||
// @Provides
|
fun provideTimeZoneDao(unittoDatabase: UnittoDatabase): TimeZoneDao {
|
||||||
// fun provideTimeZoneDao(unittoDatabase: UnittoDatabase): TimeZoneDao {
|
return unittoDatabase.timeZoneDao()
|
||||||
// return unittoDatabase.timeZoneDao()
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideCurrencyRatesDao(unittoDatabase: UnittoDatabase): CurrencyRatesDao {
|
fun provideCurrencyRatesDao(unittoDatabase: UnittoDatabase): CurrencyRatesDao {
|
||||||
|
@ -19,62 +19,48 @@
|
|||||||
package com.sadellie.unitto.data.timezone
|
package com.sadellie.unitto.data.timezone
|
||||||
|
|
||||||
import com.sadellie.unitto.data.common.lev
|
import com.sadellie.unitto.data.common.lev
|
||||||
|
import com.sadellie.unitto.data.database.TimeZoneDao
|
||||||
|
import com.sadellie.unitto.data.database.TimeZoneEntity
|
||||||
import com.sadellie.unitto.data.model.UnittoTimeZone
|
import com.sadellie.unitto.data.model.UnittoTimeZone
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class TimeZonesRepository @Inject constructor() {
|
class TimeZonesRepository @Inject constructor(
|
||||||
|
private val dao: TimeZoneDao
|
||||||
|
) {
|
||||||
private val allTimeZones: HashMap<String, UnittoTimeZone> = hashMapOf(
|
private val allTimeZones: HashMap<String, UnittoTimeZone> = hashMapOf(
|
||||||
"zulu_time_zone" to UnittoTimeZone(id = "zulu_time_zone", nameRes = "Zulu Time Zone", offsetSeconds = 0)
|
"zulu_time_zone" to UnittoTimeZone(id = "zulu_time_zone", nameRes = "Zulu Time Zone", offsetSeconds = 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
val favoriteTimeZones: MutableStateFlow<List<UnittoTimeZone>> = MutableStateFlow(emptyList())
|
val favoriteTimeZones: Flow<List<UnittoTimeZone>> = dao
|
||||||
|
.getAll()
|
||||||
|
.map { list ->
|
||||||
|
val favorites = mutableListOf<UnittoTimeZone>()
|
||||||
|
list.forEach { entity ->
|
||||||
|
val foundTimeZone = allTimeZones[entity.id] ?: return@forEach
|
||||||
|
val mapped = foundTimeZone.copy(
|
||||||
|
position = entity.position
|
||||||
|
)
|
||||||
|
favorites.add(mapped)
|
||||||
|
}
|
||||||
|
|
||||||
// UNCOMMENT FOR RELEASE
|
favorites
|
||||||
// val favoriteTimeZones: Flow<List<UnittoTimeZone>> = dao
|
}
|
||||||
// .getAll()
|
|
||||||
// .map { list ->
|
|
||||||
// val favorites = mutableListOf<UnittoTimeZone>()
|
|
||||||
// list.forEach { entity ->
|
|
||||||
// val foundTimeZone = allTimeZones[entity.id] ?: return@forEach
|
|
||||||
// val mapped = foundTimeZone.copy(
|
|
||||||
// position = entity.position
|
|
||||||
// )
|
|
||||||
// favorites.add(mapped)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// favorites
|
|
||||||
// }
|
|
||||||
|
|
||||||
suspend fun swapTimeZones(from: String, to: String) = withContext(Dispatchers.IO) {
|
suspend fun swapTimeZones(from: String, to: String) = withContext(Dispatchers.IO) {
|
||||||
// UNCOMMENT FOR RELEASE
|
dao.swap(from, to)
|
||||||
// dao.swap(from, to)
|
|
||||||
|
|
||||||
favoriteTimeZones.update {
|
|
||||||
val fromIndex = it.indexOfFirst { it.id == from }
|
|
||||||
val toIndex = it.indexOfFirst { it.id == to }
|
|
||||||
|
|
||||||
it
|
|
||||||
.toMutableList()
|
|
||||||
.apply {
|
|
||||||
add(toIndex, removeAt(fromIndex))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return@withContext
|
return@withContext
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun delete(timeZone: UnittoTimeZone) = withContext(Dispatchers.IO) {
|
suspend fun delete(timeZone: UnittoTimeZone) = withContext(Dispatchers.IO) {
|
||||||
// UNCOMMENT FOR RELEASE
|
// Only PrimaryKey is needed
|
||||||
// // Only PrimaryKey is needed
|
dao.remove(TimeZoneEntity(id = timeZone.id, position = 0))
|
||||||
// dao.remove(TimeZoneEntity(id = timeZone.id, position = 0))
|
|
||||||
|
|
||||||
favoriteTimeZones.update { it.minus(timeZone) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun filterAllTimeZones(searchQuery: String): List<UnittoTimeZone> =
|
suspend fun filterAllTimeZones(searchQuery: String): List<UnittoTimeZone> =
|
||||||
@ -118,12 +104,11 @@ class TimeZonesRepository @Inject constructor() {
|
|||||||
|
|
||||||
suspend fun addToFavorites(timeZone: UnittoTimeZone) {
|
suspend fun addToFavorites(timeZone: UnittoTimeZone) {
|
||||||
// UNCOMMENT FOR RELEASE
|
// UNCOMMENT FOR RELEASE
|
||||||
// dao.insert(
|
dao.insert(
|
||||||
// TimeZoneEntity(
|
TimeZoneEntity(
|
||||||
// id = timeZone.id,
|
id = timeZone.id,
|
||||||
// position = System.currentTimeMillis().toInt()
|
position = System.currentTimeMillis().toInt()
|
||||||
// )
|
)
|
||||||
// )
|
)
|
||||||
favoriteTimeZones.update { it.plus(timeZone) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,8 @@ import com.sadellie.unitto.feature.timezone.TimeZoneRoute
|
|||||||
import java.time.ZonedDateTime
|
import java.time.ZonedDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
private val graph = TopLevelDestinations.TimeZone.start
|
private val graph = TopLevelDestinations.TimeZone.graph
|
||||||
private val start: String = TopLevelDestinations.TimeZone.graph
|
private val start = TopLevelDestinations.TimeZone.start
|
||||||
private const val ADD_TIME_ZONE_ROUTE = "ADD_TIME_ZONE_ROUTE"
|
private const val ADD_TIME_ZONE_ROUTE = "ADD_TIME_ZONE_ROUTE"
|
||||||
private const val USER_TIME_ARG = "USER_TIME_ARG"
|
private const val USER_TIME_ARG = "USER_TIME_ARG"
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@ include(":feature:timezone")
|
|||||||
include(":feature:settings")
|
include(":feature:settings")
|
||||||
include(":data:userprefs")
|
include(":data:userprefs")
|
||||||
include(":data:licenses")
|
include(":data:licenses")
|
||||||
// include(":data:epoch")
|
|
||||||
include(":data:calculator")
|
include(":data:calculator")
|
||||||
include(":data:database")
|
include(":data:database")
|
||||||
include(":data:model")
|
include(":data:model")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user