-
Notifications
You must be signed in to change notification settings - Fork 1
Settings Screen Opener https://app.clickup.com/t/86b4y8158 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
livotov
wants to merge
13
commits into
release/5.1.0
Choose a base branch
from
dev/settings_screen_opener
base: release/5.1.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9fe4b45
settings opener
4fbc21d
docs added
37955a9
dev version up for demo project tests
64cac71
lint feedback fix
5394be9
Merge remote-tracking branch 'origin/release/5.1.0' into dev/settings…
27ccb8d
Merge branch 'release/5.1.0' into dev/settings_screen_opener
ryanmitchener a5e771b
This is potentially a lot to support so let's mark this platform as u…
0d17fea
PR feedback, code reading
4584a83
Merge remote-tracking branch 'origin/dev/settings_screen_opener' into…
d2b6fbb
docs update
ec9b741
merge, code reading
05a9339
revert signing clause for maven publishing
cb1b8e8
PR feedback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/androidMain/kotlin/com/outsidesource/oskitkmp/systemui/KmpSettingsScreen.android.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.outsidesource.oskitkmp.systemui | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.provider.Settings | ||
import com.outsidesource.oskitkmp.capability.KmpCapabilityContext | ||
import com.outsidesource.oskitkmp.outcome.Outcome | ||
|
||
actual object KmpSettingsScreenOpener : IKmpSettingsScreenOpener { | ||
actual override suspend fun open( | ||
context: KmpCapabilityContext, | ||
type: SettingsScreenType, | ||
fallbackToAppSettings: Boolean, | ||
): Outcome<Unit, KmpSettingsScreenOpenerError> { | ||
val appSettingsIntent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply { | ||
data = Uri.fromParts("package", context.activity.packageName, null) | ||
} | ||
|
||
val res = launchIntent( | ||
context.activity, | ||
when (type) { | ||
SettingsScreenType.App -> appSettingsIntent | ||
SettingsScreenType.SystemSettings -> Intent(Settings.ACTION_SETTINGS) | ||
SettingsScreenType.Bluetooth -> Intent(Settings.ACTION_BLUETOOTH_SETTINGS) | ||
SettingsScreenType.Location -> Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS) | ||
}, | ||
) | ||
|
||
return if (res is Outcome.Error && type != SettingsScreenType.App && fallbackToAppSettings) { | ||
launchIntent(context.activity, appSettingsIntent) | ||
} else { | ||
res | ||
} | ||
} | ||
|
||
private fun launchIntent(context: Context, intent: Intent): Outcome<Unit, KmpSettingsScreenOpenerError> { | ||
return try { | ||
context.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) | ||
Outcome.Ok(Unit) | ||
} catch (e: Exception) { | ||
Outcome.Error(KmpSettingsScreenOpenerError.Unknown) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/commonMain/kotlin/com/outsidesource/oskitkmp/systemui/KmpSettingsScreenOpener.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.outsidesource.oskitkmp.systemui | ||
|
||
import com.outsidesource.oskitkmp.capability.KmpCapabilityContext | ||
import com.outsidesource.oskitkmp.outcome.Outcome | ||
|
||
interface IKmpSettingsScreenOpener { | ||
suspend fun open( | ||
context: KmpCapabilityContext, | ||
type: SettingsScreenType = SettingsScreenType.App, | ||
fallbackToAppSettings: Boolean = true, | ||
): | ||
Outcome<Unit, KmpSettingsScreenOpenerError> | ||
} | ||
|
||
/** | ||
* Represents a cross-platform settings screen opener implementation. | ||
* | ||
* This class allows opening specific types of settings screens | ||
* defined by the [SettingsScreenType] enum, such as application settings, | ||
* system settings, Bluetooth settings, or location settings. | ||
* Depending on the platform's support and implementation, not all screen types | ||
* may be available. | ||
* | ||
* On platforms that do not support this functionality, the method will return | ||
* an error with `[KmpSettingsScreenOpenerError.UnsupportedPlatform]`. | ||
* | ||
* Usage: | ||
* - Create platform-specifc instances of this class via DI or expect/actual helper and use in your common module | ||
* | ||
* Functions: | ||
* - `open`: Opens the specified settings screen type. | ||
* - Arguments: | ||
* - `type`: The type of settings screen to open. | ||
* - `fallbackToAppSettings`: Specifies whether to fall back to the app settings | ||
* when the requested type is not supported. | ||
* - Returns: | ||
* - Outcome representing the success or failure. | ||
*/ | ||
expect object KmpSettingsScreenOpener : IKmpSettingsScreenOpener { | ||
override suspend fun open( | ||
context: KmpCapabilityContext, | ||
type: SettingsScreenType, | ||
fallbackToAppSettings: Boolean, | ||
): Outcome<Unit, KmpSettingsScreenOpenerError> | ||
} | ||
|
||
enum class SettingsScreenType { | ||
App, | ||
SystemSettings, | ||
Bluetooth, | ||
Location, | ||
} | ||
|
||
enum class KmpSettingsScreenOpenerError { | ||
UnsupportedPlatform, | ||
Unknown, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/iosMain/kotlin/com/outsidesource/oskitkmp/systemui/KmpSettingsScreen.ios.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.outsidesource.oskitkmp.systemui | ||
|
||
import com.outsidesource.oskitkmp.capability.KmpCapabilityContext | ||
import com.outsidesource.oskitkmp.outcome.Outcome | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import platform.Foundation.NSURL | ||
import platform.UIKit.UIApplication | ||
import platform.UIKit.UIApplicationOpenSettingsURLString | ||
|
||
actual object KmpSettingsScreenOpener : IKmpSettingsScreenOpener { | ||
actual override suspend fun open( | ||
context: KmpCapabilityContext, | ||
type: SettingsScreenType, | ||
fallbackToAppSettings: Boolean, | ||
): Outcome<Unit, KmpSettingsScreenOpenerError> { | ||
val res = when (type) { | ||
livotov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SettingsScreenType.App -> openAppSettings() | ||
else -> Outcome.Error(KmpSettingsScreenOpenerError.UnsupportedPlatform) | ||
} | ||
|
||
return if (res is Outcome.Error && type != SettingsScreenType.App && fallbackToAppSettings) { | ||
openAppSettings() | ||
} else { | ||
res | ||
} | ||
} | ||
|
||
private suspend fun openAppSettings(): Outcome<Unit, KmpSettingsScreenOpenerError> { | ||
return withContext(Dispatchers.Main) { | ||
try { | ||
val url = NSURL(string = UIApplicationOpenSettingsURLString) | ||
if (UIApplication.sharedApplication.canOpenURL(url)) { | ||
UIApplication.sharedApplication.openURL(url, emptyMap<Any?, Any>(), null) | ||
Outcome.Ok(Unit) | ||
} else { | ||
Outcome.Error(KmpSettingsScreenOpenerError.UnsupportedPlatform) | ||
} | ||
} catch (e: Throwable) { | ||
Outcome.Error(KmpSettingsScreenOpenerError.Unknown) | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/jvmMain/kotlin/com/outsidesource/oskitkmp/systemui/KmpSettingsScreen.jvm.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.outsidesource.oskitkmp.systemui | ||
|
||
import com.outsidesource.oskitkmp.capability.KmpCapabilityContext | ||
import com.outsidesource.oskitkmp.outcome.Outcome | ||
|
||
actual object KmpSettingsScreenOpener : IKmpSettingsScreenOpener { | ||
actual override suspend fun open( | ||
context: KmpCapabilityContext, | ||
type: SettingsScreenType, | ||
fallbackToAppSettings: Boolean, | ||
): Outcome<Unit, KmpSettingsScreenOpenerError> { | ||
return Outcome.Error(KmpSettingsScreenOpenerError.UnsupportedPlatform) | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/wasmJsMain/kotlin/com/outsidesource/oskitkmp/capability/KmpCapabilities.wasm.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/wasmJsMain/kotlin/com/outsidesource/oskitkmp/systemui/KmpSettingsScreen.wasmJs.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.outsidesource.oskitkmp.systemui | ||
|
||
import com.outsidesource.oskitkmp.capability.KmpCapabilityContext | ||
import com.outsidesource.oskitkmp.outcome.Outcome | ||
|
||
actual object KmpSettingsScreenOpener : IKmpSettingsScreenOpener { | ||
actual override suspend fun open( | ||
context: KmpCapabilityContext, | ||
type: SettingsScreenType, | ||
fallbackToAppSettings: Boolean, | ||
): Outcome<Unit, KmpSettingsScreenOpenerError> { | ||
return Outcome.Error(KmpSettingsScreenOpenerError.UnsupportedPlatform) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.