@@ -12,8 +12,10 @@ import android.view.ViewGroup
1212import android.widget.ArrayAdapter
1313import android.widget.TextView
1414import androidx.core.content.ContextCompat
15+ import com.google.android.material.textfield.MaterialAutoCompleteTextView
16+ import com.google.android.material.textfield.TextInputLayout
1517import com.nextcloud.android.common.ui.theme.utils.ColorRole
16- import com.nextcloud.ui.fileInfo.model.SensitivityLabel
18+ import com.nextcloud.ui.fileInfo.model.GovernanceLabel
1719import com.owncloud.android.R
1820import com.owncloud.android.databinding.FileInfoFragmentBinding
1921import com.owncloud.android.utils.theme.ViewThemeUtils
@@ -23,56 +25,75 @@ class GovernanceDetailInfo(
2325 private val viewThemeUtils : ViewThemeUtils ,
2426 private val fragment : FileInfoFragment
2527) {
28+ private val context get() = fragment.requireContext()
2629
2730 fun init () {
2831 viewThemeUtils.material.themeCardView(binding.governanceLayout)
32+ initSensitivityLabel()
33+ initFileDetentionLabel()
34+ }
35+
36+ private fun initSensitivityLabel () {
37+ initDropdown(
38+ textInputLayout = binding.sensitivityLabel,
39+ autoComplete = binding.sensitivityLabelAutoComplete,
40+ items = listOf (
41+ GovernanceLabel (" Sharing restricted" , R .drawable.ic_share),
42+ GovernanceLabel (" Download restricted" , R .drawable.ic_download_grey600),
43+ GovernanceLabel (" Upload restricted" , R .drawable.uploads)
44+ )
45+ )
46+ }
2947
30- val items = listOf (
31- SensitivityLabel (" Option 1" , R .drawable.outline_camera_24),
32- SensitivityLabel (" Option 2" , R .drawable.outline_image_24),
33- SensitivityLabel (" Option 3" , R .drawable.ic_information_outline)
48+ private fun initFileDetentionLabel () {
49+ initDropdown(
50+ textInputLayout = binding.fileDetentionLabel,
51+ autoComplete = binding.fileDetentionAutoComplete,
52+ items = listOf (
53+ GovernanceLabel (" Public" , R .drawable.file_link),
54+ GovernanceLabel (" Internal use only" , R .drawable.ic_group),
55+ GovernanceLabel (" Restricted" , R .drawable.ic_cancel)
56+ )
3457 )
58+ }
59+
60+ private fun initDropdown (
61+ textInputLayout : TextInputLayout ,
62+ autoComplete : MaterialAutoCompleteTextView ,
63+ items : List <GovernanceLabel >
64+ ) {
65+ viewThemeUtils.material.colorTextInputLayout(textInputLayout)
66+ viewThemeUtils.files.themeAutoCompleteTextView(autoComplete)
67+
68+ autoComplete.setAdapter(buildAdapter(items))
69+
70+ items.firstOrNull()?.let { applySelection(autoComplete, it) }
3571
36- val adapter = object :
37- ArrayAdapter <SensitivityLabel >(fragment.requireContext(), R .layout.item_dropdown_with_icon, items) {
72+ autoComplete.setOnItemClickListener { _, _, position, _ ->
73+ applySelection(autoComplete, items[position])
74+ }
75+ }
76+
77+ private fun buildAdapter (items : List <GovernanceLabel >) =
78+ object : ArrayAdapter <GovernanceLabel >(context, R .layout.item_dropdown_with_icon, items) {
3879 override fun getView (position : Int , convertView : View ? , parent : ViewGroup ): View {
3980 val view = super .getView(position, convertView, parent) as TextView
40- val item = getItem(position)
41- if (item != null ) {
81+ getItem(position)?.let { item ->
4282 view.text = item.text
43- val drawable = ContextCompat .getDrawable(context, item.iconRes)?.mutate()
44- drawable?.let {
45- viewThemeUtils.platform.tintDrawable(fragment.requireContext(), it, ColorRole .ON_SURFACE )
46- }
47- view.setCompoundDrawablesWithIntrinsicBounds(drawable, null , null , null )
83+ view.setCompoundDrawablesWithIntrinsicBounds(tintedDrawable(item), null , null , null )
4884 }
4985 return view
5086 }
5187 }
52- binding.sensitivityLabelAutoComplete.setAdapter(adapter)
5388
54- val defaultSelectedItem = items.firstOrNull()
55- if (defaultSelectedItem != null ) {
56- binding.sensitivityLabelAutoComplete.setText(defaultSelectedItem.text, false )
57- val drawable = ContextCompat .getDrawable(fragment.requireContext(), defaultSelectedItem.iconRes)?.mutate()
58- drawable?.let {
59- viewThemeUtils.platform.tintDrawable(fragment.requireContext(), it, ColorRole .ON_SURFACE )
60- }
61- binding.sensitivityLabelAutoComplete.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null , null , null )
62- binding.sensitivityLabelAutoComplete.compoundDrawablePadding =
63- fragment.resources.getDimensionPixelSize(R .dimen.standard_padding)
64- }
89+ private fun applySelection (autoComplete : MaterialAutoCompleteTextView , item : GovernanceLabel ) {
90+ autoComplete.setText(item.text, false )
91+ autoComplete.setCompoundDrawablesRelativeWithIntrinsicBounds(tintedDrawable(item), null , null , null )
92+ autoComplete.compoundDrawablePadding = fragment.resources.getDimensionPixelSize(R .dimen.standard_padding)
93+ }
6594
66- binding.sensitivityLabelAutoComplete.setOnItemClickListener { _, _, position, _ ->
67- val selected = items[position]
68- binding.sensitivityLabelAutoComplete.setText(selected.text, false )
69- val drawable = ContextCompat .getDrawable(fragment.requireContext(), selected.iconRes)?.mutate()
70- binding.sensitivityLabelAutoComplete.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null , null , null )
71- binding.sensitivityLabelAutoComplete.compoundDrawablePadding =
72- fragment.resources.getDimensionPixelSize(R .dimen.standard_padding)
95+ private fun tintedDrawable (item : GovernanceLabel ) =
96+ ContextCompat .getDrawable(context, item.iconRes)?.mutate()?.also {
97+ viewThemeUtils.platform.tintDrawable(context, it, ColorRole .ON_SURFACE )
7398 }
74-
75- viewThemeUtils.material.colorTextInputLayout(binding.sensitivityLabel)
76- viewThemeUtils.material.colorTextInputLayout(binding.fileDetentionLabel)
77- }
7899}
0 commit comments