refactor: add more debugging logs.

Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
KaiserBh 2024-01-10 18:48:13 +11:00
parent d1a55ed7fe
commit 646ceaf4cb
No known key found for this signature in database
GPG Key ID: 14D73B142042BBA9

View File

@ -114,23 +114,39 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
val drive = googleDriveService.driveService
if (drive == null) {
logcat(LogPriority.ERROR) { "Google Drive service not initialized" }
logcat(LogPriority.DEBUG) { "Google Drive service not initialized" }
throw Exception(context.stringResource(MR.strings.google_drive_not_signed_in))
}
val fileList = getAppDataFileList(drive)
if (fileList.isEmpty()) {
logcat(LogPriority.INFO) { "No files found in app data" }
return null
}
val gdriveFileId = fileList[0].id
logcat(LogPriority.DEBUG) { "Google Drive File ID: $gdriveFileId" }
val outputStream = ByteArrayOutputStream()
try {
drive.files().get(gdriveFileId).executeMediaAndDownloadTo(outputStream)
logcat(LogPriority.DEBUG) { "File downloaded successfully" }
} catch (e: Exception) {
logcat(LogPriority.ERROR) { "Error downloading file: ${e.message}" }
return null
}
return withContext(Dispatchers.IO) {
try {
val gzipInputStream = GZIPInputStream(ByteArrayInputStream(outputStream.toByteArray()))
val gson = Gson()
gson.fromJson(gzipInputStream.reader(Charsets.UTF_8), SyncData::class.java)
val syncData = gson.fromJson(gzipInputStream.reader(Charsets.UTF_8), SyncData::class.java)
logcat(LogPriority.DEBUG) { "JSON deserialized successfully" }
syncData
} catch (e: Exception) {
logcat(LogPriority.ERROR) { "Failed to convert json to sync data: ${e.message}" }
throw Exception(e.message)
}
}
}