diff --git a/components/feature/top-sites/src/androidTest/java/mozilla/components/feature/top/sites/db/TopSiteDaoTest.kt b/components/feature/top-sites/src/androidTest/java/mozilla/components/feature/top/sites/db/TopSiteDaoTest.kt index c74b21be925..978b6d6cd3e 100644 --- a/components/feature/top-sites/src/androidTest/java/mozilla/components/feature/top/sites/db/TopSiteDaoTest.kt +++ b/components/feature/top-sites/src/androidTest/java/mozilla/components/feature/top/sites/db/TopSiteDaoTest.kt @@ -46,6 +46,7 @@ class TopSiteDaoTest { val topSite = TopSiteEntity( title = "Mozilla", url = "https://www.mozilla.org", + isDefault = false, createdAt = 200 ).also { it.id = topSiteDao.insertTopSite(it) @@ -67,6 +68,7 @@ class TopSiteDaoTest { val topSite1 = TopSiteEntity( title = "Mozilla", url = "https://www.mozilla.org", + isDefault = false, createdAt = 200 ).also { it.id = topSiteDao.insertTopSite(it) @@ -75,6 +77,7 @@ class TopSiteDaoTest { val topSite2 = TopSiteEntity( title = "Firefox", url = "https://www.firefox.com", + isDefault = false, createdAt = 100 ).also { it.id = topSiteDao.insertTopSite(it) diff --git a/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/TopSite.kt b/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/TopSite.kt index a559c3d4963..bb688551fe9 100644 --- a/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/TopSite.kt +++ b/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/TopSite.kt @@ -22,4 +22,9 @@ interface TopSite { * The URL of the top site. */ val url: String + + /** + * Whether or not the top is a default top site (added as a default by the application). + */ + val isDefault: Boolean } diff --git a/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/TopSiteStorage.kt b/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/TopSiteStorage.kt index 94aa1ef0dc4..09c1cea645b 100644 --- a/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/TopSiteStorage.kt +++ b/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/TopSiteStorage.kt @@ -23,10 +23,11 @@ class TopSiteStorage( /** * Adds a new [TopSite]. */ - fun addTopSite(title: String, url: String) { + fun addTopSite(title: String, url: String, isDefault: Boolean = false) { TopSiteEntity( title = title, url = url, + isDefault = isDefault, createdAt = System.currentTimeMillis() ).also { entity -> entity.id = database.value.topSiteDao().insertTopSite(entity) diff --git a/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/adapter/TopSiteAdapter.kt b/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/adapter/TopSiteAdapter.kt index 2584dcd7d42..08c62e00e2b 100644 --- a/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/adapter/TopSiteAdapter.kt +++ b/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/adapter/TopSiteAdapter.kt @@ -19,6 +19,9 @@ internal class TopSiteAdapter( override val url: String get() = entity.url + override val isDefault: Boolean + get() = entity.isDefault + override fun equals(other: Any?): Boolean { if (other !is TopSiteAdapter) { return false diff --git a/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/db/TopSiteEntity.kt b/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/db/TopSiteEntity.kt index cba04063221..41b9190af71 100644 --- a/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/db/TopSiteEntity.kt +++ b/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/db/TopSiteEntity.kt @@ -23,6 +23,9 @@ internal data class TopSiteEntity( @ColumnInfo(name = "url") var url: String, + @ColumnInfo(name = "isDefault") + var isDefault: Boolean = false, + @ColumnInfo(name = "created_at") var createdAt: Long = System.currentTimeMillis() )