-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from paulcoding810/feat/add-favorite
Implement favorite feature
- Loading branch information
Showing
20 changed files
with
449 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/schemas/com.paulcoding.hviewer.database.AppDatabase/1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "f8c3310b39b34e0c6c9c004f8557d416", | ||
"entities": [ | ||
{ | ||
"tableName": "favorite_posts", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`url` TEXT NOT NULL, `name` TEXT NOT NULL, `thumbnail` TEXT NOT NULL, `site` TEXT NOT NULL, PRIMARY KEY(`url`))", | ||
"fields": [ | ||
{ | ||
"fieldPath": "url", | ||
"columnName": "url", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "name", | ||
"columnName": "name", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "thumbnail", | ||
"columnName": "thumbnail", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "site", | ||
"columnName": "site", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": false, | ||
"columnNames": [ | ||
"url" | ||
] | ||
}, | ||
"indices": [], | ||
"foreignKeys": [] | ||
} | ||
], | ||
"views": [], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f8c3310b39b34e0c6c9c004f8557d416')" | ||
] | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/schemas/com.paulcoding.hviewer.database.AppDatabase/2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 2, | ||
"identityHash": "f8c3310b39b34e0c6c9c004f8557d416", | ||
"entities": [ | ||
{ | ||
"tableName": "favorite_posts", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`url` TEXT NOT NULL, `name` TEXT NOT NULL, `thumbnail` TEXT NOT NULL, `site` TEXT NOT NULL, PRIMARY KEY(`url`))", | ||
"fields": [ | ||
{ | ||
"fieldPath": "url", | ||
"columnName": "url", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "name", | ||
"columnName": "name", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "thumbnail", | ||
"columnName": "thumbnail", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "site", | ||
"columnName": "site", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": false, | ||
"columnNames": [ | ||
"url" | ||
] | ||
}, | ||
"indices": [], | ||
"foreignKeys": [] | ||
} | ||
], | ||
"views": [], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f8c3310b39b34e0c6c9c004f8557d416')" | ||
] | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
app/schemas/com.paulcoding.hviewer.database.AppDatabase/3.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 3, | ||
"identityHash": "40109ede6ba29fdee1d23735114a2981", | ||
"entities": [ | ||
{ | ||
"tableName": "favorite_posts", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`url` TEXT NOT NULL, `name` TEXT NOT NULL, `thumbnail` TEXT NOT NULL, `site` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`url`))", | ||
"fields": [ | ||
{ | ||
"fieldPath": "url", | ||
"columnName": "url", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "name", | ||
"columnName": "name", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "thumbnail", | ||
"columnName": "thumbnail", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "site", | ||
"columnName": "site", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "createdAt", | ||
"columnName": "createdAt", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": false, | ||
"columnNames": [ | ||
"url" | ||
] | ||
}, | ||
"indices": [], | ||
"foreignKeys": [] | ||
} | ||
], | ||
"views": [], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '40109ede6ba29fdee1d23735114a2981')" | ||
] | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/paulcoding/hviewer/database/AppDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.paulcoding.hviewer.database | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import com.paulcoding.hviewer.model.PostItem | ||
|
||
@Database(entities = [PostItem::class], version = 3, exportSchema = true) | ||
abstract class AppDatabase : RoomDatabase() { | ||
abstract fun favoritePostDao(): FavoritePostDao | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/paulcoding/hviewer/database/DatabaseProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.paulcoding.hviewer.database | ||
|
||
import androidx.room.Room | ||
import com.paulcoding.hviewer.MainApp.Companion.appContext | ||
|
||
object DatabaseProvider { | ||
private var db: AppDatabase? = null | ||
|
||
fun getInstance(): AppDatabase { | ||
if (db == null) { | ||
db = Room.databaseBuilder( | ||
appContext, | ||
AppDatabase::class.java, "hviewer_db" | ||
) | ||
.addMigrations(MIGRATION_1_2, MIGRATION_2_3) | ||
.build() | ||
} | ||
return db!! | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/paulcoding/hviewer/database/FavoriteDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.paulcoding.hviewer.database | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Delete | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import com.paulcoding.hviewer.model.PostItem | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface FavoritePostDao { | ||
@Query("SELECT * FROM favorite_posts ORDER BY createdAt DESC") | ||
fun getAll(): Flow<List<PostItem>> | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insert(post: PostItem) | ||
|
||
@Delete | ||
suspend fun delete(post: PostItem) | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/paulcoding/hviewer/database/Migrations.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.paulcoding.hviewer.database | ||
|
||
import androidx.room.migration.Migration | ||
import androidx.sqlite.db.SupportSQLiteDatabase | ||
|
||
val MIGRATION_1_2 = object : Migration(1, 2) { | ||
override fun migrate(db: SupportSQLiteDatabase) { | ||
db.execSQL("ALTER TABLE favorite_posts ADD COLUMN site TEXT NOT NULL DEFAULT \"\"") | ||
} | ||
} | ||
|
||
val MIGRATION_2_3 = object : Migration(2, 3) { | ||
override fun migrate(db: SupportSQLiteDatabase) { | ||
db.execSQL("ALTER TABLE favorite_posts ADD COLUMN createdAt INTEGER NOT NULL DEFAULT 0") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.