-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99614f0
commit 7ccae7b
Showing
210 changed files
with
9,483 additions
and
0 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,101 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
namespace 'com.vitorpamplona.amethyst' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "com.vitorpamplona.amethyst" | ||
minSdk 26 | ||
targetSdk 33 | ||
versionCode 1 | ||
versionName "0.1" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
vectorDrawables { | ||
useSupportLibrary true | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled 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 '1.3.2' | ||
} | ||
packagingOptions { | ||
resources { | ||
excludes += '/META-INF/{AL2.0,LGPL2.1}' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'androidx.core:core-ktx:1.9.0' | ||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1' | ||
implementation 'androidx.activity:activity-compose:1.6.1' | ||
implementation "androidx.compose.ui:ui:$compose_ui_version" | ||
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version" | ||
implementation 'androidx.compose.material:material:1.3.1' | ||
|
||
// Navigation | ||
implementation("androidx.navigation:navigation-compose:$nav_version") | ||
implementation 'androidx.lifecycle:lifecycle-runtime-compose:2.6.0-alpha03' | ||
implementation 'androidx.compose.runtime:runtime-livedata:1.4.0-alpha03' | ||
|
||
// Input | ||
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1' | ||
|
||
// Swipe Refresh | ||
implementation 'com.google.accompanist:accompanist-swiperefresh:0.24.13-rc' | ||
|
||
// Load images from the web. | ||
implementation "io.coil-kt:coil-compose:2.2.2" | ||
|
||
// Bitcoin secp256k1 bindings to Android | ||
implementation 'fr.acinq.secp256k1:secp256k1-kmp-jni-android:0.7.0' | ||
|
||
// Nostr Base Protocol | ||
implementation('com.github.vitorpamplona.NostrPostr:nostrpostrlib:master-SNAPSHOT') { | ||
exclude group:'fr.acinq.secp256k1' | ||
exclude module: 'guava' | ||
exclude module: 'guava-testlib' | ||
} | ||
|
||
implementation 'com.squareup.retrofit2:converter-gson:2.8.1' | ||
// Websockets API | ||
implementation 'com.squareup.okhttp3:okhttp:4.10.0' | ||
|
||
// Json Serialization | ||
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.14.1' | ||
|
||
// Rendering clickable text | ||
implementation "com.google.accompanist:accompanist-flowlayout:0.28.0" | ||
|
||
// link preview | ||
implementation 'tw.com.oneup.www:Baha-UrlPreview:1.0.1' | ||
implementation 'androidx.security:security-crypto-ktx:1.1.0-alpha03' | ||
|
||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version" | ||
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version" | ||
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version" | ||
} |
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,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 |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/vitorpamplona/amethyst/ExampleInstrumentedTest.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,24 @@ | ||
package com.vitorpamplona.amethyst | ||
|
||
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.vitorpamplona.amethyst", appContext.packageName) | ||
} | ||
} |
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,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@drawable/amethyst_logo" | ||
android:label="@string/app_name" | ||
android:roundIcon="@drawable/amethyst_logo" | ||
android:enableOnBackInvokedCallback="true" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.Amethyst" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".ui.MainActivity" | ||
android:exported="true" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.Amethyst"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
|
||
<meta-data | ||
android:name="android.app.lib_name" | ||
android:value="" /> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/vitorpamplona/amethyst/KeyStorage.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,22 @@ | ||
package com.vitorpamplona.amethyst | ||
|
||
import android.content.Context | ||
import androidx.security.crypto.EncryptedSharedPreferences | ||
import androidx.security.crypto.MasterKeys | ||
|
||
class KeyStorage { | ||
|
||
fun encryptedPreferences(context: Context): EncryptedSharedPreferences { | ||
val secretKey: String = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC); | ||
val preferencesName = "secret_keeper" | ||
|
||
return EncryptedSharedPreferences.create( | ||
preferencesName, | ||
secretKey, | ||
context, | ||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, | ||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM | ||
) as EncryptedSharedPreferences | ||
} | ||
|
||
} |
92 changes: 92 additions & 0 deletions
92
app/src/main/java/com/vitorpamplona/amethyst/model/Account.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,92 @@ | ||
package com.vitorpamplona.amethyst.model | ||
|
||
import androidx.lifecycle.LiveData | ||
import com.vitorpamplona.amethyst.service.model.ReactionEvent | ||
import com.vitorpamplona.amethyst.service.model.RepostEvent | ||
import com.vitorpamplona.amethyst.service.relays.Client | ||
import nostr.postr.Persona | ||
import nostr.postr.events.TextNoteEvent | ||
import nostr.postr.toHex | ||
|
||
class Account(val loggedIn: Persona) { | ||
var seeReplies: Boolean = true | ||
|
||
fun userProfile(): User { | ||
return LocalCache.getOrCreateUser(loggedIn.pubKey) | ||
} | ||
|
||
fun isWriteable(): Boolean { | ||
return loggedIn.privKey != null | ||
} | ||
|
||
fun reactTo(note: Note) { | ||
if (!isWriteable()) return | ||
|
||
note.event?.let { | ||
val event = ReactionEvent.create(it, loggedIn.privKey!!) | ||
Client.send(event) | ||
LocalCache.consume(event) | ||
} | ||
} | ||
|
||
fun boost(note: Note) { | ||
if (!isWriteable()) return | ||
|
||
note.event?.let { | ||
val event = RepostEvent.create(it, loggedIn.privKey!!) | ||
Client.send(event) | ||
LocalCache.consume(event) | ||
} | ||
} | ||
|
||
fun sendPost(message: String, replyingTo: Note?) { | ||
if (!isWriteable()) return | ||
|
||
val replyToEvent = replyingTo?.event | ||
if (replyToEvent is TextNoteEvent) { | ||
val repliesTo = replyToEvent.replyTos.plus(replyToEvent.id.toHex()) | ||
val mentions = replyToEvent.mentions.plus(replyToEvent.pubKey.toHex()) | ||
|
||
val signedEvent = TextNoteEvent.create( | ||
msg = message, | ||
replyTos = repliesTo, | ||
mentions = mentions, | ||
privateKey = loggedIn.privKey!! | ||
) | ||
Client.send(signedEvent) | ||
LocalCache.consume(signedEvent) | ||
} else { | ||
val signedEvent = TextNoteEvent.create( | ||
msg = message, | ||
replyTos = null, | ||
mentions = null, | ||
privateKey = loggedIn.privKey!! | ||
) | ||
Client.send(signedEvent) | ||
LocalCache.consume(signedEvent) | ||
} | ||
} | ||
|
||
// Observers line up here. | ||
val live: AccountLiveData = AccountLiveData(this) | ||
|
||
private fun refreshObservers() { | ||
live.refresh() | ||
} | ||
} | ||
|
||
class AccountLiveData(private val account: Account): LiveData<AccountState>(AccountState(account)) { | ||
fun refresh() { | ||
postValue(AccountState(account)) | ||
} | ||
|
||
override fun onActive() { | ||
super.onActive() | ||
} | ||
|
||
override fun onInactive() { | ||
super.onInactive() | ||
} | ||
} | ||
|
||
class AccountState(val account: Account) |
Oops, something went wrong.