1616
1717package com.hossainkhan.android.demo.ui.dialog
1818
19+ import android.net.Uri
1920import android.os.Bundle
2021import android.view.LayoutInflater
2122import android.view.View
2223import android.view.ViewGroup
2324import android.widget.FrameLayout
2425import android.widget.TextView
26+ import androidx.browser.customtabs.CustomTabsIntent
2527import com.google.android.material.bottomsheet.BottomSheetBehavior
2628import com.google.android.material.bottomsheet.BottomSheetDialog
2729import com.google.android.material.bottomsheet.BottomSheetDialogFragment
2830import com.google.android.material.button.MaterialButton
2931import com.hossainkhan.android.demo.R
32+ import timber.log.Timber
3033
3134
3235/* *
@@ -36,11 +39,13 @@ class LayoutInfoDialog : BottomSheetDialogFragment() {
3639 companion object {
3740 private const val BUNDLE_ARG_KEY_TITLE = " BUNDLE_TITLE"
3841 private const val BUNDLE_ARG_KEY_DESC = " BUNDLE_DESCRIPTION"
42+ private const val BUNDLE_ARG_KEY_LAYOUT_URL = " BUNDLE_LAYOUT_URL"
3943
40- fun newInstance (title : String , description : String ): LayoutInfoDialog {
44+ fun newInstance (title : String , description : String , layoutUrl : String ): LayoutInfoDialog {
4145 val args = Bundle ()
4246 args.putString(BUNDLE_ARG_KEY_TITLE , title)
4347 args.putString(BUNDLE_ARG_KEY_DESC , description)
48+ args.putString(BUNDLE_ARG_KEY_LAYOUT_URL , layoutUrl)
4449
4550 val dialog = LayoutInfoDialog ()
4651
@@ -55,7 +60,6 @@ class LayoutInfoDialog : BottomSheetDialogFragment() {
5560 lateinit var infoDescription: TextView
5661 lateinit var okButton: MaterialButton
5762 lateinit var previewXml: MaterialButton
58- var previewXmlListener: (() -> Unit )? = null
5963
6064 override fun onCreateView (inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ): View ? {
6165 val view = inflater.inflate(R .layout.dialog_layout_info_sheet, container, false )
@@ -83,6 +87,7 @@ class LayoutInfoDialog : BottomSheetDialogFragment() {
8387 arguments!! .getString(BUNDLE_ARG_KEY_TITLE , " " ),
8488 arguments!! .getString(BUNDLE_ARG_KEY_DESC , " " )
8589 )
90+
8691 }
8792
8893 override fun onPause () {
@@ -98,7 +103,19 @@ class LayoutInfoDialog : BottomSheetDialogFragment() {
98103 okButton.setOnClickListener { dismiss() }
99104 previewXml.setOnClickListener {
100105 dismiss()
101- previewXmlListener?.invoke( )
106+ loadLayoutUrl(arguments !! .getString( BUNDLE_ARG_KEY_LAYOUT_URL , null ) )
102107 }
103108 }
109+
110+ /* *
111+ * Loads currently running layout from Github into chrome web view.
112+ */
113+ fun loadLayoutUrl (url : String ) {
114+ Timber .d(" Showing layout source code via: %s" , url)
115+ val builder = CustomTabsIntent .Builder ()
116+ builder.setShowTitle(false )
117+ .addDefaultShareMenuItem()
118+ val customTabsIntent = builder.build()
119+ customTabsIntent.launchUrl(context, Uri .parse(url))
120+ }
104121}
0 commit comments