-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 | ||
} | ||
} | ||
} |
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> |
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() | ||
} | ||
} | ||
} | ||
} |
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)) | ||
} | ||
} | ||
} |
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="retry">Retry</string> | ||
</resources> |