Loading app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareDetailActivity.kt +48 −43 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import it.niedermann.owncloud.notes.shared.util.extensions.getParcelableArgument import it.niedermann.owncloud.notes.shared.util.extensions.getSerializableArgument import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.text.SimpleDateFormat import java.util.Date Loading @@ -35,7 +36,8 @@ import java.util.Date * 2. This will handle both Advanced Permissions and Send New Email functionality for existing shares to modify them. */ @Suppress("TooManyFunctions") class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFragment.OnExpiryDateListener { class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFragment.OnExpiryDateListener { companion object { const val TAG = "NoteShareDetailActivity" Loading Loading @@ -243,7 +245,8 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra } private fun setupUpdateUI() { binding.shareProcessBtnNext.text = getString(R.string.note_share_detail_activity_common_next) binding.shareProcessBtnNext.text = getString(R.string.note_share_detail_activity_common_next) note.let { updateViewForFile() updateViewForShareType() Loading Loading @@ -299,7 +302,8 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra if (!isReShareShown) { binding.shareProcessAllowResharingCheckbox.visibility = View.GONE } binding.shareProcessAllowResharingCheckbox.isChecked = SharingMenuHelper.canReshare(share) binding.shareProcessAllowResharingCheckbox.isChecked = SharingMenuHelper.canReshare(share) } } Loading @@ -316,7 +320,8 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra binding.shareProcessHideDownloadCheckbox.visibility = View.GONE } else { binding.shareProcessHideDownloadCheckbox.visibility = View.VISIBLE binding.shareProcessHideDownloadCheckbox.isChecked = share?.isHideFileDownload == true binding.shareProcessHideDownloadCheckbox.isChecked = share?.isHideFileDownload == true } } } Loading @@ -343,7 +348,8 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra } private fun updateViewForFolder() { binding.shareProcessPermissionUploadEditing.text = getString(R.string.link_share_allow_upload_and_editing) binding.shareProcessPermissionUploadEditing.text = getString(R.string.link_share_allow_upload_and_editing) binding.shareProcessPermissionFileDrop.visibility = View.VISIBLE if (isSecureShare) { binding.shareProcessPermissionFileDrop.visibility = View.GONE Loading @@ -360,10 +366,12 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra binding.shareProcessEditShareLink.visibility = View.GONE binding.shareProcessGroupTwo.visibility = View.VISIBLE if (share != null) { binding.shareProcessBtnNext.text = getString(R.string.note_share_detail_activity_set_note) binding.shareProcessBtnNext.text = getString(R.string.note_share_detail_activity_set_note) binding.noteText.setText(share?.note) } else { binding.shareProcessBtnNext.text = getString(R.string.note_share_detail_activity_send_share) binding.shareProcessBtnNext.text = getString(R.string.note_share_detail_activity_send_share) binding.noteText.setText(R.string.empty) } shareProcessStep = SCREEN_TYPE_NOTE Loading @@ -377,7 +385,7 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra if (shareProcessStep == SCREEN_TYPE_PERMISSION) { validateShareProcessFirst() } else { validateShareProcessSecond() createOrUpdateShare() } } binding.shareProcessSetPasswordSwitch.setOnCheckedChangeListener { _, isChecked -> Loading @@ -402,7 +410,8 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra } private fun showChangeNameInput(isChecked: Boolean) { binding.shareProcessChangeNameContainer.visibility = if (isChecked) View.VISIBLE else View.GONE binding.shareProcessChangeNameContainer.visibility = if (isChecked) View.VISIBLE else View.GONE if (!isChecked) { binding.shareProcessChangeName.setText(R.string.empty) } Loading Loading @@ -437,7 +446,8 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra } private fun showPasswordInput(isChecked: Boolean) { binding.shareProcessEnterPasswordContainer.visibility = if (isChecked) View.VISIBLE else View.GONE binding.shareProcessEnterPasswordContainer.visibility = if (isChecked) View.VISIBLE else View.GONE // reset the password if switch is unchecked if (!isChecked) { Loading @@ -459,14 +469,20 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra private fun validateShareProcessFirst() { permission = getSelectedPermission() if (permission == OCShare.NO_PERMISSION) { DisplayUtils.showSnackMessage(binding.root, R.string.note_share_detail_activity_no_share_permission_selected) DisplayUtils.showSnackMessage( binding.root, R.string.note_share_detail_activity_no_share_permission_selected ) return } if (binding.shareProcessSetPasswordSwitch.isChecked && binding.shareProcessEnterPassword.text?.trim().isNullOrEmpty() ) { DisplayUtils.showSnackMessage(binding.root, R.string.note_share_detail_activity_share_link_empty_password) DisplayUtils.showSnackMessage( binding.root, R.string.note_share_detail_activity_share_link_empty_password ) return } Loading @@ -480,7 +496,10 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra if (binding.shareProcessChangeNameSwitch.isChecked && binding.shareProcessChangeName.text?.trim().isNullOrEmpty() ) { DisplayUtils.showSnackMessage(binding.root, R.string.note_share_detail_activity_label_empty) DisplayUtils.showSnackMessage( binding.root, R.string.note_share_detail_activity_label_empty ) return } Loading Loading @@ -520,41 +539,17 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra ClipboardUtil.copyToClipboard(this, share?.shareLink) } */ } /** * method to validate step 2 (note screen) information */ private fun validateShareProcessSecond() { /* val noteText = binding.noteText.text.toString().trim() // if modifying existing share then directly update the note and send email if (share != null && share?.note != noteText) { fileOperationsHelper?.updateNoteToShare(share, noteText) } else { // else create new share fileOperationsHelper?.shareFileWithSharee( file, shareeName, shareType, permission, binding .shareProcessHideDownloadCheckbox.isChecked, binding.shareProcessEnterPassword.text.toString().trim(), chosenExpDateInMills, noteText, binding.shareProcessChangeName.text.toString().trim(), true ) } onShareProcessClosed() */ private fun createOrUpdateShare() { val noteText = binding.noteText.text.toString().trim() lifecycleScope.launch(Dispatchers.IO) { val ssoAcc = SingleAccountHelper.getCurrentSingleSignOnAccount(this@NoteShareDetailActivity) val ssoAcc = SingleAccountHelper.getCurrentSingleSignOnAccount(this@NoteShareDetailActivity) // if modifying existing share then directly update the note and send email if (share != null && share?.note != noteText) { Loading @@ -565,8 +560,7 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra return@launch } // else create new share repository.addShare( val result = repository.addShare( ssoAcc, note!!, shareType, Loading @@ -576,6 +570,17 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra permission, noteText ) withContext(Dispatchers.Main) { if (result) { finish() } else { DisplayUtils.showSnackMessage( this@NoteShareDetailActivity, getString(R.string.note_share_detail_activity_create_share_error) ) } } } } } Loading app/src/main/java/it/niedermann/owncloud/notes/share/repository/ShareRepository.kt +4 −2 Original line number Diff line number Diff line Loading @@ -172,10 +172,10 @@ class ShareRepository(private val applicationContext: Context) { password: String = "", permissions: Int = 0, shareNote: String = "" ) { ): Boolean { val notesPathCall = notesRepository.getServerSettings(account, ApiVersion.API_VERSION_1_0) val notesPathResponse = notesPathCall.execute() val notesPathResponseResult = notesPathResponse.body() ?: return val notesPathResponseResult = notesPathResponse.body() ?: return false val notesPath = notesPathResponseResult.notesPath val notesSuffix = notesPathResponseResult.fileSuffix Loading @@ -199,5 +199,7 @@ class ShareRepository(private val applicationContext: Context) { val errorBody = response.errorBody()?.string() Log.d("", "Response failed:$errorBody") } return response.isSuccessful } } app/src/main/res/values/strings.xml +1 −0 Original line number Diff line number Diff line Loading @@ -88,6 +88,7 @@ <string name="note_share_detail_activity_no_share_permission_selected">Please select at least one permission to share.</string> <string name="note_share_detail_activity_label_empty">Label cannot be empty</string> <string name="note_share_detail_activity_cancel">Cancel</string> <string name="note_share_detail_activity_create_share_error">Failed to create a share</string> <!-- SharePasswordDialogFragment --> <string name="share_password_dialog_fragment_share_link_optional_password_title">Enter an optional password</string> Loading Loading
app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareDetailActivity.kt +48 −43 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import it.niedermann.owncloud.notes.shared.util.extensions.getParcelableArgument import it.niedermann.owncloud.notes.shared.util.extensions.getSerializableArgument import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.text.SimpleDateFormat import java.util.Date Loading @@ -35,7 +36,8 @@ import java.util.Date * 2. This will handle both Advanced Permissions and Send New Email functionality for existing shares to modify them. */ @Suppress("TooManyFunctions") class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFragment.OnExpiryDateListener { class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFragment.OnExpiryDateListener { companion object { const val TAG = "NoteShareDetailActivity" Loading Loading @@ -243,7 +245,8 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra } private fun setupUpdateUI() { binding.shareProcessBtnNext.text = getString(R.string.note_share_detail_activity_common_next) binding.shareProcessBtnNext.text = getString(R.string.note_share_detail_activity_common_next) note.let { updateViewForFile() updateViewForShareType() Loading Loading @@ -299,7 +302,8 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra if (!isReShareShown) { binding.shareProcessAllowResharingCheckbox.visibility = View.GONE } binding.shareProcessAllowResharingCheckbox.isChecked = SharingMenuHelper.canReshare(share) binding.shareProcessAllowResharingCheckbox.isChecked = SharingMenuHelper.canReshare(share) } } Loading @@ -316,7 +320,8 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra binding.shareProcessHideDownloadCheckbox.visibility = View.GONE } else { binding.shareProcessHideDownloadCheckbox.visibility = View.VISIBLE binding.shareProcessHideDownloadCheckbox.isChecked = share?.isHideFileDownload == true binding.shareProcessHideDownloadCheckbox.isChecked = share?.isHideFileDownload == true } } } Loading @@ -343,7 +348,8 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra } private fun updateViewForFolder() { binding.shareProcessPermissionUploadEditing.text = getString(R.string.link_share_allow_upload_and_editing) binding.shareProcessPermissionUploadEditing.text = getString(R.string.link_share_allow_upload_and_editing) binding.shareProcessPermissionFileDrop.visibility = View.VISIBLE if (isSecureShare) { binding.shareProcessPermissionFileDrop.visibility = View.GONE Loading @@ -360,10 +366,12 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra binding.shareProcessEditShareLink.visibility = View.GONE binding.shareProcessGroupTwo.visibility = View.VISIBLE if (share != null) { binding.shareProcessBtnNext.text = getString(R.string.note_share_detail_activity_set_note) binding.shareProcessBtnNext.text = getString(R.string.note_share_detail_activity_set_note) binding.noteText.setText(share?.note) } else { binding.shareProcessBtnNext.text = getString(R.string.note_share_detail_activity_send_share) binding.shareProcessBtnNext.text = getString(R.string.note_share_detail_activity_send_share) binding.noteText.setText(R.string.empty) } shareProcessStep = SCREEN_TYPE_NOTE Loading @@ -377,7 +385,7 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra if (shareProcessStep == SCREEN_TYPE_PERMISSION) { validateShareProcessFirst() } else { validateShareProcessSecond() createOrUpdateShare() } } binding.shareProcessSetPasswordSwitch.setOnCheckedChangeListener { _, isChecked -> Loading @@ -402,7 +410,8 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra } private fun showChangeNameInput(isChecked: Boolean) { binding.shareProcessChangeNameContainer.visibility = if (isChecked) View.VISIBLE else View.GONE binding.shareProcessChangeNameContainer.visibility = if (isChecked) View.VISIBLE else View.GONE if (!isChecked) { binding.shareProcessChangeName.setText(R.string.empty) } Loading Loading @@ -437,7 +446,8 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra } private fun showPasswordInput(isChecked: Boolean) { binding.shareProcessEnterPasswordContainer.visibility = if (isChecked) View.VISIBLE else View.GONE binding.shareProcessEnterPasswordContainer.visibility = if (isChecked) View.VISIBLE else View.GONE // reset the password if switch is unchecked if (!isChecked) { Loading @@ -459,14 +469,20 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra private fun validateShareProcessFirst() { permission = getSelectedPermission() if (permission == OCShare.NO_PERMISSION) { DisplayUtils.showSnackMessage(binding.root, R.string.note_share_detail_activity_no_share_permission_selected) DisplayUtils.showSnackMessage( binding.root, R.string.note_share_detail_activity_no_share_permission_selected ) return } if (binding.shareProcessSetPasswordSwitch.isChecked && binding.shareProcessEnterPassword.text?.trim().isNullOrEmpty() ) { DisplayUtils.showSnackMessage(binding.root, R.string.note_share_detail_activity_share_link_empty_password) DisplayUtils.showSnackMessage( binding.root, R.string.note_share_detail_activity_share_link_empty_password ) return } Loading @@ -480,7 +496,10 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra if (binding.shareProcessChangeNameSwitch.isChecked && binding.shareProcessChangeName.text?.trim().isNullOrEmpty() ) { DisplayUtils.showSnackMessage(binding.root, R.string.note_share_detail_activity_label_empty) DisplayUtils.showSnackMessage( binding.root, R.string.note_share_detail_activity_label_empty ) return } Loading Loading @@ -520,41 +539,17 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra ClipboardUtil.copyToClipboard(this, share?.shareLink) } */ } /** * method to validate step 2 (note screen) information */ private fun validateShareProcessSecond() { /* val noteText = binding.noteText.text.toString().trim() // if modifying existing share then directly update the note and send email if (share != null && share?.note != noteText) { fileOperationsHelper?.updateNoteToShare(share, noteText) } else { // else create new share fileOperationsHelper?.shareFileWithSharee( file, shareeName, shareType, permission, binding .shareProcessHideDownloadCheckbox.isChecked, binding.shareProcessEnterPassword.text.toString().trim(), chosenExpDateInMills, noteText, binding.shareProcessChangeName.text.toString().trim(), true ) } onShareProcessClosed() */ private fun createOrUpdateShare() { val noteText = binding.noteText.text.toString().trim() lifecycleScope.launch(Dispatchers.IO) { val ssoAcc = SingleAccountHelper.getCurrentSingleSignOnAccount(this@NoteShareDetailActivity) val ssoAcc = SingleAccountHelper.getCurrentSingleSignOnAccount(this@NoteShareDetailActivity) // if modifying existing share then directly update the note and send email if (share != null && share?.note != noteText) { Loading @@ -565,8 +560,7 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra return@launch } // else create new share repository.addShare( val result = repository.addShare( ssoAcc, note!!, shareType, Loading @@ -576,6 +570,17 @@ class NoteShareDetailActivity : BrandedActivity(), ExpirationDatePickerDialogFra permission, noteText ) withContext(Dispatchers.Main) { if (result) { finish() } else { DisplayUtils.showSnackMessage( this@NoteShareDetailActivity, getString(R.string.note_share_detail_activity_create_share_error) ) } } } } } Loading
app/src/main/java/it/niedermann/owncloud/notes/share/repository/ShareRepository.kt +4 −2 Original line number Diff line number Diff line Loading @@ -172,10 +172,10 @@ class ShareRepository(private val applicationContext: Context) { password: String = "", permissions: Int = 0, shareNote: String = "" ) { ): Boolean { val notesPathCall = notesRepository.getServerSettings(account, ApiVersion.API_VERSION_1_0) val notesPathResponse = notesPathCall.execute() val notesPathResponseResult = notesPathResponse.body() ?: return val notesPathResponseResult = notesPathResponse.body() ?: return false val notesPath = notesPathResponseResult.notesPath val notesSuffix = notesPathResponseResult.fileSuffix Loading @@ -199,5 +199,7 @@ class ShareRepository(private val applicationContext: Context) { val errorBody = response.errorBody()?.string() Log.d("", "Response failed:$errorBody") } return response.isSuccessful } }
app/src/main/res/values/strings.xml +1 −0 Original line number Diff line number Diff line Loading @@ -88,6 +88,7 @@ <string name="note_share_detail_activity_no_share_permission_selected">Please select at least one permission to share.</string> <string name="note_share_detail_activity_label_empty">Label cannot be empty</string> <string name="note_share_detail_activity_cancel">Cancel</string> <string name="note_share_detail_activity_create_share_error">Failed to create a share</string> <!-- SharePasswordDialogFragment --> <string name="share_password_dialog_fragment_share_link_optional_password_title">Enter an optional password</string> Loading