Update Profile, remove older app version check

This commit is contained in:
Kuba Szczodrzyński 2019-09-21 23:00:15 +02:00
parent 3827aeb9b4
commit 1bdee7857c
3 changed files with 59 additions and 17 deletions

View File

@ -514,7 +514,7 @@ public class App extends androidx.multidex.MultiDexApplication {
} }
} }
if (appConfig.lastAppVersion > BuildConfig.VERSION_CODE) { /*if (appConfig.lastAppVersion > BuildConfig.VERSION_CODE) {
BootReceiver br = new BootReceiver(); BootReceiver br = new BootReceiver();
Intent i = new Intent(); Intent i = new Intent();
//i.putExtra("UserChecked", true); //i.putExtra("UserChecked", true);
@ -522,7 +522,7 @@ public class App extends androidx.multidex.MultiDexApplication {
Toast.makeText(mContext, R.string.warning_older_version_running, Toast.LENGTH_LONG).show(); Toast.makeText(mContext, R.string.warning_older_version_running, Toast.LENGTH_LONG).show();
//Toast.makeText(mContext, "Zaktualizuj aplikację.", Toast.LENGTH_LONG).show(); //Toast.makeText(mContext, "Zaktualizuj aplikację.", Toast.LENGTH_LONG).show();
//System.exit(0); //System.exit(0);
} }*/
if (appConfig == null) { if (appConfig == null) {
appConfig = new AppConfig(this); appConfig = new AppConfig(this);

View File

@ -6,21 +6,14 @@ import android.content.Context
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.util.Log
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import com.google.gson.JsonArray import com.google.gson.JsonArray
import com.google.gson.JsonNull
import com.google.gson.JsonObject import com.google.gson.JsonObject
import im.wangchao.mhttp.Response
import im.wangchao.mhttp.callback.JsonCallbackHandler
import im.wangchao.mhttp.callback.TextCallbackHandler
import im.wangchao.mhttp.internal.exception.ResponseFailException
import pl.szczodrzynski.edziennik.datamodels.Profile import pl.szczodrzynski.edziennik.datamodels.Profile
import pl.szczodrzynski.edziennik.datamodels.Teacher import pl.szczodrzynski.edziennik.datamodels.Teacher
import pl.szczodrzynski.navlib.R
import pl.szczodrzynski.navlib.crc16 import pl.szczodrzynski.navlib.crc16
import pl.szczodrzynski.navlib.getColorFromRes import pl.szczodrzynski.navlib.getColorFromRes
import kotlin.contracts.contract
fun List<Teacher>.byId(id: Long) = firstOrNull { it.id == id } fun List<Teacher>.byId(id: Long) = firstOrNull { it.id == id }
fun List<Teacher>.byNameFirstLast(nameFirstLast: String) = firstOrNull { it.name + " " + it.surname == nameFirstLast } fun List<Teacher>.byNameFirstLast(nameFirstLast: String) = firstOrNull { it.name + " " + it.surname == nameFirstLast }
@ -28,11 +21,19 @@ fun List<Teacher>.byNameLastFirst(nameLastFirst: String) = firstOrNull { it.surn
fun List<Teacher>.byNameFDotLast(nameFDotLast: String) = firstOrNull { it.name + "." + it.surname == nameFDotLast } fun List<Teacher>.byNameFDotLast(nameFDotLast: String) = firstOrNull { it.name + "." + it.surname == nameFDotLast }
fun List<Teacher>.byNameFDotSpaceLast(nameFDotSpaceLast: String) = firstOrNull { it.name + ". " + it.surname == nameFDotSpaceLast } fun List<Teacher>.byNameFDotSpaceLast(nameFDotSpaceLast: String) = firstOrNull { it.name + ". " + it.surname == nameFDotSpaceLast }
fun JsonObject.getString(key: String): String? = get(key).let { if (it.isJsonNull) null else it.asString } fun JsonObject.getBoolean(key: String): Boolean? = get(key)?.let { if (it.isJsonNull) null else it.asBoolean }
fun JsonObject.getInt(key: String): Int? = get(key).let { if (it.isJsonNull) null else it.asInt } fun JsonObject.getString(key: String): String? = get(key)?.let { if (it.isJsonNull) null else it.asString }
fun JsonObject.getLong(key: String): Long? = get(key).let { if (it.isJsonNull) null else it.asLong } fun JsonObject.getInt(key: String): Int? = get(key)?.let { if (it.isJsonNull) null else it.asInt }
fun JsonObject.getJsonObject(key: String): JsonObject? = get(key).let { if (it.isJsonNull) null else it.asJsonObject } fun JsonObject.getLong(key: String): Long? = get(key)?.let { if (it.isJsonNull) null else it.asLong }
fun JsonObject.getJsonArray(key: String): JsonArray? = get(key).let { if (it.isJsonNull) null else it.asJsonArray } fun JsonObject.getJsonObject(key: String): JsonObject? = get(key)?.let { if (it.isJsonNull) null else it.asJsonObject }
fun JsonObject.getJsonArray(key: String): JsonArray? = get(key)?.let { if (it.isJsonNull) null else it.asJsonArray }
fun JsonObject.getBoolean(key: String, defaultValue: Boolean): Boolean = get(key)?.let { if (it.isJsonNull) defaultValue else it.asBoolean } ?: defaultValue
fun JsonObject.getString(key: String, defaultValue: String): String = get(key)?.let { if (it.isJsonNull) defaultValue else it.asString } ?: defaultValue
fun JsonObject.getInt(key: String, defaultValue: Int): Int = get(key)?.let { if (it.isJsonNull) defaultValue else it.asInt } ?: defaultValue
fun JsonObject.getLong(key: String, defaultValue: Long): Long = get(key)?.let { if (it.isJsonNull) defaultValue else it.asLong } ?: defaultValue
fun JsonObject.getJsonObject(key: String, defaultValue: JsonObject): JsonObject = get(key)?.let { if (it.isJsonNull) defaultValue else it.asJsonObject } ?: defaultValue
fun JsonObject.getJsonArray(key: String, defaultValue: JsonArray): JsonArray = get(key)?.let { if (it.isJsonNull) defaultValue else it.asJsonArray } ?: defaultValue
fun CharSequence?.isNotNullNorEmpty(): Boolean { fun CharSequence?.isNotNullNorEmpty(): Boolean {
return this != null && this.isNotEmpty() return this != null && this.isNotEmpty()
@ -53,6 +54,26 @@ fun Bundle?.getString(key: String, defaultValue: String): String {
return this?.getString(key, defaultValue) ?: defaultValue return this?.getString(key, defaultValue) ?: defaultValue
} }
fun changeStringCase(s: String): String {
val delimiters = " '-/"
val sb = StringBuilder()
var capNext = true
for (ch in s.toCharArray()) {
var c = ch
c = if (capNext)
Character.toUpperCase(c)
else
Character.toLowerCase(c)
sb.append(c)
capNext = delimiters.indexOf(c) >= 0
}
return sb.toString()
}
fun buildFullName(firstName: String?, lastName: String?): String {
return changeStringCase("$firstName $lastName").trim()
}
fun colorFromName(context: Context, name: String?): Int { fun colorFromName(context: Context, name: String?): Int {
var crc = crc16(name ?: "") var crc = crc16(name ?: "")
crc = (crc and 0xff) or (crc shr 8) crc = (crc and 0xff) or (crc shr 8)

View File

@ -47,11 +47,26 @@ open class Profile : IDrawerProfile {
var empty = true var empty = true
var archived = false var archived = false
/**
* The name of the student.
* This doesn't change, no matter if it's a parent or student account.
*/
var studentNameLong: String? = null var studentNameLong: String? = null
var studentNameShort: String? = null var studentNameShort: String? = null
/**
* The student's number in the class register.
*/
var studentNumber = -1 var studentNumber = -1
var studentData: JsonObject? = null var studentData: JsonObject? = null
/**
* A full name of the account owner.
* 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 registration = REGISTRATION_UNSPECIFIED var registration = REGISTRATION_UNSPECIFIED
var gradeColorMode = COLOR_MODE_WEIGHTED var gradeColorMode = COLOR_MODE_WEIGHTED
@ -61,7 +76,7 @@ open class Profile : IDrawerProfile {
var currentSemester = 1 var currentSemester = 1
var attendancePercentage: Float = 0.toFloat() var attendancePercentage: Float = 0.0f
var dateSemester1Start: Date? = null var dateSemester1Start: Date? = null
var dateSemester2Start: Date? = null var dateSemester2Start: Date? = null
@ -192,6 +207,12 @@ open class Profile : IDrawerProfile {
getImageHolder(imageView.context).applyTo(imageView) getImageHolder(imageView.context).applyTo(imageView)
} }
fun hasStudentData(key: String): Boolean {
if (studentData == null)
return false
return studentData?.has(key) ?: false
}
fun getStudentData(key: String, defaultValue: String?): String? { fun getStudentData(key: String, defaultValue: String?): String? {
if (studentData == null) if (studentData == null)
return defaultValue return defaultValue
@ -229,7 +250,7 @@ open class Profile : IDrawerProfile {
return element?.asBoolean ?: defaultValue return element?.asBoolean ?: defaultValue
} }
fun putStudentData(key: String, value: String) { fun putStudentData(key: String, value: String?) {
if (studentData == null) if (studentData == null)
studentData = JsonObject() studentData = JsonObject()
studentData!!.addProperty(key, value) studentData!!.addProperty(key, value)