From 8ce59a30988cb01ad4a7d3ad49d3ed7fdbca88a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Thu, 14 Jan 2021 18:36:32 +0100 Subject: [PATCH] Use userLoginId to differentiate saved mobiles devices between accounts (#1076) --- .../java/io/github/wulkanowy/data/db/dao/MobileDeviceDao.kt | 4 ++-- .../java/io/github/wulkanowy/data/db/entities/MobileDevice.kt | 2 +- .../io/github/wulkanowy/data/mappers/MobileDeviceMapper.kt | 2 +- .../wulkanowy/data/repositories/MobileDeviceRepository.kt | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/data/db/dao/MobileDeviceDao.kt b/app/src/main/java/io/github/wulkanowy/data/db/dao/MobileDeviceDao.kt index 8baba2c30..081e859a5 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/dao/MobileDeviceDao.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/dao/MobileDeviceDao.kt @@ -8,6 +8,6 @@ import kotlinx.coroutines.flow.Flow @Dao interface MobileDeviceDao : BaseDao { - @Query("SELECT * FROM MobileDevices WHERE student_id = :studentId ORDER BY date DESC") - fun loadAll(studentId: Int): Flow> + @Query("SELECT * FROM MobileDevices WHERE student_id = :userLoginId ORDER BY date DESC") + fun loadAll(userLoginId: Int): Flow> } diff --git a/app/src/main/java/io/github/wulkanowy/data/db/entities/MobileDevice.kt b/app/src/main/java/io/github/wulkanowy/data/db/entities/MobileDevice.kt index 9d8f11625..83d82c0b9 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/entities/MobileDevice.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/entities/MobileDevice.kt @@ -10,7 +10,7 @@ import java.time.LocalDateTime data class MobileDevice( @ColumnInfo(name = "student_id") - val studentId: Int, + val userLoginId: Int, @ColumnInfo(name = "device_id") val deviceId: Int, diff --git a/app/src/main/java/io/github/wulkanowy/data/mappers/MobileDeviceMapper.kt b/app/src/main/java/io/github/wulkanowy/data/mappers/MobileDeviceMapper.kt index 80f9e0549..f0c375bfa 100644 --- a/app/src/main/java/io/github/wulkanowy/data/mappers/MobileDeviceMapper.kt +++ b/app/src/main/java/io/github/wulkanowy/data/mappers/MobileDeviceMapper.kt @@ -8,7 +8,7 @@ import io.github.wulkanowy.sdk.pojo.Device as SdkDevice fun List.mapToEntities(semester: Semester) = map { MobileDevice( - studentId = semester.studentId, + userLoginId = semester.studentId, date = it.createDate, deviceId = it.id, name = it.name diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/MobileDeviceRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/MobileDeviceRepository.kt index d77dcccac..7e83ef7d5 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/MobileDeviceRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/MobileDeviceRepository.kt @@ -27,7 +27,7 @@ class MobileDeviceRepository @Inject constructor( fun getDevices(student: Student, semester: Semester, forceRefresh: Boolean) = networkBoundResource( shouldFetch = { it.isEmpty() || forceRefresh || refreshHelper.isShouldBeRefreshed(getRefreshKey(cacheKey, student)) }, - query = { mobileDb.loadAll(semester.studentId) }, + query = { mobileDb.loadAll(student.userLoginId.takeIf { it != 0 } ?: student.studentId) }, fetch = { sdk.init(student).switchDiary(semester.diaryId, semester.schoolYear) .getRegisteredDevices()