Skip to content

Commit 0fcefd7

Browse files
committed
Added a new horizontal scrolling comics list
1 parent 565feec commit 0fcefd7

37 files changed

+1005
-144
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
{
2+
"formatVersion": 1,
3+
"database": {
4+
"version": 4,
5+
"identityHash": "8ee085273581eefd769b262854fefb90",
6+
"entities": [
7+
{
8+
"tableName": "comics_table",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`num` INTEGER NOT NULL, `link` TEXT NOT NULL, `news` TEXT NOT NULL, `image` TEXT NOT NULL, `title` TEXT NOT NULL, `alt_text` TEXT NOT NULL, `safe_title` TEXT NOT NULL, `transcript` TEXT NOT NULL, `day` TEXT NOT NULL, `month` TEXT NOT NULL, `year` TEXT NOT NULL, `isFavourite` INTEGER NOT NULL, PRIMARY KEY(`num`))",
10+
"fields": [
11+
{
12+
"fieldPath": "num",
13+
"columnName": "num",
14+
"affinity": "INTEGER",
15+
"notNull": true
16+
},
17+
{
18+
"fieldPath": "link",
19+
"columnName": "link",
20+
"affinity": "TEXT",
21+
"notNull": true
22+
},
23+
{
24+
"fieldPath": "news",
25+
"columnName": "news",
26+
"affinity": "TEXT",
27+
"notNull": true
28+
},
29+
{
30+
"fieldPath": "img",
31+
"columnName": "image",
32+
"affinity": "TEXT",
33+
"notNull": true
34+
},
35+
{
36+
"fieldPath": "title",
37+
"columnName": "title",
38+
"affinity": "TEXT",
39+
"notNull": true
40+
},
41+
{
42+
"fieldPath": "alt",
43+
"columnName": "alt_text",
44+
"affinity": "TEXT",
45+
"notNull": true
46+
},
47+
{
48+
"fieldPath": "safeTitle",
49+
"columnName": "safe_title",
50+
"affinity": "TEXT",
51+
"notNull": true
52+
},
53+
{
54+
"fieldPath": "transcript",
55+
"columnName": "transcript",
56+
"affinity": "TEXT",
57+
"notNull": true
58+
},
59+
{
60+
"fieldPath": "day",
61+
"columnName": "day",
62+
"affinity": "TEXT",
63+
"notNull": true
64+
},
65+
{
66+
"fieldPath": "month",
67+
"columnName": "month",
68+
"affinity": "TEXT",
69+
"notNull": true
70+
},
71+
{
72+
"fieldPath": "year",
73+
"columnName": "year",
74+
"affinity": "TEXT",
75+
"notNull": true
76+
},
77+
{
78+
"fieldPath": "isFavourite",
79+
"columnName": "isFavourite",
80+
"affinity": "INTEGER",
81+
"notNull": true
82+
}
83+
],
84+
"primaryKey": {
85+
"columnNames": [
86+
"num"
87+
],
88+
"autoGenerate": false
89+
},
90+
"indices": [],
91+
"foreignKeys": []
92+
},
93+
{
94+
"tableName": "card_pages_table",
95+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`comicStripId` INTEGER NOT NULL, PRIMARY KEY(`comicStripId`), FOREIGN KEY(`comicStripId`) REFERENCES `comics_table`(`num`) ON UPDATE NO ACTION ON DELETE NO ACTION )",
96+
"fields": [
97+
{
98+
"fieldPath": "comicStripId",
99+
"columnName": "comicStripId",
100+
"affinity": "INTEGER",
101+
"notNull": true
102+
}
103+
],
104+
"primaryKey": {
105+
"columnNames": [
106+
"comicStripId"
107+
],
108+
"autoGenerate": false
109+
},
110+
"indices": [],
111+
"foreignKeys": [
112+
{
113+
"table": "comics_table",
114+
"onDelete": "NO ACTION",
115+
"onUpdate": "NO ACTION",
116+
"columns": [
117+
"comicStripId"
118+
],
119+
"referencedColumns": [
120+
"num"
121+
]
122+
}
123+
]
124+
},
125+
{
126+
"tableName": "comic_pages_table",
127+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`comicStripId` INTEGER NOT NULL, PRIMARY KEY(`comicStripId`), FOREIGN KEY(`comicStripId`) REFERENCES `comics_table`(`num`) ON UPDATE NO ACTION ON DELETE NO ACTION )",
128+
"fields": [
129+
{
130+
"fieldPath": "comicStripId",
131+
"columnName": "comicStripId",
132+
"affinity": "INTEGER",
133+
"notNull": true
134+
}
135+
],
136+
"primaryKey": {
137+
"columnNames": [
138+
"comicStripId"
139+
],
140+
"autoGenerate": false
141+
},
142+
"indices": [],
143+
"foreignKeys": [
144+
{
145+
"table": "comics_table",
146+
"onDelete": "NO ACTION",
147+
"onUpdate": "NO ACTION",
148+
"columns": [
149+
"comicStripId"
150+
],
151+
"referencedColumns": [
152+
"num"
153+
]
154+
}
155+
]
156+
}
157+
],
158+
"views": [],
159+
"setupQueries": [
160+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
161+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '8ee085273581eefd769b262854fefb90')"
162+
]
163+
}
164+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
{
2+
"formatVersion": 1,
3+
"database": {
4+
"version": 5,
5+
"identityHash": "63055164967a398773095b10efdddf45",
6+
"entities": [
7+
{
8+
"tableName": "comics_table",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`num` INTEGER NOT NULL, `link` TEXT NOT NULL, `news` TEXT NOT NULL, `image` TEXT NOT NULL, `title` TEXT NOT NULL, `alt_text` TEXT NOT NULL, `safe_title` TEXT NOT NULL, `transcript` TEXT NOT NULL, `day` TEXT NOT NULL, `month` TEXT NOT NULL, `year` TEXT NOT NULL, `isFavourite` INTEGER NOT NULL, PRIMARY KEY(`num`))",
10+
"fields": [
11+
{
12+
"fieldPath": "num",
13+
"columnName": "num",
14+
"affinity": "INTEGER",
15+
"notNull": true
16+
},
17+
{
18+
"fieldPath": "link",
19+
"columnName": "link",
20+
"affinity": "TEXT",
21+
"notNull": true
22+
},
23+
{
24+
"fieldPath": "news",
25+
"columnName": "news",
26+
"affinity": "TEXT",
27+
"notNull": true
28+
},
29+
{
30+
"fieldPath": "img",
31+
"columnName": "image",
32+
"affinity": "TEXT",
33+
"notNull": true
34+
},
35+
{
36+
"fieldPath": "title",
37+
"columnName": "title",
38+
"affinity": "TEXT",
39+
"notNull": true
40+
},
41+
{
42+
"fieldPath": "alt",
43+
"columnName": "alt_text",
44+
"affinity": "TEXT",
45+
"notNull": true
46+
},
47+
{
48+
"fieldPath": "safeTitle",
49+
"columnName": "safe_title",
50+
"affinity": "TEXT",
51+
"notNull": true
52+
},
53+
{
54+
"fieldPath": "transcript",
55+
"columnName": "transcript",
56+
"affinity": "TEXT",
57+
"notNull": true
58+
},
59+
{
60+
"fieldPath": "day",
61+
"columnName": "day",
62+
"affinity": "TEXT",
63+
"notNull": true
64+
},
65+
{
66+
"fieldPath": "month",
67+
"columnName": "month",
68+
"affinity": "TEXT",
69+
"notNull": true
70+
},
71+
{
72+
"fieldPath": "year",
73+
"columnName": "year",
74+
"affinity": "TEXT",
75+
"notNull": true
76+
},
77+
{
78+
"fieldPath": "isFavourite",
79+
"columnName": "isFavourite",
80+
"affinity": "INTEGER",
81+
"notNull": true
82+
}
83+
],
84+
"primaryKey": {
85+
"columnNames": [
86+
"num"
87+
],
88+
"autoGenerate": false
89+
},
90+
"indices": [],
91+
"foreignKeys": []
92+
},
93+
{
94+
"tableName": "card_pages_table",
95+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`comicStripId` INTEGER NOT NULL, PRIMARY KEY(`comicStripId`), FOREIGN KEY(`comicStripId`) REFERENCES `comics_table`(`num`) ON UPDATE NO ACTION ON DELETE NO ACTION )",
96+
"fields": [
97+
{
98+
"fieldPath": "comicStripId",
99+
"columnName": "comicStripId",
100+
"affinity": "INTEGER",
101+
"notNull": true
102+
}
103+
],
104+
"primaryKey": {
105+
"columnNames": [
106+
"comicStripId"
107+
],
108+
"autoGenerate": false
109+
},
110+
"indices": [],
111+
"foreignKeys": [
112+
{
113+
"table": "comics_table",
114+
"onDelete": "NO ACTION",
115+
"onUpdate": "NO ACTION",
116+
"columns": [
117+
"comicStripId"
118+
],
119+
"referencedColumns": [
120+
"num"
121+
]
122+
}
123+
]
124+
}
125+
],
126+
"views": [],
127+
"setupQueries": [
128+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
129+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '63055164967a398773095b10efdddf45')"
130+
]
131+
}
132+
}

