2019-05-23 19:48:22 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.share
|
2019-05-23 19:48:22 +02:00
|
|
|
|
|
|
|
import android.os.Bundle
|
2019-05-29 00:05:16 +02:00
|
|
|
import android.os.Parcelable
|
2019-05-23 19:48:22 +02:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2019-05-24 00:38:03 +02:00
|
|
|
import androidx.appcompat.app.AppCompatDialogFragment
|
2019-05-29 00:05:16 +02:00
|
|
|
import kotlinx.android.parcel.Parcelize
|
2019-05-23 19:48:22 +02:00
|
|
|
import kotlinx.android.synthetic.main.fragment_share.view.*
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
|
2019-06-13 02:13:24 +02:00
|
|
|
class ShareFragment : AppCompatDialogFragment() {
|
2019-06-15 01:46:40 +02:00
|
|
|
interface TabsSharedCallback {
|
|
|
|
fun onTabsShared(tabsSize: Int)
|
|
|
|
}
|
|
|
|
|
2019-08-23 12:54:03 +02:00
|
|
|
private lateinit var shareInteractor: ShareInteractor
|
|
|
|
private lateinit var shareCloseView: ShareCloseView
|
|
|
|
private lateinit var shareToAccountDevicesView: ShareToAccountDevicesView
|
|
|
|
private lateinit var shareToAppsView: ShareToAppsView
|
2019-05-29 00:05:16 +02:00
|
|
|
private var tabs: Array<ShareTab> = emptyArray()
|
2019-05-23 19:48:22 +02:00
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2019-05-27 06:10:50 +02:00
|
|
|
setStyle(STYLE_NO_TITLE, R.style.ShareDialogStyle)
|
2019-05-23 19:48:22 +02:00
|
|
|
}
|
|
|
|
|
2019-07-12 18:44:36 +02:00
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
2019-05-23 19:48:22 +02:00
|
|
|
val view = inflater.inflate(R.layout.fragment_share, container, false)
|
|
|
|
val args = ShareFragmentArgs.fromBundle(arguments!!)
|
2019-05-29 00:05:16 +02:00
|
|
|
if (args.url == null && args.tabs.isNullOrEmpty()) {
|
|
|
|
throw IllegalStateException("URL and tabs cannot both be null.")
|
|
|
|
}
|
|
|
|
|
|
|
|
tabs = args.tabs ?: arrayOf(ShareTab(args.url!!, args.title ?: ""))
|
|
|
|
|
2019-08-23 12:54:03 +02:00
|
|
|
shareInteractor = ShareInteractor()
|
2019-05-23 19:48:22 +02:00
|
|
|
|
2019-08-23 12:54:03 +02:00
|
|
|
shareCloseView = ShareCloseView(view.closeSharingLayout, shareInteractor)
|
|
|
|
shareToAccountDevicesView = ShareToAccountDevicesView(view.devicesShareLayout, shareInteractor)
|
|
|
|
shareToAppsView = ShareToAppsView(view.appsShareLayout, shareInteractor)
|
2019-05-29 00:05:16 +02:00
|
|
|
|
2019-08-23 12:54:03 +02:00
|
|
|
return view
|
2019-05-29 00:05:16 +02:00
|
|
|
}
|
2019-05-23 19:48:22 +02:00
|
|
|
}
|
2019-05-29 00:05:16 +02:00
|
|
|
|
|
|
|
@Parcelize
|
|
|
|
data class ShareTab(val url: String, val title: String, val sessionId: String? = null) : Parcelable
|