Skip to content

Commit

Permalink
Merge pull request #39 from dgngulcan/add-remove-custom-source
Browse files Browse the repository at this point in the history
Add remove custom source
  • Loading branch information
dgngulcan authored May 15, 2019
2 parents ee9032d + b26a8be commit 123a93e
Show file tree
Hide file tree
Showing 68 changed files with 1,268 additions and 340 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'

ext.app = [
'version' : '2.1.5',
'version_code' : 22,
'version' : '2.2.0',
'version_code' : 24,
'compile_sdk_version': 28,
'min_sdk_version' : 21,
'target_sdk_version' : 28
Expand Down Expand Up @@ -46,6 +46,7 @@ android {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

Expand Down Expand Up @@ -107,8 +108,7 @@ dependencies {
implementation deps.firebase.firestore
implementation deps.jsoup
implementation deps.gson // quick fix for version conflict between room and firestore
testImplementation deps.mockito.core
testImplementation deps.mockito.inline
testImplementation deps.mockk
testImplementation deps.junit
testImplementation deps.kotlin.coroutines_test
testImplementation deps.testx.core
Expand Down
5 changes: 4 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
-keep class com.crashlytics.** { *; }
-keepattributes *Annotation*,Signature,Exceptions

-keep public class * extends java.lang.Exception

-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
Expand All @@ -24,6 +25,7 @@
@retrofit.http.* <methods>;
}

-keep class androidx.core.app.CoreComponentFactory { *; }

-dontwarn com.crashlytics.**
-dontwarn okhttp3.**
Expand All @@ -32,4 +34,5 @@
-dontwarn com.bumptech.glide.**
-dontwarn com.google.common.**
-dontwarn com.google.api.client.googleapis.**
-dontwarn com.google.errorprone.annotations.*
-dontwarn com.google.errorprone.annotations.*

171 changes: 171 additions & 0 deletions app/schemas/com.droidfeed.data.db.AppDatabase/5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"formatVersion": 1,
"database": {
"version": 5,
"identityHash": "f70b83173d8568f3b154cbe5dce7c0fb",
"entities": [
{
"tableName": "source",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`is_active` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, `is_user_source` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "isActive",
"columnName": "is_active",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "url",
"columnName": "url",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isUserSource",
"columnName": "is_user_source",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "rss",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`bookmarked` INTEGER NOT NULL, `link` TEXT NOT NULL, `source_id` INTEGER, `pub_date` TEXT NOT NULL, `pub_date_timestamp` INTEGER NOT NULL, `title` TEXT NOT NULL, `author` TEXT NOT NULL, `content_raw` TEXT NOT NULL, `channel_title` TEXT NOT NULL, `channel_image_url` TEXT NOT NULL, `channel_link` TEXT NOT NULL, `content_image` TEXT NOT NULL, `content` TEXT NOT NULL, PRIMARY KEY(`link`), FOREIGN KEY(`source_id`) REFERENCES `source`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "bookmarked",
"columnName": "bookmarked",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "link",
"columnName": "link",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "sourceId",
"columnName": "source_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "pubDate",
"columnName": "pub_date",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "pubDateTimestamp",
"columnName": "pub_date_timestamp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "author",
"columnName": "author",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "rawContent",
"columnName": "content_raw",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "channel.title",
"columnName": "channel_title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "channel.imageUrl",
"columnName": "channel_image_url",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "channel.link",
"columnName": "channel_link",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "content.contentImage",
"columnName": "content_image",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "content.content",
"columnName": "content",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"link"
],
"autoGenerate": false
},
"indices": [
{
"name": "index_rss_source_id",
"unique": false,
"columnNames": [
"source_id"
],
"createSql": "CREATE INDEX `index_rss_source_id` ON `${TABLE_NAME}` (`source_id`)"
}
],
"foreignKeys": [
{
"table": "source",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"source_id"
],
"referencedColumns": [
"id"
]
}
]
}
],
"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, \"f70b83173d8568f3b154cbe5dce7c0fb\")"
]
}
}
63 changes: 50 additions & 13 deletions app/src/androidTest/java/com/droidfeed/db/DatabaseMigrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,18 @@ class DatabaseMigrationTest {
}

