mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-06 07:29:10 +00:00
Make Circular entity id equals as circular number and save attachments to Circular entity
This commit is contained in:
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.underdesk.circolapp.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
val url: String,
|
||||
val attachmentsNames: MutableList<String> = mutableListOf(),
|
||||
val attachmentsUrls: MutableList<String> = mutableListOf()
|
||||
) {
|
||||
companion object {
|
||||
fun generateFromString(string: String, url: String): Circular {
|
||||
val id = string.split(" ")[1]
|
||||
|
||||
return Circular(id.toLong(), string, url)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Circular>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
|
||||
49
app/src/main/java/net/underdesk/circolapp/data/Converters.kt
Normal file
49
app/src/main/java/net/underdesk/circolapp/data/Converters.kt
Normal file
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.underdesk.circolapp.data
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
|
||||
class Converters {
|
||||
|
||||
@TypeConverter
|
||||
fun stringToList(data: String?): List<String> {
|
||||
val list: MutableList<String> = mutableListOf()
|
||||
|
||||
if (data != null) {
|
||||
for (attachment in data.split(",")) {
|
||||
list.add(attachment)
|
||||
}
|
||||
}
|
||||
|
||||
return list.dropLast(1)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun listToString(list: List<String>): String {
|
||||
var string = ""
|
||||
|
||||
for (attachment in list) {
|
||||
string += "$attachment,"
|
||||
}
|
||||
|
||||
return string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,12 @@ class DataFetcher {
|
||||
val list = ArrayList<Circular>()
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user