diff --git a/build.gradle.kts b/build.gradle.kts index 18a6024..55fb7ff 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "xyz.regulad" -version = "1.2.2" +version = "1.2.3" nexusPublishing { repositories { diff --git a/compose/src/main/java/xyz/regulad/regulib/compose/ComposableWebView.kt b/compose/src/main/java/xyz/regulad/regulib/compose/ComposableWebView.kt deleted file mode 100644 index 781252a..0000000 --- a/compose/src/main/java/xyz/regulad/regulib/compose/ComposableWebView.kt +++ /dev/null @@ -1,61 +0,0 @@ -package xyz.regulad.regulib.compose - -import android.os.Bundle -import android.view.ViewGroup -import android.webkit.WebView -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.viewinterop.AndroidView -import org.jetbrains.annotations.ApiStatus.Experimental - -/** - * Implements compose-wise ways to use a [WebView]. - * - * Does not currently allow any execution of [WebView] methods, but this is planned. - * - * @see WebView - */ -@Experimental -@Composable -fun ComposableWebView( - url: String? = null, - modifier: Modifier = Modifier, - networkIsAvailable: Boolean? = null, - stateBundle: Bundle? = null, -) { - var lastStateBundle by rememberSaveable { mutableStateOf(stateBundle) } - var lastUrl by rememberSaveable { mutableStateOf(null) } - - AndroidView( - modifier = modifier, - factory = { - WebView(it).apply { - layoutParams = ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT - ) - } - }, update = { view -> - networkIsAvailable?.let { view.setNetworkAvailable(it) } - - stateBundle?.let { - if (lastStateBundle != it) { - view.restoreState(it) - lastStateBundle = it - } - } - - if (url != lastUrl) { - view.loadUrl(url ?: "about:blank") - lastUrl = url - } - }, onRelease = { view -> - stateBundle?.let { view.saveState(it) } - view.destroy() - } - ) -} diff --git a/wifi/src/main/java/xyz/regulad/regulib/wifi/WifiP2pManagerView.kt b/wifi/src/main/java/xyz/regulad/regulib/wifi/WifiP2pManagerView.kt index 9c2725b..f1ad2c1 100644 --- a/wifi/src/main/java/xyz/regulad/regulib/wifi/WifiP2pManagerView.kt +++ b/wifi/src/main/java/xyz/regulad/regulib/wifi/WifiP2pManagerView.kt @@ -247,7 +247,7 @@ class WifiP2pManagerView private constructor(private val wifiP2pManager: WifiP2p * * This can only be called once. */ - private fun teardown() { + fun teardown() { if (this::frameworkChannel.isInitialized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { frameworkChannel.close() } @@ -256,7 +256,14 @@ class WifiP2pManagerView private constructor(private val wifiP2pManager: WifiP2p } protected fun finalize() { - teardown() + if (managerInitializedState.value) { + Log.d(TAG, "WifiP2pManagerView was not torn down before being finalized. Tearing down now.") + try { + teardown() + } catch (e: Exception) { + Log.e(TAG, "Failed to teardown WifiP2pManagerView", e) + } + } } // methods