-
Notifications
You must be signed in to change notification settings - Fork 18
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
f868b77
commit 0ab928c
Showing
29 changed files
with
1,853 additions
and
172 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
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
32 changes: 32 additions & 0 deletions
32
app/src/main/kotlin/net/primal/android/auth/compose/Avatar.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,32 @@ | ||
package net.primal.android.auth.compose | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import net.primal.android.core.compose.icons.PrimalIcons | ||
import net.primal.android.core.compose.icons.primaliconpack.AvatarDefault | ||
|
||
val defaultOnboardingAvatarBackground = Color(0xFF7E382C) | ||
val defaultAvatarForeground = Color(0xFFFDB7AB) | ||
|
||
@Composable | ||
fun DefaultOnboardingAvatar() { | ||
Box( | ||
modifier = Modifier | ||
.background(color = defaultOnboardingAvatarBackground) | ||
.fillMaxSize(), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
Icon( | ||
imageVector = PrimalIcons.AvatarDefault, | ||
contentDescription = null, | ||
modifier = Modifier.fillMaxSize(), | ||
tint = defaultAvatarForeground, | ||
) | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/kotlin/net/primal/android/auth/compose/ColumnWithBackground.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,42 @@ | ||
package net.primal.android.auth.compose | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.BoxWithConstraints | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.systemBarsPadding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.unit.DpSize | ||
|
||
@Composable | ||
fun ColumnWithBackground( | ||
modifier: Modifier = Modifier, | ||
backgroundPainter: Painter, | ||
content: @Composable (DpSize) -> Unit, | ||
) { | ||
BoxWithConstraints( | ||
modifier = modifier, | ||
) { | ||
val maxSize = DpSize(width = this.maxWidth, height = this.maxHeight) | ||
|
||
Image( | ||
modifier = Modifier.fillMaxSize(), | ||
painter = backgroundPainter, | ||
contentScale = ContentScale.FillBounds, | ||
alignment = Alignment.Center, | ||
contentDescription = null, | ||
) | ||
|
||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.systemBarsPadding(), | ||
) { | ||
content(maxSize) | ||
} | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
app/src/main/kotlin/net/primal/android/auth/onboarding/CreateAccountHandler.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,57 @@ | ||
package net.primal.android.auth.onboarding | ||
|
||
import java.io.IOException | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.withContext | ||
import net.primal.android.auth.AuthRepository | ||
import net.primal.android.auth.onboarding.api.Suggestion | ||
import net.primal.android.core.coroutines.CoroutineDispatcherProvider | ||
import net.primal.android.networking.relays.errors.NostrPublishException | ||
import net.primal.android.networking.sockets.errors.WssException | ||
import net.primal.android.profile.domain.ProfileMetadata | ||
import net.primal.android.profile.repository.ProfileRepository | ||
import net.primal.android.settings.repository.SettingsRepository | ||
import net.primal.android.user.repository.RelayRepository | ||
import net.primal.android.user.repository.UserRepository | ||
import timber.log.Timber | ||
|
||
class CreateAccountHandler @Inject constructor( | ||
private val dispatcherProvider: CoroutineDispatcherProvider, | ||
private val authRepository: AuthRepository, | ||
private val relayRepository: RelayRepository, | ||
private val userRepository: UserRepository, | ||
private val profileRepository: ProfileRepository, | ||
private val settingsRepository: SettingsRepository, | ||
) { | ||
|
||
suspend fun createNostrAccount(profileMetadata: ProfileMetadata, interests: List<Suggestion>): String { | ||
val userId = authRepository.createAccountAndLogin() | ||
try { | ||
withContext(dispatcherProvider.io()) { | ||
userRepository.setProfileMetadata( | ||
userId = userId, | ||
profileMetadata = profileMetadata, | ||
) | ||
profileRepository.setFollowList( | ||
userId = userId, | ||
contacts = setOf(userId) + interests.mapToContacts(), | ||
) | ||
relayRepository.bootstrapDefaultUserRelays(userId) | ||
settingsRepository.fetchAndPersistAppSettings(userId = userId) | ||
} | ||
} catch (error: WssException) { | ||
Timber.w(error) | ||
throw AccountCreationException(cause = error) | ||
} catch (error: NostrPublishException) { | ||
Timber.w(error) | ||
throw AccountCreationException(cause = error) | ||
} | ||
return userId | ||
} | ||
|
||
private fun List<Suggestion>.mapToContacts(): Set<String> { | ||
return flatMap { it.members.map { member -> member.pubkey } }.toSet() | ||
} | ||
|
||
class AccountCreationException(cause: Throwable) : IOException(cause) | ||
} |
Oops, something went wrong.