ShareFragment.kt 2.08 KB
Newer Older
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
3
4
5
 * 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
6
7

import android.os.Bundle
8
import android.os.Parcelable
9
10
11
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
12
import androidx.appcompat.app.AppCompatDialogFragment
13
import kotlinx.android.parcel.Parcelize
14
15
16
import kotlinx.android.synthetic.main.fragment_share.view.*
import org.mozilla.fenix.R

17
class ShareFragment : AppCompatDialogFragment() {
18
19
20
21
    interface TabsSharedCallback {
        fun onTabsShared(tabsSize: Int)
    }

22
23
24
25
    private lateinit var shareInteractor: ShareInteractor
    private lateinit var shareCloseView: ShareCloseView
    private lateinit var shareToAccountDevicesView: ShareToAccountDevicesView
    private lateinit var shareToAppsView: ShareToAppsView
26
    private var tabs: Array<ShareTab> = emptyArray()
27
28
29

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
30
        setStyle(STYLE_NO_TITLE, R.style.ShareDialogStyle)
31
32
    }

33
34
35
36
37
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
38
39
        val view = inflater.inflate(R.layout.fragment_share, container, false)
        val args = ShareFragmentArgs.fromBundle(arguments!!)
40
41
42
43
44
45
        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 ?: ""))

46
        shareInteractor = ShareInteractor()
47

48
49
50
        shareCloseView = ShareCloseView(view.closeSharingLayout, shareInteractor)
        shareToAccountDevicesView = ShareToAccountDevicesView(view.devicesShareLayout, shareInteractor)
        shareToAppsView = ShareToAppsView(view.appsShareLayout, shareInteractor)
51

52
        return view
53
    }
54
}
55
56
57

@Parcelize
data class ShareTab(val url: String, val title: String, val sessionId: String? = null) : Parcelable