Anti Pattern in Connectivity View

#423 · open · 0 comments

View on GitHub ↗

Cefigueredo

In the following video, the feature that redirects the user to an explorer without first checking if the user has a connection fails, so the user gets the default chrome connectivity error view. The correct way to deal with this anti pattern could be to notify the user that he doesn't have a connection and try again when it is back. Video of the Anti pattern: https://drive.google.com/file/d/1OfRvDKO8-EyGn39aJtpfk6YfVdCwcVGy/view?usp=sharing This is found in the next path: mobile>java>com.google.samples.apps.iosched>ui>codelabs>CodelabsFragments We propose the following changes. First, check if there is connectivity. If it is true, it calls the URL. Otherwise, return a message informing the user about the issue. override fun startCodelab(codelab: Codelab) { val connectionManager: ConnectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val activeNetwork: NetworkInfo? = connectionManager.activeNetworkInfo val isConnected: Boolean = activeNetwork?.isConnectedOrConnecting == true if (isConnected) { if (codelab.hasUrl()) { openWebsiteUri( requireContext(), addCodelabsAnalyticsQueryParams(codelab.codelabUrl) ) analyticsHelper.logUiEvent( "Start codelab "${codelab.title}"", AnalyticsActions.CLICK ) } } else{ val builder = AlertDialog.Builder(this) builder.setTitle("Error") builder.setMessage("There is no network connection. Please check and try again") builder.setPositiveButton("Accept",null) val dialog: AlertDialog = builder.create() dialog.show() } }

Comments