mirror of
				https://github.com/recloudstream/cloudstream.git
				synced 2024-08-15 01:53:11 +00:00 
			
		
		
		
	Add network check before trying to load online results and fix deprecations in Context.isNetworkAvailable()
This commit is contained in:
		
							parent
							
								
									c70175f4b4
								
							
						
					
					
						commit
						283c8a4c56
					
				
					 2 changed files with 14 additions and 6 deletions
				
			
		|  | @ -40,6 +40,7 @@ import com.lagradost.cloudstream3.ui.result.FOCUS_SELF | ||||||
| import com.lagradost.cloudstream3.ui.result.setLinearListLayout | import com.lagradost.cloudstream3.ui.result.setLinearListLayout | ||||||
| import com.lagradost.cloudstream3.ui.settings.Globals.TV | import com.lagradost.cloudstream3.ui.settings.Globals.TV | ||||||
| import com.lagradost.cloudstream3.ui.settings.Globals.isLayout | import com.lagradost.cloudstream3.ui.settings.Globals.isLayout | ||||||
|  | import com.lagradost.cloudstream3.utils.AppContextUtils.isNetworkAvailable | ||||||
| import com.lagradost.cloudstream3.utils.AppContextUtils.loadResult | import com.lagradost.cloudstream3.utils.AppContextUtils.loadResult | ||||||
| import com.lagradost.cloudstream3.utils.BackPressedCallbackHelper.attachBackPressedCallback | import com.lagradost.cloudstream3.utils.BackPressedCallbackHelper.attachBackPressedCallback | ||||||
| import com.lagradost.cloudstream3.utils.BackPressedCallbackHelper.detachBackPressedCallback | import com.lagradost.cloudstream3.utils.BackPressedCallbackHelper.detachBackPressedCallback | ||||||
|  | @ -236,10 +237,12 @@ class DownloadFragment : Fragment() { | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             DOWNLOAD_ACTION_LOAD_RESULT -> { |             DOWNLOAD_ACTION_LOAD_RESULT -> { | ||||||
|  |                 if (context?.isNetworkAvailable() == true) { | ||||||
|                     activity?.loadResult(click.data.url, click.data.apiName) |                     activity?.loadResult(click.data.url, click.data.apiName) | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     private fun handleSelectedChange(selected: MutableSet<Int>) { |     private fun handleSelectedChange(selected: MutableSet<Int>) { | ||||||
|         if (selected.isNotEmpty()) { |         if (selected.isNotEmpty()) { | ||||||
|  |  | ||||||
|  | @ -43,7 +43,6 @@ import androidx.recyclerview.widget.RecyclerView | ||||||
| import androidx.tvprovider.media.tv.* | import androidx.tvprovider.media.tv.* | ||||||
| import androidx.tvprovider.media.tv.WatchNextProgram.fromCursor | import androidx.tvprovider.media.tv.WatchNextProgram.fromCursor | ||||||
| import androidx.viewpager2.widget.ViewPager2 | import androidx.viewpager2.widget.ViewPager2 | ||||||
| import com.fasterxml.jackson.module.kotlin.readValue |  | ||||||
| import com.google.android.gms.cast.framework.CastContext | import com.google.android.gms.cast.framework.CastContext | ||||||
| import com.google.android.gms.cast.framework.CastState | import com.google.android.gms.cast.framework.CastState | ||||||
| import com.google.android.gms.common.ConnectionResult | import com.google.android.gms.common.ConnectionResult | ||||||
|  | @ -678,9 +677,15 @@ object AppContextUtils { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fun Context.isNetworkAvailable(): Boolean { |     fun Context.isNetworkAvailable(): Boolean { | ||||||
|         val manager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager |         val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | ||||||
|         val activeNetworkInfo = manager.activeNetworkInfo |         return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||||||
|         return activeNetworkInfo != null && activeNetworkInfo.isConnected || manager.allNetworkInfo?.any { it.isConnected } ?: false |             val network = connectivityManager.activeNetwork ?: return false | ||||||
|  |             val networkCapabilities = connectivityManager.getNetworkCapabilities(network) ?: return false | ||||||
|  |             networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) | ||||||
|  |         } else { | ||||||
|  |             @Suppress("DEPRECATION") | ||||||
|  |             connectivityManager.activeNetworkInfo?.isConnectedOrConnecting == true | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fun splitQuery(url: URL): Map<String, String> { |     fun splitQuery(url: URL): Map<String, String> { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue