Skip to content

Commit cf2c65e

Browse files
committed
feat: update create space dialog for edit mode
1 parent 7c93afd commit cf2c65e

File tree

5 files changed

+75
-17
lines changed

5 files changed

+75
-17
lines changed

owncloudApp/src/main/java/com/owncloud/android/presentation/spaces/SpacesListFragment.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ class SpacesListFragment :
7171
private val binding get() = _binding!!
7272

7373
private var isMultiPersonal = false
74-
private var editSpacesPermission: Boolean = false
74+
private var editSpacesPermission = false
75+
private var editQuotaPermission = false
7576
private lateinit var currentSpace: OCSpace
7677

7778
private val spacesListViewModel: SpacesListViewModel by viewModel {
@@ -119,7 +120,12 @@ class SpacesListFragment :
119120
}
120121

121122
binding.fabCreateSpace.setOnClickListener {
122-
val dialog = CreateSpaceDialogFragment.newInstance(requireArguments().getString(BUNDLE_ACCOUNT_NAME), this)
123+
val dialog = CreateSpaceDialogFragment.newInstance(
124+
isEditMode = false,
125+
canEditQuota = false,
126+
currentSpace = null,
127+
listener = this
128+
)
123129
dialog.show(requireActivity().supportFragmentManager, DIALOG_CREATE_SPACE)
124130
binding.fabCreateSpace.isFocusable = false
125131
}
@@ -176,6 +182,7 @@ class SpacesListFragment :
176182
uiResult.data?.let {
177183
binding.fabCreateSpace.isVisible = it.contains(DRIVES_CREATE_ALL_PERMISSION)
178184
editSpacesPermission = it.contains(DRIVES_READ_WRITE_ALL_PERMISSION)
185+
editQuotaPermission = it.contains(DRIVES_READ_WRITE_PROJECT_QUOTA_ALL_PERMISSION)
179186
}
180187
}
181188
is UIResult.Loading -> { }
@@ -304,8 +311,12 @@ class SpacesListFragment :
304311
dialog.dismiss()
305312
when(menuOption) {
306313
SpaceMenuOption.EDIT -> {
307-
val accountName = requireArguments().getString(BUNDLE_ACCOUNT_NAME)
308-
val editDialog = CreateSpaceDialogFragment.newInstance(accountName, this@SpacesListFragment)
314+
val editDialog = CreateSpaceDialogFragment.newInstance(
315+
isEditMode = true,
316+
canEditQuota = editQuotaPermission,
317+
currentSpace = currentSpace,
318+
listener = this@SpacesListFragment
319+
)
309320
editDialog.show(requireActivity().supportFragmentManager, DIALOG_CREATE_SPACE)
310321
}
311322
}
@@ -321,6 +332,7 @@ class SpacesListFragment :
321332
const val BUNDLE_ACCOUNT_NAME = "accountName"
322333
const val DRIVES_CREATE_ALL_PERMISSION = "Drives.Create.all"
323334
const val DRIVES_READ_WRITE_ALL_PERMISSION = "Drives.ReadWrite.all"
335+
const val DRIVES_READ_WRITE_PROJECT_QUOTA_ALL_PERMISSION = "Drives.ReadWriteProjectQuota.all"
324336

325337
private const val DIALOG_CREATE_SPACE = "DIALOG_CREATE_SPACE"
326338

owncloudApp/src/main/java/com/owncloud/android/presentation/spaces/createspace/CreateSpaceDialogFragment.kt

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ import android.os.Bundle
2424
import android.view.LayoutInflater
2525
import android.view.View
2626
import android.view.ViewGroup
27+
import androidx.core.view.isVisible
2728
import androidx.core.widget.doOnTextChanged
2829
import androidx.fragment.app.DialogFragment
2930
import com.owncloud.android.R
3031
import com.owncloud.android.databinding.CreateSpaceDialogBinding
32+
import com.owncloud.android.domain.spaces.model.OCSpace
3133

