diff --git a/app/src/main/java/net/underdesk/circolapp/adapters/CircularLetterAdapter.kt b/app/src/main/java/net/underdesk/circolapp/adapters/CircularLetterAdapter.kt
index 96aa300..03a202c 100644
--- a/app/src/main/java/net/underdesk/circolapp/adapters/CircularLetterAdapter.kt
+++ b/app/src/main/java/net/underdesk/circolapp/adapters/CircularLetterAdapter.kt
@@ -1,3 +1,21 @@
+/*
+ * Circolapp
+ * Copyright (C) 2019 Matteo Schiff
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
package net.underdesk.circolapp.adapters
import android.view.LayoutInflater
diff --git a/app/src/main/java/net/underdesk/circolapp/data/AppDatabase.kt b/app/src/main/java/net/underdesk/circolapp/data/AppDatabase.kt
index 4d73749..3728b70 100644
--- a/app/src/main/java/net/underdesk/circolapp/data/AppDatabase.kt
+++ b/app/src/main/java/net/underdesk/circolapp/data/AppDatabase.kt
@@ -22,8 +22,10 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
+import androidx.room.TypeConverters
@Database(entities = [Circular::class], version = 1, exportSchema = false)
+@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun circularDao(): CircularDao
diff --git a/app/src/main/java/net/underdesk/circolapp/data/Circular.kt b/app/src/main/java/net/underdesk/circolapp/data/Circular.kt
index 45fd828..52f70cc 100644
--- a/app/src/main/java/net/underdesk/circolapp/data/Circular.kt
+++ b/app/src/main/java/net/underdesk/circolapp/data/Circular.kt
@@ -23,7 +23,17 @@ import androidx.room.PrimaryKey
@Entity(tableName = "circulars")
data class Circular(
- @PrimaryKey(autoGenerate = true) val id: Long?,
+ @PrimaryKey val id: Long,
val name: String,
- val url: String
-)
\ No newline at end of file
+ val url: String,
+ val attachmentsNames: MutableList = mutableListOf(),
+ val attachmentsUrls: MutableList = mutableListOf()
+) {
+ companion object {
+ fun generateFromString(string: String, url: String): Circular {
+ val id = string.split(" ")[1]
+
+ return Circular(id.toLong(), string, url)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/net/underdesk/circolapp/data/CircularDao.kt b/app/src/main/java/net/underdesk/circolapp/data/CircularDao.kt
index b91ecf1..2d506f9 100644
--- a/app/src/main/java/net/underdesk/circolapp/data/CircularDao.kt
+++ b/app/src/main/java/net/underdesk/circolapp/data/CircularDao.kt
@@ -25,7 +25,7 @@ import androidx.room.Query
@Dao
interface CircularDao {
- @Query("SELECT * FROM circulars")
+ @Query("SELECT * FROM circulars ORDER BY id DESC")
fun getCirculars(): List
@Insert(onConflict = OnConflictStrategy.REPLACE)
diff --git a/app/src/main/java/net/underdesk/circolapp/data/Converters.kt b/app/src/main/java/net/underdesk/circolapp/data/Converters.kt
new file mode 100644
index 0000000..1390d8f
--- /dev/null
+++ b/app/src/main/java/net/underdesk/circolapp/data/Converters.kt
@@ -0,0 +1,49 @@
+/*
+ * Circolapp
+ * Copyright (C) 2019 Matteo Schiff
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package net.underdesk.circolapp.data
+
+import androidx.room.TypeConverter
+
+class Converters {
+
+ @TypeConverter
+ fun stringToList(data: String?): List {
+ val list: MutableList = mutableListOf()
+
+ if (data != null) {
+ for (attachment in data.split(",")) {
+ list.add(attachment)
+ }
+ }
+
+ return list.dropLast(1)
+ }
+
+ @TypeConverter
+ fun listToString(list: List): String {
+ var string = ""
+
+ for (attachment in list) {
+ string += "$attachment,"
+ }
+
+ return string
+ }
+}
+
diff --git a/app/src/main/java/net/underdesk/circolapp/server/DataFetcher.kt b/app/src/main/java/net/underdesk/circolapp/server/DataFetcher.kt
index dea7bf9..1c4edee 100644
--- a/app/src/main/java/net/underdesk/circolapp/server/DataFetcher.kt
+++ b/app/src/main/java/net/underdesk/circolapp/server/DataFetcher.kt
@@ -43,7 +43,12 @@ class DataFetcher {
val list = ArrayList()
htmlList.forEach { element ->
- list.add(Circular(null, element.text(), element.attr("href")))
+ if (element.text().startsWith("All")) {
+ list.last().attachmentsNames.add(element.text())
+ list.last().attachmentsUrls.add(element.attr("href"))
+ } else {
+ list.add(Circular.generateFromString(element.text(), element.attr("href")))
+ }
}
return list