Skip to content

Commit 1414f8e

Browse files
wip
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent b461aee commit 1414f8e

4 files changed

Lines changed: 20 additions & 18 deletions

File tree

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ import androidx.recyclerview.widget.RecyclerView
1717
import com.owncloud.android.R
1818
import com.owncloud.android.lib.resources.tags.Tag
1919

20-
class TagListAdapter(
21-
private val onTagChecked: (Tag, Boolean) -> Unit,
22-
private val onCreateTag: (String) -> Unit
23-
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
20+
class TagListAdapter(private val onTagChecked: (Tag, Boolean) -> Unit, private val onCreateTag: (String) -> Unit) :
21+
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
2422

2523
private var tags: List<Tag> = emptyList()
2624
private var assignedTagIds: Set<String> = emptySet()
@@ -49,9 +47,8 @@ class TagListAdapter(
4947

5048
override fun getItemCount(): Int = tags.size + if (showCreateItem) 1 else 0
5149

52-
override fun getItemViewType(position: Int): Int {
53-
return if (showCreateItem && position == tags.size) VIEW_TYPE_CREATE else VIEW_TYPE_TAG
54-
}
50+
override fun getItemViewType(position: Int): Int =
51+
if (showCreateItem && position == tags.size) VIEW_TYPE_CREATE else VIEW_TYPE_TAG
5552

5653
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
5754
val inflater = LayoutInflater.from(parent.context)
@@ -70,6 +67,7 @@ class TagListAdapter(
7067
val tag = tags[position]
7168
holder.bind(tag, tag.id in assignedTagIds)
7269
}
70+
7371
is CreateTagViewHolder -> {
7472
holder.bind(query)
7573
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import com.owncloud.android.utils.theme.ViewThemeUtils
3030
import kotlinx.coroutines.launch
3131
import javax.inject.Inject
3232

33-
class TagManagementBottomSheet : BottomSheetDialogFragment(), Injectable {
33+
class TagManagementBottomSheet :
34+
BottomSheetDialogFragment(),
35+
Injectable {
3436

3537
@Inject
3638
lateinit var vmFactory: ViewModelFactory
@@ -101,11 +103,13 @@ class TagManagementBottomSheet : BottomSheetDialogFragment(), Injectable {
101103
binding.loadingIndicator.visibility = View.VISIBLE
102104
binding.tagList.visibility = View.GONE
103105
}
106+
104107
is TagManagementViewModel.TagUiState.Loaded -> {
105108
binding.loadingIndicator.visibility = View.GONE
106109
binding.tagList.visibility = View.VISIBLE
107110
tagAdapter.update(state.allTags, state.assignedTagIds, state.query)
108111
}
112+
109113
is TagManagementViewModel.TagUiState.Error -> {
110114
binding.loadingIndicator.visibility = View.GONE
111115
binding.tagList.visibility = View.GONE
@@ -130,13 +134,12 @@ class TagManagementBottomSheet : BottomSheetDialogFragment(), Injectable {
130134
private const val ARG_FILE_ID = "ARG_FILE_ID"
131135
private const val ARG_CURRENT_TAGS = "ARG_CURRENT_TAGS"
132136

133-
fun newInstance(fileId: Long, currentTags: List<Tag>): TagManagementBottomSheet {
134-
return TagManagementBottomSheet().apply {
137+
fun newInstance(fileId: Long, currentTags: List<Tag>): TagManagementBottomSheet =
138+
TagManagementBottomSheet().apply {
135139
arguments = bundleOf(
136140
ARG_FILE_ID to fileId,
137141
ARG_CURRENT_TAGS to ArrayList(currentTags)
138142
)
139143
}
140-
}
141144
}
142145
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ class TagManagementViewModel @Inject constructor(
2929

3030
sealed interface TagUiState {
3131
object Loading : TagUiState
32-
data class Loaded(
33-
val allTags: List<Tag>,
34-
val assignedTagIds: Set<String>,
35-
val query: String = ""
36-
) : TagUiState
32+
data class Loaded(val allTags: List<Tag>, val assignedTagIds: Set<String>, val query: String = "") : TagUiState
3733

3834
data class Error(val message: String) : TagUiState
3935
}
@@ -45,14 +41,19 @@ class TagManagementViewModel @Inject constructor(
4541

4642
fun load(fileId: Long, currentTags: List<Tag>) {
4743
this.fileId = fileId
48-
val assignedIds = currentTags.map { it.id }.toSet()
44+
val assignedTagNames = currentTags.map { it.name }.toSet()
4945

5046
viewModelScope.launch(Dispatchers.IO) {
5147
try {
5248
val client = clientFactory.create(currentAccountProvider.user)
5349
val result = GetTagsRemoteOperation().execute(client)
5450

5551
if (result.isSuccess) {
52+
val assignedIds = result.resultData
53+
.filter { it.name in assignedTagNames }
54+
.map { it.id }
55+
.toSet()
56+
5657
_uiState.update {
5758
TagUiState.Loaded(
5859
allTags = result.resultData,

app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ private void refreshTagChips(Context context) {
331331
viewThemeUtils.material.themeChipSuggestion(editChip);
332332
editChip.setOnClickListener(v -> {
333333
TagManagementBottomSheet bottomSheet = TagManagementBottomSheet.Companion.newInstance(
334-
getFile().getFileId(),
334+
getFile().getLocalId(),
335335
getFile().getTags()
336336
);
337337
// FileActionsBottomSheet bottomSheet = FileActionsBottomSheet.Companion.newInstance(getFile(), false);

0 commit comments

Comments
 (0)