3234
class CreateSpaceDialogFragment : DialogFragment() {
3335
private var _binding: CreateSpaceDialogBinding? = null
@@ -44,12 +46,31 @@ class CreateSpaceDialogFragment : DialogFragment() {
4446

4547
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
4648
super.onViewCreated(view, savedInstanceState)
49+
val currentSpace = requireArguments().getParcelable<OCSpace>(ARG_CURRENT_SPACE)
50+
val isEditMode = requireArguments().getBoolean(ARG_EDIT_SPACE_MODE)
4751
binding.apply {
4852
cancelCreateSpaceButton.setOnClickListener { dialog?.dismiss() }
4953
createSpaceDialogNameValue.doOnTextChanged { name, _, _, _ ->
5054
val errorMessage = validateName(name.toString())
5155
updateUI(errorMessage)
5256
}
57+
58+
if (isEditMode) {
59+
createSpaceDialogTitle.text = getString(R.string.edit_space)
60+
val canEditQuota = requireArguments().getBoolean(ARG_CAN_EDIT_SPACE_QUOTA)
61+
createSpaceDialogQuotaSection.isVisible = canEditQuota
62+
63+
currentSpace?.let {
64+
createSpaceDialogNameValue.setText(it.name)
65+
createSpaceDialogSubtitleValue.setText(it.description)
66+
}
67+
68+
createSpaceButton.apply {
69+
text = getString(R.string.edit_space_button)
70+
contentDescription = getString(R.string.edit_space_button)
71+
}
72+
}
73+
5374
createSpaceButton.setOnClickListener {
5475
val spaceQuota = convertToBytes(binding.createSpaceDialogQuotaUnit.selectedItem.toString())
5576
createSpaceListener.createSpace(
@@ -94,12 +115,21 @@ class CreateSpaceDialogFragment : DialogFragment() {
94115
}
95116

96117
companion object {
97-
private const val ARG_ACCOUNT_NAME = "ACCOUNT_NAME"
118+
private const val ARG_EDIT_SPACE_MODE = "EDIT_SPACE_MODE"
119+
private const val ARG_CAN_EDIT_SPACE_QUOTA = "CAN_EDIT_SPACE_QUOTA"
120+
private const val ARG_CURRENT_SPACE = "CURRENT_SPACE"
98121
private const val FORBIDDEN_CHARACTERS = """[/\\.:?*"'><|]"""
99122

100-
fun newInstance(accountName: String?, listener: CreateSpaceListener): CreateSpaceDialogFragment {
123+
fun newInstance(
124+
isEditMode: Boolean,
125+
canEditQuota: Boolean,
126+
currentSpace: OCSpace?,
127+
listener: CreateSpaceListener
128+
): CreateSpaceDialogFragment {
101129
val args = Bundle().apply {
102-
putString(ARG_ACCOUNT_NAME, accountName)
130+
putBoolean(ARG_EDIT_SPACE_MODE, isEditMode)
131+
putBoolean(ARG_CAN_EDIT_SPACE_QUOTA, canEditQuota)
132+
putParcelable(ARG_CURRENT_SPACE, currentSpace)
103133
}
104134
return CreateSpaceDialogFragment().apply {
105135
createSpaceListener = listener

owncloudApp/src/main/res/layout/create_space_dialog.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2424
xmlns:app="http://schemas.android.com/apk/res-auto"
2525
android:layout_width="match_parent"
26+
android:minWidth="275dp"
2627
android:layout_height="match_parent"
2728
android:orientation="vertical"
2829
android:padding="@dimen/standard_half_margin">
@@ -119,6 +120,7 @@
119120
</androidx.constraintlayout.widget.ConstraintLayout>
120121

121122
<LinearLayout
123+
android:id="@+id/create_space_dialog_quota_section"
122124
android:layout_width="match_parent"
123125
android:layout_height="wrap_content"
124126
android:orientation="horizontal"

owncloudApp/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@
851851
<string name="create_space_correctly">Space created correctly</string>
852852
<string name="create_space_failed">Space could not be created</string>
853853
<string name="edit_space">Edit space</string>
854+
<string name="edit_space_button">Edit</string>
854855

855856
<string name="feedback_dialog_get_in_contact_description"><![CDATA[ Ask for help in our <a href=\"%1$s\"><b>forum</b></a> or contribute in our <a href=\"%2$s\"><b>GitHub repo</b></a>]]></string>
856857

owncloudDomain/src/main/java/com/owncloud/android/domain/spaces/model/OCSpace.kt

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
*
44
* @author Abel García de Prada
55
* @author Juan Carlos Garrote Gascón
6+
* @author Jorge Aguado Recio
67
*
7-
* Copyright (C) 2024 ownCloud GmbH.
8+
* Copyright (C) 2025 ownCloud GmbH.
89
*
910
* This program is free software: you can redistribute it and/or modify
1011
* it under the terms of the GNU General Public License version 2,
@@ -21,6 +22,10 @@
2122

2223
package com.owncloud.android.domain.spaces.model
2324

25+
import android.os.Parcelable
26+
import kotlinx.parcelize.Parcelize
27+
28+
@Parcelize
2429
data class OCSpace(
2530
val accountName: String,
2631
val driveAlias: String?,
@@ -34,7 +39,7 @@ data class OCSpace(
3439
val webUrl: String?,
3540
val description: String?,
3641
val special: List<SpaceSpecial>?,
37-
) {
42+
) : Parcelable {
3843
val isPersonal get() = driveType == DRIVE_TYPE_PERSONAL
3944
val isProject get() = driveType == DRIVE_TYPE_PROJECT
4045

@@ -57,24 +62,28 @@ data class OCSpace(
5762
}
5863
}
5964

65+
@Parcelize
6066
data class SpaceOwner(
6167
val user: SpaceUser
62-
)
68+
) : Parcelable
6369

70+
@Parcelize
6471
data class SpaceQuota(
6572
val remaining: Long?,
6673
val state: String?,
6774
val total: Long,
6875
val used: Long?,
69-
)
76+
) : Parcelable
7077

78+
@Parcelize
7179
data class SpaceRoot(
7280
val eTag: String?,
7381
val id: String,
7482
val webDavUrl: String,
7583
val deleted: SpaceDeleted?,
76-
)
84+
) : Parcelable
7785

86+
@Parcelize
7887
data class SpaceSpecial(
7988
val eTag: String,
8089
val file: SpaceFile,
@@ -84,20 +93,24 @@ data class SpaceSpecial(
8493
val size: Int,
8594
val specialFolder: SpaceSpecialFolder,
8695
val webDavUrl: String
87-
)
96+
) : Parcelable
8897

98+
@Parcelize
8999
data class SpaceDeleted(
90100
val state: String,
91-
)
101+
) : Parcelable
92102

103+
@Parcelize
93104
data class SpaceUser(
94105
val id: String
95-
)
106+
) : Parcelable
96107

108+
@Parcelize
97109
data class SpaceFile(
98110
val mimeType: String
99-
)
111+
) : Parcelable
100112

113+
@Parcelize
101114
data class SpaceSpecialFolder(
102115
val name: String
103-
)
116+
) : Parcelable

0 commit comments

Comments
 (0)