-
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.
Add Wear OS app
- Loading branch information
Showing
26 changed files
with
707 additions
and
19 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
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
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,71 @@ | ||
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.kotlin.datetime) | ||
|
||
implementation(libs.decompose.core) | ||
implementation(libs.decompose.compose) | ||
|
||
api(libs.moko.resources.core) | ||
implementation(libs.magister.api) | ||
} |
Oops, something went wrong.