Skip to content

Commit

Permalink
Fixes mozilla-mobile#4528 - Prevent share menu from jumping
Browse files Browse the repository at this point in the history
Plus a bunch of docs and refactoring
  • Loading branch information
NotWoods authored and vespertineSiren committed Nov 19, 2019
1 parent 98627e0 commit 3e15188
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/org/mozilla/fenix/share/ShareController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.getRootView
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.share.listadapters.AppShareOption
import org.mozilla.fenix.share.listadapters.AndroidShareOption

/**
* [ShareFragment] controller.
Expand All @@ -36,7 +36,7 @@ import org.mozilla.fenix.share.listadapters.AppShareOption
interface ShareController {
fun handleReauth()
fun handleShareClosed()
fun handleShareToApp(app: AppShareOption)
fun handleShareToApp(app: AndroidShareOption.App)
fun handleAddNewDevice()
fun handleShareToDevice(device: Device)
fun handleShareToAllDevices(devices: List<Device>)
Expand Down Expand Up @@ -72,7 +72,7 @@ class DefaultShareController(
dismiss()
}

override fun handleShareToApp(app: AppShareOption) {
override fun handleShareToApp(app: AndroidShareOption.App) {
val intent = Intent(ACTION_SEND).apply {
putExtra(EXTRA_TEXT, getShareText())
type = "text/plain"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/mozilla/fenix/share/ShareInteractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package org.mozilla.fenix.share

import mozilla.components.concept.sync.Device
import org.mozilla.fenix.share.listadapters.AppShareOption
import org.mozilla.fenix.share.listadapters.AndroidShareOption

/**
* Interactor for the share screen.
Expand Down Expand Up @@ -37,7 +37,7 @@ class ShareInteractor(
controller.handleShareToAllDevices(devices)
}

override fun onShareToApp(appToShareTo: AppShareOption) {
override fun onShareToApp(appToShareTo: AndroidShareOption.App) {
controller.handleShareToApp(appToShareTo)
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/org/mozilla/fenix/share/ShareToAppsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import android.view.ViewGroup
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.share_to_apps.*
import org.mozilla.fenix.R
import org.mozilla.fenix.share.listadapters.AndroidShareOption
import org.mozilla.fenix.share.listadapters.AppShareAdapter
import org.mozilla.fenix.share.listadapters.AppShareOption

/**
* Callbacks for possible user interactions on the [ShareCloseView]
*/
interface ShareToAppsInteractor {
fun onShareToApp(appToShareTo: AppShareOption)
fun onShareToApp(appToShareTo: AndroidShareOption.App)
}

class ShareToAppsView(
Expand All @@ -34,7 +34,7 @@ class ShareToAppsView(
appsList.adapter = adapter
}

fun setShareTargets(targets: List<AppShareOption>) {
fun setShareTargets(targets: List<AndroidShareOption>) {
progressBar.visibility = View.GONE
appsList.visibility = View.VISIBLE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.share.listadapters.AppShareOption
import org.mozilla.fenix.share.listadapters.AndroidShareOption
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

Expand Down Expand Up @@ -84,7 +84,7 @@ class ShareControllerTest {
fun `handleShareToApp should start a new sharing activity and close this`() {
val appPackageName = "package"
val appClassName = "activity"
val appShareOption = AppShareOption("app", mockk(), appPackageName, appClassName)
val appShareOption = AndroidShareOption.App("app", mockk(), appPackageName, appClassName)
val shareIntent = slot<Intent>()
// Our share Intent uses `FLAG_ACTIVITY_NEW_TASK` but when resolving the startActivity call
// needed for capturing the actual Intent used the `slot` one doesn't have this flag so we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.mockk.mockk
import io.mockk.verify
import mozilla.components.concept.sync.Device
import org.junit.Test
import org.mozilla.fenix.share.listadapters.AppShareOption
import org.mozilla.fenix.share.listadapters.AndroidShareOption

class ShareInteractorTest {
private val controller = mockk<ShareController>(relaxed = true)
Expand Down Expand Up @@ -62,7 +62,7 @@ class ShareInteractorTest {

@Test
fun onShareToApp() {
val app = mockk<AppShareOption>()
val app = mockk<AndroidShareOption.App>()

interactor.onShareToApp(app)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import io.mockk.verifyOrder
import kotlinx.android.synthetic.main.app_share_list_item.view.*
import mozilla.components.support.test.robolectric.testContext
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -27,11 +28,11 @@ import org.robolectric.annotation.Config
@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 appOptions = mutableListOf<AndroidShareOption>(
AndroidShareOption.App("App 0", mockk(), "package 0", "activity 0"),
AndroidShareOption.App("App 1", mockk(), "package 1", "activity 1")
)
private val appOptionsEmpty = emptyList<AppShareOption>()
private val appOptionsEmpty = emptyList<AndroidShareOption>()
private val interactor: ShareInteractor = mockk(relaxed = true)

@Test
Expand Down

0 comments on commit 3e15188

Please sign in to comment.