Update proguard-rules.pro
This commit is contained in:
parent
4335a847ce
commit
e10f5c161f
3 changed files with 43 additions and 28 deletions
14
app/proguard-rules.pro
vendored
14
app/proguard-rules.pro
vendored
|
|
@ -14,8 +14,18 @@
|
||||||
|
|
||||||
# Uncomment this to preserve the line number information for
|
# Uncomment this to preserve the line number information for
|
||||||
# debugging stack traces.
|
# debugging stack traces.
|
||||||
#-keepattributes SourceFile,LineNumberTable
|
-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
# If you keep the line number information, uncomment this to
|
# If you keep the line number information, uncomment this to
|
||||||
# hide the original source file name.
|
# 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
|
||||||
|
|
@ -29,53 +29,58 @@ suspend fun loadNewBooks(
|
||||||
cache: IAPICacheRepository,
|
cache: IAPICacheRepository,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val cached = cache.new
|
val cached = cache.new
|
||||||
val updated = client.service.new()
|
val response: BookListResponse = client.service.new()
|
||||||
|
|
||||||
if (updated.isError) {
|
return when {
|
||||||
Log.e("loadNewBooks", updated.message ?: "")
|
response.isError -> {
|
||||||
throw NewBookFetchException(updated.message)
|
Log.e("loadNewBooks", response.message ?: "")
|
||||||
}
|
throw NewBookFetchException(response.message)
|
||||||
|
}
|
||||||
return if (cached != updated) {
|
cached != response -> {
|
||||||
cache.new = updated
|
cache.new = response
|
||||||
true
|
true
|
||||||
} else {
|
}
|
||||||
false
|
else -> {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will fetch all book from [client] and save them into the [repository]
|
* This method will fetch all book from [client] and save them into the [repository]
|
||||||
* @param client the client used to fetch the data.
|
* @param client the client used to fetch the data.
|
||||||
* @param cache the cache used to read the new book data.
|
* @param cache the cache used to read the new book data.
|
||||||
* @param repository the repository to save the 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.
|
* @return this method will return true the books have been correctly fetch, otherwise false.
|
||||||
*/
|
*/
|
||||||
suspend fun loadAllBooks(
|
suspend fun loadAllBooks(
|
||||||
client: IBibLibClient,
|
client: IBibLibClient,
|
||||||
cache: IAPICacheRepository,
|
cache: IAPICacheRepository,
|
||||||
repository: IBookRepository,
|
repository: IBookRepository,
|
||||||
|
factory: BookFactory = BookFactory(),
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val response: BookListResponse = client.service.list().also { response ->
|
val response: BookListResponse = client.service.list()
|
||||||
if (response.isError) {
|
|
||||||
|
return when {
|
||||||
|
response.isError -> {
|
||||||
Log.e("loadAllBooks", response.message ?: "")
|
Log.e("loadAllBooks", response.message ?: "")
|
||||||
throw BookFetchException(response.message)
|
throw BookFetchException(response.message)
|
||||||
}
|
}
|
||||||
|
else -> {
|
||||||
val newIds = cache.new?.data?.map { it.book_id } ?: listOf()
|
val newIds = cache.new?.data?.map { it.book_id } ?: listOf()
|
||||||
val factory = BookFactory()
|
val books = response.data?.map { dto ->
|
||||||
val books = response.data?.mapNotNull { dto ->
|
val isNew = newIds.contains(dto.book_id)
|
||||||
val isNew = newIds.contains(dto.book_id)
|
val index = newIds.indexOf(dto.book_id)
|
||||||
val index = newIds.indexOf(dto.book_id)
|
|
||||||
try {
|
|
||||||
factory.fromListResponseToBook(dto, isNew, index)
|
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()
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
package com.pixelized.biblib.utils.exception
|
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")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue