Skip to content

Commit

Permalink
Revert "Revert "fixed network issue"" (#266)
Browse files Browse the repository at this point in the history
* Revert "Revert "fixed network issue (#264)" (#265)"

This reverts commit b3b7446.

* removed print statement
  • Loading branch information
aman-alfresco authored Jun 22, 2023
1 parent b3b7446 commit ed8a5a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.alfresco.content.network
import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import androidx.annotation.RequiresApi
import androidx.core.content.getSystemService
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -31,6 +32,34 @@ object ConnectivityTracker {
isTracking = true
}

/**
* returns true if network is metered otherwise false
*/
fun isActiveNetworkMetered(context: Context): Boolean =
context.getSystemService<ConnectivityManager>()?.isActiveNetworkMetered == true

/**
* returns true if network is active otherwise false
*/
fun isActiveNetwork(context: Context): Boolean {

val connectivityManager = context.getSystemService<ConnectivityManager>() ?: return false

val network = context.getSystemService<ConnectivityManager>()?.activeNetwork ?: return false

val activeNetwork = connectivityManager.getNetworkCapabilities(network) ?: return false

return when {
// Indicates this network uses a Wi-Fi transport,
// or WiFi has network connectivity
activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true

// Indicates this network uses a Cellular transport. or
// Cellular has network connectivity
activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true

// else return false
else -> false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.alfresco.content.data.SearchFacetQueries
import com.alfresco.content.data.SearchFilter
import com.alfresco.content.data.SearchFilters
import com.alfresco.content.data.SearchRepository
import com.alfresco.content.data.Settings
import com.alfresco.content.data.emptyAdvanceFilters
import com.alfresco.content.data.emptySearchFacetFields
import com.alfresco.content.data.emptySearchFacetIntervals
Expand Down Expand Up @@ -425,9 +424,7 @@ class SearchViewModel(
/**
* returns true if device has active network connection otherwise false
*/
fun canSearchOverCurrentNetwork() =
Settings(context).canSyncOverMeteredNetwork ||
!ConnectivityTracker.isActiveNetworkMetered(context)
fun canSearchOverCurrentNetwork() = ConnectivityTracker.isActiveNetwork(context)

override fun emptyMessageArgs(state: ListViewState) =
Triple(R.drawable.ic_empty_search, R.string.search_empty_title, R.string.search_empty_message)
Expand Down

0 comments on commit ed8a5a7

Please sign in to comment.