diff --git a/Core b/Core index bd8d927e4e..c3d20a3b9f 160000 --- a/Core +++ b/Core @@ -1 +1 @@ -Subproject commit bd8d927e4ea81990b81d871cbb04b6f9be970328 +Subproject commit c3d20a3b9f85572ef7b732b74279bfb13faa11d0 diff --git a/app/src/main/java/com/infomaniak/drive/data/models/File.kt b/app/src/main/java/com/infomaniak/drive/data/models/File.kt index 736ac56565..e3be8103a6 100644 --- a/app/src/main/java/com/infomaniak/drive/data/models/File.kt +++ b/app/src/main/java/com/infomaniak/drive/data/models/File.kt @@ -380,9 +380,11 @@ open class File( RECENT_TRASHED("desc", "deleted_at", R.string.sortRecent), SMALLER("asc", "files.size", R.string.sortSmaller), BIGGER("desc", "files.size", R.string.sortBigger), - //EXTENSION("asc", "extension", R.string.sortExtension); // TODO : Awaiting API + // EXTENSION("asc", "extension", R.string.sortExtension); // TODO: Awaiting API } + enum class SortTypeUsage { FILE_LIST, TRASH } + @Parcelize enum class FolderPermission( override val icon: Int, diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/FileListFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/FileListFragment.kt index cef37153fc..01f0a7a4b1 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/FileListFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/FileListFragment.kt @@ -47,6 +47,7 @@ import com.infomaniak.drive.data.api.ApiRepository import com.infomaniak.drive.data.api.ErrorCode.Companion.translateError import com.infomaniak.drive.data.cache.FileController import com.infomaniak.drive.data.models.* +import com.infomaniak.drive.data.models.File.* import com.infomaniak.drive.data.services.DownloadWorker import com.infomaniak.drive.data.services.MqttClientWrapper import com.infomaniak.drive.data.services.UploadWorker @@ -109,6 +110,7 @@ open class FileListFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener { protected open var hideBackButtonWhenRoot: Boolean = true protected open var showPendingFiles = true protected open var allowCancellation = true + protected var sortTypeUsage: SortTypeUsage? = null protected var userDrive: UserDrive? = null @@ -467,9 +469,9 @@ open class FileListFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener { } fileListViewModel.isListMode.value = UISettings(requireContext()).listMode - sortButton.setText(fileListViewModel.sortType.translation) - sortButton.setOnClickListener { - safeNavigate(R.id.sortFilesBottomSheetDialog, bundleOf("sortType" to fileListViewModel.sortType)) + sortButton.apply { + setText(fileListViewModel.sortType.translation) + setOnClickListener { navigateToSortFilesDialog() } } uploadFileInProgress.setUploadFileInProgress(R.string.uploadInThisFolderTitle) { @@ -477,6 +479,15 @@ open class FileListFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener { } } + private fun navigateToSortFilesDialog() { + safeNavigate( + R.id.sortFilesBottomSheetDialog, + bundleOf("sortType" to fileListViewModel.sortType).apply { + sortTypeUsage?.let { putSerializable("sortTypeUsage", it) } + } + ) + } + protected open fun setupFileAdapter() { mainViewModel.isInternetAvailable.observe(viewLifecycleOwner) { isInternetAvailable -> fileAdapter.toggleOfflineMode(requireContext(), !isInternetAvailable) @@ -796,7 +807,7 @@ open class FileListFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener { private inner class SortFiles : () -> Unit { override fun invoke() { - getBackNavigationResult(SORT_TYPE_OPTION_KEY) { newSortType -> + getBackNavigationResult(SORT_TYPE_OPTION_KEY) { newSortType -> fileListViewModel.sortType = newSortType sortButton?.setText(fileListViewModel.sortType.translation) diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/SortFilesBottomSheetAdapter.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/SortFilesBottomSheetAdapter.kt index e007feb30f..61121e1346 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/SortFilesBottomSheetAdapter.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/SortFilesBottomSheetAdapter.kt @@ -22,13 +22,15 @@ import android.view.ViewGroup import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import com.infomaniak.drive.R -import com.infomaniak.drive.data.models.File +import com.infomaniak.drive.data.models.File.SortType +import com.infomaniak.drive.data.models.File.SortTypeUsage import com.infomaniak.lib.core.views.ViewHolder import kotlinx.android.synthetic.main.item_select_bottom_sheet.view.* class SortFilesBottomSheetAdapter( - private val selectedSortType: File.SortType, - private val onItemClicked: (sortType: File.SortType) -> Unit + private val selectedType: SortType, + private val usage: SortTypeUsage, + private val onItemClicked: (sortType: SortType) -> Unit ) : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { @@ -36,14 +38,29 @@ class SortFilesBottomSheetAdapter( } override fun onBindViewHolder(holder: ViewHolder, position: Int) { - File.SortType.values()[position].let { sortType -> + usage.types()[position].let { sortType -> holder.itemView.apply { itemSelectText.setText(sortType.translation) - itemSelectActiveIcon.isVisible = selectedSortType == sortType + itemSelectActiveIcon.isVisible = selectedType == sortType setOnClickListener { onItemClicked(sortType) } } } } - override fun getItemCount() = File.SortType.values().size -} \ No newline at end of file + override fun getItemCount() = usage.types().size + + private fun SortTypeUsage.types(): Array { + return when (this) { + SortTypeUsage.FILE_LIST -> SortType.values().fileListTypes() + SortTypeUsage.TRASH -> SortType.values().trashTypes() + } + } + + private fun Array.fileListTypes(): Array { + return filter { it != SortType.OLDER_TRASHED && it != SortType.RECENT_TRASHED }.toTypedArray() + } + + private fun Array.trashTypes(): Array { + return filter { it != SortType.OLDER && it != SortType.RECENT }.toTypedArray() + } +} diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/SortFilesBottomSheetDialog.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/SortFilesBottomSheetDialog.kt index 89f5570daa..85d9d1e20d 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/SortFilesBottomSheetDialog.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/SortFilesBottomSheetDialog.kt @@ -21,7 +21,7 @@ import android.os.Bundle import android.view.View import androidx.navigation.fragment.navArgs import com.infomaniak.drive.R -import com.infomaniak.drive.data.models.File +import com.infomaniak.drive.data.models.File.SortType import com.infomaniak.drive.utils.setBackNavigationResult import com.infomaniak.drive.views.SelectBottomSheetDialog import kotlinx.android.synthetic.main.fragment_bottom_sheet_select.* @@ -30,17 +30,13 @@ class SortFilesBottomSheetDialog : SelectBottomSheetDialog() { private val navigationArgs: SortFilesBottomSheetDialogArgs by navArgs() - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + override fun onViewCreated(view: View, savedInstanceState: Bundle?) = with(navigationArgs) { super.onViewCreated(view, savedInstanceState) - selectTitle.setText(R.string.sortTitle) - - selectRecyclerView.adapter = SortFilesBottomSheetAdapter(navigationArgs.sortType) { - onSortTypeClicked(it) - } + selectRecyclerView.adapter = SortFilesBottomSheetAdapter(sortType, sortTypeUsage) { onSortTypeClicked(it) } } - private fun onSortTypeClicked(sortType: File.SortType) { + private fun onSortTypeClicked(sortType: SortType) { setBackNavigationResult(FileListFragment.SORT_TYPE_OPTION_KEY, sortType) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/infomaniak/drive/ui/menu/TrashFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/menu/TrashFragment.kt index 30282f3da8..bd2640eb6b 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/menu/TrashFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/menu/TrashFragment.kt @@ -24,6 +24,8 @@ import androidx.navigation.navGraphViewModels import com.infomaniak.drive.R import com.infomaniak.drive.data.api.ErrorCode.Companion.translateError import com.infomaniak.drive.data.models.File +import com.infomaniak.drive.data.models.File.SortType +import com.infomaniak.drive.data.models.File.SortTypeUsage import com.infomaniak.drive.utils.* import com.infomaniak.drive.utils.Utils.ROOT_ID import kotlinx.android.synthetic.main.fragment_file_list.* @@ -33,7 +35,8 @@ class TrashFragment : FileSubTypeListFragment() { val trashViewModel: TrashViewModel by navGraphViewModels(R.id.trashFragment) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - fileListViewModel.sortType = File.SortType.RECENT_TRASHED + sortTypeUsage = SortTypeUsage.TRASH + fileListViewModel.sortType = SortType.RECENT_TRASHED sortFiles = SortFiles() downloadFiles = DownloadFiles( @@ -98,10 +101,10 @@ class TrashFragment : FileSubTypeListFragment() { private inner class SortFiles : () -> Unit { override fun invoke() { - getBackNavigationResult(SORT_TYPE_OPTION_KEY) { newSortType -> + getBackNavigationResult(SORT_TYPE_OPTION_KEY) { newSortType -> fileListViewModel.sortType = when (newSortType) { - File.SortType.OLDER -> File.SortType.OLDER_TRASHED - File.SortType.RECENT -> File.SortType.RECENT_TRASHED + SortType.OLDER -> SortType.OLDER_TRASHED + SortType.RECENT -> SortType.RECENT_TRASHED else -> newSortType } sortButton.setText(fileListViewModel.sortType.translation) diff --git a/app/src/main/res/layout/item_select_bottom_sheet.xml b/app/src/main/res/layout/item_select_bottom_sheet.xml index ef13473d7e..4a948eae32 100644 --- a/app/src/main/res/layout/item_select_bottom_sheet.xml +++ b/app/src/main/res/layout/item_select_bottom_sheet.xml @@ -20,7 +20,8 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="@dimen/buttonHeight" - android:background="?selectableItemBackground"> + android:background="?selectableItemBackground" + tools:context=".ui.fileList.SortFilesBottomSheetDialog"> - \ No newline at end of file + diff --git a/app/src/main/res/navigation/main_navigation.xml b/app/src/main/res/navigation/main_navigation.xml index 445840938f..c98e6c5159 100644 --- a/app/src/main/res/navigation/main_navigation.xml +++ b/app/src/main/res/navigation/main_navigation.xml @@ -385,6 +385,10 @@ android:name="sortType" android:defaultValue="NAME_AZ" app:argType="com.infomaniak.drive.data.models.File$SortType" /> + +