feat: refs#8682 refactorWebFragment
This commit is contained in:
parent
0fe4c3c7d3
commit
ab064e52aa
|
@ -30,10 +30,6 @@ import es.verdnatura.presentation.common.ToolBarAdapterTooltip
|
|||
import es.verdnatura.presentation.view.component.CustomDialog
|
||||
import es.verdnatura.presentation.view.feature.main.activity.MainActivity
|
||||
import org.json.JSONObject
|
||||
import org.mozilla.geckoview.GeckoRuntime
|
||||
import org.mozilla.geckoview.GeckoSession
|
||||
import org.mozilla.geckoview.GeckoSession.ContentDelegate
|
||||
import org.mozilla.geckoview.GeckoView
|
||||
import kotlin.math.abs
|
||||
|
||||
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
|
||||
|
@ -45,8 +41,6 @@ class WebFragment(
|
|||
private lateinit var customDialog: CustomDialog
|
||||
private lateinit var backDispatcher: OnBackPressedDispatcher
|
||||
private lateinit var binding: FragmentWebBinding
|
||||
private var sRuntime: GeckoRuntime? = null
|
||||
private var session: GeckoSession? = null
|
||||
|
||||
companion object {
|
||||
fun newInstance(entryPoint: String) = WebFragment(entryPoint)
|
||||
|
@ -61,7 +55,7 @@ class WebFragment(
|
|||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View? {
|
||||
): View {
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_web, container, false)
|
||||
binding.lifecycleOwner = this
|
||||
return binding.root
|
||||
|
@ -107,15 +101,6 @@ class WebFragment(
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
session = GeckoSession()
|
||||
session!!.contentDelegate = object : ContentDelegate {}
|
||||
// Usa el gestor para obtener la instancia única de GeckoRuntime
|
||||
sRuntime = GeckoManager.getRuntime(requireContext())
|
||||
session!!.open(sRuntime!!)
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility", "SetJavaScriptEnabled")
|
||||
private fun setWeb() {
|
||||
|
||||
|
@ -146,17 +131,9 @@ class WebFragment(
|
|||
}
|
||||
|
||||
val dataScanned = JSONObject(entryPoint)
|
||||
if (dataScanned.toString().contains("Cmrs")) {
|
||||
val view: GeckoView = binding.geckoView
|
||||
view.setSession(session!!)
|
||||
session!!.loadUri("${dataScanned.get("web")}")
|
||||
|
||||
} else {
|
||||
binding.webView.loadUrl(dataScanned.get("web").toString())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun setToolbar() {
|
||||
|
||||
binding.mainToolbar.toolbarTitle.text = buildString {
|
||||
|
@ -169,8 +146,6 @@ class WebFragment(
|
|||
iconPrint.setImageResource(R.drawable.ic_print_black_24dp)
|
||||
iconPrint.tooltipText = getString(R.string.print)
|
||||
|
||||
//listIcons.add(iconPrint)
|
||||
|
||||
binding.mainToolbar.toolbarIcons.adapter =
|
||||
ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener {
|
||||
override fun onOptionsItemSelected(item: Drawable) {
|
||||
|
@ -220,14 +195,3 @@ class WebFragment(
|
|||
|
||||
}
|
||||
|
||||
object GeckoManager {
|
||||
private var runtime: GeckoRuntime? = null
|
||||
|
||||
fun getRuntime(context: Context): GeckoRuntime {
|
||||
if (runtime == null) {
|
||||
runtime = GeckoRuntime.create(context)
|
||||
}
|
||||
return runtime!!
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -429,22 +429,17 @@ class TicketsFragment : BaseFragment<FragmentTicketsBinding, DeliveryViewModel>(
|
|||
override fun onItemButtonCMRRowClickListener(
|
||||
item: Ticket
|
||||
) {
|
||||
ma.onPasillerosItemClickListener(
|
||||
PasillerosItemVO(
|
||||
title = R.string.titleWebViewer,
|
||||
), entryPoint = Gson().toJson(
|
||||
mutableMapOf(
|
||||
"entryPoint" to route.id,
|
||||
"web" to "${
|
||||
mobileApplication.dataStoreApp.getServerLilium()
|
||||
}/api/Cmrs/${item.cmrFk}/print?access_token=${
|
||||
|
||||
val url =
|
||||
"${mobileApplication.dataStoreApp.getServerLilium()}/api/Cmrs/${item.cmrFk}/print?access_token=${
|
||||
mobileApplication.dataStoreApp.readDataStoreKey<String>(
|
||||
TOKEN
|
||||
)
|
||||
}"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val intent = Intent(Intent.ACTION_QUICK_VIEW, Uri.parse(url))
|
||||
intent.setDataAndType(Uri.parse(url), "application/pdf")
|
||||
startActivity(intent)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -24,10 +24,5 @@
|
|||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="0dp" />
|
||||
|
||||
<org.mozilla.geckoview.GeckoView
|
||||
android:id="@+id/gecko_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
||||
|
|
Loading…
Reference in New Issue