Fixes #216.
This commit is contained in:
parent
1aa68d3449
commit
40d9c97f73
@ -248,7 +248,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
badgeNew--
|
||||
reloadBadgeContent()
|
||||
|
||||
val tagHashes = i.tags.split(",").map { it.longHash() }
|
||||
val tagHashes = i.tags.tags.split(",").map { it.longHash() }
|
||||
tagsBadge = tagsBadge.map {
|
||||
if (tagHashes.contains(it.key)) {
|
||||
(it.key to (it.value - 1))
|
||||
@ -367,7 +367,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
thread {
|
||||
if (response.body() != null) {
|
||||
val apiItems = (response.body() as ArrayList<Item>).filter {
|
||||
maybeTagFilter != null || filter(it.tags)
|
||||
maybeTagFilter != null || filter(it.tags.tags)
|
||||
} as ArrayList<Item>
|
||||
db.itemsDao().deleteAllItems()
|
||||
db.itemsDao()
|
||||
@ -999,7 +999,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
getAndStoreAllItems()
|
||||
items = response.body() as ArrayList<Item>
|
||||
items = items.filter {
|
||||
maybeTagFilter != null || filter(it.tags)
|
||||
maybeTagFilter != null || filter(it.tags.tags)
|
||||
} as ArrayList<Item>
|
||||
|
||||
if (allItems.isEmpty()) {
|
||||
@ -1299,7 +1299,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
val ids = allItems.map { it.id }
|
||||
val itemsByTag: Map<Long, Int> =
|
||||
allItems.flattenTags()
|
||||
.groupBy { it.tags.longHash() }
|
||||
.groupBy { it.tags.tags.longHash() }
|
||||
.map { it.key to it.value.size }
|
||||
.toMap()
|
||||
|
||||
|
@ -66,6 +66,7 @@ class SelfossApi(
|
||||
val gson =
|
||||
GsonBuilder()
|
||||
.registerTypeAdapter(Boolean::class.javaPrimitiveType, BooleanTypeAdapter())
|
||||
.registerTypeAdapter(SelfossTagType::class.java, SelfossTagTypeTypeAdapter())
|
||||
.setLenient()
|
||||
.create()
|
||||
|
||||
|
@ -71,7 +71,7 @@ data class Item(
|
||||
@SerializedName("icon") val icon: String,
|
||||
@SerializedName("link") val link: String,
|
||||
@SerializedName("sourcetitle") val sourcetitle: String,
|
||||
@SerializedName("tags") val tags: String
|
||||
@SerializedName("tags") val tags: SelfossTagType
|
||||
) : Parcelable {
|
||||
|
||||
var config: Config? = null
|
||||
@ -94,7 +94,7 @@ data class Item(
|
||||
icon = source.readString(),
|
||||
link = source.readString(),
|
||||
sourcetitle = source.readString(),
|
||||
tags = source.readString()
|
||||
tags = source.readParcelable(ClassLoader.getSystemClassLoader())
|
||||
)
|
||||
|
||||
override fun describeContents() = 0
|
||||
@ -110,7 +110,7 @@ data class Item(
|
||||
dest.writeString(icon)
|
||||
dest.writeString(link)
|
||||
dest.writeString(sourcetitle)
|
||||
dest.writeString(tags)
|
||||
dest.writeParcelable(tags, flags)
|
||||
}
|
||||
|
||||
fun getIcon(app: Context): String {
|
||||
@ -154,3 +154,26 @@ data class Item(
|
||||
return stringUrl
|
||||
}
|
||||
}
|
||||
|
||||
data class SelfossTagType(val tags: String) : Parcelable {
|
||||
|
||||
companion object {
|
||||
@JvmField val CREATOR: Parcelable.Creator<SelfossTagType> =
|
||||
object : Parcelable.Creator<SelfossTagType> {
|
||||
override fun createFromParcel(source: Parcel): SelfossTagType =
|
||||
SelfossTagType(source)
|
||||
|
||||
override fun newArray(size: Int): Array<SelfossTagType?> = arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(source: Parcel) : this(
|
||||
tags = source.readString()
|
||||
)
|
||||
|
||||
override fun describeContents() = 0
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
dest.writeString(tags)
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package apps.amine.bou.readerforselfoss.api.selfoss
|
||||
|
||||
import com.google.gson.JsonDeserializationContext
|
||||
import com.google.gson.JsonDeserializer
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonParseException
|
||||
import java.lang.reflect.Type
|
||||
|
||||
internal class SelfossTagTypeTypeAdapter : JsonDeserializer<SelfossTagType> {
|
||||
|
||||
@Throws(JsonParseException::class)
|
||||
override fun deserialize(
|
||||
json: JsonElement,
|
||||
typeOfT: Type,
|
||||
context: JsonDeserializationContext
|
||||
): SelfossTagType? =
|
||||
if (json.isJsonArray) {
|
||||
SelfossTagType(json.asJsonArray.joinToString(",") { it.toString() })
|
||||
} else {
|
||||
SelfossTagType(json.toString())
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package apps.amine.bou.readerforselfoss.utils
|
||||
import android.content.Context
|
||||
import android.text.format.DateUtils
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossTagType
|
||||
import org.acra.ACRA
|
||||
import java.text.ParseException
|
||||
import java.text.SimpleDateFormat
|
||||
@ -44,8 +45,8 @@ fun Item.toggleStar(): Item {
|
||||
fun List<Item>.flattenTags(): List<Item> =
|
||||
this.flatMap {
|
||||
val item = it
|
||||
val tags: List<String> = it.tags.split(",")
|
||||
tags.map {
|
||||
item.copy(tags = it.trim())
|
||||
val tags: List<String> = it.tags.tags.split(",")
|
||||
tags.map { t ->
|
||||
item.copy(tags = SelfossTagType(t.trim()))
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package apps.amine.bou.readerforselfoss.utils.persistence
|
||||
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossTagType
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Source
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Tag
|
||||
import apps.amine.bou.readerforselfoss.persistence.entities.ItemEntity
|
||||
@ -53,7 +54,7 @@ fun ItemEntity.toView(): Item =
|
||||
this.icon,
|
||||
this.link,
|
||||
this.sourcetitle,
|
||||
this.tags
|
||||
SelfossTagType(this.tags)
|
||||
)
|
||||
|
||||
fun Item.toEntity(): ItemEntity =
|
||||
@ -68,5 +69,5 @@ fun Item.toEntity(): ItemEntity =
|
||||
this.icon,
|
||||
this.link,
|
||||
this.sourcetitle,
|
||||
this.tags
|
||||
this.tags.tags
|
||||
)
|
Loading…
Reference in New Issue
Block a user