feat: refs#8682 refactorWebFragment

This commit is contained in:
Sergio De la torre 2025-01-27 16:49:10 +01:00
parent 0fe4c3c7d3
commit ab064e52aa
3 changed files with 12 additions and 58 deletions

View File

@ -30,10 +30,6 @@ import es.verdnatura.presentation.common.ToolBarAdapterTooltip
import es.verdnatura.presentation.view.component.CustomDialog import es.verdnatura.presentation.view.component.CustomDialog
import es.verdnatura.presentation.view.feature.main.activity.MainActivity import es.verdnatura.presentation.view.feature.main.activity.MainActivity
import org.json.JSONObject 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 import kotlin.math.abs
@Suppress("UNUSED_ANONYMOUS_PARAMETER") @Suppress("UNUSED_ANONYMOUS_PARAMETER")
@ -45,8 +41,6 @@ class WebFragment(
private lateinit var customDialog: CustomDialog private lateinit var customDialog: CustomDialog
private lateinit var backDispatcher: OnBackPressedDispatcher private lateinit var backDispatcher: OnBackPressedDispatcher
private lateinit var binding: FragmentWebBinding private lateinit var binding: FragmentWebBinding
private var sRuntime: GeckoRuntime? = null
private var session: GeckoSession? = null
companion object { companion object {
fun newInstance(entryPoint: String) = WebFragment(entryPoint) fun newInstance(entryPoint: String) = WebFragment(entryPoint)
@ -61,7 +55,7 @@ class WebFragment(
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? { ): View {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_web, container, false) binding = DataBindingUtil.inflate(inflater, R.layout.fragment_web, container, false)
binding.lifecycleOwner = this binding.lifecycleOwner = this
return binding.root return binding.root
@ -107,15 +101,6 @@ class WebFragment(
super.onViewCreated(view, savedInstanceState) 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") @SuppressLint("ClickableViewAccessibility", "SetJavaScriptEnabled")
private fun setWeb() { private fun setWeb() {
@ -146,15 +131,7 @@ class WebFragment(
} }
val dataScanned = JSONObject(entryPoint) val dataScanned = JSONObject(entryPoint)
if (dataScanned.toString().contains("Cmrs")) { binding.webView.loadUrl(dataScanned.get("web").toString())
val view: GeckoView = binding.geckoView
view.setSession(session!!)
session!!.loadUri("${dataScanned.get("web")}")
} else {
binding.webView.loadUrl(dataScanned.get("web").toString())
}
} }
private fun setToolbar() { private fun setToolbar() {
@ -169,8 +146,6 @@ class WebFragment(
iconPrint.setImageResource(R.drawable.ic_print_black_24dp) iconPrint.setImageResource(R.drawable.ic_print_black_24dp)
iconPrint.tooltipText = getString(R.string.print) iconPrint.tooltipText = getString(R.string.print)
//listIcons.add(iconPrint)
binding.mainToolbar.toolbarIcons.adapter = binding.mainToolbar.toolbarIcons.adapter =
ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener {
override fun onOptionsItemSelected(item: Drawable) { 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!!
}
}

View File

@ -429,22 +429,17 @@ class TicketsFragment : BaseFragment<FragmentTicketsBinding, DeliveryViewModel>(
override fun onItemButtonCMRRowClickListener( override fun onItemButtonCMRRowClickListener(
item: Ticket item: Ticket
) { ) {
ma.onPasillerosItemClickListener(
PasillerosItemVO( val url =
title = R.string.titleWebViewer, "${mobileApplication.dataStoreApp.getServerLilium()}/api/Cmrs/${item.cmrFk}/print?access_token=${
), entryPoint = Gson().toJson( mobileApplication.dataStoreApp.readDataStoreKey<String>(
mutableMapOf( TOKEN
"entryPoint" to route.id,
"web" to "${
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)
} }
}) })

View File

@ -24,10 +24,5 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="0dp" /> 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> </androidx.constraintlayout.widget.ConstraintLayout>
</layout> </layout>