Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace kotlin extension with view bindings in the 3 full screen bottom sheet left #1056

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,31 @@ import com.infomaniak.drive.data.models.Permission
import com.infomaniak.drive.data.models.ShareLink.*
import com.infomaniak.drive.data.models.Shareable
import com.infomaniak.drive.data.models.Shareable.ShareablePermission
import com.infomaniak.drive.databinding.FragmentSelectPermissionBinding
import com.infomaniak.drive.ui.fileList.fileShare.PermissionsAdapter
import com.infomaniak.drive.views.FullScreenBottomSheetDialog
import com.infomaniak.lib.core.models.ApiResponse
import com.infomaniak.lib.core.utils.*
import kotlinx.android.parcel.Parcelize
import kotlinx.android.synthetic.main.fragment_select_permission.permissionsRecyclerView
import kotlinx.android.synthetic.main.fragment_select_permission.saveButton
import kotlinx.android.synthetic.main.fragment_select_permission.toolbar
import kotlinx.coroutines.Dispatchers

class SelectPermissionBottomSheetDialog : FullScreenBottomSheetDialog() {

private var binding: FragmentSelectPermissionBinding by safeBinding()
LunarX marked this conversation as resolved.
Show resolved Hide resolved

private lateinit var adapter: PermissionsAdapter
private lateinit var permissionsGroup: PermissionsGroup
private val navigationArgs: SelectPermissionBottomSheetDialogArgs by navArgs()
private val selectPermissionViewModel: SelectPermissionViewModel by viewModels()

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_select_permission, container, false)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return FragmentSelectPermissionBinding.inflate(inflater, container, false).also { binding = it }.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

toolbar.setNavigationOnClickListener { findNavController().popBackStack() }
binding.toolbar.setNavigationOnClickListener { findNavController().popBackStack() }

selectPermissionViewModel.apply {
currentPermission = currentPermission ?: navigationArgs.currentPermission
Expand All @@ -83,7 +84,7 @@ class SelectPermissionBottomSheetDialog : FullScreenBottomSheetDialog() {
setAll(getPermissions())
selectionPosition = permissionList.indexOf(selectPermissionViewModel.currentPermission)
}
permissionsRecyclerView.adapter = adapter
binding.permissionsRecyclerView.adapter = adapter
}

