From 852c46c8253188328683337604c8d8b335e9a037 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 27 Mar 2019 13:44:12 +0100 Subject: [PATCH] Apply CR changes --- owncloudApp/build.gradle | 2 +- .../datamodel/FileDataStorageManager.java | 4 +- .../CreateShareViaLinkOperation.java | 2 +- .../CreateShareWithShareeOperation.java | 2 +- .../datasource/OCRemoteSharesDataSource.kt | 2 +- .../ui/fragment/PublicShareDialogFragment.kt | 303 ++++++++---------- .../shares/ui/fragment/ShareFileFragment.kt | 140 ++++---- .../shares/viewmodel/OCShareViewModel.kt | 3 +- .../asynctasks/GetSharesForFileAsyncTask.java | 1 - .../ui/errorhandling/ErrorMessageAdapter.kt | 152 +++------ 10 files changed, 240 insertions(+), 371 deletions(-) diff --git a/owncloudApp/build.gradle b/owncloudApp/build.gradle index adb63028e6a..5ddcb01f941 100644 --- a/owncloudApp/build.gradle +++ b/owncloudApp/build.gradle @@ -1,8 +1,8 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' - apply plugin: 'kotlin-allopen' +apply plugin: 'kotlin-android-extensions' def commitSHA1 = 'COMMIT_SHA1' def gitRemote = 'GIT_REMOTE' diff --git a/owncloudApp/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/owncloudApp/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java index cd9573f0adb..ab9e5749a1a 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/owncloudApp/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -1430,7 +1430,7 @@ public void removeShare(OCShare share) { } } - public void saveShares(ArrayList shares) { + public void saveShares(List shares) { ArrayList operations = new ArrayList(); // Reset flags & Remove shares for this files @@ -1530,7 +1530,7 @@ public void saveSharesInFolder(ArrayList shares, OCFile folder) { * @return */ private ArrayList prepareInsertShares( - ArrayList shares, ArrayList operations) { + List shares, ArrayList operations) { if (shares != null) { // prepare operations to insert or update files to save in the given folder diff --git a/owncloudApp/src/main/java/com/owncloud/android/operations/CreateShareViaLinkOperation.java b/owncloudApp/src/main/java/com/owncloud/android/operations/CreateShareViaLinkOperation.java index 8b6611c6617..cd7cf3e4d01 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/operations/CreateShareViaLinkOperation.java +++ b/owncloudApp/src/main/java/com/owncloud/android/operations/CreateShareViaLinkOperation.java @@ -143,7 +143,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { createOp.setPassword(mPassword); createOp.setExpirationDateInMillis(mExpirationDateInMillis); createOp.setPublicUpload(mPublicUpload); - createOp.setGetShareDetails(true); + createOp.setRetrieveShareDetails(true); RemoteOperationResult result = createOp.execute(client); if (result.isSuccess()) { diff --git a/owncloudApp/src/main/java/com/owncloud/android/operations/CreateShareWithShareeOperation.java b/owncloudApp/src/main/java/com/owncloud/android/operations/CreateShareWithShareeOperation.java index fbf57195772..997fa9b042b 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/operations/CreateShareWithShareeOperation.java +++ b/owncloudApp/src/main/java/com/owncloud/android/operations/CreateShareWithShareeOperation.java @@ -74,7 +74,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { mShareeName, mPermissions ); - operation.setGetShareDetails(true); + operation.setRetrieveShareDetails(true); RemoteOperationResult result = operation.execute(client); if (result.isSuccess()) { diff --git a/owncloudApp/src/main/java/com/owncloud/android/shares/datasource/OCRemoteSharesDataSource.kt b/owncloudApp/src/main/java/com/owncloud/android/shares/datasource/OCRemoteSharesDataSource.kt index ce3de32dd15..f54bf2fdf99 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/shares/datasource/OCRemoteSharesDataSource.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/shares/datasource/OCRemoteSharesDataSource.kt @@ -54,7 +54,7 @@ class OCRemoteSharesDataSource( createRemoteShareOperation.password = password createRemoteShareOperation.expirationDateInMillis = expirationTimeInMillis createRemoteShareOperation.publicUpload = publicUpload - createRemoteShareOperation.getShareDetails = true + createRemoteShareOperation.retrieveShareDetails = true return createRemoteShareOperation.execute(client) } } diff --git a/owncloudApp/src/main/java/com/owncloud/android/shares/ui/fragment/PublicShareDialogFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/shares/ui/fragment/PublicShareDialogFragment.kt index 5a446ac0698..c1fb467bdbc 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/shares/ui/fragment/PublicShareDialogFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/shares/ui/fragment/PublicShareDialogFragment.kt @@ -35,40 +35,35 @@ import android.view.ViewGroup import android.view.WindowManager import android.view.inputmethod.InputMethodManager import android.widget.CompoundButton -import android.widget.EditText -import android.widget.LinearLayout -import android.widget.RadioButton -import android.widget.RadioGroup import android.widget.TextView - -import com.owncloud.android.R -import com.owncloud.android.datamodel.OCFile -import com.owncloud.android.lib.common.utils.Log_OC -import com.owncloud.android.lib.resources.shares.RemoteShare -import com.owncloud.android.lib.resources.status.OCCapability -import com.owncloud.android.lib.resources.status.OwnCloudVersion -import com.owncloud.android.shares.db.OCShare -import com.owncloud.android.ui.activity.FileActivity -import com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment -import com.owncloud.android.utils.DateUtils - -import java.text.ParseException -import java.text.SimpleDateFormat -import java.util.Date - import androidx.appcompat.widget.SwitchCompat import androidx.fragment.app.DialogFragment import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProviders +import com.owncloud.android.R import com.owncloud.android.ViewModelFactory +import com.owncloud.android.datamodel.OCFile +import com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.lib.resources.shares.RemoteShare import com.owncloud.android.lib.resources.shares.ShareType +import com.owncloud.android.lib.resources.status.OCCapability +import com.owncloud.android.lib.resources.status.OwnCloudVersion import com.owncloud.android.operations.common.OperationType +import com.owncloud.android.shares.db.OCShare import com.owncloud.android.shares.viewmodel.OCShareViewModel import com.owncloud.android.ui.activity.BaseActivity +import com.owncloud.android.ui.activity.FileActivity +import com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment import com.owncloud.android.ui.errorhandling.ErrorMessageAdapter import com.owncloud.android.ui.fragment.ShareFragmentListener +import com.owncloud.android.utils.DateUtils import com.owncloud.android.vo.Status +import kotlinx.android.synthetic.main.share_public_dialog.* +import kotlinx.android.synthetic.main.share_public_dialog.view.* +import java.text.ParseException +import java.text.SimpleDateFormat +import java.util.Date class PublicShareDialogFragment : DialogFragment() { @@ -85,7 +80,7 @@ class PublicShareDialogFragment : DialogFragment() { /* * OC account holding the file to share, received as a parameter in construction time */ - private lateinit var account: Account + private var account: Account? = null /** * Reference to parent listener @@ -107,30 +102,11 @@ class PublicShareDialogFragment : DialogFragment() { */ private var onExpirationDateInteractionListener: OnExpirationDateInteractionListener? = null - /** - * UI elements - */ - - private var nameSelectionLayout: LinearLayout? = null - private var nameValueEdit: EditText? = null - private var passwordLabel: TextView? = null - private var passwordSwitch: SwitchCompat? = null - private var passwordValueEdit: EditText? = null - private var expirationDateLabel: TextView? = null - private var expirationDateSwitch: SwitchCompat? = null - private var expirationDateExplanationLabel: TextView? = null - private var expirationDateValueLabel: TextView? = null - private var errorMessageLabel: TextView? = null - private var permissionRadioGroup: RadioGroup? = null - private var readOnlyButton: RadioButton? = null - private var readWriteButton: RadioButton? = null - private var uploadOnlyButton: RadioButton? = null - private val isSharedFolder: Boolean get() = file?.isFolder == true || publicShare?.isFolder == true private val isPasswordVisible: Boolean - get() = view != null && passwordValueEdit!!.inputType and + get() = view != null && shareViaLinkPasswordValue.inputType and InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD private// Parse expiration date and convert it to milliseconds @@ -138,8 +114,8 @@ class PublicShareDialogFragment : DialogFragment() { val expirationDateValueInMillis: Long get() { var publicLinkExpirationDateInMillis: Long = -1 - val expirationDate = expirationDateValueLabel!!.text.toString() - if (expirationDate.length > 0) { + val expirationDate = shareViaLinkExpirationValue?.text.toString() + if (expirationDate.isNotEmpty()) { try { publicLinkExpirationDateInMillis = ExpirationDatePickerDialogFragment.getDateFormat().parse(expirationDate).time @@ -155,18 +131,18 @@ class PublicShareDialogFragment : DialogFragment() { * Get expiration date imposed by the server, if any */ private val imposedExpirationDate: Long - get() = if (capabilities != null && capabilities!!.filesSharingPublicExpireDateEnforced.isTrue) { + get() = if (capabilities?.filesSharingPublicExpireDateEnforced?.isTrue == true) { DateUtils.addDaysToDate( Date(), - capabilities!!.filesSharingPublicExpireDateDays + capabilities?.filesSharingPublicExpireDateDays!! ) .time } else -1 var viewModelFactory: ViewModelProvider.Factory = ViewModelFactory.build { OCShareViewModel( - account, + account!!, file?.remotePath!!, listOf(ShareType.PUBLIC_LINK) ) @@ -190,9 +166,7 @@ class PublicShareDialogFragment : DialogFragment() { setStyle(DialogFragment.STYLE_NO_TITLE, 0) } - private fun updating(): Boolean { - return publicShare != null - } + private fun updating(): Boolean = publicShare != null override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -203,92 +177,73 @@ class PublicShareDialogFragment : DialogFragment() { Log_OC.d(TAG, "onCreateView") - val dialogTitleLabel = view.findViewById(R.id.publicShareDialogTitle) - nameSelectionLayout = view.findViewById(R.id.shareViaLinkNameSection) - nameValueEdit = view.findViewById(R.id.shareViaLinkNameValue) - passwordLabel = view.findViewById(R.id.shareViaLinkPasswordLabel) - passwordSwitch = view.findViewById(R.id.shareViaLinkPasswordSwitch) - passwordValueEdit = view.findViewById(R.id.shareViaLinkPasswordValue) - expirationDateLabel = view.findViewById(R.id.shareViaLinkExpirationLabel) - expirationDateSwitch = view.findViewById(R.id.shareViaLinkExpirationSwitch) - expirationDateExplanationLabel = view.findViewById(R.id.shareViaLinkExpirationExplanationLabel) - errorMessageLabel = view.findViewById(R.id.public_link_error_message) - expirationDateValueLabel = view.findViewById(R.id.shareViaLinkExpirationValue) - permissionRadioGroup = view.findViewById(R.id.shareViaLinkEditPermissionGroup) - readOnlyButton = view.findViewById(R.id.shareViaLinkEditPermissionReadOnly) - readWriteButton = view.findViewById(R.id.shareViaLinkEditPermissionReadAndWrite) - uploadOnlyButton = view.findViewById(R.id.shareViaLinkEditPermissionUploadFiles) - // Get and set the values saved previous to the screen rotation, if any if (savedInstanceState != null) { val expirationDate = savedInstanceState.getString(KEY_EXPIRATION_DATE) - if (expirationDate!!.length > 0) { - expirationDateValueLabel!!.visibility = View.VISIBLE - expirationDateValueLabel!!.text = expirationDate + if (!expirationDate.isNullOrEmpty()) { + view.shareViaLinkExpirationValue?.visibility = View.VISIBLE + view.shareViaLinkExpirationValue?.text = expirationDate } } if (updating()) { - dialogTitleLabel.setText(R.string.share_via_link_edit_title) - nameValueEdit!!.setText(publicShare!!.name) + view.publicShareDialogTitle?.setText(R.string.share_via_link_edit_title) + view.shareViaLinkNameValue?.setText(publicShare?.name) - when (publicShare!!.permissions) { + when (publicShare?.permissions) { RemoteShare.CREATE_PERMISSION_FLAG or RemoteShare.DELETE_PERMISSION_FLAG or RemoteShare.UPDATE_PERMISSION_FLAG - or RemoteShare.READ_PERMISSION_FLAG -> readWriteButton!!.isChecked = true - RemoteShare.CREATE_PERMISSION_FLAG -> uploadOnlyButton!!.isChecked = true - else -> readOnlyButton!!.isChecked = true + or RemoteShare.READ_PERMISSION_FLAG -> + view.shareViaLinkEditPermissionReadAndWrite.isChecked = true + RemoteShare.CREATE_PERMISSION_FLAG -> view.shareViaLinkEditPermissionUploadFiles.isChecked = true + else -> view.shareViaLinkEditPermissionReadOnly.isChecked = true } - if (publicShare!!.isPasswordProtected) { - + if (publicShare?.isPasswordProtected!!) { setPasswordSwitchChecked(true) - passwordValueEdit!!.visibility = View.VISIBLE - passwordValueEdit!!.setHint(R.string.share_via_link_default_password) + view.shareViaLinkPasswordValue?.visibility = View.VISIBLE + view.shareViaLinkPasswordValue?.hint = getString(R.string.share_via_link_default_password) } - if (publicShare!!.expirationDate != 0L) { + if (publicShare?.expirationDate != 0L) { setExpirationDateSwitchChecked(true) val formattedDate = ExpirationDatePickerDialogFragment.getDateFormat().format( - Date(publicShare!!.expirationDate) + Date(publicShare?.expirationDate!!) ) - expirationDateValueLabel!!.visibility = View.VISIBLE - expirationDateValueLabel!!.text = formattedDate + view.shareViaLinkExpirationValue?.visibility = View.VISIBLE + view.shareViaLinkExpirationValue?.text = formattedDate } } else { - nameValueEdit!!.setText(arguments!!.getString(ARG_DEFAULT_LINK_NAME, "")) + view.shareViaLinkNameValue?.setText(arguments!!.getString(ARG_DEFAULT_LINK_NAME, "")) } - initPasswordListener() - initExpirationListener() - initPasswordFocusChangeListener() - initPasswordToggleListener() - - view.findViewById(R.id.saveButton) - .setOnClickListener { v -> onSaveShareSetting() } - - view.findViewById(R.id.cancelButton) - .setOnClickListener { v -> dismiss() } - return view } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { ocShareViewModel = ViewModelProviders.of(this, viewModelFactory).get(OCShareViewModel::class.java) + + initPasswordListener() + initExpirationListener() + initPasswordFocusChangeListener() + initPasswordToggleListener() + + saveButton.setOnClickListener { onSaveShareSetting() } + cancelButton.setOnClickListener { dismiss() } } private fun onSaveShareSetting() { // Get data filled by user - val publicLinkName = nameValueEdit!!.text.toString() - var publicLinkPassword: String? = passwordValueEdit!!.text.toString() + val publicLinkName = shareViaLinkNameValue?.text.toString() + var publicLinkPassword: String? = shareViaLinkPasswordValue?.text.toString() val publicLinkExpirationDateInMillis = expirationDateValueInMillis val publicLinkPermissions: Int var publicUploadPermission: Boolean - when (permissionRadioGroup!!.checkedRadioButtonId) { + when (shareViaLinkEditPermissionGroup?.checkedRadioButtonId) { R.id.shareViaLinkEditPermissionUploadFiles -> { publicLinkPermissions = RemoteShare.CREATE_PERMISSION_FLAG publicUploadPermission = true @@ -314,10 +269,8 @@ class PublicShareDialogFragment : DialogFragment() { // at 10.0.4 we don't need publicUploadPermission there anymore. By setting it to false // it will not be sent to the server. if (capabilities != null) { - publicUploadPermission = - capabilities!!.versionMayor >= 10 && - (capabilities!!.versionMinor > 1 || capabilities!!.versionMicro > 3) - && publicUploadPermission + val serverVersion = OwnCloudVersion(capabilities?.versionString!!) + publicUploadPermission = serverVersion.isPublicUploadPermissionNeeded && publicUploadPermission } if (!updating()) { // Creating a new public share @@ -355,9 +308,9 @@ class PublicShareDialogFragment : DialogFragment() { } ) } else { // Updating an existing public share - if (!passwordSwitch!!.isChecked) { + if (!shareViaLinkPasswordSwitch.isChecked) { publicLinkPassword = "" - } else if (passwordValueEdit!!.length() == 0) { + } else if (shareViaLinkPasswordValue.text.isEmpty()) { // User has not added a new password, so do not update it publicLinkPassword = null } @@ -374,7 +327,7 @@ class PublicShareDialogFragment : DialogFragment() { } private fun initPasswordFocusChangeListener() { - passwordValueEdit!!.setOnFocusChangeListener { v: View, hasFocus: Boolean -> + shareViaLinkPasswordValue?.setOnFocusChangeListener { v: View, hasFocus: Boolean -> if (v.id == R.id.shareViaLinkPasswordValue) { onPasswordFocusChanged(hasFocus) } @@ -382,7 +335,7 @@ class PublicShareDialogFragment : DialogFragment() { } private fun initPasswordToggleListener() { - passwordValueEdit!!.setOnTouchListener(object : RightDrawableOnTouchListener() { + shareViaLinkPasswordValue?.setOnTouchListener(object : RightDrawableOnTouchListener() { override fun onDrawableTouch(event: MotionEvent): Boolean { if (event.action == MotionEvent.ACTION_UP) { onViewPasswordClick() @@ -454,9 +407,9 @@ class PublicShareDialogFragment : DialogFragment() { } else { showPassword() } - passwordValueEdit!!.setSelection( - passwordValueEdit!!.selectionStart, - passwordValueEdit!!.selectionEnd + shareViaLinkPasswordValue?.setSelection( + shareViaLinkPasswordValue.selectionStart, + shareViaLinkPasswordValue.selectionEnd ) } } @@ -467,19 +420,19 @@ class PublicShareDialogFragment : DialogFragment() { else R.drawable.ic_hide_black if (view != null) { - passwordValueEdit!!.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable, 0) + shareViaLinkPasswordValue?.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable, 0) } } private fun hidePasswordButton() { if (view != null) { - passwordValueEdit!!.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) + shareViaLinkPasswordValue?.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) } } private fun showPassword() { if (view != null) { - passwordValueEdit!!.inputType = InputType.TYPE_CLASS_TEXT or + shareViaLinkPasswordValue?.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS showViewPasswordButton() @@ -488,7 +441,7 @@ class PublicShareDialogFragment : DialogFragment() { private fun hidePassword() { if (view != null) { - passwordValueEdit!!.inputType = InputType.TYPE_CLASS_TEXT or + shareViaLinkPasswordValue?.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS showViewPasswordButton() @@ -505,7 +458,7 @@ class PublicShareDialogFragment : DialogFragment() { override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - outState.putString(KEY_EXPIRATION_DATE, expirationDateValueLabel!!.text.toString()) + outState.putString(KEY_EXPIRATION_DATE, shareViaLinkExpirationValue?.text.toString()) } override fun onAttach(activity: Activity?) { @@ -530,7 +483,7 @@ class PublicShareDialogFragment : DialogFragment() { */ private fun initPasswordListener() { onPasswordInteractionListener = OnPasswordInteractionListener() - passwordSwitch!!.setOnCheckedChangeListener(onPasswordInteractionListener) + shareViaLinkPasswordSwitch?.setOnCheckedChangeListener(onPasswordInteractionListener) } /** @@ -546,18 +499,18 @@ class PublicShareDialogFragment : DialogFragment() { */ override fun onCheckedChanged(switchView: CompoundButton, isChecked: Boolean) { if (isChecked) { - passwordValueEdit!!.visibility = View.VISIBLE - passwordValueEdit!!.requestFocus() + shareViaLinkPasswordValue?.visibility = View.VISIBLE + shareViaLinkPasswordValue?.requestFocus() // Show keyboard to fill in the password val mgr = activity!!.getSystemService( Context.INPUT_METHOD_SERVICE ) as InputMethodManager - mgr.showSoftInput(passwordValueEdit, InputMethodManager.SHOW_IMPLICIT) + mgr.showSoftInput(shareViaLinkPasswordValue, InputMethodManager.SHOW_IMPLICIT) } else { - passwordValueEdit!!.visibility = View.GONE - passwordValueEdit!!.text.clear() + shareViaLinkPasswordValue?.visibility = View.GONE + shareViaLinkPasswordValue?.text?.clear() } } } @@ -569,9 +522,9 @@ class PublicShareDialogFragment : DialogFragment() { */ private fun initExpirationListener() { onExpirationDateInteractionListener = OnExpirationDateInteractionListener() - expirationDateSwitch!!.setOnCheckedChangeListener(onExpirationDateInteractionListener) - expirationDateLabel!!.setOnClickListener(onExpirationDateInteractionListener) - expirationDateValueLabel!!.setOnClickListener(onExpirationDateInteractionListener) + shareViaLinkExpirationSwitch?.setOnCheckedChangeListener(onExpirationDateInteractionListener) + shareViaLinkExpirationLabel?.setOnClickListener(onExpirationDateInteractionListener) + shareViaLinkExpirationValue?.setOnClickListener(onExpirationDateInteractionListener) } /** @@ -605,8 +558,8 @@ class PublicShareDialogFragment : DialogFragment() { ExpirationDatePickerDialogFragment.DATE_PICKER_DIALOG ) } else { - expirationDateValueLabel!!.visibility = View.INVISIBLE - expirationDateValueLabel!!.text = "" + shareViaLinkExpirationValue?.visibility = View.INVISIBLE + shareViaLinkExpirationValue?.text = "" } } @@ -636,8 +589,8 @@ class PublicShareDialogFragment : DialogFragment() { * @param date date selected by the user */ override fun onDateSet(date: String) { - expirationDateValueLabel!!.visibility = View.VISIBLE - expirationDateValueLabel!!.text = date + shareViaLinkExpirationValue?.visibility = View.VISIBLE + shareViaLinkExpirationValue?.text = date } override fun onCancelDatePicker() { @@ -645,7 +598,7 @@ class PublicShareDialogFragment : DialogFragment() { val expirationToggle = view!!.findViewById(R.id.shareViaLinkExpirationSwitch) // If the date has not been set yet, uncheck the toggle - if (expirationToggle.isChecked && expirationDateValueLabel!!.text === "") { + if (expirationToggle.isChecked && shareViaLinkExpirationValue?.text === "") { expirationToggle.isChecked = false } } @@ -659,7 +612,7 @@ class PublicShareDialogFragment : DialogFragment() { */ fun refreshModelFromStorageManager() { if ((listener as BaseActivity).storageManager != null) { - capabilities = (listener as BaseActivity).storageManager.getCapability(account.name) + capabilities = (listener as BaseActivity).storageManager.getCapability(account?.name) updateInputFormAccordingToServerCapabilities() } @@ -678,19 +631,19 @@ class PublicShareDialogFragment : DialogFragment() { * - set the default value for expiration date if defined (only if creating a new share). */ private fun updateInputFormAccordingToServerCapabilities() { - val serverVersion = OwnCloudVersion(capabilities!!.versionString) + val serverVersion = OwnCloudVersion(capabilities?.versionString!!) // Server version <= 9.x, multiple public sharing not supported if (!serverVersion.isMultiplePublicSharingSupported) { - nameSelectionLayout!!.visibility = View.GONE + publicShareDialogTitle?.visibility = View.GONE } else { dialog.window!!.setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE ) } - if (capabilities!!.filesSharingPublicUpload.isTrue && isSharedFolder) { - permissionRadioGroup!!.visibility = View.VISIBLE + if (capabilities?.filesSharingPublicUpload?.isTrue == true && isSharedFolder) { + shareViaLinkEditPermissionGroup?.visibility = View.VISIBLE } // Show file listing option if all the following is true: @@ -700,64 +653,63 @@ class PublicShareDialogFragment : DialogFragment() { // - Allow editing capability is set if (!(isSharedFolder && serverVersion.isPublicSharingWriteOnlySupported && - capabilities!!.filesSharingPublicSupportsUploadOnly.isTrue && - capabilities!!.filesSharingPublicUpload.isTrue) + capabilities?.filesSharingPublicSupportsUploadOnly?.isTrue == true && + capabilities?.filesSharingPublicUpload?.isTrue == true) ) { - permissionRadioGroup!!.visibility = View.GONE + shareViaLinkEditPermissionGroup?.visibility = View.GONE } // Show default date enforced by the server, if any - if (!updating() && capabilities!!.filesSharingPublicExpireDateDays > 0) { + if (!updating() && capabilities?.filesSharingPublicExpireDateDays!! > 0) { setExpirationDateSwitchChecked(true) val formattedDate = SimpleDateFormat.getDateInstance().format( DateUtils.addDaysToDate( Date(), - capabilities!!.filesSharingPublicExpireDateDays + capabilities?.filesSharingPublicExpireDateDays!! ) ) - expirationDateValueLabel!!.visibility = View.VISIBLE - - expirationDateValueLabel!!.text = formattedDate + shareViaLinkExpirationValue?.visibility = View.VISIBLE + shareViaLinkExpirationValue?.text = formattedDate } // Hide expiration date switch if date is enforced to prevent it is removed - if (capabilities!!.filesSharingPublicExpireDateEnforced.isTrue) { - expirationDateLabel!!.setText(R.string.share_via_link_expiration_date_enforced_label) - expirationDateSwitch!!.visibility = View.GONE - expirationDateExplanationLabel!!.visibility = View.VISIBLE - expirationDateExplanationLabel!!.text = getString( + if (capabilities?.filesSharingPublicExpireDateEnforced?.isTrue == true) { + shareViaLinkExpirationLabel?.text = getString(R.string.share_via_link_expiration_date_enforced_label) + shareViaLinkExpirationSwitch?.visibility = View.GONE + shareViaLinkExpirationExplanationLabel?.visibility = View.VISIBLE + shareViaLinkExpirationExplanationLabel?.text = getString( R.string.share_via_link_expiration_date_explanation_label, - capabilities!!.filesSharingPublicExpireDateDays + capabilities?.filesSharingPublicExpireDateDays ) } // Set password label when opening the dialog - if (readOnlyButton!!.isChecked && capabilities!!.filesSharingPublicPasswordEnforcedReadOnly.isTrue || - readWriteButton!!.isChecked && capabilities!!.filesSharingPublicPasswordEnforcedReadWrite.isTrue || - uploadOnlyButton!!.isChecked && capabilities!!.filesSharingPublicPasswordEnforcedUploadOnly.isTrue + if (shareViaLinkEditPermissionReadOnly.isChecked && capabilities?.filesSharingPublicPasswordEnforcedReadOnly?.isTrue == true || + shareViaLinkEditPermissionReadAndWrite.isChecked && capabilities?.filesSharingPublicPasswordEnforcedReadWrite?.isTrue == true || + shareViaLinkEditPermissionUploadFiles.isChecked && capabilities?.filesSharingPublicPasswordEnforcedUploadOnly?.isTrue == true ) { setPasswordEnforced() } // Set password label depending on the checked permission option - permissionRadioGroup!!.setOnCheckedChangeListener { group, checkedId -> - if (checkedId == readOnlyButton!!.id) { - if (capabilities!!.filesSharingPublicPasswordEnforcedReadOnly.isTrue) { + shareViaLinkEditPermissionGroup?.setOnCheckedChangeListener { group, checkedId -> + if (checkedId == shareViaLinkEditPermissionReadOnly.id) { + if (capabilities?.filesSharingPublicPasswordEnforcedReadOnly?.isTrue == true) { setPasswordEnforced() } else { setPasswordNotEnforced() } - } else if (checkedId == readWriteButton!!.id) { - if (capabilities!!.filesSharingPublicPasswordEnforcedReadWrite.isTrue) { + } else if (checkedId == shareViaLinkEditPermissionReadAndWrite.id) { + if (capabilities?.filesSharingPublicPasswordEnforcedReadWrite?.isTrue == true) { setPasswordEnforced() } else { setPasswordNotEnforced() } - } else if (checkedId == uploadOnlyButton!!.id) { - if (capabilities!!.filesSharingPublicPasswordEnforcedUploadOnly.isTrue) { + } else if (checkedId == shareViaLinkEditPermissionUploadFiles.id) { + if (capabilities?.filesSharingPublicPasswordEnforcedUploadOnly?.isTrue == true) { setPasswordEnforced() } else { setPasswordNotEnforced() @@ -766,26 +718,26 @@ class PublicShareDialogFragment : DialogFragment() { } // When there's no password enforced for capability - val hasPasswordEnforcedFor = capabilities!!.filesSharingPublicPasswordEnforcedReadOnly.isTrue || - capabilities!!.filesSharingPublicPasswordEnforcedReadWrite.isTrue || - capabilities!!.filesSharingPublicPasswordEnforcedUploadOnly.isTrue + val hasPasswordEnforcedFor = capabilities?.filesSharingPublicPasswordEnforcedReadOnly?.isTrue == true || + capabilities?.filesSharingPublicPasswordEnforcedReadWrite?.isTrue == true || + capabilities?.filesSharingPublicPasswordEnforcedUploadOnly?.isTrue == true // hide password switch if password is enforced to prevent it is removed - if (!hasPasswordEnforcedFor && capabilities!!.filesSharingPublicPasswordEnforced.isTrue) { + if (!hasPasswordEnforcedFor && capabilities?.filesSharingPublicPasswordEnforced?.isTrue == true) { setPasswordEnforced() } } private fun setPasswordNotEnforced() { - passwordLabel!!.setText(R.string.share_via_link_password_label) - passwordSwitch!!.visibility = View.VISIBLE - passwordValueEdit!!.visibility = View.GONE + shareViaLinkPasswordLabel?.text = getString(R.string.share_via_link_password_label) + shareViaLinkPasswordSwitch?.visibility = View.VISIBLE + shareViaLinkPasswordValue?.visibility = View.GONE } private fun setPasswordEnforced() { - passwordLabel!!.setText(R.string.share_via_link_password_enforced_label) - passwordSwitch!!.visibility = View.GONE - passwordValueEdit!!.visibility = View.VISIBLE + shareViaLinkPasswordLabel?.text = getString(R.string.share_via_link_password_enforced_label) + shareViaLinkPasswordSwitch?.visibility = View.GONE + shareViaLinkPasswordValue?.visibility = View.VISIBLE } /** @@ -793,20 +745,20 @@ class PublicShareDialogFragment : DialogFragment() { * @param errorMessage */ fun showError(errorMessage: String) { - errorMessageLabel!!.visibility = View.VISIBLE - errorMessageLabel!!.text = errorMessage + public_link_error_message?.visibility = View.VISIBLE + public_link_error_message?.text = errorMessage } private fun setPasswordSwitchChecked(checked: Boolean) { - passwordSwitch!!.setOnCheckedChangeListener(null) - passwordSwitch!!.isChecked = checked - passwordSwitch!!.setOnCheckedChangeListener(onPasswordInteractionListener) + shareViaLinkPasswordSwitch?.setOnCheckedChangeListener(null) + shareViaLinkPasswordSwitch?.isChecked = checked + shareViaLinkPasswordSwitch?.setOnCheckedChangeListener(onPasswordInteractionListener) } private fun setExpirationDateSwitchChecked(checked: Boolean) { - expirationDateSwitch!!.setOnCheckedChangeListener(null) - expirationDateSwitch!!.isChecked = checked - expirationDateSwitch!!.setOnCheckedChangeListener(onExpirationDateInteractionListener) + shareViaLinkExpirationSwitch?.setOnCheckedChangeListener(null) + shareViaLinkExpirationSwitch?.isChecked = checked + shareViaLinkExpirationSwitch?.setOnCheckedChangeListener(onExpirationDateInteractionListener) } companion object { @@ -867,5 +819,4 @@ class PublicShareDialogFragment : DialogFragment() { return publicShareDialogFragment } } - -} \ No newline at end of file +} diff --git a/owncloudApp/src/main/java/com/owncloud/android/shares/ui/fragment/ShareFileFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/shares/ui/fragment/ShareFileFragment.kt index 049c6bd795a..e03c55f0183 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/shares/ui/fragment/ShareFileFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/shares/ui/fragment/ShareFileFragment.kt @@ -30,7 +30,8 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.* +import android.widget.ListView +import android.widget.Toast import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider @@ -58,8 +59,10 @@ import com.owncloud.android.ui.fragment.ShareFragmentListener import com.owncloud.android.utils.DisplayUtils import com.owncloud.android.utils.MimetypeIconUtil import com.owncloud.android.vo.Status -import java.util.* -import kotlin.collections.ArrayList +import kotlinx.android.synthetic.main.share_file_layout.* +import kotlinx.android.synthetic.main.share_file_layout.view.* +import java.util.Collections +import java.util.Locale /** * Fragment for Sharing a file with sharees (users or groups) or creating @@ -190,14 +193,6 @@ class ShareFileFragment : Fragment(), ShareUserListAdapter.ShareUserAdapterListe private val isPublicShareDisabled: Boolean get() = capabilities != null && capabilities!!.filesSharingPublicEnabled.isFalse - /// BEWARE: next methods will failed with NullPointerException if called before onCreateView() finishes - - private val shareViaLinkSection: LinearLayout - get() = view!!.findViewById(R.id.shareViaLinkSection) as LinearLayout - - private val addPublicLinkButton: ImageButton - get() = view!!.findViewById(R.id.addPublicLinkButton) as ImageButton - var viewModelFactory: ViewModelProvider.Factory = ViewModelFactory.build { OCShareViewModel( account!!, @@ -235,8 +230,7 @@ class ShareFileFragment : Fragment(), ShareUserListAdapter.ShareUserAdapterListe // Setup layout // Image - val icon = view.findViewById(R.id.shareFileIcon) - icon.setImageResource( + view.shareFileIcon?.setImageResource( MimetypeIconUtil.getFileTypeIconId( file?.mimetype, file?.fileName @@ -246,53 +240,56 @@ class ShareFileFragment : Fragment(), ShareUserListAdapter.ShareUserAdapterListe val remoteId = file?.remoteId.toString() val thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(remoteId) if (thumbnail != null) { - icon.setImageBitmap(thumbnail) + view.shareFileIcon?.setImageBitmap(thumbnail) } } // Name - val fileNameHeader = view.findViewById(R.id.shareFileName) - fileNameHeader.text = file?.fileName + view.shareFileName?.text = file?.fileName + // Size - val size = view.findViewById(R.id.shareFileSize) if (file!!.isFolder) { - size.visibility = View.GONE + view.shareFileSize?.visibility = View.GONE } else { - size.text = DisplayUtils.bytesToHumanReadable(file!!.fileLength, activity) + view.shareFileSize?.text = DisplayUtils.bytesToHumanReadable(file!!.fileLength, activity) } // Private link button - val getPrivateLinkButton = view.findViewById(R.id.getPrivateLinkButton) if (file?.privateLink.isNullOrEmpty()) { - getPrivateLinkButton.visibility = View.INVISIBLE - + view.getPrivateLinkButton?.visibility = View.INVISIBLE } else { - getPrivateLinkButton.visibility = View.VISIBLE - - getPrivateLinkButton.setOnClickListener { listener?.copyOrSendPrivateLink(file) } - - getPrivateLinkButton.setOnLongClickListener { - // Show a toast message explaining what a private link is - Toast.makeText(activity, R.string.private_link_info, Toast.LENGTH_LONG).show() - true - } + view.getPrivateLinkButton?.visibility = View.VISIBLE } val shareWithUsersEnable = serverVersion != null && serverVersion!!.isSearchUsersSupported - val shareNoUsers = view.findViewById(R.id.shareNoUsers) - - // Add User/Groups Button - val addUserGroupButton = view.findViewById(R.id.addUserButton) - // Change the sharing text depending on the server version (at least version 8.2 is needed // for sharing with other users) if (!shareWithUsersEnable) { - shareNoUsers.setText(R.string.share_incompatible_version) - shareNoUsers.gravity = View.TEXT_ALIGNMENT_CENTER - addUserGroupButton.visibility = View.GONE + view.shareNoUsers?.setText(R.string.share_incompatible_version) + view.shareNoUsers?.gravity = View.TEXT_ALIGNMENT_CENTER + view.addUserButton?.visibility = View.GONE + } + + // Hide share features sections that are not enabled + hideSectionsDisabledInBuildTime(view) + + return view + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + ocShareViewModel = ViewModelProviders.of(this, viewModelFactory).get(OCShareViewModel::class.java) + + getPrivateLinkButton?.setOnClickListener { listener?.copyOrSendPrivateLink(file) } + + getPrivateLinkButton?.setOnLongClickListener { + // Show a toast message explaining what a private link is + Toast.makeText(activity, R.string.private_link_info, Toast.LENGTH_LONG).show() + true } - addUserGroupButton.setOnClickListener { + val shareWithUsersEnable = serverVersion != null && serverVersion!!.isSearchUsersSupported + + addUserButton?.setOnClickListener { if (shareWithUsersEnable) { // Show Search Fragment listener?.showSearchUsersAndGroups() @@ -308,21 +305,10 @@ class ShareFileFragment : Fragment(), ShareUserListAdapter.ShareUserAdapterListe } // Add Public Link Button - val addPublicLinkButton = view.findViewById(R.id.addPublicLinkButton) - addPublicLinkButton.setOnClickListener { // Show Add Public Link Fragment listener?.showAddPublicShare(availableDefaultPublicName) } - - // Hide share features sections that are not enabled - hideSectionsDisabledInBuildTime(view) - - return view - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - ocShareViewModel = ViewModelProviders.of(this, viewModelFactory).get(OCShareViewModel::class.java) } override fun copyOrSendPublicLink(share: OCShare) { @@ -415,24 +401,18 @@ class ShareFileFragment : Fragment(), ShareUserListAdapter.ShareUserAdapterListe ) // Show data - val noShares = view!!.findViewById(R.id.shareNoUsers) - val usersList = view!!.findViewById(R.id.shareUsersList) - if (privateShares!!.size > 0) { - noShares.visibility = View.GONE - usersList.visibility = View.VISIBLE - usersList.adapter = userGroupsAdapter - setListViewHeightBasedOnChildren( - usersList - ) + shareNoUsers?.visibility = View.GONE + shareUsersList?.visibility = View.VISIBLE + shareUsersList?.adapter = userGroupsAdapter + setListViewHeightBasedOnChildren(shareUsersList) } else { - noShares.visibility = View.VISIBLE - usersList.visibility = View.GONE + shareNoUsers?.visibility = View.VISIBLE + shareUsersList?.visibility = View.GONE } // Set Scroll to initial position - val scrollView = view!!.findViewById(R.id.shareScroll) - scrollView.scrollTo(0, 0) + shareScroll?.scrollTo(0, 0) } override fun unshareButtonPressed(share: OCShare) { @@ -498,26 +478,19 @@ class ShareFileFragment : Fragment(), ShareUserListAdapter.ShareUserAdapterListe this ) - // Show data - val noPublicLinks = view!!.findViewById(R.id.shareNoPublicLinks) - val publicLinksList = view!!.findViewById(R.id.sharePublicLinksList) - // Show or hide public links and no public links message if (publicLinks!!.size > 0) { - noPublicLinks.visibility = View.GONE - publicLinksList.visibility = View.VISIBLE - publicLinksList.adapter = publicLinksAdapter - setListViewHeightBasedOnChildren( - publicLinksList - ) + shareNoPublicLinks?.visibility = View.GONE + sharePublicLinksList?.visibility = View.VISIBLE + sharePublicLinksList?.adapter = publicLinksAdapter + setListViewHeightBasedOnChildren(sharePublicLinksList) } else { - noPublicLinks.visibility = View.VISIBLE - publicLinksList.visibility = View.GONE + shareNoPublicLinks?.visibility = View.VISIBLE + sharePublicLinksList?.visibility = View.GONE } // Set Scroll to initial position - val scrollView = view!!.findViewById(R.id.shareScroll) - scrollView.scrollTo(0, 0) + shareScroll?.scrollTo(0, 0) } /** @@ -530,30 +503,25 @@ class ShareFileFragment : Fragment(), ShareUserListAdapter.ShareUserAdapterListe /** * Hide share features sections that are not enabled * - * @param view */ private fun hideSectionsDisabledInBuildTime(view: View) { - val shareWithUsersSection = view.findViewById(R.id.shareWithUsersSection) - val shareViaLinkSection = view.findViewById(R.id.shareViaLinkSection) - val warningAboutPerilsOfSharingPublicStuff = view.findViewById(R.id.shareWarning) - val shareViaLinkAllowed = activity!!.resources.getBoolean(R.bool.share_via_link_feature) val shareWithUsersAllowed = activity!!.resources.getBoolean(R.bool.share_with_users_feature) val shareWarningAllowed = activity!!.resources.getBoolean(R.bool.warning_sharing_public_link) // Hide share via link section if it is not enabled if (!shareViaLinkAllowed) { - shareViaLinkSection.visibility = View.GONE + view.shareViaLinkSection.visibility = View.GONE } // Hide share with users section if it is not enabled if (!shareWithUsersAllowed) { - shareWithUsersSection.visibility = View.GONE + view.shareWithUsersSection?.visibility = View.GONE } // Hide warning about public links if not enabled if (!shareWarningAllowed) { - warningAboutPerilsOfSharingPublicStuff.visibility = View.GONE + view.shareWarning?.visibility = View.GONE } } diff --git a/owncloudApp/src/main/java/com/owncloud/android/shares/viewmodel/OCShareViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/shares/viewmodel/OCShareViewModel.kt index ef1a53b94bd..26f20dc8575 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/shares/viewmodel/OCShareViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/shares/viewmodel/OCShareViewModel.kt @@ -21,7 +21,6 @@ package com.owncloud.android.shares.viewmodel import android.accounts.Account import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import com.owncloud.android.MainApp import com.owncloud.android.lib.common.OwnCloudAccount @@ -55,7 +54,7 @@ class OCShareViewModel( ) : ViewModel() { val sharesForFile: LiveData>> = shareRepository.loadSharesForFile( - filePath, account.name, shareTypes, true, false + filePath, account.name, shareTypes, reshares = true, subfiles = false ) fun insertPublicShareForFile( diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/asynctasks/GetSharesForFileAsyncTask.java b/owncloudApp/src/main/java/com/owncloud/android/ui/asynctasks/GetSharesForFileAsyncTask.java index bfa72b65d6c..4617e283176 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/asynctasks/GetSharesForFileAsyncTask.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/asynctasks/GetSharesForFileAsyncTask.java @@ -85,7 +85,6 @@ protected Pair doInBackground(Object... @Override protected void onPostExecute(Pair result) { - // a cancelled task shouldn't call the listener, even if the reference exists; // the Activity responsible could be stopped, and its abilities to do things constrained if (result != null && !isCancelled()) { diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/errorhandling/ErrorMessageAdapter.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/errorhandling/ErrorMessageAdapter.kt index 30380341302..68a97558202 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/errorhandling/ErrorMessageAdapter.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/errorhandling/ErrorMessageAdapter.kt @@ -21,10 +21,8 @@ * along with this program. If not, see //www.gnu.org/licenses/>. */ - package com.owncloud.android.ui.errorhandling - import android.content.res.Resources import com.owncloud.android.R import com.owncloud.android.lib.common.operations.RemoteOperation @@ -103,23 +101,6 @@ class ErrorMessageAdapter { return f.format(R.string.sync_file_nothing_to_do_msg) } - if (operation is CreateShareWithShareeOperation - || operation is CreateShareViaLinkOperation - || operation is RemoveShareOperation - || operation is UpdateShareViaLinkOperation - || operation is UpdateSharePermissionsOperation - ) { - - val shareResult = result as RemoteOperationResult - -// if (shareResult.data != null) { -// return if (shareResult.data.shares != null && shareResult.data.shares.size > 0) { -// shareResult.data.shares[0].toString() -// } else { -// shareResult.data.parserMessage -// } -// } - } when (result.code) { RemoteOperationResult.ResultCode.LOCAL_STORAGE_FULL -> return f.format( R.string.error__upload__local_file_not_copied, @@ -339,60 +320,44 @@ class ErrorMessageAdapter { when (resultCode) { RemoteOperationResult.ResultCode.FORBIDDEN -> { - if (operationType == OperationType.UPLOAD_FILE) - return f.format(R.string.forbidden_permissions, R.string.uploader_upload_forbidden_permissions) - if (operationType == OperationType.DOWNLOAD_FILE) - return f.forbidden(R.string.downloader_download_forbidden_permissions) - if (operationType == OperationType.REMOVE_FILE) - return f.forbidden(R.string.forbidden_permissions_delete) - if (operationType == OperationType.RENAME_FILE) - return f.forbidden(R.string.forbidden_permissions_rename) - if (operationType == OperationType.CREATE_FOLDER) - return f.forbidden(R.string.forbidden_permissions_create) - if (operationType == OperationType.MOVE_FILE) return f.forbidden(R.string.forbidden_permissions_move) - return if (operationType == OperationType.COPY_FILE) f.forbidden(R.string.forbidden_permissions_copy) else f.format( - R.string.filename_forbidden_charaters_from_server - ) + return when (operationType) { + OperationType.UPLOAD_FILE -> + f.format(R.string.forbidden_permissions, R.string.uploader_upload_forbidden_permissions) + OperationType.DOWNLOAD_FILE -> f.forbidden(R.string.downloader_download_forbidden_permissions) + OperationType.REMOVE_FILE -> f.forbidden(R.string.forbidden_permissions_delete) + OperationType.RENAME_FILE -> f.forbidden(R.string.forbidden_permissions_rename) + OperationType.CREATE_FOLDER -> f.forbidden(R.string.forbidden_permissions_create) + OperationType.MOVE_FILE -> f.forbidden(R.string.forbidden_permissions_move) + OperationType.COPY_FILE -> f.forbidden(R.string.forbidden_permissions_copy) + else -> getCommonMessageForResult(operationType, resultCode, resultException, resources) + } } RemoteOperationResult.ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER -> return f.format(R.string.filename_forbidden_charaters_from_server) RemoteOperationResult.ResultCode.QUOTA_EXCEEDED -> return f.format(R.string.failed_upload_quota_exceeded_text) RemoteOperationResult.ResultCode.FILE_NOT_FOUND -> { - if (operationType == OperationType.UPLOAD_FILE) - return f.format(R.string.uploads_view_upload_status_failed_folder_error) - if (operationType == OperationType.DOWNLOAD_FILE) - return f.format(R.string.downloader_download_forbidden_permissions) - if (operationType == OperationType.RENAME_FILE) return f.format(R.string.rename_server_fail_msg) - if (operationType == OperationType.MOVE_FILE) return f.format(R.string.move_file_not_found) -// if (operationType == OperationType.SYNCHRONIZE_FOLDER) -// return f.format( -// R.string.sync_current_folder_was_removed, -// File(operation.folderPath).name -// ) - return if (operationType == OperationType.COPY_FILE) - f.format(R.string.copy_file_not_found) else f.format(R.string.rename_local_fail_msg) + return when (operationType) { + OperationType.UPLOAD_FILE -> f.format(R.string.uploads_view_upload_status_failed_folder_error) + OperationType.DOWNLOAD_FILE -> f.format(R.string.downloader_download_forbidden_permissions) + OperationType.RENAME_FILE -> f.format(R.string.rename_server_fail_msg) + OperationType.MOVE_FILE -> f.format(R.string.move_file_not_found) + OperationType.COPY_FILE -> f.format(R.string.copy_file_not_found) + else -> getCommonMessageForResult(operationType, resultCode, resultException, resources) + } } RemoteOperationResult.ResultCode.INVALID_LOCAL_FILE_NAME -> return f.format(R.string.rename_local_fail_msg) RemoteOperationResult.ResultCode.INVALID_CHARACTER_IN_NAME -> return f.format(R.string.filename_forbidden_characters) RemoteOperationResult.ResultCode.SHARE_NOT_FOUND -> { - if (operationType == OperationType.CREATE_PUBLIC_SHARE) - return f.format(R.string.share_link_file_no_exist) - if (operationType == OperationType.REMOVE_SHARE) - return f.format(R.string.unshare_link_file_no_exist) - if (operationType == OperationType.UPDATE_SHARE_PERMISSIONS || - operationType == OperationType.UPDATE_PUBLIC_SHARE) - return f.format(R.string.update_link_file_no_exist) - if (operationType == OperationType.CREATE_PUBLIC_SHARE) - return f.forbidden(R.string.share_link_forbidden_permissions) - if (operationType == OperationType.REMOVE_SHARE) - return f.forbidden(R.string.unshare_link_forbidden_permissions) - return if (operationType == OperationType.UPDATE_SHARE_PERMISSIONS || - operationType == OperationType.UPDATE_PUBLIC_SHARE) - f.forbidden(R.string.update_link_forbidden_permissions) - else f.format(R.string.move_file_invalid_into_descendent) + return when (operationType) { + OperationType.CREATE_PUBLIC_SHARE -> f.format(R.string.share_link_file_no_exist) + OperationType.REMOVE_SHARE -> f.format(R.string.unshare_link_file_no_exist) + OperationType.UPDATE_SHARE_PERMISSIONS, OperationType.UPDATE_PUBLIC_SHARE -> + f.format(R.string.update_link_file_no_exist) + else -> getCommonMessageForResult(operationType, resultCode, resultException, resources) + } } RemoteOperationResult.ResultCode.SHARE_FORBIDDEN -> { if (operationType == OperationType.CREATE_PUBLIC_SHARE) @@ -406,11 +371,14 @@ class ErrorMessageAdapter { R.string.update_link_forbidden_permissions ) else f.format(R.string.move_file_invalid_into_descendent) } - RemoteOperationResult.ResultCode.INVALID_MOVE_INTO_DESCENDANT -> return f.format(R.string.move_file_invalid_into_descendent) + RemoteOperationResult.ResultCode.INVALID_MOVE_INTO_DESCENDANT -> + return f.format(R.string.move_file_invalid_into_descendent) RemoteOperationResult.ResultCode.INVALID_OVERWRITE -> { - if (operationType == OperationType.MOVE_FILE) return f.format(R.string.move_file_invalid_overwrite) - return if (operationType == OperationType.COPY_FILE) f.format(R.string.copy_file_invalid_overwrite) - else f.format(R.string.move_file_error) + return when (operationType) { + OperationType.MOVE_FILE -> f.format(R.string.move_file_invalid_overwrite) + OperationType.COPY_FILE -> f.format(R.string.copy_file_invalid_overwrite) + else -> f.format(R.string.move_file_error) + } } RemoteOperationResult.ResultCode.CONFLICT -> return f.format(R.string.move_file_error) RemoteOperationResult.ResultCode.INVALID_COPY_INTO_DESCENDANT -> @@ -477,8 +445,6 @@ class ErrorMessageAdapter { return f.format(R.string.auth_account_not_the_same) RemoteOperationResult.ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION -> return f.format(R.string.auth_redirect_non_secure_connection_title) -// else -> if (result.httpPhrase != null && result.httpPhrase.length > 0) -// return result.httpPhrase } return getGenericErrorMessageForOperation(operation, resultCode, res) @@ -497,39 +463,25 @@ class ErrorMessageAdapter { res: Resources ): String { val f = Formatter(res) - -// if (operation == OperationType.UPLOAD_FILE) -// return f.format( -// R.string.uploader_upload_failed_content_single, -// operation.fileName -// ) -// if (operation == OperationType.DOWNLOAD_FILE) -// return f.format( -// R.string.downloader_download_failed_content, -// File(operation.savePath).name -// ) - if (operationType == OperationType.REMOVE_FILE) return f.format(R.string.remove_fail_msg) - if (operationType == OperationType.RENAME_FILE) return f.format(R.string.rename_server_fail_msg) - if (operationType == OperationType.CREATE_FOLDER) return f.format(R.string.create_dir_fail_msg) - if (operationType == OperationType.CREATE_PUBLIC_SHARE || - operationType == OperationType.CREATE_SHARE_WITH_SHAREES) - return f.format(R.string.share_link_file_error) - if (operationType == OperationType.REMOVE_SHARE) return f.format(R.string.unshare_link_file_error) - if (operationType == OperationType.UPDATE_PUBLIC_SHARE || - operationType == OperationType.UPDATE_SHARE_PERMISSIONS) - return f.format(R.string.update_link_file_error) - if (operationType == OperationType.MOVE_FILE) return f.format(R.string.move_file_error) -// if (operationType == OperationType.SYNCHRONIZE_FOLDER) -// return f.format( -// R.string.sync_folder_failed_content, -// File(operation.folderPath).name -// ) - if (operationType == OperationType.COPY_FILE) return f.format(R.string.copy_file_error) - // if everything else failes - return if (resultCode == RemoteOperationResult.ResultCode.OK) - f.format(android.R.string.ok) - else - f.format(R.string.common_error_unknown) + return when (operationType) { + OperationType.REMOVE_FILE -> f.format(R.string.remove_fail_msg) + OperationType.RENAME_FILE -> f.format(R.string.rename_server_fail_msg) + OperationType.CREATE_FOLDER -> f.format(R.string.create_dir_fail_msg) + OperationType.CREATE_PUBLIC_SHARE, OperationType.CREATE_SHARE_WITH_SHAREES -> + f.format(R.string.share_link_file_error) + OperationType.REMOVE_SHARE -> f.format(R.string.unshare_link_file_error) + OperationType.UPDATE_PUBLIC_SHARE, OperationType.UPDATE_SHARE_PERMISSIONS -> + f.format(R.string.update_link_file_error) + OperationType.MOVE_FILE -> f.format(R.string.move_file_error) + OperationType.COPY_FILE -> f.format(R.string.copy_file_error) + else -> { + if (resultCode == RemoteOperationResult.ResultCode.OK) { + f.format(android.R.string.ok) + } else { + f.format(R.string.common_error_unknown) + } + } + } } } } \ No newline at end of file