mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-19 05:16:56 -06:00
[API] Fix config not reading from DB. Do not sync device if not changed.
This commit is contained in:
parent
f9c7492726
commit
1abb9ac378
@ -40,6 +40,11 @@ class Config(val db: AppDb) : CoroutineScope, AbstractConfig {
|
|||||||
get() { mDataVersion = mDataVersion ?: values.get("dataVersion", 0); return mDataVersion ?: 0 }
|
get() { mDataVersion = mDataVersion ?: values.get("dataVersion", 0); return mDataVersion ?: 0 }
|
||||||
set(value) { set("dataVersion", value); mDataVersion = value }
|
set(value) { set("dataVersion", value); mDataVersion = value }
|
||||||
|
|
||||||
|
private var mHash: String? = null
|
||||||
|
var hash: String
|
||||||
|
get() { mHash = mHash ?: values.get("hash", ""); return mHash ?: "" }
|
||||||
|
set(value) { set("hash", value); mHash = value }
|
||||||
|
|
||||||
private var mAppVersion: Int? = null
|
private var mAppVersion: Int? = null
|
||||||
var appVersion: Int
|
var appVersion: Int
|
||||||
get() { mAppVersion = mAppVersion ?: values.get("appVersion", BuildConfig.VERSION_CODE); return mAppVersion ?: BuildConfig.VERSION_CODE }
|
get() { mAppVersion = mAppVersion ?: values.get("appVersion", BuildConfig.VERSION_CODE); return mAppVersion ?: BuildConfig.VERSION_CODE }
|
||||||
@ -90,11 +95,11 @@ class Config(val db: AppDb) : CoroutineScope, AbstractConfig {
|
|||||||
ConfigMigration(app, this)
|
ConfigMigration(app, this)
|
||||||
}
|
}
|
||||||
fun getFor(profileId: Int): ProfileConfig {
|
fun getFor(profileId: Int): ProfileConfig {
|
||||||
return profileConfigs[profileId] ?: ProfileConfig(db, profileId, rawEntries)
|
return profileConfigs[profileId] ?: ProfileConfig(db, profileId, db.configDao().getAllNow(profileId)).also {
|
||||||
}
|
profileConfigs[profileId] = it
|
||||||
fun forProfile(): ProfileConfig {
|
}
|
||||||
return profileConfigs[App.profileId] ?: ProfileConfig(db, App.profileId, rawEntries)
|
|
||||||
}
|
}
|
||||||
|
fun forProfile() = getFor(App.profileId)
|
||||||
|
|
||||||
fun setProfile(profileId: Int) {
|
fun setProfile(profileId: Int) {
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,11 @@ class ProfileConfig(val db: AppDb, val profileId: Int, rawEntries: List<ConfigEn
|
|||||||
get() { mDataVersion = mDataVersion ?: values.get("dataVersion", 0); return mDataVersion ?: 0 }
|
get() { mDataVersion = mDataVersion ?: values.get("dataVersion", 0); return mDataVersion ?: 0 }
|
||||||
set(value) { set("dataVersion", value); mDataVersion = value }
|
set(value) { set("dataVersion", value); mDataVersion = value }
|
||||||
|
|
||||||
|
private var mHash: String? = null
|
||||||
|
var hash: String
|
||||||
|
get() { mHash = mHash ?: values.get("hash", ""); return mHash ?: "" }
|
||||||
|
set(value) { set("hash", value); mHash = value }
|
||||||
|
|
||||||
init {
|
init {
|
||||||
rawEntries.toHashMap(profileId, values)
|
rawEntries.toHashMap(profileId, values)
|
||||||
/*if (dataVersion < DATA_VERSION)
|
/*if (dataVersion < DATA_VERSION)
|
||||||
|
@ -21,6 +21,7 @@ import pl.szczodrzynski.edziennik.data.api.szkolny.response.WebPushResponse
|
|||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||||
|
import pl.szczodrzynski.edziennik.md5
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
@ -61,25 +62,45 @@ class SzkolnyApi(val app: App) {
|
|||||||
|
|
||||||
val response = api.serverSync(ServerSyncRequest(
|
val response = api.serverSync(ServerSyncRequest(
|
||||||
deviceId = app.deviceId,
|
deviceId = app.deviceId,
|
||||||
device = ServerSyncRequest.Device(
|
device = run {
|
||||||
osType = "Android",
|
val config = app.config
|
||||||
osVersion = Build.VERSION.RELEASE,
|
val device = ServerSyncRequest.Device(
|
||||||
hardware = "${Build.MANUFACTURER} ${Build.MODEL}",
|
osType = "Android",
|
||||||
pushToken = app.config.sync.tokenApp,
|
osVersion = Build.VERSION.RELEASE,
|
||||||
appVersion = BuildConfig.VERSION_NAME,
|
hardware = "${Build.MANUFACTURER} ${Build.MODEL}",
|
||||||
appType = BuildConfig.BUILD_TYPE,
|
pushToken = app.config.sync.tokenApp,
|
||||||
appVersionCode = BuildConfig.VERSION_CODE,
|
appVersion = BuildConfig.VERSION_NAME,
|
||||||
syncInterval = app.config.sync.interval
|
appType = BuildConfig.BUILD_TYPE,
|
||||||
),
|
appVersionCode = BuildConfig.VERSION_CODE,
|
||||||
|
syncInterval = app.config.sync.interval
|
||||||
|
)
|
||||||
|
device.toString().md5().let {
|
||||||
|
if (it == config.hash)
|
||||||
|
null
|
||||||
|
else {
|
||||||
|
config.hash = it
|
||||||
|
device
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
userCodes = profiles.map { it.userCode },
|
userCodes = profiles.map { it.userCode },
|
||||||
users = profiles.map { profile ->
|
users = profiles.mapNotNull { profile ->
|
||||||
ServerSyncRequest.User(
|
val config = app.config.getFor(profile.id)
|
||||||
|
val user = ServerSyncRequest.User(
|
||||||
profile.userCode,
|
profile.userCode,
|
||||||
profile.studentNameLong ?: "",
|
profile.studentNameLong ?: "",
|
||||||
profile.studentNameShort ?: "",
|
profile.studentNameShort ?: "",
|
||||||
profile.loginStoreType,
|
profile.loginStoreType,
|
||||||
teams.filter { it.profileId == profile.id }.map { it.code }
|
teams.filter { it.profileId == profile.id }.map { it.code }
|
||||||
)
|
)
|
||||||
|
user.toString().md5().let {
|
||||||
|
if (it == config.hash)
|
||||||
|
null
|
||||||
|
else {
|
||||||
|
config.hash = it
|
||||||
|
user
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
notifications = notifications.map { ServerSyncRequest.Notification(it.profileName ?: "", it.type, it.text) }
|
notifications = notifications.map { ServerSyncRequest.Notification(it.profileName ?: "", it.type, it.text) }
|
||||||
)).execute().body()
|
)).execute().body()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user