Skip to content

Commit

Permalink
feat/style: include modify all records measure units and change icon …
Browse files Browse the repository at this point in the history
…for release
  • Loading branch information
cromega08 committed Dec 20, 2024
1 parent b9d6cc5 commit 7c81f33
Show file tree
Hide file tree
Showing 45 changed files with 820 additions and 222 deletions.
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ class UserInfo(

var language: Languages
var darkTheme: Boolean
var defaultMetricSystemUnitId: Int

init {
try { readJSONFile() }
catch (e: Exception) {
catch (e: Exception)
{
Locale.getDefault()
updateUserInfo(jsonString = generateDefaultUserInfoJSON()) }
updateUserInfo(jsonString = generateDefaultUserInfoJSON())
}
finally {
val json: JSONObject = readJSONFile()
language =
Expand All @@ -28,6 +31,7 @@ class UserInfo(
localeAcronym = json.get("language") as String
)
darkTheme = json.get("dark_theme") as Boolean
defaultMetricSystemUnitId = json.get("default_metric_system_unit_id") as Int
}
}

Expand All @@ -40,7 +44,7 @@ class UserInfo(
val selectedLanguage: Languages =
Languages.findFromLocaleAcronym(localeAcronym = locale)

return """{"language":"${selectedLanguage.localeAcronym}","dark_theme":false}"""
return """{"language":"${selectedLanguage.localeAcronym}","dark_theme":false,"default_metric_system_unit_id":1}"""
}

private fun updateUserInfo(jsonString: String) =
Expand All @@ -57,5 +61,5 @@ class UserInfo(
}

override fun toString(): String =
"""{"language":"${language.localeAcronym}","dark_theme":$darkTheme}"""
"""{"language":"${language.localeAcronym}","dark_theme":$darkTheme,"default_metric_system_unit_id":$defaultMetricSystemUnitId}"""
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import cromega.studio.measurepedia.data.database.tables.instances.MetricSystemsU
import cromega.studio.measurepedia.data.database.tables.instances.PersonsTable
import cromega.studio.measurepedia.data.database.tables.instances.RecordsTable
import cromega.studio.measurepedia.data.models.instances.Field
import cromega.studio.measurepedia.data.models.instances.MetricSystemUnit
import cromega.studio.measurepedia.extensions.extractIds
import cromega.studio.measurepedia.extensions.isNeitherNullOrEmpty
import cromega.studio.measurepedia.extensions.isNotNull
Expand Down Expand Up @@ -42,7 +41,7 @@ class FieldsManager(
}
}

