Skip to content

Commit 3cc0159

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

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import android.view.Menu
2929
import android.view.MenuInflater
3030
import android.view.View
3131
import android.view.ViewGroup
32-
import android.widget.ImageView
33-
import android.widget.TextView
3432
import androidx.appcompat.widget.SearchView
3533
import androidx.core.os.bundleOf
3634
import androidx.core.view.isVisible
@@ -40,6 +38,7 @@ import androidx.recyclerview.widget.GridLayoutManager
4038
import com.google.android.material.bottomsheet.BottomSheetBehavior
4139
import com.google.android.material.bottomsheet.BottomSheetDialog
4240
import com.owncloud.android.R
41+
import com.owncloud.android.databinding.FileOptionsBottomSheetFragmentBinding
4342
import com.owncloud.android.databinding.SpacesListFragmentBinding
4443
import com.owncloud.android.domain.files.model.FileListOption
4544
import com.owncloud.android.domain.spaces.model.OCSpace
@@ -171,27 +170,27 @@ class SpacesListFragment : SpacesListAdapter.SpacesListAdapterListener, Fragment
171170
}
172171

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

178-
val fileOptionsBottomSheetSingleFileBehavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(spaceOptionsBottomSheet.parent as View)
179-
val closeBottomSheetButton = spaceOptionsBottomSheet.findViewById<ImageView>(R.id.close_bottom_sheet)
177+
val fileOptionsBottomSheetSingleFileBehavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(
178+
spaceOptionsBottomSheetBinding.root.parent as View)
179+
val closeBottomSheetButton = spaceOptionsBottomSheetBinding.closeBottomSheet
180180
closeBottomSheetButton.setOnClickListener {
181-
dialog.hide()
182181
dialog.dismiss()
183182
}
184183

185-
val thumbnailBottomSheet = spaceOptionsBottomSheet.findViewById<ImageView>(R.id.thumbnail_bottom_sheet)
184+
val thumbnailBottomSheet = spaceOptionsBottomSheetBinding.thumbnailBottomSheet
186185
thumbnailBottomSheet.setImageResource(R.drawable.ic_menu_space)
187186

188-
val spaceNameBottomSheet = spaceOptionsBottomSheet.findViewById<TextView>(R.id.file_name_bottom_sheet)
187+
val spaceNameBottomSheet = spaceOptionsBottomSheetBinding.fileNameBottomSheet
189188
spaceNameBottomSheet.text = ocSpace.name
190189

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

194-
val spaceSeparatorBottomSheet = spaceOptionsBottomSheet.findViewById<TextView>(R.id.file_separator_bottom_sheet)
193+
val spaceSeparatorBottomSheet = spaceOptionsBottomSheetBinding.fileSeparatorBottomSheet
195194
spaceSeparatorBottomSheet.visibility = View.GONE
196195

197196
fileOptionsBottomSheetSingleFileBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
@@ -203,7 +202,7 @@ class SpacesListFragment : SpacesListAdapter.SpacesListAdapterListener, Fragment
203202
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
204203
})
205204

206-
dialog.setOnShowListener { fileOptionsBottomSheetSingleFileBehavior.peekHeight = spaceOptionsBottomSheet.measuredHeight }
205+
dialog.setOnShowListener { fileOptionsBottomSheetSingleFileBehavior.peekHeight = spaceOptionsBottomSheetBinding.root.measuredHeight }
207206
dialog.show()
208207
}
209208

0 commit comments

Comments
 (0)