app/src/main/java/com/michaelfotiads/xkcdreader/data/db/ComicsDatabase.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ package com.michaelfotiads.xkcdreader.data.db
88

99
import androidx.room.Database
1010
import androidx.room.RoomDatabase
11+
import com.michaelfotiads.xkcdreader.data.db.dao.CardPagesDao
1112
import com.michaelfotiads.xkcdreader.data.db.dao.ComicsDao
12-
import com.michaelfotiads.xkcdreader.data.db.dao.PagesDao
13+
import com.michaelfotiads.xkcdreader.data.db.entity.CardPageEntity
1314
import com.michaelfotiads.xkcdreader.data.db.entity.ComicEntity
14-
import com.michaelfotiads.xkcdreader.data.db.entity.PageEntity
1515

1616
@Database(
17-
entities = [ComicEntity::class, PageEntity::class],
18-
version = 3
17+
entities = [ComicEntity::class, CardPageEntity::class],
18+
version = 5
1919
)
2020
abstract class ComicsDatabase : RoomDatabase() {
2121

2222
abstract fun comicsDao(): ComicsDao
2323

24-
abstract fun pagesDao(): PagesDao
24+
abstract fun cardPagesDao(): CardPagesDao
2525
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.michaelfotiads.xkcdreader.data.db.dao
2+
3+
import androidx.paging.DataSource
4+
import androidx.room.Dao
5+
import androidx.room.Insert
6+
import androidx.room.OnConflictStrategy
7+
import androidx.room.Query
8+
import com.michaelfotiads.xkcdreader.data.db.entity.CardPageEntity
9+
import com.michaelfotiads.xkcdreader.data.db.entity.CardPageWithComic
10+
11+
@Dao
12+
interface CardPagesDao {
13+
14+
@Insert(onConflict = OnConflictStrategy.REPLACE)
15+
fun upsert(pageEntity: CardPageEntity)
16+
17+
@Query("DELETE FROM card_pages_table")
18+
fun deleteAll()
19+
20+
@Query("SELECT * from card_pages_table, comics_table where num = comicStripId ORDER BY comicStripId DESC")
21+
fun getAllPages(): List<CardPageWithComic>
22+
23+
@Query("SELECT * from card_pages_table, comics_table where num = comicStripId ORDER BY comicStripId DESC")
24+
fun getComicsPaged(): DataSource.Factory<Int, CardPageWithComic>
25+
}

app/src/main/java/com/michaelfotiads/xkcdreader/data/db/dao/PagesDao.kt

Lines changed: 0 additions & 25 deletions
This file was deleted.

app/src/main/java/com/michaelfotiads/xkcdreader/data/db/entity/PageEntity.kt renamed to app/src/main/java/com/michaelfotiads/xkcdreader/data/db/entity/CardPageEntity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import androidx.room.Entity
44
import androidx.room.ForeignKey
55
import androidx.room.PrimaryKey
66

7-
@Entity(tableName = "pages_table", foreignKeys = [ForeignKey(
7+
@Entity(tableName = "card_pages_table", foreignKeys = [ForeignKey(
88
entity = ComicEntity::class,
99
parentColumns = arrayOf("num"),
1010
childColumns = arrayOf("comicStripId"))])
11-
data class PageEntity(
11+
data class CardPageEntity(
1212
@PrimaryKey(autoGenerate = false) var comicStripId: Int
1313
)

app/src/main/java/com/michaelfotiads/xkcdreader/data/db/entity/PageWithComic.kt renamed to app/src/main/java/com/michaelfotiads/xkcdreader/data/db/entity/CardPageWithComic.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.michaelfotiads.xkcdreader.data.db.entity
22

33
import androidx.room.Embedded
44

5-
data class PageWithComic(
6-
@Embedded var pageEntity: PageEntity,
5+
data class CardPageWithComic(
6+
@Embedded var pageEntity: CardPageEntity,
77
@Embedded var comicEntity: ComicEntity
88
)

0 commit comments

Comments
 (0)