srctree

Robin Linden parent 1246543a 924dd4ff
Simplify UserManager::create's signature

inlinesplit
atox/src/main/kotlin/ui/create_profile/CreateProfileFragment.kt added: 14, removed: 13, total 1
@@ -19,6 +19,7 @@ import kotlinx.android.synthetic.main.fragment_profile.view.*
import ltd.evilcorp.atox.R
import ltd.evilcorp.atox.setUpFullScreenUi
import ltd.evilcorp.atox.vmFactory
import ltd.evilcorp.core.vo.User
 
private const val IMPORT = 42
 
@@ -53,11 +54,12 @@ class CreateProfileFragment : Fragment() {
btnCreate.isEnabled = false
 
viewModel.startTox()
viewModel.createUser(
viewModel.publicKey,
if (username.text.isNotEmpty()) username.text.toString() else "aTox user",
if (password.text.isNotEmpty()) password.text.toString() else ""
val user = User(
publicKey = viewModel.publicKey.string(),
name = if (username.text.isNotEmpty()) username.text.toString() else "aTox user",
password = if (password.text.isNotEmpty()) password.text.toString() else ""
)
viewModel.create(user)
 
findNavController().popBackStack()
}
 
atox/src/main/kotlin/ui/create_profile/CreateProfileViewModel.kt added: 14, removed: 13, total 1
@@ -4,6 +4,7 @@ import android.content.Context
import android.net.Uri
import androidx.lifecycle.ViewModel
import ltd.evilcorp.atox.tox.ToxStarter
import ltd.evilcorp.core.vo.User
import ltd.evilcorp.domain.feature.UserManager
import ltd.evilcorp.domain.tox.PublicKey
import ltd.evilcorp.domain.tox.Tox
@@ -22,8 +23,6 @@ class CreateProfileViewModel @Inject constructor(
fun tryImportToxSave(uri: Uri): ByteArray? =
context.contentResolver.openInputStream(uri)?.readBytes()
 
fun createUser(publicKey: PublicKey, name: String, password: String) =
userManager.create(publicKey, name, password)
 
fun create(user: User) = userManager.create(user)
fun verifyUserExists(publicKey: PublicKey) = userManager.verifyExists(publicKey)
}
 
domain/src/main/kotlin/feature/UserManager.kt added: 14, removed: 13, total 1
@@ -16,9 +16,9 @@ class UserManager @Inject constructor(
) : CoroutineScope by GlobalScope {
fun get(publicKey: PublicKey) = userRepository.get(publicKey.string())
 
fun create(publicKey: PublicKey, name: String, password: String) = launch {
userRepository.add(User(publicKey = publicKey.string(), name = name, password = password))
tox.setName(name)
fun create(user: User) = launch {
userRepository.add(user)
tox.setName(user.name)
}
 
fun verifyExists(publicKey: PublicKey) = launch {