Skip to content

Commit 04b055e

Browse files
committed
refactor: use view binding instead of inflate and findViewById for space bottom sheet dialog
1 parent 7de75a2 commit 04b055e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import androidx.recyclerview.widget.GridLayoutManager
4040
import com.google.android.material.bottomsheet.BottomSheetBehavior
4141
import com.google.android.material.bottomsheet.BottomSheetDialog
4242
import com.owncloud.android.R
43+
import com.owncloud.android.databinding.FileOptionsBottomSheetFragmentBinding
4344
import com.owncloud.android.databinding.SpacesListFragmentBinding
4445
import com.owncloud.android.domain.files.model.FileListOption
4546
import com.owncloud.android.domain.spaces.model.OCSpace
@@ -171,27 +172,27 @@ class SpacesListFragment : SpacesListAdapter.SpacesListAdapterListener, Fragment
171172
}
172173

173174
override fun onThreeDotButtonClick(ocSpace: OCSpace) {
174-
val spaceOptionsBottomSheet = layoutInflater.inflate(R.layout.file_options_bottom_sheet_fragment, null)
175+
val spaceOptionsBottomSheetBinding = FileOptionsBottomSheetFragmentBinding.inflate(layoutInflater)
175176
val dialog = BottomSheetDialog(requireContext())
176-
dialog.setContentView(spaceOptionsBottomSheet)
177+
dialog.setContentView(spaceOptionsBottomSheetBinding.root)
177178

178-
val fileOptionsBottomSheetSingleFileBehavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(spaceOptionsBottomSheet.parent as View)
179-
val closeBottomSheetButton = spaceOptionsBottomSheet.findViewById<ImageView>(R.id.close_bottom_sheet)
179+
val fileOptionsBottomSheetSingleFileBehavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(
180+
spaceOptionsBottomSheetBinding.root.parent as View)
181+
val closeBottomSheetButton = spaceOptionsBottomSheetBinding.closeBottomSheet
180182
closeBottomSheetButton.setOnClickListener {
181-
dialog.hide()
182183
dialog.dismiss()
183184
}
184185

185-
val thumbnailBottomSheet = spaceOptionsBottomSheet.findViewById<ImageView>(R.id.thumbnail_bottom_sheet)
186+
val thumbnailBottomSheet = spaceOptionsBottomSheetBinding.thumbnailBottomSheet
186187
thumbnailBottomSheet.setImageResource(R.drawable.ic_menu_space)
187188

188-
val spaceNameBottomSheet = spaceOptionsBottomSheet.findViewById<TextView>(R.id.file_name_bottom_sheet)
189+
val spaceNameBottomSheet = spaceOptionsBottomSheetBinding.fileNameBottomSheet
189190
spaceNameBottomSheet.text = ocSpace.name
190191

191-
val spaceSizeBottomSheet = spaceOptionsBottomSheet.findViewById<TextView>(R.id.file_size_bottom_sheet)
192+
val spaceSizeBottomSheet = spaceOptionsBottomSheetBinding.fileSizeBottomSheet
192193
spaceSizeBottomSheet.text = DisplayUtils.bytesToHumanReadable(ocSpace.quota?.used ?: 0L, requireContext(), true)
193194

194-
val spaceSeparatorBottomSheet = spaceOptionsBottomSheet.findViewById<TextView>(R.id.file_separator_bottom_sheet)
195+
val spaceSeparatorBottomSheet = spaceOptionsBottomSheetBinding.fileSeparatorBottomSheet
195196
spaceSeparatorBottomSheet.visibility = View.GONE
196197

197198
fileOptionsBottomSheetSingleFileBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
@@ -203,7 +204,7 @@ class SpacesListFragment : SpacesListAdapter.SpacesListAdapterListener, Fragment
203204
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
204205
})
205206

206-
dialog.setOnShowListener { fileOptionsBottomSheetSingleFileBehavior.peekHeight = spaceOptionsBottomSheet.measuredHeight }
207+
dialog.setOnShowListener { fileOptionsBottomSheetSingleFileBehavior.peekHeight = spaceOptionsBottomSheetBinding.root.measuredHeight }
207208
dialog.show()
208209
}
209210

0 commit comments

Comments
 (0)