@Test
fun migration_from_1_to_4_should_contain_correct_data() {
fun migration_from_1_to_5_should_contain_correct_data() {
createAndPopulateDBVersion1()

val migrations = arrayOf(
MIGRATION_1_2,
MIGRATION_1_4,
MIGRATION_2_3,
MIGRATION_3_4
MIGRATION_3_4,
MIGRATION_4_5
)

val posts = getMigrationValidatedRoomDatabase(migrations)
val posts = getMigrationValidatedRoomDatabase(5, migrations)
.postDao()
.getAllAsLiveData()
.blockingObserve() ?: emptyList()
Expand All @@ -85,15 +86,17 @@ class DatabaseMigrationTest {
}

@Test
fun migration_from_2_to_4_should_contain_correct_data() {
fun migration_from_2_to_5_should_contain_correct_data() {
createAndPopulateDBVersion2()

val migrations = arrayOf(
MIGRATION_1_4,
MIGRATION_1_5,
MIGRATION_2_3,
MIGRATION_2_5,
MIGRATION_3_4
)
val migratedDb = getMigrationValidatedRoomDatabase(migrations)
val migratedDb = getMigrationValidatedRoomDatabase(5, migrations)

mSqliteTestDbHelper.writableDatabase.use { database ->
database.execSQL(
Expand Down Expand Up @@ -130,10 +133,11 @@ class DatabaseMigrationTest {

val migrations = arrayOf(
MIGRATION_1_4,
MIGRATION_3_4
MIGRATION_3_4,
MIGRATION_4_5
)

val posts = getMigrationValidatedRoomDatabase(migrations)
val posts = getMigrationValidatedRoomDatabase(4, migrations)
.postDao()
.getAllAsLiveData().blockingObserve() ?: emptyList()

Expand All @@ -142,6 +146,26 @@ class DatabaseMigrationTest {
assertEquals(1, posts[0].bookmarked)
}

@Test
fun migration_from_4_to_5_should_contain_correct_data() {
createAndPopulateDBVersion4()

val migrations = arrayOf(
MIGRATION_3_5,
MIGRATION_4_5
)

val sources = getMigrationValidatedRoomDatabase(5, migrations)
.sourceDao()
.getSources().blockingObserve() ?: emptyList()

assertEquals(2, sources.size)
assertEquals(0, sources[0].id)
assertEquals(false, sources[0].isUserSource)

}


private fun createAndPopulateDBVersion1() {
mMigrationTestHelper.createDatabase(dbName, 1).use { database ->
database.execSQL(
Expand All @@ -154,8 +178,8 @@ class DatabaseMigrationTest {
private fun createAndPopulateDBVersion2() {
mMigrationTestHelper.createDatabase(dbName, 2).use { database ->
database.apply {
execSQL("INSERT INTO `source` (url, name, is_active) VALUES ('https://some.url','source name', '0') ;")
execSQL("INSERT INTO `source` (url, name, is_active) VALUES ('https://some.url2','source name2', '1') ;")
execSQL("INSERT INTO `source` (url, name, is_active) VALUES ('https://some.url', 'source name', '0') ;")
execSQL("INSERT INTO `source` (url, name, is_active) VALUES ('https://some.url2', 'source name2', '1') ;")
execSQL("INSERT INTO `rss` (bookmarked,content, content_image, channel_image_url,channel_title, content_raw, author, title, pub_date_timestamp, pub_date, contentImage, link, channel_link) VALUES ('1','', '', '', '', '', 'author', 'ptitle', 'pub_date_timestamp', 'pub date', 'image', 'https://post.link.test', 'https://some.url2');")
}
}
Expand All @@ -164,13 +188,26 @@ class DatabaseMigrationTest {
private fun createAndPopulateDBVersion3() {
mMigrationTestHelper.createDatabase(dbName, 3).use { database ->
database.apply {
execSQL("INSERT INTO `source` (id, url, name, is_active) VALUES ('0','https://some.url','source name', '0') ;")
execSQL("INSERT INTO `source` (id, url, name, is_active) VALUES ('0', 'https://some.url', 'source name', '0') ;")
execSQL("INSERT INTO `rss` (bookmarked,content, content_image, channel_image_url,channel_title, content_raw, author, title, pub_date_timestamp, pub_date, content_image, link, channel_link) VALUES ('1','', '', '', '', '', 'author', 'ptitle', 'pub_date_timestamp', 'pub date', 'image', 'https://post.link.test', 'https://channel.link.test');")
}
}
}

private fun getMigrationValidatedRoomDatabase(migrations: Array<Migration>): AppDatabase {
private fun createAndPopulateDBVersion4() {
mMigrationTestHelper.createDatabase(dbName, 3).use { database ->
database.apply {
execSQL("INSERT INTO `source` (id, url, name, is_active) VALUES ('0', 'https://some.url', 'source name', '0') ;")
execSQL("INSERT INTO `source` (id, url, name, is_active) VALUES ('1', 'https://some.url2', 'source name2', '1') ;")

}
}
}

private fun getMigrationValidatedRoomDatabase(
version: Int,
migrations: Array<Migration>
): AppDatabase {
return Room.databaseBuilder(
context,
AppDatabase::class.java,
Expand All @@ -182,10 +219,10 @@ class DatabaseMigrationTest {
build()
}.also { database ->
mMigrationTestHelper.closeWhenFinished(database)

//
mMigrationTestHelper.runMigrationsAndValidate(
dbName,
3,
version,
true,
*migrations
)
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<application
android:name=".App"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/com/droidfeed/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@ class App : Application(), HasActivityInjector {
super.onCreate()
initDagger()

initSources()

sharedPrefs.appOpenCount += 1
}

private fun initSources() {
}

private fun initDagger() {
DaggerAppComponent
.builder()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/droidfeed/data/db/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.droidfeed.data.model.Source
@Database(
entities = [(Source::class),
(Post::class)],
version = 4
version = 5
)
abstract class AppDatabase : RoomDatabase() {

Expand Down
Loading

0 comments on commit 123a93e

Please sign in to comment.