Skip to content

Commit 2280c23

Browse files
committed
copy password
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
1 parent af95b98 commit 2280c23

5 files changed

Lines changed: 326 additions & 129 deletions

File tree

app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt

Lines changed: 88 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ package com.nextcloud.talk.conversationcreation
1212

1313
import android.annotation.SuppressLint
1414
import android.app.Activity
15+
import android.content.ClipData
16+
import android.content.ClipboardManager
1517
import android.content.Context
1618
import android.content.Intent
1719
import android.net.Uri
@@ -466,63 +468,84 @@ fun RoomCreationOptions(conversationCreationViewModel: ConversationCreationViewM
466468
fontSize = 14.sp,
467469
modifier = Modifier.padding(top = 24.dp, start = 16.dp, end = 16.dp)
468470
)
469-
ConversationOptions(
470-
icon = R.drawable.ic_avatar_link,
471-
text = R.string.nc_guest_access_allow_title,
472-
switch = {
473-
Switch(
474-
checked = isGuestsAllowed,
475-
onCheckedChange = {
476-
conversationCreationViewModel.isGuestsAllowed.value = it
477-
}
478-
)
479-
},
480-
conversationCreationViewModel = conversationCreationViewModel
481-
)
482471

483-
if (isGuestsAllowed && !isPasswordSet) {
472+
Column {
484473
ConversationOptions(
485-
icon = R.drawable.baseline_lock_open_24,
486-
text = R.string.nc_set_password,
487-
conversationCreationViewModel = conversationCreationViewModel
474+
icon = R.drawable.ic_avatar_link,
475+
text = R.string.nc_guest_access_allow_title,
476+
switch = {
477+
Switch(
478+
checked = isGuestsAllowed,
479+
onCheckedChange = {
480+
conversationCreationViewModel.isGuestsAllowed.value = it
481+
}
482+
)
483+
},
484+
conversationCreationViewModel = conversationCreationViewModel,
485+
isPasswordSetOrChange = false,
486+
copyPassword = false
488487
)
489-
}
490488

491-
if (isGuestsAllowed && isPasswordSet) {
492-
ConversationOptions(
493-
icon = R.drawable.ic_lock_grey600_24px,
494-
text = R.string.nc_change_password,
495-
conversationCreationViewModel = conversationCreationViewModel
496-
)
497-
}
489+
if (isGuestsAllowed && !isPasswordSet) {
490+
ConversationOptions(
491+
icon = R.drawable.baseline_lock_open_24,
492+
text = R.string.nc_set_password,
493+
conversationCreationViewModel = conversationCreationViewModel,
494+
isPasswordSetOrChange = true,
495+
copyPassword = false
496+
)
497+
}
498498

499-
ConversationOptions(
500-
icon = R.drawable.baseline_format_list_bulleted_24,
501-
text = R.string.nc_open_conversation_to_registered_users,
502-
switch = {
503-
Switch(
504-
checked = isConversationAvailableForRegisteredUsers,
505-
onCheckedChange = {
506-
conversationCreationViewModel.isConversationAvailableForRegisteredUsers.value = it
507-
}
499+
if (isGuestsAllowed && isPasswordSet) {
500+
ConversationOptions(
501+
icon = R.drawable.ic_lock_grey600_24px,
502+
text = R.string.nc_change_password,
503+
conversationCreationViewModel = conversationCreationViewModel,
504+
isPasswordSetOrChange = true,
505+
copyPassword = false
508506
)
509-
},
510-
conversationCreationViewModel = conversationCreationViewModel
511-
)
507+
}
508+
if (isGuestsAllowed && isPasswordSet) {
509+
ConversationOptions(
510+
icon = R.drawable.ic_content_copy,
511+
text = R.string.nc_copy_password,
512+
conversationCreationViewModel = conversationCreationViewModel,
513+
isPasswordSetOrChange = false,
514+
copyPassword = true
515+
)
516+
}
512517

513-
if (isConversationAvailableForRegisteredUsers) {
514518
ConversationOptions(
515-
text = R.string.nc_open_to_guest_app_users,
519+
icon = R.drawable.baseline_format_list_bulleted_24,
520+
text = R.string.nc_open_conversation_to_registered_users,
516521
switch = {
517522
Switch(
518-
checked = isOpenForGuestAppUsers,
523+
checked = isConversationAvailableForRegisteredUsers,
519524
onCheckedChange = {
520-
conversationCreationViewModel.openForGuestAppUsers.value = it
525+
conversationCreationViewModel.isConversationAvailableForRegisteredUsers.value = it
521526
}
522527
)
523528
},
524-
conversationCreationViewModel = conversationCreationViewModel
529+
conversationCreationViewModel = conversationCreationViewModel,
530+
isPasswordSetOrChange = false,
531+
copyPassword = false
525532
)
533+
if (isConversationAvailableForRegisteredUsers) {
534+
ConversationOptions(
535+
text = R.string.nc_open_to_guest_app_users,
536+
switch = {
537+
Switch(
538+
checked = isOpenForGuestAppUsers,
539+
onCheckedChange = {
540+
conversationCreationViewModel.openForGuestAppUsers.value = it
541+
}
542+
)
543+
},
544+
conversationCreationViewModel = conversationCreationViewModel,
545+
isPasswordSetOrChange = false,
546+
copyPassword = false
547+
)
548+
}
526549
}
527550
}
528551

@@ -531,8 +554,11 @@ fun ConversationOptions(
531554
icon: Int? = null,
532555
text: Int,
533556
switch: @Composable (() -> Unit)? = null,
534-
conversationCreationViewModel: ConversationCreationViewModel
557+
conversationCreationViewModel: ConversationCreationViewModel,
558+
isPasswordSetOrChange: Boolean,
559+
copyPassword: Boolean
535560
) {
561+
val context = LocalContext.current
536562
var showPasswordDialog by rememberSaveable { mutableStateOf(false) }
537563
var showPasswordChangeDialog by rememberSaveable { mutableStateOf(false) }
538564
val passwordValidationState by conversationCreationViewModel.validPasswordViewState.collectAsStateWithLifecycle()
@@ -541,19 +567,29 @@ fun ConversationOptions(
541567
.fillMaxWidth()
542568
.padding(start = 16.dp, end = 16.dp, bottom = 8.dp)
543569
.then(
544-
if (!conversationCreationViewModel.isPasswordEnabled.value) {
570+
if (!conversationCreationViewModel.isPasswordEnabled.value && isPasswordSetOrChange) {
545571
Modifier.clickable {
546572
showPasswordDialog = true
547573
}
548-
} else if (conversationCreationViewModel.isPasswordEnabled.value) {
574+
} else if (conversationCreationViewModel.isPasswordEnabled.value && isPasswordSetOrChange) {
549575
Modifier.clickable {
550576
showPasswordChangeDialog = true
551577
}
578+
} else if (copyPassword) {
579+
Modifier.clickable {
580+
val clipboardManager =
581+
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
582+
val clip = ClipData.newPlainText(
583+
context.getString(R.string.nc_app_product_name),
584+
conversationCreationViewModel.password.value
585+
)
586+
clipboardManager.setPrimaryClip(clip)
587+
}
552588
} else {
553589
Modifier
554590
}
555591
),
556-
horizontalArrangement = Arrangement.SpaceBetween,
592+
horizontalArrangement = Arrangement.SpaceEvenly,
557593
verticalAlignment = Alignment.CenterVertically
558594
) {
559595
if (icon != null) {
@@ -755,19 +791,23 @@ fun PasswordValidationMessage(passwordValidationState: ValidPasswordUiState) {
755791
is ValidPasswordUiState.Success -> Text(
756792
text = passwordValidationState.result.reason
757793
?: stringResource(R.string.nc_password_secure),
758-
color = if ((passwordValidationState as ValidPasswordUiState.Success).result.passed == false) {
794+
color = if ((passwordValidationState).result.passed == false) {
759795
colorResource(
760796
id = R.color
761797
.nc_darkRed
762798
)
763799
} else {
764800
colorResource(id = R.color.nc_darkGreen)
765801
},
802+
style = MaterialTheme.typography.bodySmall,
766803
modifier = Modifier.fillMaxWidth()
767804
)
768805

769806
is ValidPasswordUiState.Error -> {
770-
Text(text = passwordValidationState.message)
807+
Text(
808+
text = passwordValidationState.message,
809+
style = MaterialTheme.typography.bodySmall
810+
)
771811
}
772812

773813
else -> {

0 commit comments

Comments
 (0)