Skip to content

Commit

Permalink
Restore the restore follows button
Browse files Browse the repository at this point in the history
  • Loading branch information
greenart7c3 committed Jan 22, 2025
1 parent 9da899b commit 78a3261
Show file tree
Hide file tree
Showing 8 changed files with 661 additions and 378 deletions.
192 changes: 192 additions & 0 deletions app/schemas/com.greenart7c3.citrine.database.HistoryDatabase/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "bf90c485bbfb3751761eb581ab24cf07",
"entities": [
{
"tableName": "EventEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `pubkey` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `kind` INTEGER NOT NULL, `content` TEXT NOT NULL, `sig` TEXT NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "pubkey",
"columnName": "pubkey",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "createdAt",
"columnName": "createdAt",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "kind",
"columnName": "kind",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "content",
"columnName": "content",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "sig",
"columnName": "sig",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [
{
"name": "id_is_hash",
"unique": true,
"columnNames": [
"id"
],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `id_is_hash` ON `${TABLE_NAME}` (`id`)"
},
{
"name": "most_common_search_is_pubkey_kind",
"unique": false,
"columnNames": [
"pubkey",
"kind"
],
"orders": [
"ASC",
"ASC"
],
"createSql": "CREATE INDEX IF NOT EXISTS `most_common_search_is_pubkey_kind` ON `${TABLE_NAME}` (`pubkey` ASC, `kind` ASC)"
},
{
"name": "most_common_search_is_kind",
"unique": false,
"columnNames": [
"kind"
],
"orders": [
"ASC"
],
"createSql": "CREATE INDEX IF NOT EXISTS `most_common_search_is_kind` ON `${TABLE_NAME}` (`kind` ASC)"
}
],
"foreignKeys": []
},
{
"tableName": "TagEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`pk` INTEGER PRIMARY KEY AUTOINCREMENT, `pkEvent` TEXT, `position` INTEGER NOT NULL, `col0Name` TEXT, `col1Value` TEXT, `col2Differentiator` TEXT, `col3Amount` TEXT, `col4Plus` TEXT NOT NULL, FOREIGN KEY(`pkEvent`) REFERENCES `EventEntity`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "pk",
"columnName": "pk",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "pkEvent",
"columnName": "pkEvent",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "position",
"columnName": "position",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "col0Name",
"columnName": "col0Name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "col1Value",
"columnName": "col1Value",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "col2Differentiator",
"columnName": "col2Differentiator",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "col3Amount",
"columnName": "col3Amount",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "col4Plus",
"columnName": "col4Plus",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"pk"
]
},
"indices": [
{
"name": "tags_by_pk_event",
"unique": false,
"columnNames": [
"pkEvent"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `tags_by_pk_event` ON `${TABLE_NAME}` (`pkEvent`)"
},
{
"name": "tags_by_tags_on_person_or_events",
"unique": false,
"columnNames": [
"col0Name",
"col1Value"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `tags_by_tags_on_person_or_events` ON `${TABLE_NAME}` (`col0Name`, `col1Value`)"
}
],
"foreignKeys": [
{
"table": "EventEntity",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"pkEvent"
],
"referencedColumns": [
"id"
]
}
]
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'bf90c485bbfb3751761eb581ab24cf07')"
]
}
}
116 changes: 88 additions & 28 deletions app/src/main/java/com/greenart7c3/citrine/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import com.greenart7c3.citrine.database.toTags
import com.greenart7c3.citrine.server.Settings
import com.greenart7c3.citrine.service.CustomWebSocketService
import com.greenart7c3.citrine.service.LocalPreferences
import com.greenart7c3.citrine.ui.ContactsScreen
import com.greenart7c3.citrine.ui.HomeViewModel
import com.greenart7c3.citrine.ui.LogcatScreen
import com.greenart7c3.citrine.ui.SettingsScreen
Expand Down Expand Up @@ -154,7 +155,7 @@ class MainActivity : ComponentActivity() {

Scaffold(
bottomBar = {
if (destinationRoute != Route.Logs.route && !destinationRoute.startsWith("Feed") && destinationRoute != Route.DatabaseInfo.route) {
if (destinationRoute != Route.Logs.route && !destinationRoute.startsWith("Feed") && destinationRoute != Route.DatabaseInfo.route && !destinationRoute.startsWith("Contacts")) {
NavigationBar(tonalElevation = 0.dp) {
items.forEach {
val selected = destinationRoute == it.route
Expand All @@ -177,7 +178,7 @@ class MainActivity : ComponentActivity() {
)
}
}
} else if (destinationRoute.startsWith("Feed") || destinationRoute == Route.DatabaseInfo.route) {
} else if (destinationRoute.startsWith("Feed") || destinationRoute == Route.DatabaseInfo.route || destinationRoute.startsWith("Contacts")) {
BottomAppBar {
IconRow(
center = true,
Expand All @@ -192,14 +193,16 @@ class MainActivity : ComponentActivity() {
}
},
topBar = {
if (destinationRoute.startsWith("Feed") || destinationRoute == Route.DatabaseInfo.route) {
if (destinationRoute.startsWith("Feed") || destinationRoute == Route.DatabaseInfo.route || destinationRoute.startsWith("Contacts")) {
CenterAlignedTopAppBar(
title = {
Text(
text = if (destinationRoute.startsWith("Feed")) {
stringResource(R.string.feed)
} else {
} else if (destinationRoute == Route.DatabaseInfo.route) {
stringResource(R.string.database)
} else {
stringResource(R.string.restore_follows)
},
)
},
Expand Down Expand Up @@ -294,6 +297,45 @@ class MainActivity : ComponentActivity() {
}
}

val launcherLoginContacts = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult(),
onResult = { result ->
if (result.resultCode != RESULT_OK) {
Toast.makeText(
context,
getString(R.string.sign_request_rejected),
Toast.LENGTH_SHORT,
).show()
} else {
result.data?.let {
try {
val key = it.getStringExtra("signature") ?: ""
val packageName = it.getStringExtra("package") ?: ""

val returnedKey = if (key.startsWith("npub")) {
when (val parsed = Nip19Bech32.uriToRoute(key)?.entity) {
is Nip19Bech32.NPub -> parsed.hex
else -> ""
}
} else {
key
}

homeViewModel.signer = NostrSignerExternal(
returnedKey,
ExternalSignerLauncher(returnedKey, packageName),
)

homeViewModel.setPubKey(returnedKey)
navController.navigate(Route.ContactsScreen.route.replace("{pubkey}", returnedKey))
} catch (e: Exception) {
Log.d(Citrine.TAG, e.message ?: "", e)
}
}
}
},
)

val launcherLogin = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult(),
onResult = { result ->
Expand Down Expand Up @@ -528,30 +570,31 @@ class MainActivity : ComponentActivity() {
)
}

// ElevatedButton(
// onClick = {
// try {
// val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:"))
// val signerType = "get_public_key"
// intent.putExtra("type", signerType)
// intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
// launcherLogin.launch(intent)
// } catch (e: Exception) {
// Log.d(Citrine.TAG, e.message ?: "", e)
// coroutineScope.launch(Dispatchers.Main) {
// Toast.makeText(
// context,
// getString(R.string.no_external_signer_installed),
// Toast.LENGTH_SHORT,
// ).show()
// }
// val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/greenart7c3/Amber/releases"))
// launcherLogin.launch(intent)
// }
// },
// ) {
// Text(stringResource(R.string.restore_follows))
// }
ElevatedButton(
modifier = Modifier.fillMaxWidth(),
onClick = {
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:"))
val signerType = "get_public_key"
intent.putExtra("type", signerType)
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
launcherLoginContacts.launch(intent)
} catch (e: Exception) {
Log.d(Citrine.TAG, e.message ?: "", e)
coroutineScope.launch(Dispatchers.Main) {
Toast.makeText(
context,
getString(R.string.no_external_signer_installed),
Toast.LENGTH_SHORT,
).show()
}
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/greenart7c3/Amber/releases"))
launcherLoginContacts.launch(intent)
}
},
) {
Text(stringResource(R.string.restore_follows))
}

ElevatedButton(
modifier = Modifier.fillMaxWidth(),
Expand Down Expand Up @@ -711,6 +754,23 @@ class MainActivity : ComponentActivity() {
},
)

composable(
Route.ContactsScreen.route,
arguments = listOf(navArgument("pubkey") { type = NavType.StringType }),
content = {
it.arguments?.getString("pubkey")?.let { pubkey ->
ContactsScreen(
modifier = Modifier
.fillMaxSize()
.padding(padding)
.padding(16.dp),
pubKey = pubkey,
navController = navController,
)
}
},
)

composable(Route.Settings.route) {
val context = LocalContext.current
SettingsScreen(
Expand Down
Loading

0 comments on commit 78a3261

Please sign in to comment.