fun insert(name: String, bodyPartId: Int, active: Boolean? = null)
fun insert(name: String, bodyPartId: Int, active: Boolean? = null, defaultMetricSystemUnitId: Int)
{
val insertedFieldId: Long = fieldsTable
.insert(
Expand All @@ -51,8 +50,6 @@ class FieldsManager(
active = active
)

val defaultMetricSystemUnit: MetricSystemUnit = metricSystemsUnitsTable.readAll()[0]

if (insertedFieldId > 0)
{
personsTable
Expand All @@ -62,7 +59,7 @@ class FieldsManager(
.insert(
personId = person.id,
fieldId = insertedFieldId.toInt(),
metricSystemUnitId = defaultMetricSystemUnit.id
metricSystemUnitId = defaultMetricSystemUnitId
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@ class MetricSystemsUnitsManager(
abbreviation = abbreviation
)

fun delete(id: Int)
fun delete(id: Int, defaultMetricSystemUnitId: Int)
{
val metricSystemUnits: List<MetricSystemUnit> =
metricSystemsUnitsTable.readAll()

val records: List<Record> =
recordsTable.readAll()

val defaultMetricSystemUnit: MetricSystemUnit =
metricSystemUnits.find { it.id != id }!!

records
.forEach { record ->
if (record.metricSystemUnitId == id)
Expand All @@ -46,13 +40,13 @@ class MetricSystemsUnitsManager(
personId = record.personId,
fieldId = record.fieldId,
measure = record.measure,
metricSystemUnitId = defaultMetricSystemUnit.id
metricSystemUnitId = defaultMetricSystemUnitId
)
}

metricSystemsUnitsTable.delete(id = id)
}

fun deleteByIds(ids: List<Int>) =
ids.forEach { metricSystemUnitIndex -> delete(id = metricSystemUnitIndex) }
fun deleteByIds(ids: List<Int>, defaultMetricSystemUnitId: Int) =
ids.forEach { metricSystemUnitIndex -> delete(id = metricSystemUnitIndex, defaultMetricSystemUnitId = defaultMetricSystemUnitId) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import cromega.studio.measurepedia.data.database.tables.instances.FieldsTable
import cromega.studio.measurepedia.data.database.tables.instances.MetricSystemsUnitsTable
import cromega.studio.measurepedia.data.database.tables.instances.PersonsTable
import cromega.studio.measurepedia.data.database.tables.instances.RecordsTable
import cromega.studio.measurepedia.data.models.instances.Field
import cromega.studio.measurepedia.data.models.instances.MetricSystemUnit
import cromega.studio.measurepedia.data.models.instances.Person
import cromega.studio.measurepedia.enums.DateOrder
import cromega.studio.measurepedia.enums.MeasuredOrder
Expand Down Expand Up @@ -53,7 +51,7 @@ class PersonsManager(
}
}

fun insert(name: String, alias: String? = null, updated: Date? = null)
fun insert(name: String, alias: String? = null, updated: Date? = null, defaultMetricSystemUnitId: Int)
{
val personInsertResult: Int =
personsTable
Expand All @@ -64,21 +62,16 @@ class PersonsManager(
)
.toInt()

val personInsertedCorrectly: Boolean = personInsertResult > 0

if (personInsertedCorrectly)
{
val metricSystemUnitDefault: MetricSystemUnit = metricSystemsUnitsTable.readAll()[0]
val fields: List<Field> = fieldsTable.readAll()

fields.forEach { field ->
recordsTable.insert(
personId = personInsertResult,
fieldId = field.id,
metricSystemUnitId = metricSystemUnitDefault.id
)
}
}
if (personInsertResult > 0)
fieldsTable
.readAll()
.forEach { field ->
recordsTable.insert(
personId = personInsertResult,
fieldId = field.id,
metricSystemUnitId = defaultMetricSystemUnitId
)
}
}

fun update(id: Int, name: String, alias: String? = null, updated: Date? = null, measured: Boolean? = null) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,45 @@ class RecordsManager(
metricSystemUnitId = metricSystemUnitId
)

fun updateRecordsRequiringDefaultMetricSystemUnitId(metricSystemUnitId: Int)
{
val records: List<Record> = recordsTable.readAll()

records
.forEach { record ->
if (record.metricSystemUnitId == 0)
{
record.metricSystemUnitId = metricSystemUnitId

update(
id = record.id,
personId = record.personId,
fieldId = record.fieldId,
measure = record.measure,
metricSystemUnitId = record.metricSystemUnitId
)
}
}
}

fun updateAllRecordsMetricSystemUnitId(metricSystemUnitId: Int)
{
val records: List<Record> = recordsTable.readAll()

records
.forEach { record ->
record.metricSystemUnitId = metricSystemUnitId

update(
id = record.id,
personId = record.personId,
fieldId = record.fieldId,
measure = record.measure,
metricSystemUnitId = record.metricSystemUnitId
)
}
}

fun delete(id: Int) = recordsTable.delete(id = id)

fun deleteByFieldsIds(fieldIds: List<Int>) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class FieldsActivity : Activity<FieldsViewModel, FieldsScreen>()
FieldsScreen(
viewModel = viewModel,
resources = resources,
darkTheme = userInfo.darkTheme,
showToastFunction = ::showInsufficientToast
)
}
Expand Down
Loading

0 comments on commit 7c81f33

Please sign in to comment.