From 054426c9cc645d1a03a40930d0fb144441ff0da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sun, 27 Oct 2019 18:03:58 +0100 Subject: [PATCH] [APIv2/DB] Add profile account name, class, school year fields. --- .../pl/szczodrzynski/edziennik/Extensions.kt | 26 ++++++++++++++++++- .../edziennik/data/db/AppDb.java | 13 ++++++++-- .../data/db/modules/profiles/Profile.kt | 4 ++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt index 5edf5fc4..ea33eaa1 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt @@ -69,6 +69,21 @@ fun Bundle?.getString(key: String, defaultValue: String): String { return this?.getString(key, defaultValue) ?: defaultValue } +fun String.fixName(): String { + return this.fixWhiteSpaces().toProperCase() +} + +fun String.toProperCase(): String = changeStringCase(this) + +fun String.swapFirstLastName(): String { + return this.split(" ").let { + if (it.size > 1) + it[1]+" "+it[0] + else + it[0] + } +} + fun changeStringCase(s: String): String { val delimiters = " '-/" val sb = StringBuilder() @@ -86,7 +101,16 @@ fun changeStringCase(s: String): String { } fun buildFullName(firstName: String?, lastName: String?): String { - return changeStringCase("$firstName $lastName").trim() + return "$firstName $lastName".fixName() +} + +fun String.getShortName(): String { + return split(" ").let { + if (it.size > 1) + "${it[0]} ${it[1][0]}." + else + it[0] + } } fun colorFromName(context: Context, name: String?): Int { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.java b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.java index d43d5301..800dcc69 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.java @@ -103,7 +103,7 @@ import pl.szczodrzynski.edziennik.utils.models.Date; Classroom.class, NoticeType.class, AttendanceType.class, - Metadata.class}, version = 62) + Metadata.class}, version = 63) @TypeConverters({ ConverterTime.class, ConverterDate.class, @@ -721,6 +721,14 @@ public abstract class AppDb extends RoomDatabase { ")"); } }; + private static final Migration MIGRATION_62_63 = new Migration(62, 63) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase database) { + database.execSQL("ALTER TABLE profiles ADD COLUMN accountNameLong TEXT DEFAULT NULL"); + database.execSQL("ALTER TABLE profiles ADD COLUMN studentClassName TEXT DEFAULT NULL"); + database.execSQL("ALTER TABLE profiles ADD COLUMN studentSchoolYear TEXT DEFAULT NULL"); + } + }; public static AppDb getDatabase(final Context context) { @@ -780,7 +788,8 @@ public abstract class AppDb extends RoomDatabase { MIGRATION_58_59, MIGRATION_59_60, MIGRATION_60_61, - MIGRATION_61_62 + MIGRATION_61_62, + MIGRATION_62_63 ) .allowMainThreadQueries() //.fallbackToDestructiveMigration() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/profiles/Profile.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/profiles/Profile.kt index 82d07f86..fabfef68 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/profiles/Profile.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/profiles/Profile.kt @@ -56,9 +56,11 @@ open class Profile : IDrawerProfile { * If null, then it's a student account. * If not null, then it's a parent account with this name. */ - @Ignore var accountNameLong: String? = null + var studentClassName: String? = null + var studentSchoolYear: String? = null + var registration = REGISTRATION_UNSPECIFIED var gradeColorMode = COLOR_MODE_WEIGHTED