Repository: android/compose-samples
File: Jetcaster/app/src/main/java/com/example/jetcaster/ui/JetcasterApp.kt (Kotlin)

Code before:
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.jetcaster.ui

import android.content.Context
import android.net.ConnectivityManager
import androidx.compose.material.AlertDialog
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.res.stringResource
import com.example.jetcaster.R
import com.example.jetcaster.ui.home.Home


@Composable
fun JetcasterApp() {
    val context = AmbientContext.current
    val isOnline = remember { mutableStateOf(checkIfOnline(context)) }

    fun retry() {
        isOnline.value = checkIfOnline(context)
    }

    // TODO: add some navigation
    if(isOnline.value) {
        Home()
    } else {
        OfflineDialog { isOnline.value = checkIfOnline(context) }
    }
}

// TODO: Use a better way to check internet connection
@Suppress("DEPRECATION")
fun checkIfOnline(context: Context): Boolean {
    val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
    val activeNetwork = cm.activeNetworkInfo
    return activeNetwork?.isConnectedOrConnecting == true
}

@Composable
fun OfflineDialog(onRetry: () -> Unit) {
    AlertDialog(
        onDismissRequest = {},

Review comment (suggestion):
using `by` avoids having to use the `.value` below which reads better

```suggestion
    var isOnline by remember { mutableStateOf(checkIfOnline(context)) }
```

Code after:
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.jetcaster.ui

import android.content.Context
import android.net.ConnectivityManager
import androidx.compose.material.AlertDialog
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.res.stringResource
import com.example.jetcaster.R
import com.example.jetcaster.ui.home.Home

@Composable
fun JetcasterApp() {
    val context = AmbientContext.current
    var isOnline by remember { mutableStateOf(checkIfOnline(context)) }

    // TODO: add some navigation
    if (isOnline) {
        Home()
    } else {
        OfflineDialog { isOnline = checkIfOnline(context) }
    }
}

// TODO: Use a better way to check internet connection
@Suppress("DEPRECATION")
private fun checkIfOnline(context: Context): Boolean {
    val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
    val activeNetwork = cm.activeNetworkInfo
    return activeNetwork?.isConnectedOrConnecting == true
}

@Composable
fun OfflineDialog(onRetry: () -> Unit) {
    AlertDialog(
        onDismissRequest = {},
        title = { Text(text = stringResource(R.string.connection_error_title)) },
        text = { Text(text = stringResource(R.string.connection_error_message)) },
        confirmButton = {