Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,19 @@ ownCloud admins and users.
been implemented and, it is shown when the floating action button is tapped.

https://github.com/owncloud/android/issues/4606
https://github.com/owncloud/android/issues/4688
https://github.com/owncloud/android/pull/4683
https://github.com/owncloud/android/pull/4694

* Enhancement - Edit a space: [#4607](https://github.com/owncloud/android/issues/4607)

A new edit space option has been added to the bottom sheet, available only to
users with the required permissions when the three-dot menu button is tapped.

https://github.com/owncloud/android/issues/4607
https://github.com/owncloud/android/issues/4688
https://github.com/owncloud/android/pull/4687
https://github.com/owncloud/android/pull/4694

* Enhancement - Update test in GitHub Actions: [#4663](https://github.com/owncloud/android/pull/4663)

Expand Down
2 changes: 2 additions & 0 deletions changelog/unreleased/4683
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ A new floating action button has been added to the spaces list, visible only to
In addition, a new dialog for space creation has been implemented and, it is shown when the floating action button is tapped.

https://github.com/owncloud/android/issues/4606
https://github.com/owncloud/android/issues/4688
https://github.com/owncloud/android/pull/4683
https://github.com/owncloud/android/pull/4694
2 changes: 2 additions & 0 deletions changelog/unreleased/4687
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ A new edit space option has been added to the bottom sheet, available only to us
with the required permissions when the three-dot menu button is tapped.

https://github.com/owncloud/android/issues/4607
https://github.com/owncloud/android/issues/4688
https://github.com/owncloud/android/pull/4687
https://github.com/owncloud/android/pull/4694
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.fragment.app.DialogFragment
import com.owncloud.android.R
import com.owncloud.android.databinding.CreateSpaceDialogBinding
import com.owncloud.android.domain.spaces.model.OCSpace
import com.owncloud.android.utils.DisplayUtils

class CreateSpaceDialogFragment : DialogFragment() {
private var _binding: CreateSpaceDialogBinding? = null
Expand All @@ -51,9 +52,20 @@ class CreateSpaceDialogFragment : DialogFragment() {
val canEditQuota = requireArguments().getBoolean(ARG_CAN_EDIT_SPACE_QUOTA)
binding.apply {
cancelCreateSpaceButton.setOnClickListener { dialog?.dismiss() }
createSpaceDialogNameValue.doOnTextChanged { name, _, _, _ ->
val errorMessage = validateName(name.toString())
updateUI(errorMessage)
createSpaceDialogNameValue.doOnTextChanged { _, _, _, _ ->
updateUI()
}

createSpaceDialogQuotaValue.doOnTextChanged { _, _, _, _ ->
updateUI()
}

createSpaceDialogQuotaSwitch.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) { createSpaceDialogQuotaValue.setText("1") }
updateUI()
createSpaceDialogQuotaNoRestrictionLabel.isVisible = !isChecked
createSpaceDialogQuotaLayout.isVisible = isChecked
createSpaceDialogQuotaGbLabel.isVisible = isChecked
}

if (isEditMode) {
Expand All @@ -63,7 +75,11 @@ class CreateSpaceDialogFragment : DialogFragment() {
currentSpace?.let {
createSpaceDialogNameValue.setText(it.name)
createSpaceDialogSubtitleValue.setText(it.description)
createSpaceDialogQuotaUnit.setSelection(getQuotaValueForSpinner(it.quota!!.total))
val totalQuota = it.quota?.total ?: 0L
if (totalQuota != 0L) {
createSpaceDialogQuotaSwitch.isChecked = true
createSpaceDialogQuotaValue.setText(DisplayUtils.formatFromBytesToGb(totalQuota))
}
}

createSpaceButton.apply {
Expand All @@ -75,7 +91,7 @@ class CreateSpaceDialogFragment : DialogFragment() {
createSpaceButton.setOnClickListener {
val spaceName = createSpaceDialogNameValue.text.toString()
val spaceSubtitle = createSpaceDialogSubtitleValue.text.toString()
val spaceQuota = convertToBytes(createSpaceDialogQuotaUnit.selectedItem.toString())
val spaceQuota = if (createSpaceDialogQuotaSwitch.isChecked) convertToBytes(createSpaceDialogQuotaValue.text.toString()) else 0L

if (isEditMode) {
currentSpace?.let {
Expand Down Expand Up @@ -106,37 +122,39 @@ class CreateSpaceDialogFragment : DialogFragment() {
else -> null
}

private fun updateUI(errorMessage: String?) {
val colorButton = if (errorMessage == null) {
private fun validateQuota(spaceQuota: String): String? {
if (!binding.createSpaceDialogQuotaSwitch.isChecked) return null

return when {
spaceQuota.isEmpty() -> getString(R.string.create_space_dialog_quota_empty_error)
spaceQuota.toDouble() == MIN_SPACE_QUOTA_GB -> getString(R.string.create_space_dialog_quota_zero_error)
spaceQuota.toDouble() > MAX_SPACE_QUOTA_GB -> getString(R.string.create_space_dialog_quota_too_large_error)
else -> null
}
}

private fun updateUI() {
val nameError = validateName(binding.createSpaceDialogNameValue.text.toString())
val quotaError = validateQuota(binding.createSpaceDialogQuotaValue.text.toString())
val noErrors = nameError == null && quotaError == null

val colorButton = if (noErrors) {
resources.getColor(R.color.primary_button_background_color, null)
} else {
resources.getColor(R.color.grey, null)
}

binding.createSpaceDialogNameValue.error = errorMessage
binding.createSpaceDialogNameValue.error = nameError
binding.createSpaceDialogQuotaValue.error = quotaError
binding.createSpaceButton.apply {
setTextColor(colorButton)
isEnabled = errorMessage == null
isEnabled = noErrors
}
}

private fun convertToBytes(spaceQuota: String): Long {
val quotaNumber = spaceQuota.removeSuffix(" GB").toLongOrNull() ?: return 0L
return quotaNumber * 1_000_000_000L
}

private fun getQuotaValueForSpinner(spaceQuota: Long): Int {
val totalGB = spaceQuota / 1_000_000_000.0
return when (totalGB) {
1.0 -> 0
2.0 -> 1
5.0 -> 2
10.0 -> 3
50.0 -> 4
100.0 -> 5
0.0 -> 6
else -> 0
}
val quotaNumber = spaceQuota.toDoubleOrNull() ?: return 0L
return (quotaNumber * 1_000_000_000L).toLong()
}

interface CreateSpaceListener {
Expand All @@ -149,6 +167,8 @@ class CreateSpaceDialogFragment : DialogFragment() {
private const val ARG_CAN_EDIT_SPACE_QUOTA = "CAN_EDIT_SPACE_QUOTA"
private const val ARG_CURRENT_SPACE = "CURRENT_SPACE"
private const val FORBIDDEN_CHARACTERS = """[/\\.:?*"'><|]"""
private const val MIN_SPACE_QUOTA_GB = 0.0
private const val MAX_SPACE_QUOTA_GB = 1_000_000.0

fun newInstance(
isEditMode: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,9 @@ public static int getDrawerHeaderHeight(int displayCutout, Resources resources)
return (int) resources.getDimension(R.dimen.nav_drawer_header_height);
}
}

public static String formatFromBytesToGb(long bytes) {
BigDecimal valueInGB = new BigDecimal(bytes).divide(BigDecimal.valueOf(1_000_000_000L)).stripTrailingZeros();
return valueInGB.toPlainString();
}
}
79 changes: 65 additions & 14 deletions owncloudApp/src/main/res/layout/create_space_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,33 +119,84 @@

</androidx.constraintlayout.widget.ConstraintLayout>

<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/create_space_dialog_quota_section"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_marginTop="@dimen/standard_half_padding"
android:layout_marginEnd="@dimen/standard_half_padding">
android:layout_height="wrap_content">

<TextView
android:id="@+id/create_space_dialog_quota"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_half_margin"
android:padding="@dimen/standard_padding"
android:text="@string/create_space_dialog_quota"
android:textColor="@color/black"
android:textSize="15sp" />
android:textSize="15sp"
android:labelFor="@+id/create_space_dialog_quota_value"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>

<Spinner
android:id="@+id/create_space_dialog_quota_unit"
android:layout_width="0dp"
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/create_space_dialog_quota_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:spinnerMode="dropdown"
android:entries="@array/create_space_dialog_quota_units"/>
android:layout_marginTop="@dimen/standard_half_margin"
android:contentDescription="@string/content_description_quota_switch"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/create_space_dialog_quota"/>

</LinearLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/create_space_dialog_quota_layout"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/standard_half_margin"
android:layout_marginStart="@dimen/standard_half_margin"
android:visibility="gone"
app:layout_constraintStart_toEndOf="@id/create_space_dialog_quota_switch"
app:layout_constraintTop_toTopOf="parent">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/create_space_dialog_quota_value"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:textSize="15sp"
android:gravity="end"
app:layout_constraintTop_toTopOf="parent"/>

</com.google.android.material.textfield.TextInputLayout>

<TextView
android:id="@+id/create_space_dialog_quota_gb_label"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/standard_half_margin"
android:layout_marginStart="@dimen/standard_half_margin"
android:text="@string/create_space_dialog_gb_unit"
android:textColor="@color/black"
android:textSize="15sp"
android:gravity="center_vertical"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/create_space_dialog_quota_layout" />

<TextView
android:id="@+id/create_space_dialog_quota_no_restriction_label"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/standard_half_margin"
android:layout_marginTop="@dimen/standard_half_margin"
android:text="@string/create_space_dialog_no_restriction"
android:textColor="@color/black"
android:textSize="15sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/create_space_dialog_quota_switch" />

</androidx.constraintlayout.widget.ConstraintLayout>

<LinearLayout
android:layout_width="match_parent"
Expand Down
9 changes: 0 additions & 9 deletions owncloudApp/src/main/res/values-et-rEE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -771,15 +771,6 @@
<string name="create_space_dialog_name">Nimi</string>
<string name="create_space_dialog_subtitle">Alapealkiri</string>
<string name="create_space_dialog_quota">Mahupiir</string>
<string-array name="create_space_dialog_quota_units">
<item>1 GB</item>
<item>2 GB</item>
<item>5 GB</item>
<item>10 GB</item>
<item>50 GB</item>
<item>100 GB</item>
<item>Piiranguteta</item>
</string-array>
<string name="create_space_dialog_empty_error">Ruumi nimi ei tohi olla tühi</string>
<string name="create_space_dialog_length_error">Ruumi nii ei tphi olla pikem kui 255 märki</string>
<string name="create_space_dialog_characters_error">Keelatud märgid: / \\ . : ? * \" \' &gt; &lt; |</string>
Expand Down
9 changes: 0 additions & 9 deletions owncloudApp/src/main/res/values-sq/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -769,15 +769,6 @@
<string name="create_space_dialog_name">Emër</string>
<string name="create_space_dialog_subtitle">Nëntitull</string>
<string name="create_space_dialog_quota">Kuota</string>
<string-array name="create_space_dialog_quota_units">
<item>1 GB</item>
<item>2 GB</item>
<item>5 GB</item>
<item>10 GB</item>
<item>50 GB</item>
<item>100 GB</item>
<item>Pa kufizim</item>
</string-array>
<string name="create_space_dialog_empty_error">Emri i hapësirës s’mund të jetë i zbrazët</string>
<string name="create_space_dialog_length_error">Emri i hapësirës s’mund të jetë më i gjatë se 255 shenja</string>
<string name="create_space_dialog_characters_error">Shenja të ndaluara: / \\ . : ? * \" \' &gt; &lt; |</string>
Expand Down
15 changes: 6 additions & 9 deletions owncloudApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@
<string name="content_description_space_subtitle">%1$s space subtitle</string>
<string name="content_description_create_button">Create button</string>
<string name="content_description_cancel_button">Cancel button</string>
<string name="content_description_quota_switch">Space quota</string>

<string name="create_shortcut_dialog_title">Create a shortcut</string>
<string name="create_shortcut_dialog_url">URL</string>
Expand All @@ -839,18 +840,14 @@
<string name="create_space_dialog_name">Name</string>
<string name="create_space_dialog_subtitle">Subtitle</string>
<string name="create_space_dialog_quota">Quota</string>
<string-array name="create_space_dialog_quota_units">
<item>1 GB</item>
<item>2 GB</item>
<item>5 GB</item>
<item>10 GB</item>
<item>50 GB</item>
<item>100 GB</item>
<item>No restriction</item>
</string-array>
<string name="create_space_dialog_no_restriction">No restriction</string>
<string name="create_space_dialog_gb_unit">GB</string>
<string name="create_space_dialog_empty_error">Space name must not be empty</string>
<string name="create_space_dialog_length_error">Space name must not be longer than 255 characters</string>
<string name="create_space_dialog_characters_error">Forbidden characters: / \\ . : ? * &quot; ' &gt; &lt; |</string>
<string name="create_space_dialog_quota_empty_error">Space quota must not be empty</string>
<string name="create_space_dialog_quota_zero_error">Space quota must be greater than zero</string>
<string name="create_space_dialog_quota_too_large_error">Space quota cannot exceed 1 PB</string>
<string name="create_space_correctly">Space created correctly</string>
<string name="create_space_failed">Space could not be created</string>
<string name="edit_space">Edit space</string>
Expand Down
Loading