Skip to content

Commit

Permalink
Issue mozilla-mobile#6331: Add isDefault bool to TopSiteEntity and AP…
Browse files Browse the repository at this point in the history
…Is for flagging default top sites
  • Loading branch information
gabrielluong committed Apr 9, 2020
1 parent 4ebfff7 commit a98f29d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)

0 comments on commit a98f29d

Please sign in to comment.