network

mail@pastecode.io avatar
unknown
kotlin
2 years ago
1.2 kB
13
Indexable
Never
fun setinternet(): Boolean {
        var i = false
        networkMonitor.result = { isAvailable, type ->
            requireActivity().runOnUiThread {
                when (isAvailable) {
                    true -> {
                        when (type) {
                            ConnectionType.Wifi -> {
                                Log.i("Internet", "NetworkCapabilities.WIFI")
//                                presenter.getNews(1, 5)
                            }
                            ConnectionType.Cellular -> {
                                Log.i("Internet", "NetworkCapabilities.TRANSPORT_CELLULAR")
//                                presenter.getNews(1, 5)
                                i = true
                            }
                            else -> {
                            }
                        }
                    }
                    false -> {
                        Log.i("Internet", "No Network")
                        Toast.makeText(requireContext(),"No network",Toast.LENGTH_SHORT).show()
                        i = false
                    }
                }
            }
        }
        return i
    }