mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
For #3478 - Add Tab sent snackbar confirmation for device sharing
This commit is contained in:
parent
1f12ee0f8c
commit
21c75ca1bb
@ -17,6 +17,7 @@ import androidx.navigation.NavController
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.NavigationUI
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import io.sentry.Sentry
|
||||
import io.sentry.event.Breadcrumb
|
||||
import io.sentry.event.BreadcrumbBuilder
|
||||
@ -31,9 +32,11 @@ import mozilla.components.support.base.feature.BackHandler
|
||||
import mozilla.components.support.ktx.kotlin.isUrl
|
||||
import mozilla.components.support.ktx.kotlin.toNormalizedUrl
|
||||
import mozilla.components.support.utils.SafeIntent
|
||||
import org.mozilla.fenix.components.FenixSnackbar
|
||||
import org.mozilla.fenix.components.isSentryEnabled
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.getRootView
|
||||
import org.mozilla.fenix.ext.nav
|
||||
import org.mozilla.fenix.home.HomeFragmentDirections
|
||||
import org.mozilla.fenix.library.bookmarks.BookmarkFragmentDirections
|
||||
@ -44,10 +47,11 @@ import org.mozilla.fenix.settings.AccountProblemFragmentDirections
|
||||
import org.mozilla.fenix.settings.PairFragmentDirections
|
||||
import org.mozilla.fenix.settings.SettingsFragmentDirections
|
||||
import org.mozilla.fenix.settings.TurnOnSyncFragmentDirections
|
||||
import org.mozilla.fenix.share.ShareFragment
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
||||
@SuppressWarnings("TooManyFunctions")
|
||||
open class HomeActivity : AppCompatActivity() {
|
||||
@SuppressWarnings("TooManyFunctions", "LargeClass")
|
||||
open class HomeActivity : AppCompatActivity(), ShareFragment.TabsSharedCallback {
|
||||
open val isCustomTab = false
|
||||
private var sessionObserver: SessionManager.Observer? = null
|
||||
|
||||
@ -370,6 +374,17 @@ open class HomeActivity : AppCompatActivity() {
|
||||
}.also { components.core.sessionManager.register(it, this) }
|
||||
}
|
||||
|
||||
override fun onTabsShared(tabsSize: Int) {
|
||||
this@HomeActivity.getRootView()?.let {
|
||||
FenixSnackbar.make(it, Snackbar.LENGTH_SHORT).setText(
|
||||
getString(
|
||||
if (tabsSize == 1) R.string.sync_sent_tab_snackbar else
|
||||
R.string.sync_sent_tabs_snackbar
|
||||
)
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val OPEN_TO_BROWSER = "open_to_browser"
|
||||
}
|
||||
|
@ -104,7 +104,6 @@ import java.net.URL
|
||||
|
||||
@SuppressWarnings("TooManyFunctions", "LargeClass")
|
||||
class BrowserFragment : Fragment(), BackHandler {
|
||||
|
||||
private lateinit var toolbarComponent: ToolbarComponent
|
||||
|
||||
private var tabCollectionObserver: Observer<List<TabCollection>>? = null
|
||||
@ -953,7 +952,7 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||
}
|
||||
|
||||
private fun shareUrl(url: String) {
|
||||
val directions = BrowserFragmentDirections.actionBrowserFragmentToShareFragment(url)
|
||||
val directions = BrowserFragmentDirections.actionBrowserFragmentToShareFragment(url = url)
|
||||
nav(R.id.browserFragment, directions)
|
||||
}
|
||||
|
||||
|
@ -717,7 +717,10 @@ class HomeFragment : Fragment(), AccountObserver {
|
||||
|
||||
private fun share(url: String? = null, tabs: List<ShareTab>? = null) {
|
||||
val directions =
|
||||
HomeFragmentDirections.actionHomeFragmentToShareFragment(url = url, tabs = tabs?.toTypedArray())
|
||||
HomeFragmentDirections.actionHomeFragmentToShareFragment(
|
||||
url = url,
|
||||
tabs = tabs?.toTypedArray()
|
||||
)
|
||||
nav(R.id.homeFragment, directions)
|
||||
}
|
||||
|
||||
|
@ -217,8 +217,8 @@ class BookmarkFragment : Fragment(), BackHandler, AccountObserver {
|
||||
nav(
|
||||
R.id.bookmarkFragment,
|
||||
BookmarkFragmentDirections.actionBookmarkFragmentToShareFragment(
|
||||
this,
|
||||
it.item.title
|
||||
url = this,
|
||||
title = it.item.title
|
||||
)
|
||||
)
|
||||
metrics()?.track(Event.ShareBookmark)
|
||||
|
@ -287,7 +287,10 @@ class HistoryFragment : Fragment(), BackHandler {
|
||||
|
||||
private fun share(url: String? = null, tabs: List<ShareTab>? = null) {
|
||||
val directions =
|
||||
HistoryFragmentDirections.actionHistoryFragmentToShareFragment(url = url, tabs = tabs?.toTypedArray())
|
||||
HistoryFragmentDirections.actionHistoryFragmentToShareFragment(
|
||||
url = url,
|
||||
tabs = tabs?.toTypedArray()
|
||||
)
|
||||
nav(R.id.historyFragment, directions)
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import kotlinx.android.synthetic.main.fragment_share.view.*
|
||||
import mozilla.components.concept.sync.DeviceEventOutgoing
|
||||
import mozilla.components.concept.sync.OAuthAccount
|
||||
import org.mozilla.fenix.FenixViewModelProvider
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.nav
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
@ -28,6 +29,10 @@ import org.mozilla.fenix.mvi.ActionBusFactory
|
||||
import org.mozilla.fenix.mvi.getAutoDisposeObservable
|
||||
|
||||
class ShareFragment : AppCompatDialogFragment() {
|
||||
interface TabsSharedCallback {
|
||||
fun onTabsShared(tabsSize: Int)
|
||||
}
|
||||
|
||||
private lateinit var component: ShareComponent
|
||||
private var tabs: Array<ShareTab> = emptyArray()
|
||||
|
||||
@ -39,7 +44,6 @@ class ShareFragment : AppCompatDialogFragment() {
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val view = inflater.inflate(R.layout.fragment_share, container, false)
|
||||
val args = ShareFragmentArgs.fromBundle(arguments!!)
|
||||
|
||||
if (args.url == null && args.tabs.isNullOrEmpty()) {
|
||||
throw IllegalStateException("URL and tabs cannot both be null.")
|
||||
}
|
||||
@ -131,6 +135,7 @@ class ShareFragment : AppCompatDialogFragment() {
|
||||
)
|
||||
}
|
||||
}
|
||||
(activity as? HomeActivity)?.onTabsShared(tabs.size)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,8 +419,8 @@
|
||||
<argument
|
||||
android:name="tabs"
|
||||
android:defaultValue="@null"
|
||||
app:nullable="true"
|
||||
app:argType="org.mozilla.fenix.share.ShareTab[]" />
|
||||
app:argType="org.mozilla.fenix.share.ShareTab[]"
|
||||
app:nullable="true" />
|
||||
<action
|
||||
android:id="@+id/action_shareFragment_to_turnOnSyncFragment"
|
||||
app:destination="@+id/turnOnSyncFragment"
|
||||
|
Loading…
Reference in New Issue
Block a user