Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
android-components
Commits
dc7ee797
Commit
dc7ee797
authored
Aug 04, 2020
by
Gabriel Luong
Browse files
Issue #7978: Part 3 - Replace Top prefix to Pinned for TopSiteDao, TopSite, TopSiteAdapter
parent
f3705791
Changes
10
Hide whitespace changes
Inline
Side-by-side
components/feature/top-sites/src/androidTest/java/mozilla/components/feature/top/sites/PinnedSitesStorageTest.kt
View file @
dc7ee797
...
...
@@ -63,8 +63,8 @@ class PinnedSitesStorageTest {
@Test
fun
testAddingTopSite
()
{
storage
.
add
Top
Site
(
"Mozilla"
,
"https://www.mozilla.org"
)
storage
.
add
Top
Site
(
"Firefox"
,
"https://www.firefox.com"
,
isDefault
=
true
)
storage
.
add
Pinned
Site
(
"Mozilla"
,
"https://www.mozilla.org"
)
storage
.
add
Pinned
Site
(
"Firefox"
,
"https://www.firefox.com"
,
isDefault
=
true
)
val
topSites
=
getAllTopSites
()
...
...
@@ -80,13 +80,13 @@ class PinnedSitesStorageTest {
@Test
fun
testRemovingTopSites
()
{
storage
.
add
Top
Site
(
"Mozilla"
,
"https://www.mozilla.org"
)
storage
.
add
Top
Site
(
"Firefox"
,
"https://www.firefox.com"
)
storage
.
add
Pinned
Site
(
"Mozilla"
,
"https://www.mozilla.org"
)
storage
.
add
Pinned
Site
(
"Firefox"
,
"https://www.firefox.com"
)
getAllTopSites
().
let
{
topSites
->
assertEquals
(
2
,
topSites
.
size
)
storage
.
remove
Top
Site
(
topSites
[
0
])
storage
.
remove
Pinned
Site
(
topSites
[
0
])
}
getAllTopSites
().
let
{
topSites
->
...
...
@@ -99,10 +99,10 @@ class PinnedSitesStorageTest {
@Test
fun
testGettingTopSites
()
=
runBlocking
{
storage
.
add
Top
Site
(
"Mozilla"
,
"https://www.mozilla.org"
)
storage
.
add
Top
Site
(
"Firefox"
,
"https://www.firefox.com"
,
isDefault
=
true
)
storage
.
add
Pinned
Site
(
"Mozilla"
,
"https://www.mozilla.org"
)
storage
.
add
Pinned
Site
(
"Firefox"
,
"https://www.firefox.com"
,
isDefault
=
true
)
val
topSites
=
storage
.
get
Top
Sites
().
first
()
val
topSites
=
storage
.
get
Pinned
Sites
().
first
()
assertNotNull
(
topSites
)
assertEquals
(
2
,
topSites
.
size
)
...
...
@@ -247,8 +247,8 @@ class PinnedSitesStorageTest {
}
}
private
fun
getAllTopSites
():
List
<
Top
Site
>
{
val
dataSource
=
storage
.
get
Top
SitesPaged
().
create
()
private
fun
getAllTopSites
():
List
<
Pinned
Site
>
{
val
dataSource
=
storage
.
get
Pinned
SitesPaged
().
create
()
val
pagedList
=
PagedList
.
Builder
(
dataSource
,
10
)
.
setNotifyExecutor
(
executor
)
...
...
components/feature/top-sites/src/androidTest/java/mozilla/components/feature/top/sites/db/
Top
SiteDaoTest.kt
→
components/feature/top-sites/src/androidTest/java/mozilla/components/feature/top/sites/db/
Pinned
SiteDaoTest.kt
View file @
dc7ee797
...
...
@@ -17,12 +17,12 @@ import org.junit.Test
import
java.util.concurrent.ExecutorService
import
java.util.concurrent.Executors
class
Top
SiteDaoTest
{
class
Pinned
SiteDaoTest
{
private
val
context
:
Context
get
()
=
ApplicationProvider
.
getApplicationContext
()
private
lateinit
var
database
:
TopSiteDatabase
private
lateinit
var
top
SiteDao
:
Top
SiteDao
private
lateinit
var
pinned
SiteDao
:
Pinned
SiteDao
private
lateinit
var
executor
:
ExecutorService
@
get
:
Rule
...
...
@@ -31,7 +31,7 @@ class TopSiteDaoTest {
@Before
fun
setUp
()
{
database
=
Room
.
inMemoryDatabaseBuilder
(
context
,
TopSiteDatabase
::
class
.
java
).
build
()
top
SiteDao
=
database
.
top
SiteDao
()
pinned
SiteDao
=
database
.
pinned
SiteDao
()
executor
=
Executors
.
newSingleThreadExecutor
()
}
...
...
@@ -49,10 +49,10 @@ class TopSiteDaoTest {
isDefault
=
false
,
createdAt
=
200
).
also
{
it
.
id
=
top
SiteDao
.
insert
Top
Site
(
it
)
it
.
id
=
pinned
SiteDao
.
insert
Pinned
Site
(
it
)
}
val
dataSource
=
top
SiteDao
.
get
Top
SitesPaged
().
create
()
val
dataSource
=
pinned
SiteDao
.
get
Pinned
SitesPaged
().
create
()
val
pagedList
=
PagedList
.
Builder
(
dataSource
,
10
)
.
setNotifyExecutor
(
executor
)
...
...
@@ -71,7 +71,7 @@ class TopSiteDaoTest {
isDefault
=
false
,
createdAt
=
200
).
also
{
it
.
id
=
top
SiteDao
.
insert
Top
Site
(
it
)
it
.
id
=
pinned
SiteDao
.
insert
Pinned
Site
(
it
)
}
val
topSite2
=
PinnedSiteEntity
(
...
...
@@ -80,12 +80,12 @@ class TopSiteDaoTest {
isDefault
=
false
,
createdAt
=
100
).
also
{
it
.
id
=
top
SiteDao
.
insert
Top
Site
(
it
)
it
.
id
=
pinned
SiteDao
.
insert
Pinned
Site
(
it
)
}
top
SiteDao
.
delete
Top
Site
(
topSite1
)
pinned
SiteDao
.
delete
Pinned
Site
(
topSite1
)
val
dataSource
=
top
SiteDao
.
get
Top
SitesPaged
().
create
()
val
dataSource
=
pinned
SiteDao
.
get
Pinned
SitesPaged
().
create
()
val
pagedList
=
PagedList
.
Builder
(
dataSource
,
10
)
.
setNotifyExecutor
(
executor
)
...
...
components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/
Top
Site.kt
→
components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/
Pinned
Site.kt
View file @
dc7ee797
...
...
@@ -5,26 +5,26 @@
package
mozilla.components.feature.top.sites
/**
* A
top
site.
* A
pinned
site.
*/
interface
Top
Site
{
interface
Pinned
Site
{
/**
* Unique ID of this
top
site.
* Unique ID of this
pinned
site.
*/
val
id
:
Long
/**
* The title of the
top
site.
* The title of the
pinned
site.
*/
val
title
:
String
/**
* The URL of the
top
site.
* The URL of the
pinned
site.
*/
val
url
:
String
/**
* Whether or not the
top
site is a default
top
site (added as a default by the application).
* Whether or not the
pinned
site is a default
pinned
site (added as a default by the application).
*/
val
isDefault
:
Boolean
}
components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/PinnedSiteStorage.kt
View file @
dc7ee797
...
...
@@ -8,12 +8,12 @@ import android.content.Context
import
androidx.paging.DataSource
import
kotlinx.coroutines.flow.Flow
import
kotlinx.coroutines.flow.map
import
mozilla.components.feature.top.sites.adapter.
Top
SiteAdapter
import
mozilla.components.feature.top.sites.adapter.
Pinned
SiteAdapter
import
mozilla.components.feature.top.sites.db.TopSiteDatabase
import
mozilla.components.feature.top.sites.db.PinnedSiteEntity
/**
* A storage implementation for organizing
top
sites.
* A storage implementation for organizing
pinned
sites.
*/
class
PinnedSiteStorage
(
context
:
Context
...
...
@@ -21,46 +21,46 @@ class PinnedSiteStorage(
internal
var
database
:
Lazy
<
TopSiteDatabase
>
=
lazy
{
TopSiteDatabase
.
get
(
context
)
}
/**
* Adds a new [
Top
Site].
* Adds a new [
Pinned
Site].
*
* @param title The title string.
* @param url The URL string.
* @param isDefault Whether or not the
top
site added should be a default
top
site. This
is
* used to identify
top
sites that are added by the application.
* @param isDefault Whether or not the
pinned
site added should be a default
pinned
site. This
*
is
used to identify
pinned
sites that are added by the application.
*/
fun
add
Top
Site
(
title
:
String
,
url
:
String
,
isDefault
:
Boolean
=
false
)
{
fun
add
Pinned
Site
(
title
:
String
,
url
:
String
,
isDefault
:
Boolean
=
false
)
{
PinnedSiteEntity
(
title
=
title
,
url
=
url
,
isDefault
=
isDefault
,
createdAt
=
System
.
currentTimeMillis
()
).
also
{
entity
->
entity
.
id
=
database
.
value
.
top
SiteDao
().
insert
Top
Site
(
entity
)
entity
.
id
=
database
.
value
.
pinned
SiteDao
().
insert
Pinned
Site
(
entity
)
}
}
/**
* Returns a [Flow] list of all the [
Top
Site] instances.
* Returns a [Flow] list of all the [
Pinned
Site] instances.
*/
fun
get
Top
Sites
():
Flow
<
List
<
Top
Site
>>
{
return
database
.
value
.
top
SiteDao
().
get
Top
Sites
().
map
{
list
->
list
.
map
{
entity
->
Top
SiteAdapter
(
entity
)
}
fun
get
Pinned
Sites
():
Flow
<
List
<
Pinned
Site
>>
{
return
database
.
value
.
pinned
SiteDao
().
get
Pinned
Sites
().
map
{
list
->
list
.
map
{
entity
->
Pinned
SiteAdapter
(
entity
)
}
}
}
/**
* Returns all [
Top
Site]s as a [DataSource.Factory].
* Returns all [
Pinned
Site]s as a [DataSource.Factory].
*/
fun
get
Top
SitesPaged
():
DataSource
.
Factory
<
Int
,
Top
Site
>
=
database
.
value
.
top
SiteDao
()
.
get
Top
SitesPaged
()
.
map
{
entity
->
Top
SiteAdapter
(
entity
)
}
fun
get
Pinned
SitesPaged
():
DataSource
.
Factory
<
Int
,
Pinned
Site
>
=
database
.
value
.
pinned
SiteDao
()
.
get
Pinned
SitesPaged
()
.
map
{
entity
->
Pinned
SiteAdapter
(
entity
)
}
/**
* Removes the given [
Top
Site].
* Removes the given [
Pinned
Site].
*/
fun
remove
Top
Site
(
site
:
Top
Site
)
{
val
top
SiteEntity
=
(
site
as
Top
SiteAdapter
).
entity
database
.
value
.
top
SiteDao
().
delete
TopSite
(
top
SiteEntity
)
fun
remove
Pinned
Site
(
site
:
Pinned
Site
)
{
val
pinned
SiteEntity
=
(
site
as
Pinned
SiteAdapter
).
entity
database
.
value
.
pinned
SiteDao
().
delete
PinnedSite
(
pinned
SiteEntity
)
}
}
components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/adapter/
Top
SiteAdapter.kt
→
components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/adapter/
Pinned
SiteAdapter.kt
View file @
dc7ee797
...
...
@@ -4,12 +4,12 @@
package
mozilla.components.feature.top.sites.adapter
import
mozilla.components.feature.top.sites.
Top
Site
import
mozilla.components.feature.top.sites.
Pinned
Site
import
mozilla.components.feature.top.sites.db.PinnedSiteEntity
internal
class
Top
SiteAdapter
(
internal
class
Pinned
SiteAdapter
(
internal
val
entity
:
PinnedSiteEntity
)
:
Top
Site
{
)
:
Pinned
Site
{
override
val
id
:
Long
get
()
=
entity
.
id
!!
...
...
@@ -23,7 +23,7 @@ internal class TopSiteAdapter(
get
()
=
entity
.
isDefault
override
fun
equals
(
other
:
Any
?):
Boolean
{
if
(
other
!
is
Top
SiteAdapter
)
{
if
(
other
!
is
Pinned
SiteAdapter
)
{
return
false
}
...
...
components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/db/
Top
SiteDao.kt
→
components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/db/
Pinned
SiteDao.kt
View file @
dc7ee797
...
...
@@ -16,18 +16,18 @@ import kotlinx.coroutines.flow.Flow
* Internal DAO for accessing [PinnedSiteEntity] instances.
*/
@Dao
internal
interface
Top
SiteDao
{
internal
interface
Pinned
SiteDao
{
@Insert
fun
insert
Top
Site
(
site
:
PinnedSiteEntity
):
Long
fun
insert
Pinned
Site
(
site
:
PinnedSiteEntity
):
Long
@Delete
fun
delete
Top
Site
(
site
:
PinnedSiteEntity
)
fun
delete
Pinned
Site
(
site
:
PinnedSiteEntity
)
@Transaction
@Query
(
"SELECT * FROM top_sites"
)
fun
get
Top
Sites
():
Flow
<
List
<
PinnedSiteEntity
>>
fun
get
Pinned
Sites
():
Flow
<
List
<
PinnedSiteEntity
>>
@Transaction
@Query
(
"SELECT * FROM top_sites"
)
fun
get
Top
SitesPaged
():
DataSource
.
Factory
<
Int
,
PinnedSiteEntity
>
fun
get
Pinned
SitesPaged
():
DataSource
.
Factory
<
Int
,
PinnedSiteEntity
>
}
components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/db/PinnedSiteEntity.kt
View file @
dc7ee797
...
...
@@ -9,7 +9,7 @@ import androidx.room.Entity
import
androidx.room.PrimaryKey
/**
* Internal entity representing a
top
site.
* Internal entity representing a
pinned
site.
*/
@Entity
(
tableName
=
"top_sites"
)
internal
data class
PinnedSiteEntity
(
...
...
components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/db/TopSiteDatabase.kt
View file @
dc7ee797
...
...
@@ -16,7 +16,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
*/
@Database
(
entities
=
[
PinnedSiteEntity
::
class
],
version
=
3
)
internal
abstract
class
TopSiteDatabase
:
RoomDatabase
()
{
abstract
fun
top
SiteDao
():
Top
SiteDao
abstract
fun
pinned
SiteDao
():
Pinned
SiteDao
companion
object
{
@Volatile
...
...
components/support/migration/src/main/java/mozilla/components/support/migration/FennecMigrator.kt
View file @
dc7ee797
...
...
@@ -1305,7 +1305,7 @@ class FennecMigrator private constructor(
// Reversed, so that first pinned site in Fennec ends up as the first one in Fenix, as well.
pinnedSitesWithUrl
.
reversed
().
forEach
{
pinnedSite
->
try
{
pinnedSitesStorage
.
add
Top
Site
(
pinnedSite
.
title
?:
""
,
pinnedSite
.
url
!!
)
pinnedSitesStorage
.
add
Pinned
Site
(
pinnedSite
.
title
?:
""
,
pinnedSite
.
url
!!
)
}
catch
(
e
:
Exception
)
{
failedToImport
++
// Let's not spam Sentry and submit the same exception multiple times
...
...
components/support/migration/src/test/java/mozilla/components/support/migration/FennecMigratorTest.kt
View file @
dc7ee797
...
...
@@ -272,7 +272,7 @@ class FennecMigratorTest {
assertTrue
(
historyStore
.
getVisited
().
isEmpty
())
assertTrue
(
bookmarksStore
.
searchBookmarks
(
"mozilla"
).
isEmpty
())
verify
(
topSiteStorage
,
never
()).
add
Top
Site
(
any
(),
any
(),
anyBoolean
())
verify
(
topSiteStorage
,
never
()).
add
Pinned
Site
(
any
(),
any
(),
anyBoolean
())
// Can run once.
with
(
migrator
.
migrateAsync
(
mock
()).
await
())
{
...
...
@@ -300,12 +300,12 @@ class FennecMigratorTest {
assertEquals
(
5
,
historyStore
.
getVisited
().
size
)
assertEquals
(
2
,
bookmarksStore
.
searchBookmarks
(
"mozilla"
).
size
)
verify
(
topSiteStorage
,
times
(
2
)).
add
Top
Site
(
any
(),
any
(),
anyBoolean
())
verify
(
topSiteStorage
).
add
Top
Site
(
verify
(
topSiteStorage
,
times
(
2
)).
add
Pinned
Site
(
any
(),
any
(),
anyBoolean
())
verify
(
topSiteStorage
).
add
Pinned
Site
(
"Featured extensions for Android – Add-ons for Firefox Android (en-US)"
,
"https://addons.mozilla.org/en-US/android/collections/4757633/mob/?page=1&collection_sort=-popularity"
)
verify
(
topSiteStorage
).
add
Top
Site
(
verify
(
topSiteStorage
).
add
Pinned
Site
(
"Internet for people, not profit — Mozilla"
,
"https://www.mozilla.org/en-US/"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment