Skip to content

Commit

Permalink
refactor: refactor methods with more than 100 lines
Browse files Browse the repository at this point in the history
  • Loading branch information
JuancaG05 committed Dec 11, 2024
1 parent f5e6c18 commit fd7e026
Show file tree
Hide file tree
Showing 7 changed files with 567 additions and 502 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,71 +207,7 @@ class FileListAdapter(
holder.itemView.findViewById<ImageView>(R.id.shared_via_users_icon).isVisible =
file.sharedWithSharee == true || file.isSharedWithMe

when (viewType) {
ViewType.LIST_ITEM.ordinal -> {
val view = holder as ListViewHolder
view.binding.let {
it.fileListConstraintLayout.filterTouchesWhenObscured = PreferenceUtils.shouldDisallowTouchesWithOtherVisibleWindows(context)
it.Filename.text = file.fileName
it.fileListSize.text = DisplayUtils.bytesToHumanReadable(file.length, context, true)
it.fileListLastMod.text = DisplayUtils.getRelativeTimestamp(context, file.modificationTimestamp)
it.threeDotMenu.isVisible = getCheckedItems().isEmpty()
it.threeDotMenu.contentDescription = context.getString(R.string.content_description_file_operations, file.fileName)
if (fileListOption.isAvailableOffline() || (fileListOption.isSharedByLink() && fileWithSyncInfo.space == null)) {
it.spacePathLine.path.apply {
text = file.getParentRemotePath()
isVisible = true
}
fileWithSyncInfo.space?.let { space ->
it.spacePathLine.spaceIcon.isVisible = true
it.spacePathLine.spaceName.isVisible = true
if (space.isPersonal) {
it.spacePathLine.spaceIcon.setImageResource(R.drawable.ic_folder)
it.spacePathLine.spaceName.setText(R.string.bottom_nav_personal)
} else {
it.spacePathLine.spaceName.text = space.name
}
}
} else {
it.spacePathLine.path.isVisible = false
it.spacePathLine.spaceIcon.isVisible = false
it.spacePathLine.spaceName.isVisible = false
}
it.threeDotMenu.setOnClickListener {
listener.onThreeDotButtonClick(fileWithSyncInfo = fileWithSyncInfo)
}
}
}

ViewType.GRID_ITEM.ordinal -> {
// Filename
val view = holder as GridViewHolder
view.binding.Filename.text = file.fileName
}

ViewType.GRID_IMAGE.ordinal -> {
val view = holder as GridImageViewHolder
val layoutParams = fileIcon.layoutParams as ViewGroup.MarginLayoutParams

if (thumbnail == null) {
view.binding.Filename.text = file.fileName
// Reset layout params values default
manageGridLayoutParams(
layoutParams = layoutParams,
marginVertical = 0,
height = context.resources.getDimensionPixelSize(R.dimen.item_file_grid_height),
width = context.resources.getDimensionPixelSize(R.dimen.item_file_grid_width),
)
} else {
manageGridLayoutParams(
layoutParams = layoutParams,
marginVertical = context.resources.getDimensionPixelSize(R.dimen.item_file_image_grid_margin),
height = ViewGroup.LayoutParams.MATCH_PARENT,
width = ViewGroup.LayoutParams.MATCH_PARENT,
)
}
}
}
setSpecificViewHolder(viewType, holder, fileWithSyncInfo, thumbnail)

setIconPinAccordingToFilesLocalState(holder.itemView.findViewById(R.id.localFileIndicator), fileWithSyncInfo)

Expand Down Expand Up @@ -342,6 +278,77 @@ class FileListAdapter(
}
}

private fun setSpecificViewHolder(viewType: Int, holder: RecyclerView.ViewHolder, fileWithSyncInfo: OCFileWithSyncInfo, thumbnail: Bitmap?) {
val file = fileWithSyncInfo.file

when (viewType) {
ViewType.LIST_ITEM.ordinal -> {
val view = holder as ListViewHolder
view.binding.let {
it.fileListConstraintLayout.filterTouchesWhenObscured = PreferenceUtils.shouldDisallowTouchesWithOtherVisibleWindows(context)
it.Filename.text = file.fileName
it.fileListSize.text = DisplayUtils.bytesToHumanReadable(file.length, context, true)
it.fileListLastMod.text = DisplayUtils.getRelativeTimestamp(context, file.modificationTimestamp)
it.threeDotMenu.isVisible = getCheckedItems().isEmpty()
it.threeDotMenu.contentDescription = context.getString(R.string.content_description_file_operations, file.fileName)
if (fileListOption.isAvailableOffline() || (fileListOption.isSharedByLink() && fileWithSyncInfo.space == null)) {
it.spacePathLine.path.apply {
text = file.getParentRemotePath()
isVisible = true
}
fileWithSyncInfo.space?.let { space ->
it.spacePathLine.spaceIcon.isVisible = true
it.spacePathLine.spaceName.isVisible = true
if (space.isPersonal) {
it.spacePathLine.spaceIcon.setImageResource(R.drawable.ic_folder)
it.spacePathLine.spaceName.setText(R.string.bottom_nav_personal)
} else {
it.spacePathLine.spaceName.text = space.name
}
}
} else {
it.spacePathLine.path.isVisible = false
it.spacePathLine.spaceIcon.isVisible = false
it.spacePathLine.spaceName.isVisible = false
}
it.threeDotMenu.setOnClickListener {
listener.onThreeDotButtonClick(fileWithSyncInfo = fileWithSyncInfo)
}
}
}

ViewType.GRID_ITEM.ordinal -> {
// Filename
val view = holder as GridViewHolder
view.binding.Filename.text = file.fileName
}

ViewType.GRID_IMAGE.ordinal -> {
val view = holder as GridImageViewHolder
val fileIcon = holder.itemView.findViewById<ImageView>(R.id.thumbnail)
val layoutParams = fileIcon.layoutParams as ViewGroup.MarginLayoutParams

if (thumbnail == null) {
view.binding.Filename.text = file.fileName
// Reset layout params values default
manageGridLayoutParams(
layoutParams = layoutParams,
marginVertical = 0,
height = context.resources.getDimensionPixelSize(R.dimen.item_file_grid_height),
width = context.resources.getDimensionPixelSize(R.dimen.item_file_grid_width),
)
} else {
manageGridLayoutParams(
layoutParams = layoutParams,
marginVertical = context.resources.getDimensionPixelSize(R.dimen.item_file_image_grid_margin),
height = ViewGroup.LayoutParams.MATCH_PARENT,
width = ViewGroup.LayoutParams.MATCH_PARENT,
)
}
}
}
}

private fun manageGridLayoutParams(layoutParams: ViewGroup.MarginLayoutParams, marginVertical: Int, height: Int, width: Int) {
val marginHorizontal = context.resources.getDimensionPixelSize(R.dimen.item_file_image_grid_margin)
layoutParams.setMargins(marginHorizontal, marginVertical, marginHorizontal, marginVertical)
Expand Down
Loading

0 comments on commit fd7e026

Please sign in to comment.