Update proguard-rules.pro

This commit is contained in:
Thomas Andres Gomez 2022-07-06 12:17:50 +02:00
parent 4335a847ce
commit e10f5c161f
3 changed files with 43 additions and 28 deletions

View file

@ -14,8 +14,18 @@
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-renamesourcefileattribute SourceFile
# For SerializedName
-keepattributes *Annotation*
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}
-keep,allowobfuscation @interface com.google.gson.annotations.SerializedName

View file

@ -29,53 +29,58 @@ suspend fun loadNewBooks(
cache: IAPICacheRepository,
): Boolean {
val cached = cache.new
val updated = client.service.new()
val response: BookListResponse = client.service.new()
if (updated.isError) {
Log.e("loadNewBooks", updated.message ?: "")
throw NewBookFetchException(updated.message)
}
return if (cached != updated) {
cache.new = updated
true
} else {
false
return when {
response.isError -> {
Log.e("loadNewBooks", response.message ?: "")
throw NewBookFetchException(response.message)
}
cached != response -> {
cache.new = response
true
}
else -> {
false
}
}
}
/**
* This method will fetch all book from [client] and save them into the [repository]
* @param client the client used to fetch the data.
* @param cache the cache used to read the new book data.
* @param repository the repository to save the book data.
* @return factory the factory use to convert dto to bo.
* @return this method will return true the books have been correctly fetch, otherwise false.
*/
suspend fun loadAllBooks(
client: IBibLibClient,
cache: IAPICacheRepository,
repository: IBookRepository,
factory: BookFactory = BookFactory(),
): Boolean {
val response: BookListResponse = client.service.list().also { response ->
if (response.isError) {
val response: BookListResponse = client.service.list()
return when {
response.isError -> {
Log.e("loadAllBooks", response.message ?: "")
throw BookFetchException(response.message)
}
val newIds = cache.new?.data?.map { it.book_id } ?: listOf()
val factory = BookFactory()
val books = response.data?.mapNotNull { dto ->
val isNew = newIds.contains(dto.book_id)
val index = newIds.indexOf(dto.book_id)
try {
else -> {
val newIds = cache.new?.data?.map { it.book_id } ?: listOf()
val books = response.data?.map { dto ->
val isNew = newIds.contains(dto.book_id)
val index = newIds.indexOf(dto.book_id)
factory.fromListResponseToBook(dto, isNew, index)
} catch (exception: Exception) {
null
}
if (books.isNullOrEmpty()) {
Log.e("loadAllBooks", "Book list is empty")
throw BookFetchException("Book list is empty")
}
books.let { data -> repository.update(data) }
true
}
books?.let { data -> repository.update(data) }
}
return response.isError.not()
}

View file

@ -1,3 +1,3 @@
package com.pixelized.biblib.utils.exception
class BookFetchException(message: String?): RuntimeException("New Book fetch failed.\n$message")
class BookFetchException(message: String?): RuntimeException("Book fetch failed.\n$message")