Skip to content

Commit

Permalink
Add Android App
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed May 20, 2023
1 parent 9ee64c0 commit d554784
Show file tree
Hide file tree
Showing 44 changed files with 525 additions and 78 deletions.
8 changes: 8 additions & 0 deletions .idea/artifacts/client_js_1_2_2.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/client_js_1_2_3.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/client_jvm_1_2_2.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/client_jvm_1_2_3.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/common_js_1_2_2.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/common_js_1_2_3.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/common_jvm_1_2_2.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/common_jvm_1_2_3.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/shared_desktop_1_2_2.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/shared_desktop_1_2_3.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/shared_js_1_2_2.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/shared_js_1_2_3.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/web_js_1_2_2.xml

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

8 changes: 8 additions & 0 deletions .idea/artifacts/web_js_1_2_3.xml

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

15 changes: 4 additions & 11 deletions .idea/gradle.xml

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

3 changes: 1 addition & 2 deletions .idea/misc.xml

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

46 changes: 46 additions & 0 deletions app/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import dev.schlaubi.tonbrett.gradle.sdkInt
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("android")
id("com.android.application")
id("org.jetbrains.compose")
}

dependencies {
implementation(projects.app.shared)
implementation(libs.androidx.activity)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core)
implementation(libs.androidx.browser)
implementation("com.google.android.material:material:1.5.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.3")
}

android {
namespace = "dev.schlaubi.tonbrett.app.android"
compileSdk = sdkInt
defaultConfig {
applicationId = "dev.schlaubi.tonbrett.android"
minSdk = 26
targetSdk = sdkInt
versionCode = 1
versionName = rootProject.version.toString()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
}

buildFeatures {
compose = true
}
}

tasks {
withType<KotlinCompile> {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
}
}
}
29 changes: 29 additions & 0 deletions app/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="tonbrett" />

<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".AppActivity"
android:exported="false" />
</application>

</manifest>
28 changes: 28 additions & 0 deletions app/android/src/main/java/AppActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.schlaubi.tonbrett.app.android

import android.content.Intent
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import dev.schlaubi.tonbrett.app.TonbrettApp
import dev.schlaubi.tonbrett.app.api.AppContext
import dev.schlaubi.tonbrett.app.api.ProvideContext
import dev.schlaubi.tonbrett.app.api.tokenKey

class AppActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val context = object : AppContext(applicationContext) {
override fun reAuthorize() {
vault.deleteObject(tokenKey)
startActivity(Intent(applicationContext, MainActivity::class.java))
}
}
context.resetApi()
ProvideContext(context) {
TonbrettApp()
}
}
}
}
47 changes: 47 additions & 0 deletions app/android/src/main/java/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dev.schlaubi.tonbrett.app.android

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import androidx.browser.customtabs.CustomTabsIntent
import dev.schlaubi.tonbrett.app.api.AppContext
import dev.schlaubi.tonbrett.app.api.getUrl
import dev.schlaubi.tonbrett.app.api.tokenKey
import dev.schlaubi.tonbrett.common.Route
import io.ktor.http.URLBuilder
import io.ktor.resources.href
import io.ktor.resources.serialization.ResourcesFormat

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val button = findViewById<Button>(R.id.btn_retry)
button.setOnClickListener {
onAttachedToWindow()
}
}

override fun onAttachedToWindow() {
val context = AppContext(applicationContext)
if (intent.data?.scheme == "tonbrett" && intent.data?.host == "login") {
val token = intent.data?.getQueryParameter("token")
if (token != null) {
context.vault.set(tokenKey, token)
startActivity(Intent(this, AppActivity::class.java))
return
}
}
if (context.getTokenOrNull() == null) {
val urlBuilder = URLBuilder(getUrl())
href(ResourcesFormat(), Route.Auth(Route.Auth.Type.MOBILE_APP), urlBuilder)
val intent = CustomTabsIntent.Builder()
.build()
intent.launchUrl(this, Uri.parse(urlBuilder.buildString()))
} else {
startActivity(Intent(this, AppActivity::class.java))
}
}
}
22 changes: 22 additions & 0 deletions app/android/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >

<Button
android:id="@+id/btn_retry"
android:text="@string/retry"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions app/android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="retry">Retry</string>
</resources>
2 changes: 0 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ plugins {
kotlin("jvm") apply false
kotlin("multiplatform") apply false
kotlin("android") apply false
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.compose) apply false
}

Expand Down
Loading

0 comments on commit d554784

Please sign in to comment.