Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushBherwani1998 committed Mar 22, 2024
1 parent 9f62b84 commit 1ce319f
Show file tree
Hide file tree
Showing 53 changed files with 1,061 additions and 0 deletions.
Binary file added .gradle/8.2/checksums/checksums.lock
Binary file not shown.
Binary file added .gradle/8.2/checksums/md5-checksums.bin
Binary file not shown.
Binary file added .gradle/8.2/checksums/sha1-checksums.bin
Binary file not shown.
Binary file not shown.
Binary file added .gradle/8.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file added .gradle/8.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file added .gradle/8.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file added .gradle/8.2/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file added .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 2 additions & 0 deletions .gradle/buildOutputCleanup/cache.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Fri Mar 22 13:40:55 IST 2024
gradle.version=8.2
Binary file added .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
2 changes: 2 additions & 0 deletions .gradle/config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Fri Mar 22 13:39:34 IST 2024
java.home=/Applications/Android Studio.app/Contents/jbr/Contents/Home
15 changes: 15 additions & 0 deletions tkey-android-mpc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions tkey-android-mpc/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
82 changes: 82 additions & 0 deletions tkey-android-mpc/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}

android {
namespace = "com.example.tkey_android_mpc"
compileSdk = 34

defaultConfig {
applicationId = "com.example.tkey_android_mpc"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
manifestPlaceholders["torusRedirectScheme"] = "torusapp"
manifestPlaceholders [ "torusRedirectHost"] = "org.torusresearch.customauthandroid"
manifestPlaceholders["torusRedirectPathPrefix"]= "/redirect"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

vectorDrawables {
useSupportLibrary = true
}
}

configurations {
all {
exclude("com.github.grvgoel81","fetch-node-details-java")
exclude("org.torusresearch", "torus-utils-java")
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {
implementation("io.insert-koin:koin-android:3.5.3")
implementation("org.torusresearch:customauth-android-sdk:5.0.2")
implementation("com.github.tkey:tkey-mpc-android:0.1.1")
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.activity:activity-compose:1.8.2")
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
}
21 changes: 21 additions & 0 deletions tkey-android-mpc/app/proguard-rules.pro
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.tkey_android_mpc

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.tkey_android_mpc", appContext.packageName)
}
}
29 changes: 29 additions & 0 deletions tkey-android-mpc/app/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"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:label="@string/app_name"
android:theme="@style/Theme.Tkeyandroidmpc">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.tkey_android_mpc

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.example.tkey_android_mpc.di.appModule
import com.example.tkey_android_mpc.ui.presentation.MainScreen
import com.example.tkey_android_mpc.ui.theme.TkeyandroidmpcTheme
import com.example.tkey_android_mpc.viewmodel.MainViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.GlobalContext.startKoin

class MainActivity : ComponentActivity() {
private val viewModel: MainViewModel by viewModel()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
startKoin {
androidContext(this@MainActivity)
modules(appModule)
}
setContent {
TkeyandroidmpcTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
MainScreen(viewModel = viewModel)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.tkey_android_mpc.di

import android.content.Context
import com.example.tkey_android_mpc.viewmodel.MainViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module
import org.torusresearch.customauth.CustomAuth
import org.torusresearch.customauth.types.CustomAuthArgs
import org.torusresearch.fetchnodedetails.types.TorusNetwork

val appModule = module {
single {
getCustomAuth(get())
}

viewModel { MainViewModel(get()) }
}

private fun getCustomAuth(context: Context): CustomAuth {
val customAuthArgs = CustomAuthArgs(
"https://scripts.toruswallet.io/redirect.html",
TorusNetwork.TESTNET,
"torusapp://org.torusresearch.customauthandroid/redirect",
)

return CustomAuth(customAuthArgs, context)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.tkey_android_mpc.ui.presentation

import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.example.tkey_android_mpc.viewmodel.MainViewModel

@Composable
fun LoginScreen(viewModel: MainViewModel) {
val context = LocalContext.current
Column(
modifier = Modifier.fillMaxSize().padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
text = "tKey Android Example",
textAlign = TextAlign.Center,
style = MaterialTheme.typography.headlineSmall
)

LoginButton {
try {
viewModel.loginWithOAuth()
} catch (e: Exception) {
Toast.makeText(context, e.localizedMessage, Toast.LENGTH_LONG).show()
}
}
}
}

@Composable
fun LoginButton(onClick: () -> Unit) {
Button(onClick = { onClick() }) {
Text("Login with Google")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.tkey_android_mpc.ui.presentation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import com.example.tkey_android_mpc.viewmodel.MainViewModel

@Composable
fun MainScreen(viewModel: MainViewModel) {
val isLoggedIn = viewModel.isLoggedIn.collectAsState()
if (!isLoggedIn.value) {
return LoginScreen(viewModel)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.tkey_android_mpc.ui.theme

import androidx.compose.ui.graphics.Color

val Purple80 = Color(0xFFD0BCFF)
val PurpleGrey80 = Color(0xFFCCC2DC)
val Pink80 = Color(0xFFEFB8C8)

val Purple40 = Color(0xFF6650a4)
val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)
Loading

0 comments on commit 1ce319f

Please sign in to comment.