Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit 24929c4

Browse files
Accounts refactor (#586)
- Making it so account data is stored in a database instead of multiple proto files - Removed different thread view options. Tree is not the only option --------- Co-authored-by: John Oberhauser <j.git-global@obez.io>
1 parent a9db4c6 commit 24929c4

64 files changed

Lines changed: 735 additions & 787 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ dependencies {
9191
implementation(project(":feature:followedHashTags"))
9292
implementation(project(":feature:bookmarks"))
9393
implementation(project(":core:ui:chooseAccount"))
94+
implementation(project(":core:accounts"))
9495

9596
implementation(kotlin("reflect"))
9697

app/src/main/kotlin/social/firefly/IntentHandler.kt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,34 @@ package social.firefly
33
import android.content.Intent
44
import android.net.Uri
55
import android.os.Parcelable
6-
import social.firefly.core.datastore.UserPreferencesDatastoreManager
6+
import kotlinx.coroutines.CoroutineScope
7+
import kotlinx.coroutines.Dispatchers
8+
import kotlinx.coroutines.launch
9+
import social.firefly.core.accounts.AccountsManager
710
import social.firefly.core.navigation.Event
811
import social.firefly.core.navigation.EventRelay
912
import social.firefly.core.share.ShareInfo
1013

1114
class IntentHandler(
1215
private val eventRelay: EventRelay,
13-
private val userPreferencesDatastoreManager: UserPreferencesDatastoreManager,
16+
private val accountsManager: AccountsManager,
1417
) {
1518

1619
fun handleIntent(intent: Intent) {
17-
if (!userPreferencesDatastoreManager.isLoggedInToAtLeastOneAccount) return
18-
when {
19-
intent.action == Intent.ACTION_SEND -> {
20-
when {
21-
intent.type == "text/plain" -> {
22-
handleSendTextIntentReceived(intent)
23-
}
24-
intent.type?.contains("image") == true -> {
25-
handleSendImageIntentReceived(intent)
26-
}
27-
intent.type?.contains("video") == true -> {
28-
handleSendVideoIntentReceived(intent)
20+
CoroutineScope(Dispatchers.Default).launch {
21+
if (accountsManager.getAllAccounts().isEmpty()) return@launch
22+
when {
23+
intent.action == Intent.ACTION_SEND -> {
24+
when {
25+
intent.type == "text/plain" -> {
26+
handleSendTextIntentReceived(intent)
27+
}
28+
intent.type?.contains("image") == true -> {
29+
handleSendImageIntentReceived(intent)
30+
}
31+
intent.type?.contains("video") == true -> {
32+
handleSendVideoIntentReceived(intent)
33+
}
2934
}
3035
}
3136
}

app/src/main/kotlin/social/firefly/MainApplication.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.koin.androidx.workmanager.koin.workManagerFactory
2121
import org.koin.core.context.startKoin
2222
import org.koin.dsl.module
2323
import social.firefly.common.Version
24+
import social.firefly.core.accounts.accountsModule
2425
import social.firefly.core.analytics.AppAnalytics
2526
import social.firefly.core.repository.mastodon.AuthCredentialObserver
2627
import social.firefly.core.workmanager.workManagerModule
@@ -102,6 +103,7 @@ class MainApplication : Application(), ImageLoaderFactory {
102103
workManagerModule,
103104
pushModule,
104105
chooseAccountModule,
106+
accountsModule,
105107
)
106108
}
107109
}

app/src/main/kotlin/social/firefly/splash/SplashViewModel.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import androidx.lifecycle.ViewModel
55
import androidx.lifecycle.viewModelScope
66
import kotlinx.coroutines.launch
77
import social.firefly.IntentHandler
8-
import social.firefly.core.datastore.UserPreferencesDatastoreManager
8+
import social.firefly.core.accounts.AccountsManager
99
import social.firefly.core.navigation.NavigationDestination
1010
import social.firefly.core.navigation.usecases.NavigateTo
1111
import social.firefly.core.repository.mastodon.TimelineRepository
@@ -14,10 +14,10 @@ import social.firefly.ui.AppState
1414

1515
class SplashViewModel(
1616
private val navigateTo: NavigateTo,
17-
private val userPreferencesDatastoreManager: UserPreferencesDatastoreManager,
1817
private val timelineRepository: TimelineRepository,
1918
private val updateAllLoggedInAccounts: UpdateAllLoggedInAccounts,
2019
private val intentHandler: IntentHandler,
20+
private val accountsManager: AccountsManager,
2121
) : ViewModel() {
2222

2323
fun initialize(intent: Intent?) {
@@ -27,7 +27,7 @@ class SplashViewModel(
2727

2828
AppState.navigationCollectionCompletable.await()
2929

30-
if (userPreferencesDatastoreManager.isLoggedInToAtLeastOneAccount) {
30+
if (accountsManager.getAllAccounts().isNotEmpty()) {
3131
navigateTo(NavigationDestination.Tabs)
3232
intent?.let { intentHandler.handleIntent(intent) }
3333
updateAllLoggedInAccounts()

core/accounts/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

core/accounts/build.gradle.kts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
plugins {
2+
id("social.firefly.android.library")
3+
alias(libs.plugins.kotlin.ksp)
4+
alias(libs.plugins.kotlinx.serialization)
5+
}
6+
7+
android {
8+
namespace = "social.firefly.core.accounts"
9+
10+
defaultConfig {
11+
ksp {
12+
arg("room.schemaLocation", "$projectDir/schemas")
13+
}
14+
}
15+
}
16+
17+
dependencies {
18+
implementation(project(":core:model"))
19+
20+
implementation(libs.koin.android)
21+
22+
implementation(libs.androidx.room.runtime)
23+
ksp(libs.androidx.room.compiler)
24+
implementation(libs.androidx.room)
25+
26+
implementation(libs.kotlinx.serialization.json)
27+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"formatVersion": 1,
3+
"database": {
4+
"version": 1,
5+
"identityHash": "fa0fd12964a2830e2fdd786ebac516aa",
6+
"entities": [
7+
{
8+
"tableName": "mastodonAccounts",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accessToken` TEXT NOT NULL, `accountId` TEXT NOT NULL, `domain` TEXT NOT NULL, `avatarUrl` TEXT NOT NULL, `userName` TEXT NOT NULL, `defaultLanguage` TEXT NOT NULL, `serializedPushKeys` TEXT, `lastSeenHomeStatusId` TEXT, PRIMARY KEY(`accountId`))",
10+
"fields": [
11+
{
12+
"fieldPath": "accessToken",
13+
"columnName": "accessToken",
14+
"affinity": "TEXT",
15+
"notNull": true
16+
},
17+
{
18+
"fieldPath": "accountId",
19+
"columnName": "accountId",
20+
"affinity": "TEXT",
21+
"notNull": true
22+
},
23+
{
24+
"fieldPath": "domain",
25+
"columnName": "domain",
26+
"affinity": "TEXT",
27+
"notNull": true
28+
},
29+
{
30+
"fieldPath": "avatarUrl",
31+
"columnName": "avatarUrl",
32+
"affinity": "TEXT",
33+
"notNull": true
34+
},
35+
{
36+
"fieldPath": "userName",
37+
"columnName": "userName",
38+
"affinity": "TEXT",
39+
"notNull": true
40+
},
41+
{
42+
"fieldPath": "defaultLanguage",
43+
"columnName": "defaultLanguage",
44+
"affinity": "TEXT",
45+
"notNull": true
46+
},
47+
{
48+
"fieldPath": "serializedPushKeys",
49+
"columnName": "serializedPushKeys",
50+
"affinity": "TEXT",
51+
"notNull": false
52+
},
53+
{
54+
"fieldPath": "lastSeenHomeStatusId",
55+
"columnName": "lastSeenHomeStatusId",
56+
"affinity": "TEXT",
57+
"notNull": false
58+
}
59+
],
60+
"primaryKey": {
61+
"autoGenerate": false,
62+
"columnNames": [
63+
"accountId"
64+
]
65+
},
66+
"indices": [],
67+
"foreignKeys": []
68+
},
69+
{
70+
"tableName": "activeAccount",
71+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` INTEGER NOT NULL, `accountType` TEXT NOT NULL, `accountId` TEXT NOT NULL, PRIMARY KEY(`key`), FOREIGN KEY(`accountId`) REFERENCES `mastodonAccounts`(`accountId`) ON UPDATE CASCADE ON DELETE CASCADE )",
72+
"fields": [
73+
{
74+
"fieldPath": "key",
75+
"columnName": "key",
76+
"affinity": "INTEGER",
77+
"notNull": true
78+
},
79+
{
80+
"fieldPath": "accountType",
81+
"columnName": "accountType",
82+
"affinity": "TEXT",
83+
"notNull": true
84+
},
85+
{
86+
"fieldPath": "accountId",
87+
"columnName": "accountId",
88+
"affinity": "TEXT",
89+
"notNull": true
90+
}
91+
],
92+
"primaryKey": {
93+
"autoGenerate": false,
94+
"columnNames": [
95+
"key"
96+
]
97+
},
98+
"indices": [],
99+
"foreignKeys": [
100+
{
101+
"table": "mastodonAccounts",
102+
"onDelete": "CASCADE",
103+
"onUpdate": "CASCADE",
104+
"columns": [
105+
"accountId"
106+
],
107+
"referencedColumns": [
108+
"accountId"
109+
]
110+
}
111+
]
112+
}
113+
],
114+
"views": [],
115+
"setupQueries": [
116+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
117+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'fa0fd12964a2830e2fdd786ebac516aa')"
118+
]
119+
}
120+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
</manifest>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package social.firefly.core.accounts
2+
3+
import androidx.room.Database
4+
import androidx.room.RoomDatabase
5+
import social.firefly.core.accounts.dao.ActiveAccountDao
6+
import social.firefly.core.accounts.dao.MastodonAccountsDao
7+
import social.firefly.core.accounts.model.ActiveAccount
8+
import social.firefly.core.accounts.model.MastodonAccount
9+
10+
@Database(
11+
entities = [
12+
MastodonAccount::class,
13+
ActiveAccount::class,
14+
],
15+
version = 1,
16+
autoMigrations = [
17+
18+
],
19+
exportSchema = true
20+
)
21+
internal abstract class AccountsDatabase : RoomDatabase() {
22+
abstract fun mastodonAccountsDao(): MastodonAccountsDao
23+
abstract fun activeAccountsDao(): ActiveAccountDao
24+
}

0 commit comments

Comments
 (0)