Skip to content

Commit bf31347

Browse files
wip
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent 8a57446 commit bf31347

7 files changed

Lines changed: 106 additions & 62 deletions

File tree

app/src/main/java/com/nextcloud/ui/tags/TagManagementBottomSheet.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import androidx.lifecycle.ViewModelProvider
1818
import androidx.lifecycle.lifecycleScope
1919
import androidx.lifecycle.repeatOnLifecycle
2020
import androidx.recyclerview.widget.LinearLayoutManager
21+
import com.nextcloud.ui.tags.adapter.TagListAdapter
2122
import com.google.android.material.bottomsheet.BottomSheetBehavior
2223
import com.google.android.material.bottomsheet.BottomSheetDialog
2324
import com.google.android.material.bottomsheet.BottomSheetDialogFragment

app/src/main/java/com/nextcloud/ui/tags/TagManagementViewModel.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
*/
77
package com.nextcloud.ui.tags
88

9+
import androidx.annotation.StringRes
910
import androidx.lifecycle.ViewModel
1011
import androidx.lifecycle.viewModelScope
1112
import com.nextcloud.client.account.CurrentAccountProvider
1213
import com.nextcloud.client.network.ClientFactory
14+
import com.owncloud.android.R
1315
import com.owncloud.android.lib.resources.tags.CreateTagRemoteOperation
1416
import com.owncloud.android.lib.resources.tags.DeleteTagRemoteOperation
1517
import com.owncloud.android.lib.resources.tags.GetTagsRemoteOperation
@@ -31,7 +33,7 @@ class TagManagementViewModel @Inject constructor(
3133
object Loading : TagUiState
3234
data class Loaded(val allTags: List<Tag>, val assignedTagIds: Set<String>, val query: String = "") : TagUiState
3335

34-
data class Error(val message: String) : TagUiState
36+
data class Error(@StringRes val messageId: Int) : TagUiState
3537
}
3638

3739
private val _uiState = MutableStateFlow<TagUiState>(TagUiState.Loading)
@@ -61,10 +63,10 @@ class TagManagementViewModel @Inject constructor(
6163
)
6264
}
6365
} else {
64-
_uiState.update { TagUiState.Error("Failed to load tags") }
66+
_uiState.update { TagUiState.Error(R.string.failed_to_load_tags) }
6567
}
6668
} catch (e: ClientFactory.CreationException) {
67-
_uiState.update { TagUiState.Error("Failed to create client") }
69+
_uiState.update { TagUiState.Error(R.string.failed_to_load_tags) }
6870
}
6971
}
7072
}

app/src/main/java/com/nextcloud/ui/tags/TagListAdapter.kt renamed to app/src/main/java/com/nextcloud/ui/tags/adapter/TagListAdapter.kt

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
55
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
66
*/
7-
package com.nextcloud.ui.tags
7+
package com.nextcloud.ui.tags.adapter
88

9-
import android.graphics.Color
10-
import android.graphics.drawable.GradientDrawable
119
import android.view.LayoutInflater
12-
import android.view.View
1310
import android.view.ViewGroup
14-
import android.widget.CheckBox
15-
import android.widget.TextView
1611
import androidx.recyclerview.widget.RecyclerView
12+
import com.nextcloud.ui.tags.adapter.viewholder.CreateTagViewHolder
13+
import com.nextcloud.ui.tags.adapter.viewholder.TagViewHolder
1714
import com.owncloud.android.R
1815
import com.owncloud.android.lib.resources.tags.Tag
1916

@@ -54,10 +51,10 @@ class TagListAdapter(private val onTagChecked: (Tag, Boolean) -> Unit, private v
5451
val inflater = LayoutInflater.from(parent.context)
5552
return if (viewType == VIEW_TYPE_CREATE) {
5653
val view = inflater.inflate(R.layout.tag_list_item, parent, false)
57-
CreateTagViewHolder(view)
54+
CreateTagViewHolder(view, onCreateTag)
5855
} else {
5956
val view = inflater.inflate(R.layout.tag_list_item, parent, false)
60-
TagViewHolder(view)
57+
TagViewHolder(view, onTagChecked)
6158
}
6259
}
6360

