Allow searchable serialization to fail
This commit is contained in:
parent
be2b1479ac
commit
c5393f3eaa
@ -18,9 +18,10 @@ data class FavoritesItem(
|
||||
var pinPosition: Int,
|
||||
var hidden: Boolean
|
||||
) : KoinComponent {
|
||||
private val serializer: SearchableSerializer by inject { parametersOf(searchable) }
|
||||
private val serializer: SearchableSerializer? by inject { parametersOf(searchable) }
|
||||
|
||||
fun toDatabaseEntity(): FavoritesItemEntity {
|
||||
fun toDatabaseEntity(): FavoritesItemEntity? {
|
||||
val serializer = serializer ?: return null
|
||||
|
||||
return FavoritesItemEntity(
|
||||
key = key,
|
||||
|
||||
@ -103,7 +103,7 @@ internal class FavoritesRepositoryImpl(
|
||||
pinPosition = 1,
|
||||
hidden = false
|
||||
)
|
||||
dao.insertReplaceExisting(favoritesItem.toDatabaseEntity())
|
||||
favoritesItem.toDatabaseEntity()?.let { dao.insertReplaceExisting(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -132,7 +132,7 @@ internal class FavoritesRepositoryImpl(
|
||||
pinPosition = 0,
|
||||
hidden = true
|
||||
)
|
||||
dao.insertReplaceExisting(favoritesItem.toDatabaseEntity())
|
||||
favoritesItem.toDatabaseEntity()?.let { dao.insertReplaceExisting(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -149,8 +149,10 @@ internal class FavoritesRepositoryImpl(
|
||||
scope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
val item = FavoritesItem(searchable.key, searchable, 0, 0, false)
|
||||
AppDatabase.getInstance(context).searchDao()
|
||||
.incrementLaunchCount(item.toDatabaseEntity())
|
||||
item.toDatabaseEntity()?.let {
|
||||
AppDatabase.getInstance(context).searchDao()
|
||||
.incrementLaunchCount(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,7 +169,7 @@ internal class FavoritesRepositoryImpl(
|
||||
scope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
AppDatabase.getInstance(context).searchDao()
|
||||
.saveFavorites(favorites.map { it.toDatabaseEntity() })
|
||||
.saveFavorites(favorites.mapNotNull { it.toDatabaseEntity() })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ val favoritesModule = module {
|
||||
if (searchable is Website) {
|
||||
return@factory WebsiteSerializer()
|
||||
}
|
||||
throw IllegalArgumentException("No known serializer exists for type ${searchable.javaClass.canonicalName}")
|
||||
return@factory null
|
||||
}
|
||||
|
||||
factory { (serialized: String) ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user