Skip to content

Instantly share code, notes, and snippets.

View vladimirpetrovski's full-sized avatar

Vladimir Petrovski vladimirpetrovski

View GitHub Profile
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
connectivityManager.bindProcessToNetwork(null)
} else {
ConnectivityManager.setProcessDefaultNetwork(null)
}
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
connectivityManager.bindProcessToNetwork(network)
} else {
ConnectivityManager.setProcessDefaultNetwork(network)
}
val network: Network? = connectivityManager.allNetworks.find {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
connectivityManager.getNetworkCapabilities(it)
.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
} else {
connectivityManager.getNetworkInfo(it).extraInfo == wifiSSID
}
}
fun checkLocationSettings(onSuccessCallback: () -> Unit) {
val locationRequest = LocationRequest.create()
locationRequest.priority = LocationRequest.PRIORITY_LOW_POWER
val builder = LocationSettingsRequest.Builder()
builder.addLocationRequest(locationRequest)
val client = LocationServices.getSettingsClient(this)
val task = client.checkLocationSettings(builder.build())
task.addOnSuccessListener(this) {
onSuccessCallback()
}
fun isWiFiEnabled(): Boolean {
val wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
return wifiManager.isWifiEnabled
}
include(":shared", ":androidApp")
rootProject.name = "xxx"
enableFeaturePreview("GRADLE_METADATA")
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.6.3")
classpath(kotlin("gradle-plugin", "1.3.71"))
plugins {
id("com.android.application")
kotlin("android")
kotlin("android.extensions")
kotlin("kapt")
id("androidx.navigation.safeargs.kotlin")
}
android {
compileSdkVersion(Versions.compile_sdk)
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
id("com.android.library")
}
android {
compileSdkVersion(29)
defaultConfig {
minSdkVersion(21)
class WifiConnectionViewModel(
private val context: Context,
wifiScanUseCase: WiFiScanUseCase,
private val wifiConnectUseCase: WiFiConnectDockUseCase,
private val wifiConnectLegacyUseCase: WiFiConnectDockLegacyUseCase,
private val wifiDisconnectUseCase: WiFiDisconnectDockUseCase
) : ViewModel() {
private val disposables = CompositeDisposable();