@@ -73,55 +70,4 @@ class TagListAdapter(private val onTagChecked: (Tag, Boolean) -> Unit, private v
7370
}
7471
}
7572
}
76-
77-
inner class TagViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
78-
private val colorDot: View = itemView.findViewById(R.id.tag_color_dot)
79-
private val tagName: TextView = itemView.findViewById(R.id.tag_name)
80-
private val checkBox: CheckBox = itemView.findViewById(R.id.tag_checkbox)
81-
82-
fun bind(tag: Tag, isAssigned: Boolean) {
83-
tagName.text = tag.name
84-
85-
if (tag.color != null) {
86-
try {
87-
val color = Color.parseColor(tag.color)
88-
val background = colorDot.background
89-
if (background is GradientDrawable) {
90-
background.setColor(color)
91-
}
92-
colorDot.visibility = View.VISIBLE
93-
} catch (e: IllegalArgumentException) {
94-
colorDot.visibility = View.INVISIBLE
95-
}
96-
} else {
97-
colorDot.visibility = View.INVISIBLE
98-
}
99-
100-
checkBox.setOnCheckedChangeListener(null)
101-
checkBox.isChecked = isAssigned
102-
checkBox.setOnCheckedChangeListener { _, isChecked ->
103-
onTagChecked(tag, isChecked)
104-
}
105-
106-
itemView.setOnClickListener {
107-
checkBox.isChecked = !checkBox.isChecked
108-
}
109-
}
110-
}
111-
112-
inner class CreateTagViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
113-
private val colorDot: View = itemView.findViewById(R.id.tag_color_dot)
114-
private val tagName: TextView = itemView.findViewById(R.id.tag_name)
115-
private val checkBox: CheckBox = itemView.findViewById(R.id.tag_checkbox)
116-
117-
fun bind(name: String) {
118-
colorDot.visibility = View.INVISIBLE
119-
tagName.text = itemView.context.getString(R.string.create_tag_format, name)
120-
checkBox.visibility = View.GONE
121-
122-
itemView.setOnClickListener {
123-
onCreateTag(name)
124-
}
125-
}
126-
}
12773
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
6+
*/
7+
package com.nextcloud.ui.tags.adapter.viewholder
8+
9+
import android.view.View
10+
import android.widget.CheckBox
11+
import android.widget.TextView
12+
import androidx.recyclerview.widget.RecyclerView
13+
import com.owncloud.android.R
14+
15+
class CreateTagViewHolder(
16+
itemView: View,
17+
private val onCreateTag: (String) -> Unit
18+
) : RecyclerView.ViewHolder(itemView) {
19+
private val colorDot: View = itemView.findViewById(R.id.tag_color_dot)
20+
private val tagName: TextView = itemView.findViewById(R.id.tag_name)
21+
private val checkBox: CheckBox = itemView.findViewById(R.id.tag_checkbox)
22+
23+
fun bind(name: String) {
24+
colorDot.visibility = View.INVISIBLE
25+
tagName.text = itemView.context.getString(R.string.create_tag_format, name)
26+
checkBox.visibility = View.GONE
27+
28+
itemView.setOnClickListener {
29+
onCreateTag(name)
30+
}
31+
}
32+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
6+
*/
7+
package com.nextcloud.ui.tags.adapter.viewholder
8+
9+
import android.graphics.Color
10+
import android.graphics.drawable.GradientDrawable
11+
import android.view.View
12+
import android.widget.CheckBox
13+
import android.widget.TextView
14+
import androidx.recyclerview.widget.RecyclerView
15+
import com.owncloud.android.R
16+
import com.owncloud.android.lib.resources.tags.Tag
17+
18+
class TagViewHolder(
19+
itemView: View,
20+
private val onTagChecked: (Tag, Boolean) -> Unit
21+
) : RecyclerView.ViewHolder(itemView) {
22+
private val colorDot: View = itemView.findViewById(R.id.tag_color_dot)
23+
private val tagName: TextView = itemView.findViewById(R.id.tag_name)
24+
private val checkBox: CheckBox = itemView.findViewById(R.id.tag_checkbox)
25+
26+
fun bind(tag: Tag, isAssigned: Boolean) {
27+
tagName.text = tag.name
28+
29+
if (tag.color != null) {
30+
try {
31+
val color = Color.parseColor(tag.color)
32+
val background = colorDot.background
33+
if (background is GradientDrawable) {
34+
background.setColor(color)
35+
}
36+
colorDot.visibility = View.VISIBLE
37+
} catch (e: IllegalArgumentException) {
38+
colorDot.visibility = View.INVISIBLE
39+
}
40+
} else {
41+
colorDot.visibility = View.INVISIBLE
42+
}
43+
44+
checkBox.setOnCheckedChangeListener(null)
45+
checkBox.isChecked = isAssigned
46+
checkBox.setOnCheckedChangeListener { _, isChecked ->
47+
onTagChecked(tag, isChecked)
48+
}
49+
50+
itemView.setOnClickListener {
51+
checkBox.isChecked = !checkBox.isChecked
52+
}
53+
}
54+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,7 @@
15181518
<string name="editor_web_view_cannot_open_file">Cannot open file chooser</string>
15191519
<string name="send_copy_to">Send copy to</string>
15201520
<string name="failed_to_start_action">Failed to start action!</string>
1521+
<string name="failed_to_load_tags">Failed to load tags</string>
15211522
<string name="action_triggered">Action triggered</string>
15221523

15231524
<string name="sync_conflict_notification_title">File upload conflicts</string>

gradle/verification-metadata.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20830,6 +20830,14 @@
2083020830
<sha256 value="c29795ee883fc3364b2f16be5b9246b927271b961214f1a661b2caa2f42459a8" origin="Generated by Gradle" reason="Artifact is not signed"/>
2083120831
</artifact>
2083220832
</component>
20833+
<component group="com.github.nextcloud" name="android-library" version="0e8aab9b3f56426fd5e4ffc88242b1dcf44ac0db">
20834+
<artifact name="android-library-0e8aab9b3f56426fd5e4ffc88242b1dcf44ac0db.aar">
20835+
<sha256 value="ced0564fae24551ce27ea4b4ce6f7e49861168ff143a1e66e3b81f61c370b4d3" origin="Generated by Gradle" reason="Artifact is not signed"/>
20836+
</artifact>
20837+
<artifact name="android-library-0e8aab9b3f56426fd5e4ffc88242b1dcf44ac0db.module">
20838+
<sha256 value="7f30904505fee8e32a2daea3bb894aae7a3a0e260bc49ec5aa5f045ec92f54a0" origin="Generated by Gradle" reason="Artifact is not signed"/>
20839+
</artifact>
20840+
</component>
2083320841
<component group="com.github.nextcloud" name="android-library" version="0edf15760b8a086ab9969e103c7229dad973efbd">
2083420842
<artifact name="android-library-0edf15760b8a086ab9969e103c7229dad973efbd.aar">
2083520843
<sha256 value="37176d4d4a54d4176436355c5f948a4558c91458a03a20d874ae6da0739e7411" origin="Generated by Gradle" reason="Artifact is not signed"/>

0 commit comments

Comments
 (0)