Skip to content

Commit

Permalink
Move extensions.ContextExt content into ui.utils.ContextExt
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Sep 3, 2024
1 parent 1f5e941 commit 43df165
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 66 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.extensions.goToPlayStore
import com.infomaniak.swisstransfer.extensions.openAppNotificationSettings
import com.infomaniak.swisstransfer.extensions.openUrl
import com.infomaniak.swisstransfer.ui.components.TwoPaneScaffold
import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsOptionScreens.*
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewMobile
import com.infomaniak.swisstransfer.ui.utils.PreviewTablet
import com.infomaniak.swisstransfer.ui.utils.*

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,51 @@
package com.infomaniak.swisstransfer.ui.utils

import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import kotlin.reflect.KClass


fun <T : Activity> Context.launchActivity(kClass: KClass<T>, options: Bundle? = null) {
startActivity(Intent(this, kClass.java), options)
}

fun Context.openUrl(url: String) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
}

fun Context.goToPlayStore() {
try {
startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=${packageName}"))
)
} catch (_: ActivityNotFoundException) {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=${packageName}")
)
)
}
}

fun Context.openAppNotificationSettings() {
Intent().apply {
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {
action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
}
else -> {
action = "Settings.ACTION_APP_NOTIFICATION_SETTINGS"
putExtra("app_package", packageName)
putExtra("app_uid", applicationInfo.uid)
}
}
}.also(::startActivity)
}

0 comments on commit 43df165

Please sign in to comment.