private fun getPermissions(): ArrayList<Permission> {
Expand Down Expand Up @@ -124,7 +125,7 @@ class SelectPermissionBottomSheetDialog : FullScreenBottomSheetDialog() {
}

private fun configureSaveButton() {
saveButton.setOnClickListener {
binding.saveButton.setOnClickListener {
with(selectPermissionViewModel) {
when (permissionsGroup) {
PermissionsGroup.EXTERNAL_USERS_RIGHTS, PermissionsGroup.USERS_RIGHTS -> {
Expand All @@ -148,7 +149,7 @@ class SelectPermissionBottomSheetDialog : FullScreenBottomSheetDialog() {
}
}

private fun updateShareLinkOfficePermission(file: File, permission: Permission?) {
private fun updateShareLinkOfficePermission(file: File, permission: Permission?) = with(binding) {
saveButton.initProgress(viewLifecycleOwner)
saveButton.showProgress()
selectPermissionViewModel.editFileShareLinkOfficePermission(
Expand All @@ -159,7 +160,7 @@ class SelectPermissionBottomSheetDialog : FullScreenBottomSheetDialog() {
}
}

private fun updatePermission(file: File, shareableItem: Shareable?, permission: ShareablePermission? = null) {
private fun updatePermission(file: File, shareableItem: Shareable?, permission: ShareablePermission? = null) = with(binding) {
saveButton.initProgress(viewLifecycleOwner)
saveButton.showProgress()
shareableItem?.let { shareable ->
Expand Down Expand Up @@ -198,7 +199,7 @@ class SelectPermissionBottomSheetDialog : FullScreenBottomSheetDialog() {
} else {
SnackbarUtils.showSnackbar(requireView(), errorMessage)
}
saveButton.hideProgress(R.string.buttonSave)
binding.saveButton.hideProgress(R.string.buttonSave)
}

internal class SelectPermissionViewModel : ViewModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,59 +24,64 @@ import android.view.ViewGroup
import android.widget.PopupWindow
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import com.infomaniak.drive.R
import com.infomaniak.drive.data.cache.DriveInfosController
import com.infomaniak.drive.data.models.drive.Drive
import com.infomaniak.drive.databinding.FragmentBottomSheetSelectDriveBinding
import com.infomaniak.drive.databinding.PopupSelectUserBinding
import com.infomaniak.drive.ui.menu.UserAdapter
import com.infomaniak.drive.utils.AccountUtils
import com.infomaniak.drive.utils.setUserView
import com.infomaniak.drive.views.FullScreenBottomSheetDialog
import com.infomaniak.lib.core.models.user.User
import kotlinx.android.synthetic.main.fragment_bottom_sheet_select_drive.driveList
import kotlinx.android.synthetic.main.fragment_bottom_sheet_select_drive.toolbar
import kotlinx.android.synthetic.main.fragment_bottom_sheet_select_drive.userCardview
import kotlinx.android.synthetic.main.popup_select_user.view.usersRecyclerView
import com.infomaniak.lib.core.utils.safeBinding

class SelectDriveDialog : FullScreenBottomSheetDialog() {

private var binding: FragmentBottomSheetSelectDriveBinding by safeBinding()
private var popupLayoutBinding: PopupSelectUserBinding by safeBinding()

private val selectDriveViewModel: SelectDriveViewModel by activityViewModels()
private lateinit var popupLayout: View

private lateinit var popupWindow: PopupWindow

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
popupLayout = inflater.inflate(R.layout.popup_select_user, container, false)
return inflater.inflate(R.layout.fragment_bottom_sheet_select_drive, container, false)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
popupLayoutBinding = PopupSelectUserBinding.inflate(inflater, container, false)
return FragmentBottomSheetSelectDriveBinding.inflate(inflater, container, false).also { binding = it }.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) = with(selectDriveViewModel) {
super.onViewCreated(view, savedInstanceState)

toolbar.setNavigationOnClickListener { dismiss() }
binding.toolbar.setNavigationOnClickListener { dismiss() }

val driveListAdapter = DriveListAdapter(getDriveList(), false) { newSelectedDrive ->
selectedDrive.value = newSelectedDrive
dismiss()
}
driveList.adapter = driveListAdapter
binding.driveList.adapter = driveListAdapter

AccountUtils.getAllUsers().observe(viewLifecycleOwner) { users ->
if (users.size > 1) {
val selectedUser = users.find { it.id == selectedUserId.value } ?: users.first()
userCardview.setUserView(selectedUser) {
popupWindow = PopupWindow(popupLayout, userCardview.width, ViewGroup.LayoutParams.WRAP_CONTENT).apply {
binding.userCardview.root.setUserView(selectedUser) {
popupWindow = PopupWindow(
popupLayoutBinding.root,
binding.userCardview.root.width,
ViewGroup.LayoutParams.WRAP_CONTENT,
).apply {
isOutsideTouchable = true
isFocusable = true
elevation = 20.0f
showAsDropDown(userCardview)
showAsDropDown(binding.userCardview.root)
}
}
userCardview.isVisible = true
binding.userCardview.root.isVisible = true

popupLayout.usersRecyclerView.adapter = UserAdapter(users as ArrayList<User>, isCardview = false) { user ->
popupLayoutBinding.usersRecyclerView.adapter = UserAdapter(users as ArrayList<User>, isCardview = false) { user ->
selectedUserId.value = user.id
driveListAdapter.setDrives(getDriveList())

userCardview.setUserView(user) { popupWindow.showAsDropDown(userCardview) }
binding.userCardview.root.setUserView(user) { popupWindow.showAsDropDown(binding.userCardview.root) }

popupWindow.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,36 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.*
import com.infomaniak.drive.R
import com.infomaniak.drive.data.models.MediaFolder
import com.infomaniak.drive.databinding.FragmentBottomSheetSelectMediaFoldersBinding
import com.infomaniak.drive.utils.DrivePermissions
import com.infomaniak.drive.utils.IsComplete
import com.infomaniak.drive.utils.MediaFoldersProvider
import com.infomaniak.drive.views.FullScreenBottomSheetDialog
import com.infomaniak.drive.views.NoItemsLayoutView
import com.infomaniak.lib.core.utils.safeBinding
import com.infomaniak.lib.core.views.DividerItemDecorator
import io.realm.Realm
import kotlinx.android.synthetic.main.fragment_bottom_sheet_select_media_folders.mediaFolderList
import kotlinx.android.synthetic.main.fragment_bottom_sheet_select_media_folders.noMediaFolderLayout
import kotlinx.android.synthetic.main.fragment_bottom_sheet_select_media_folders.swipeRefreshLayout
import kotlinx.android.synthetic.main.fragment_bottom_sheet_select_media_folders.toolbar
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.runInterruptible

class SelectMediaFoldersDialog : FullScreenBottomSheetDialog(), NoItemsLayoutView.INoItemsLayoutView {

private var binding: FragmentBottomSheetSelectMediaFoldersBinding by safeBinding()

private val mediaViewModel: MediaViewModel by viewModels()
private lateinit var mediaFoldersAdapter: MediaFoldersAdapter

override val noItemsIcon = R.drawable.ic_folder_filled
override val noItemsTitle = R.string.noMediaFolderTitle
override val noItemsInitialListView: View by lazy { mediaFolderList }
override val noItemsInitialListView: View by lazy { binding.mediaFolderList }

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_bottom_sheet_select_media_folders, container, false)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return FragmentBottomSheetSelectMediaFoldersBinding.inflate(inflater, container, false).also { binding = it }.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) = with(binding) {
super.onViewCreated(view, savedInstanceState)

toolbar.setNavigationOnClickListener {
Expand All @@ -66,7 +66,7 @@ class SelectMediaFoldersDialog : FullScreenBottomSheetDialog(), NoItemsLayoutVie

swipeRefreshLayout.isEnabled = false

noMediaFolderLayout.iNoItemsLayoutView = this
noMediaFolderLayout.iNoItemsLayoutView = this@SelectMediaFoldersDialog

mediaFoldersAdapter = MediaFoldersAdapter { mediaFolder, isChecked ->
lifecycleScope.launch(Dispatchers.IO) {
Expand All @@ -84,7 +84,7 @@ class SelectMediaFoldersDialog : FullScreenBottomSheetDialog(), NoItemsLayoutVie
if (drivePermissions.checkWriteStoragePermission()) loadFolders()
}

private fun loadFolders() {
private fun loadFolders() = with(binding) {
swipeRefreshLayout.isRefreshing = true
mediaViewModel.elementsToRemove.observe(viewLifecycleOwner) { elementsToRemove ->
mediaFolderList.post {
Expand All @@ -103,7 +103,7 @@ class SelectMediaFoldersDialog : FullScreenBottomSheetDialog(), NoItemsLayoutVie
)
}
if (isComplete) {
swipeRefreshLayout?.isRefreshing = false
swipeRefreshLayout.isRefreshing = false
}
}
}
Expand Down
Loading