[APIv2/DB] Add profile account name, class, school year fields.

This commit is contained in:
Kuba Szczodrzyński 2019-10-27 18:03:58 +01:00
parent 10c439afad
commit 054426c9cc
3 changed files with 39 additions and 4 deletions

View File

@ -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 {

View File

@ -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()

View File

@ -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