-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
484 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
17 changes: 17 additions & 0 deletions
17
androidApp/src/main/java/nl/tiebe/otarium/androidApp/WearListener.kt
This file contains 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,17 @@ | ||
package nl.tiebe.otarium.androidApp | ||
|
||
import android.content.Intent | ||
import com.google.android.gms.wearable.MessageEvent | ||
import com.google.android.gms.wearable.WearableListenerService | ||
|
||
class WearListener : WearableListenerService() { | ||
override fun onMessageReceived(messageEvent: MessageEvent) { | ||
val intent = Intent(applicationContext, WearLoginActivity::class.java) | ||
intent.putExtra("uri", messageEvent.data) | ||
intent.putExtra("node", messageEvent.sourceNodeId) | ||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
|
||
startActivity(intent) | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
androidApp/src/main/java/nl/tiebe/otarium/androidApp/WearLoginActivity.kt
This file contains 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,85 @@ | ||
package nl.tiebe.otarium.androidApp | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import android.view.ViewGroup | ||
import android.webkit.WebResourceRequest | ||
import android.webkit.WebResourceResponse | ||
import android.webkit.WebView | ||
import android.webkit.WebViewClient | ||
import androidx.activity.addCallback | ||
import androidx.activity.compose.setContent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.viewinterop.AndroidView | ||
import com.google.android.gms.wearable.Wearable | ||
import nl.tiebe.otarium.ui.login.getActivity | ||
import nl.tiebe.otarium.utils.ui.Android | ||
|
||
class WearLoginActivity : AppCompatActivity() { | ||
@SuppressLint("SetJavaScriptEnabled") | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
val onBackDispatcher = onBackPressedDispatcher | ||
|
||
Android.context = this | ||
Android.window = window | ||
|
||
val url = intent.extras?.getByteArray("uri")!!.decodeToString() | ||
val node = intent.extras?.getString("node")!! | ||
|
||
setContent { | ||
AndroidView(factory = { | ||
val webViewClient: WebViewClient = object : WebViewClient() { | ||
override fun shouldOverrideUrlLoading( | ||
view: WebView, | ||
webResourceRequest: WebResourceRequest | ||
): Boolean { | ||
val checkUrl = webResourceRequest.url.toString() | ||
|
||
if (checkUrl.startsWith("m6loapp://oauth2redirect")) { | ||
println("sending....") | ||
Wearable.getMessageClient(applicationContext).sendMessage(node, "/login_completed", checkUrl.toByteArray()) | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
override fun shouldInterceptRequest( | ||
view: WebView?, | ||
request: WebResourceRequest? | ||
): WebResourceResponse? { | ||
if (request?.url.toString().contains("playconsolelogin")) { | ||
Wearable.getMessageClient(applicationContext).sendMessage(node, "/login_bypass", null) | ||
} | ||
return super.shouldInterceptRequest(view, request) | ||
} | ||
} | ||
|
||
val webView = WebView(it).apply { | ||
settings.javaScriptEnabled = true | ||
layoutParams = ViewGroup.LayoutParams( | ||
ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.MATCH_PARENT | ||
) | ||
this.webViewClient = webViewClient | ||
loadUrl(url) | ||
} | ||
|
||
onBackDispatcher.addCallback { | ||
if (webView.canGoBack()) webView.goBack() | ||
else getActivity(it)?.finishAfterTransition() | ||
} | ||
|
||
webView | ||
}, update = { | ||
it.loadUrl(url) | ||
}, modifier = Modifier.fillMaxSize()) | ||
} | ||
|
||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -18,3 +18,4 @@ rootProject.name = "Otarium" | |
|
||
include(":androidApp") | ||
include(":shared") | ||
include(":wearApp") |
This file contains 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
This file contains 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 @@ | ||
/build |
This file contains 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,69 @@ | ||
plugins { | ||
id("com.android.application") | ||
kotlin("android") | ||
id("kotlin-parcelize") | ||
id("kotlinx-serialization") | ||
} | ||
|
||
android { | ||
namespace = "nl.tiebe.otarium.wear" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
applicationId = "nl.tiebe.otarium" | ||
minSdk = 30 | ||
targetSdk = libs.versions.android.sdk.compile.get().toInt() | ||
versionCode = libs.versions.app.version.code.get().toInt() | ||
versionName = libs.versions.app.version.string.get() | ||
vectorDrawables { | ||
useSupportLibrary = true | ||
} | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "11" | ||
} | ||
buildFeatures { | ||
compose = true | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get() | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(":shared")) | ||
|
||
implementation(libs.play.services.wearable) | ||
implementation(platform(libs.wear.compose.bom)) | ||
implementation(libs.compose.ui) | ||
// implementation(libs.wear.tooling.preview) | ||
implementation(libs.androidx.wear.compose.compose.material) | ||
implementation(libs.androidx.wear.compose.compose.material3) | ||
implementation(libs.compose.foundation) | ||
implementation(libs.compose.activity) | ||
implementation(libs.core.splashscreen) | ||
implementation(libs.androidx.wear.phone.interactions) | ||
debugImplementation(libs.ui.tooling) | ||
debugImplementation(libs.ui.test.manifest) | ||
|
||
implementation(libs.decompose.core) | ||
implementation(libs.decompose.compose) | ||
|
||
api(libs.moko.resources.core) | ||
implementation(libs.magister.api) | ||
} |
This file contains 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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains 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,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.WAKE_LOCK" /> | ||
|
||
<uses-feature android:name="android.hardware.type.watch" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@android:style/Theme.DeviceDefault"> | ||
<uses-library | ||
android:name="com.google.android.wearable" | ||
android:required="true" /> | ||
|
||
<meta-data | ||
android:name="com.google.android.wearable.standalone" | ||
android:value="true" /> | ||
|
||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true" | ||
android:taskAffinity="" | ||
android:theme="@style/MainActivityTheme.Starting"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
52 changes: 52 additions & 0 deletions
52
wearApp/src/main/java/nl/tiebe/otarium/wear/MainActivity.kt
This file contains 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,52 @@ | ||
package nl.tiebe.otarium.wear | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen | ||
import com.arkivanov.decompose.ComponentContext | ||
import com.arkivanov.decompose.defaultComponentContext | ||
import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState | ||
import com.google.android.gms.wearable.MessageEvent | ||
import nl.tiebe.otarium.ProvideComponentContext | ||
import nl.tiebe.otarium.logic.default.DefaultRootComponent | ||
import nl.tiebe.otarium.logic.root.RootComponent | ||
import nl.tiebe.otarium.setup | ||
import nl.tiebe.otarium.wear.theme.OtariumTheme | ||
import nl.tiebe.otarium.wear.ui.home.HomeScreen | ||
import nl.tiebe.otarium.wear.ui.login.LoginScreen | ||
|
||
class MainActivity : ComponentActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
installSplashScreen() | ||
|
||
super.onCreate(savedInstanceState) | ||
|
||
setTheme(android.R.style.Theme_DeviceDefault) | ||
|
||
val componentContext = defaultComponentContext() | ||
|
||
setContent { | ||
ProvideComponentContext(componentContext) { | ||
setup() | ||
|
||
WearApp(DefaultRootComponent(componentContext), componentContext) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun WearApp(component: RootComponent, componentContext: ComponentContext) { | ||
OtariumTheme { | ||
val currentScreen by component.currentScreen.subscribeAsState() | ||
|
||
when (val screen = currentScreen) { | ||
is RootComponent.ChildScreen.HomeChild -> HomeScreen(componentContext) | ||
is RootComponent.ChildScreen.LoginChild -> LoginScreen(screen.component) | ||
is RootComponent.ChildScreen.OnboardingChild -> screen.component.exitOnboarding() | ||
} | ||
} | ||
} |
Oops, something went wrong.