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
Matthew Finkel
fenix
Commits
a4439ff3
Commit
a4439ff3
authored
Oct 01, 2019
by
Denys M
Committed by
Emily Kager
Oct 07, 2019
Browse files
For #3563. Use `ListAdapter` for App Share list.
parent
e55eda30
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/org/mozilla/fenix/share/ShareFragment.kt
View file @
a4439ff3
...
...
@@ -157,7 +157,7 @@ class ShareFragment : AppCompatDialogFragment() {
val
devicesShareOptions
=
devicesListDeferred
.
await
()
shareToAccountDevicesView
.
setSharetargets
(
devicesShareOptions
)
val
appsToShareTo
=
appsListDeferred
.
await
()
shareToAppsView
.
setShare
t
argets
(
appsToShareTo
)
shareToAppsView
.
setShare
T
argets
(
appsToShareTo
)
}
}
...
...
app/src/main/java/org/mozilla/fenix/share/ShareToAppsView.kt
View file @
a4439ff3
...
...
@@ -8,10 +8,10 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
kotlinx.android.extensions.LayoutContainer
import
org.mozilla.fenix.R
import
org.mozilla.fenix.share.listadapters.AppShareOption
import
kotlinx.android.synthetic.main.share_to_apps.*
import
org.mozilla.fenix.R
import
org.mozilla.fenix.share.listadapters.AppShareAdapter
import
org.mozilla.fenix.share.listadapters.AppShareOption
/**
* Callbacks for possible user interactions on the [ShareCloseView]
...
...
@@ -24,19 +24,20 @@ class ShareToAppsView(
override
val
containerView
:
ViewGroup
,
interactor
:
ShareToAppsInteractor
)
:
LayoutContainer
{
private
val
adapter
=
AppShareAdapter
(
interactor
)
init
{
LayoutInflater
.
from
(
containerView
.
context
)
.
inflate
(
R
.
layout
.
share_to_apps
,
containerView
,
true
)
appsList
.
adapter
=
AppShareAdapter
(
interactor
)
appsList
.
adapter
=
adapter
}
fun
setShare
t
argets
(
targets
:
List
<
AppShareOption
>)
{
fun
setShare
T
argets
(
targets
:
List
<
AppShareOption
>)
{
progressBar
.
visibility
=
View
.
GONE
appsList
.
visibility
=
View
.
VISIBLE
with
(
appsList
.
adapter
as
AppShareAdapter
)
{
updateData
(
targets
)
}
adapter
.
submitList
(
targets
)
}
}
app/src/main/java/org/mozilla/fenix/share/listadapters/AppShareAdapter.kt
View file @
a4439ff3
...
...
@@ -7,14 +7,14 @@ package org.mozilla.fenix.share.listadapters
import
android.graphics.drawable.Drawable
import
android.view.LayoutInflater
import
android.view.ViewGroup
import
androidx.recyclerview.widget.RecyclerView
import
androidx.recyclerview.widget.DiffUtil
import
androidx.recyclerview.widget.ListAdapter
import
org.mozilla.fenix.share.ShareToAppsInteractor
import
org.mozilla.fenix.share.viewholders.AppViewHolder
class
AppShareAdapter
(
private
val
interactor
:
ShareToAppsInteractor
,
private
val
applications
:
MutableList
<
AppShareOption
>
=
mutableListOf
()
)
:
RecyclerView
.
Adapter
<
AppViewHolder
>()
{
private
val
interactor
:
ShareToAppsInteractor
)
:
ListAdapter
<
AppShareOption
,
AppViewHolder
>(
DiffCallback
)
{
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
AppViewHolder
{
val
view
=
LayoutInflater
.
from
(
parent
.
context
)
...
...
@@ -23,17 +23,18 @@ class AppShareAdapter(
return
AppViewHolder
(
view
,
interactor
)
}
override
fun
getItemCount
():
Int
=
applications
.
size
override
fun
onBindViewHolder
(
holder
:
AppViewHolder
,
position
:
Int
)
{
holder
.
bind
(
applications
[
position
]
)
holder
.
bind
(
getItem
(
position
)
)
}
}
fun
updateData
(
applications
:
List
<
AppShareOption
>)
{
this
.
applications
.
clear
()
this
.
applications
.
addAll
(
applications
)
notifyDataSetChanged
()
}
private
object
DiffCallback
:
DiffUtil
.
ItemCallback
<
AppShareOption
>()
{
override
fun
areItemsTheSame
(
oldItem
:
AppShareOption
,
newItem
:
AppShareOption
)
=
oldItem
.
packageName
==
newItem
.
packageName
override
fun
areContentsTheSame
(
oldItem
:
AppShareOption
,
newItem
:
AppShareOption
)
=
oldItem
==
newItem
}
data class
AppShareOption
(
...
...
app/src/test/java/org/mozilla/fenix/share/listadapters/AppShareAdapterTest.kt
View file @
a4439ff3
...
...
@@ -28,26 +28,25 @@ import org.robolectric.annotation.Config
@RunWith
(
RobolectricTestRunner
::
class
)
@Config
(
application
=
TestApplication
::
class
)
class
AppShareAdapterTest
{
private
val
appOptions
=
mutableListOf
(
AppShareOption
(
"App 0"
,
mockk
(),
"package 0"
,
"activity 0"
),
AppShareOption
(
"App 1"
,
mockk
(),
"package 1"
,
"activity 1"
)
)
private
val
appOptionsEmpty
=
mutable
List
Of
<
AppShareOption
>()
private
val
appOptionsEmpty
=
empty
List
<
AppShareOption
>()
private
val
interactor
:
ShareInteractor
=
mockk
(
relaxed
=
true
)
@Test
fun
`updateData
should
replace
all
previous
data
with
argument
and
call
notifyDataSetChanged
()
`
()
{
// Used AppShareAdapter as a spy to ease testing of
notifyDataSetChanged
()
fun
`updateData
should
call
submitList
()
`
()
{
// Used AppShareAdapter as a spy to ease testing of
submitList
()
// and appOptionsEmpty to be able to record them being called
val
adapter
=
spyk
(
AppShareAdapter
(
mockk
()
,
appOptionsEmpty
))
every
{
adapter
.
notifyDataSetChanged
(
)
}
just
Runs
val
adapter
=
spyk
(
AppShareAdapter
(
mockk
()
).
apply
{
submitList
(
appOptionsEmpty
)
}
)
every
{
adapter
.
submitList
(
any
()
)
}
just
Runs
adapter
.
updateData
(
appOptions
)
adapter
.
submitList
(
appOptions
)
verifyOrder
{
appOptionsEmpty
.
clear
()
appOptionsEmpty
.
addAll
(
appOptions
)
adapter
.
notifyDataSetChanged
()
adapter
.
submitList
(
appOptions
)
}
}
...
...
@@ -60,7 +59,7 @@ class AppShareAdapterTest {
@Test
fun
`getItemCount
after
updateData
()
call
should
return
the
the
passed
in
list
'
s
size`
()
{
val
adapter
=
AppShareAdapter
(
mockk
()
,
appOptions
)
val
adapter
=
AppShareAdapter
(
mockk
()
).
apply
{
submitList
(
appOptions
)
}
assertThat
(
adapter
.
itemCount
).
isEqualTo
(
2
)
}
...
...
@@ -89,7 +88,7 @@ class AppShareAdapterTest {
@Test
fun
`the
adapter
binds
the
right
item
to
a
ViewHolder`
()
{
val
adapter
=
AppShareAdapter
(
interactor
,
appOptions
)
val
adapter
=
AppShareAdapter
(
interactor
).
apply
{
submitList
(
appOptions
)
}
val
parentView
:
ViewGroup
=
mockk
(
relaxed
=
true
)
val
itemView
:
ViewGroup
=
mockk
(
relaxed
=
true
)
every
{
parentView
.
context
}
returns
testContext
...
...
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