Skip to content

Commit

Permalink
More work on Android Quiltthub Webview app
Browse files Browse the repository at this point in the history
Still need to solve below problem:
1. Upon logout and log back in, the hub webapp doesn't get the token
2. Haven't handle token expires
  • Loading branch information
tom-quiltt committed Feb 29, 2024
1 parent b0b8999 commit 63469ca
Show file tree
Hide file tree
Showing 37 changed files with 88 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
android:name=".QuilttConnectorActivity"
android:launchMode="singleTop"
android:exported="true">
<tools:validation testUrl="https://www.quiltthub.com/mobile/reconnect" />
<tools:validation testUrl="https://www.quiltthub.com/mobile/connect" />

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

Expand All @@ -28,6 +31,29 @@
android:scheme="quilttandroidexample"
android:host="open.kotlin.app" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https" />
<data android:host="www.quiltthub.com" />
<data android:pathPattern="/mobile/connect" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:scheme="https"
android:host="www.quiltthub.com"
android:pathPattern="/mobile/reconnect" />
<data android:host="www.quiltthub.com" />
<data android:pathPattern="/mobile/reconnect" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ plugins {
}

android {
namespace = "app.quiltt.app_jetpack_compose"
namespace = "app.quiltt.app_quiltthub_webview_example"
compileSdk = 34

defaultConfig {
applicationId = "app.quiltt.app_jetpack_compose"
applicationId = "app.quiltt.app_quiltthub_webview_example"
minSdk = 26
targetSdk = 34
versionCode = 1
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.quiltt.app_jetpack_compose
package app.quiltt.app_quiltthub_webview_example

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@drawable/quiltt_app_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@drawable/quiltt_app_icon"
android:supportsRtl="true"
android:theme="@style/Theme.App.First">
<activity
Expand All @@ -23,16 +23,6 @@
android:theme="@style/Theme.QuilttConnector">
<tools:validation testUrl="https://quiltt.app/mobile/hub/connect" />

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https" />
<data android:host="quiltt.app" />
<data android:pathPattern="/mobile/hub/connect" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.quiltt.app_jetpack_compose
package app.quiltt.app_quiltthub_webview_example

object AppConfig {
val ingressConnectorId = BuildConfig.INGRESS_CONNECTOR_ID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.quiltt.app_jetpack_compose
package app.quiltt.app_quiltthub_webview_example

import android.content.Intent
import android.os.Bundle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.quiltt.app_jetpack_compose
package app.quiltt.app_quiltthub_webview_example

import android.app.Activity
import android.os.Bundle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.quiltt.app_jetpack_compose
package app.quiltt.app_quiltthub_webview_example

import android.content.Intent
import android.os.Bundle
Expand Down Expand Up @@ -32,6 +32,11 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.res.painterResource

class QuilttHubActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -50,7 +55,7 @@ class QuilttHubActivity : ComponentActivity() {
.setMessage("Are you sure you want to logout?")
.setPositiveButton("Yes") { _, _ ->
logout()
startActivity((Intent(this, MainActivity::class.java)))
// startActivity((Intent(this, MainActivity::class.java)))
}
.setNegativeButton("No", null)
.show()
Expand Down Expand Up @@ -80,7 +85,12 @@ fun QuilttHubContent() {
val url = "https://www.quiltthub.com/login?mode=webview&token=$token"
Column {
TopAppBar(
title = { Text(text = "Quiltt Hub") },
title = {
Image(
painter = painterResource(id = R.drawable.quiltt_app_icon),
contentDescription = "Quiltt Hub Logo",
modifier = Modifier.size(40.dp))
},
actions = {
Button(onClick = {
val intent = Intent(context, QuilttConnectorActivity::class.java)
Expand Down Expand Up @@ -117,15 +127,18 @@ fun WebViewComposable(url: String) {
webViewClient = object : WebViewClient() {
val activity = context as QuilttHubActivity
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
val url = request?.url.toString()
if (url != null && url.startsWith("https://quiltt.app/mobile/hub/reconnect")) {
val urlComponents = Uri.parse(url.toString())
val url = request?.url?.toString()
if (url != null && url.startsWith("https://www.quiltthub.com/mobile/hub/reconnect")) {
val urlComponents = Uri.parse(url)
val connectionId = urlComponents.getQueryParameter("connectionId")
val intent = Intent(context, QuilttConnectorActivity::class.java)
intent.putExtra("connectionId", connectionId)
activity.startActivity(intent)
return true
}
if (url != null && url.startsWith("https://www.quiltthub.com")) {
return false
}
// TODO: Sometimes connector is publishing Options?
if (url != null && url.startsWith("quilttconnector://")) {
return true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.quiltt.app_jetpack_compose
package app.quiltt.app_quiltthub_webview_example

import android.content.Context
import android.content.SharedPreferences
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.quiltt.app_jetpack_compose.ui.theme
package app.quiltt.app_quiltthub_webview_example.ui.theme

import androidx.compose.ui.graphics.Color

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.quiltt.app_jetpack_compose.ui.theme
package app.quiltt.app_quiltthub_webview_example.ui.theme

import android.app.Activity
import android.os.Build
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.quiltt.app_jetpack_compose.ui.theme
package app.quiltt.app_quiltthub_webview_example.ui.theme

import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:scaleX="1"
android:scaleY="1"
android:translateX="1.0"
android:translateY="-0.5">
<path
android:pathData="m22,19.888 l-2.926,-1.659 1.236,-0.705 -0.003,-10.98L10.687,1 4.52,4.497l0.005,0.007L1,6.502v11L10.698,23l3.286,-1.872 3.086,1.74 4.93,-2.98ZM19.083,7.233v9.599l-1.235,0.704 -0.753,-0.428L17.095,8.375L8.681,3.526l2.001,-1.134 8.4,4.841ZM10.7,21.61l-8.472,-4.803L2.228,7.196L7.47,4.223l8.4,4.84v7.35l-2.077,-1.177v-4.993L7.38,6.603 4.299,8.55v7.122l8.457,4.765 -2.058,1.172ZM12.571,10.937v3.604L9.393,12.74L9.393,9.136l3.177,1.8ZM5.527,14.977L5.527,9.205l1.889,-1.194 0.752,0.427v4.995l11.44,6.487 -2.558,1.547 -11.523,-6.492Z">
<aapt:attr name="android:fillColor">
<gradient
android:startX="1"
android:startY="15"
android:endX="22"
android:endY="12"
android:type="linear">
<item android:offset="0" android:color="#FF441DBC"/>
<item android:offset="1" android:color="#FF25217C"/>
</gradient>
</aapt:attr>
</path>
</group>
</vector>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">App Jetpack Compose</string>
<string name="app_name">Quiltt Hub</string>
<string name="title_activity_quiltt_connector">QuilttConnectorActivity</string>
<string name="title_activity_quiltt_hub">QuilttHubActivity</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.quiltt.app_jetpack_compose
package app.quiltt.app_quiltthub_webview_example

import org.junit.Test

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ dependencyResolutionManagement {
rootProject.name = "quiltt-android"
include(":app")
include(":connector")
include(":app_jetpack_compose")
include(":app_quiltthub_webview_example")

0 comments on commit 63469ca

Please sign in to comment.