diff --git a/CHANGELOG.md b/CHANGELOG.md index 511b35c..10c643d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,17 @@ +## v1.0.0-beta-8 (25.05.2024) +* Sorting feature added for file and media items +* The synchronization issue with the show hidden files setting button has been fixed + ## v1.0.0-beta7 (26.04.2024) -* ActivityNotFoundException and ClassNotFoundException fixed. +* ActivityNotFoundException and ClassNotFoundException fixed ## v1.0.0-beta6 (24.04.2024) * The "Rename" feature added. * Dialogs UI improvement * The issue of license URLs redirecting to the wrong address fixed -* The 'Access Denied' error in the function calculating file count and size fixed. +* The 'Access Denied' error in the function calculating file count and size fixed ## v1.0.0-beta5 (08.04.2024) diff --git a/app/build.gradle b/app/build.gradle index 483dec5..9190ba0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,8 +39,8 @@ android { applicationId "com.sn.snfilemanager" minSdk 26 targetSdk 34 - versionCode 7 - versionName "1.0.0-beta7" + versionCode 8 + versionName "1.0.0-beta8" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/sn/snfilemanager/MainViewModel.kt b/app/src/main/java/com/sn/snfilemanager/MainViewModel.kt index 3764c51..b8f32e9 100644 --- a/app/src/main/java/com/sn/snfilemanager/MainViewModel.kt +++ b/app/src/main/java/com/sn/snfilemanager/MainViewModel.kt @@ -3,7 +3,10 @@ package com.sn.snfilemanager import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import com.sn.snfilemanager.core.util.Config import com.sn.snfilemanager.core.util.Event +import com.sn.snfilemanager.core.util.SortCriterion +import com.sn.snfilemanager.core.util.SortOrder import com.sn.snfilemanager.providers.preferences.MySharedPreferences import com.sn.snfilemanager.providers.preferences.PrefsTag import dagger.hilt.android.lifecycle.HiltViewModel @@ -20,10 +23,24 @@ class MainViewModel init { checkFirsRun() + getSortData() } private fun checkFirsRun() { val firstRun: Boolean = mySharedPreferences.getBoolean(PrefsTag.FIRST_RUN) _firstRunLiveData.postValue(Event(firstRun)) } + + private fun getSortData() { + val criterionString = mySharedPreferences.getString(PrefsTag.SORT_CRITERION) + val sortOrderString = mySharedPreferences.getString(PrefsTag.SORT_ORDER) + val mediaCriterionString = mySharedPreferences.getString(PrefsTag.MEDIA_SORT_CRITERION) + val mediaSortOrderString = mySharedPreferences.getString(PrefsTag.MEDIA_SORT_ORDER) + + Config.sortCriterion = SortCriterion.valueOf(criterionString ?: SortCriterion.NAME.name) + Config.sortOrder = SortOrder.valueOf(sortOrderString ?: SortOrder.ASCENDING.name) + + Config.mediaSortCriterion = SortCriterion.valueOf(mediaCriterionString ?: SortCriterion.NAME.name) + Config.mediaSortOrder = SortOrder.valueOf(mediaSortOrderString ?: SortOrder.ASCENDING.name) + } } diff --git a/app/src/main/java/com/sn/snfilemanager/core/extensions/String.kt b/app/src/main/java/com/sn/snfilemanager/core/extensions/String.kt index 17238d9..ab1ab3b 100644 --- a/app/src/main/java/com/sn/snfilemanager/core/extensions/String.kt +++ b/app/src/main/java/com/sn/snfilemanager/core/extensions/String.kt @@ -1,6 +1,9 @@ package com.sn.snfilemanager.core.extensions import android.webkit.MimeTypeMap +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale fun String.getDirectoryNameFromPath(): String { val lastSeparatorIndex = this.lastIndexOf("/") @@ -24,3 +27,11 @@ fun String.getMimeType(): String? { val ext = if (extension.isNullOrEmpty()) this.getFileExtension() else extension return MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext) } + +fun String.toDate(format: String = "dd/MM/yyyy"): Date? { + return try { + SimpleDateFormat(format, Locale.getDefault()).parse(this) + } catch (e: Exception) { + null + } +} diff --git a/app/src/main/java/com/sn/snfilemanager/core/util/Config.kt b/app/src/main/java/com/sn/snfilemanager/core/util/Config.kt index 94655e3..e4d6759 100644 --- a/app/src/main/java/com/sn/snfilemanager/core/util/Config.kt +++ b/app/src/main/java/com/sn/snfilemanager/core/util/Config.kt @@ -2,4 +2,8 @@ package com.sn.snfilemanager.core.util object Config { var hiddenFile: Boolean = false + var sortCriterion: SortCriterion = SortCriterion.NAME + var sortOrder: SortOrder = SortOrder.ASCENDING + var mediaSortCriterion: SortCriterion = SortCriterion.NAME + var mediaSortOrder: SortOrder = SortOrder.ASCENDING } diff --git a/app/src/main/java/com/sn/snfilemanager/core/util/SortCriterion.kt b/app/src/main/java/com/sn/snfilemanager/core/util/SortCriterion.kt new file mode 100644 index 0000000..1736163 --- /dev/null +++ b/app/src/main/java/com/sn/snfilemanager/core/util/SortCriterion.kt @@ -0,0 +1,6 @@ +package com.sn.snfilemanager.core.util + +enum class SortCriterion { + NAME, + LAST_MODIFIED, +} diff --git a/app/src/main/java/com/sn/snfilemanager/core/util/SortOrder.kt b/app/src/main/java/com/sn/snfilemanager/core/util/SortOrder.kt new file mode 100644 index 0000000..66c2307 --- /dev/null +++ b/app/src/main/java/com/sn/snfilemanager/core/util/SortOrder.kt @@ -0,0 +1,6 @@ +package com.sn.snfilemanager.core.util + +enum class SortOrder { + ASCENDING, + DESCENDING, +} diff --git a/app/src/main/java/com/sn/snfilemanager/feature/files/presentation/FilesListFragment.kt b/app/src/main/java/com/sn/snfilemanager/feature/files/presentation/FilesListFragment.kt index 83a13ac..2736ad3 100644 --- a/app/src/main/java/com/sn/snfilemanager/feature/files/presentation/FilesListFragment.kt +++ b/app/src/main/java/com/sn/snfilemanager/feature/files/presentation/FilesListFragment.kt @@ -21,6 +21,8 @@ import com.sn.snfilemanager.core.extensions.openFileWithOtherApp import com.sn.snfilemanager.core.extensions.shareFiles import com.sn.snfilemanager.core.extensions.visible import com.sn.snfilemanager.core.extensions.warningToast +import com.sn.snfilemanager.core.util.Config.sortCriterion +import com.sn.snfilemanager.core.util.Config.sortOrder import com.sn.snfilemanager.core.util.RootPath import com.sn.snfilemanager.databinding.FragmentFilesListBinding import com.sn.snfilemanager.feature.files.adapter.FileItemAdapter @@ -37,6 +39,7 @@ import com.sn.snfilemanager.view.dialog.ConflictDialog import com.sn.snfilemanager.view.dialog.CreateDirectoryDialog import com.sn.snfilemanager.view.dialog.RenameFileDialog import com.sn.snfilemanager.view.dialog.detail.DetailDialog +import com.sn.snfilemanager.view.dialog.sort.SortDialog import dagger.hilt.android.AndroidEntryPoint import java.io.File import java.nio.file.Files @@ -68,6 +71,11 @@ class FilesListFragment : true } + R.id.sort -> { + showSortDialog() + true + } + R.id.create_folder -> { viewModel.currentPath?.let { path -> showCreateDirectoryDialog(path) @@ -188,7 +196,10 @@ class FilesListFragment : JobType.CREATE -> { activity?.runOnUiThread { data?.filterIsInstance()?.firstOrNull()?.toFileModel()?.let { file -> - adapter?.addItem(file) + // adapter?.addItem(file) + viewModel.currentPath?.let { path -> + viewModel.getFilesList(path) + } } } } @@ -196,7 +207,10 @@ class FilesListFragment : JobType.RENAME -> { activity?.runOnUiThread { data?.filterIsInstance()?.firstOrNull()?.let { file -> - adapter?.updateItem(file) + // adapter?.updateItem(file) + viewModel.currentPath?.let { path -> + viewModel.getFilesList(path) + } } } } @@ -379,6 +393,14 @@ class FilesListFragment : }).showDialog(childFragmentManager) } + private fun showSortDialog() { + SortDialog(isMedia = false, onConfirm = { sortData -> + sortCriterion = sortData.first + sortOrder = sortData.second + with(viewModel) { currentPath?.let { getFilesList(it) } } + }).showDialog(childFragmentManager) + } + private fun showRenameDialog() { RenameFileDialog(file = viewModel.getSelectedItem().first(), onRename = { newName -> viewModel.renameFile(newName) diff --git a/app/src/main/java/com/sn/snfilemanager/feature/files/presentation/FilesListViewModel.kt b/app/src/main/java/com/sn/snfilemanager/feature/files/presentation/FilesListViewModel.kt index 8ff4aa0..2900d8d 100644 --- a/app/src/main/java/com/sn/snfilemanager/feature/files/presentation/FilesListViewModel.kt +++ b/app/src/main/java/com/sn/snfilemanager/feature/files/presentation/FilesListViewModel.kt @@ -9,9 +9,14 @@ import androidx.lifecycle.viewModelScope import com.sn.mediastorepv.data.ConflictStrategy import com.sn.mediastorepv.data.MediaType import com.sn.snfilemanager.core.base.BaseResult +import com.sn.snfilemanager.core.extensions.toDate import com.sn.snfilemanager.core.util.Config +import com.sn.snfilemanager.core.util.Config.sortCriterion +import com.sn.snfilemanager.core.util.Config.sortOrder import com.sn.snfilemanager.core.util.Event import com.sn.snfilemanager.core.util.RootPath +import com.sn.snfilemanager.core.util.SortCriterion +import com.sn.snfilemanager.core.util.SortOrder import com.sn.snfilemanager.feature.files.data.FileModel import com.sn.snfilemanager.feature.files.data.toFileModel import com.sn.snfilemanager.providers.filepath.FilePathProvider @@ -28,6 +33,7 @@ import java.lang.Long.min import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths +import java.util.Locale import javax.inject.Inject @HiltViewModel @@ -73,7 +79,8 @@ class FilesListViewModel private val _startCreateFolderJob: MutableLiveData> = MutableLiveData() val startCreateFolderJob: LiveData> = _startCreateFolderJob - private val _startRenameFileJob: MutableLiveData>> = MutableLiveData() + private val _startRenameFileJob: MutableLiveData>> = + MutableLiveData() val startRenameFileJob: LiveData>> = _startRenameFileJob var conflictDialogDeferred = CompletableDeferred>() @@ -153,15 +160,13 @@ class FilesListViewModel .limit(currentBatchSize) .forEach { file -> if (Files.isReadable(file) && ( - Config.hiddenFile || - !Files.isHidden( - file, - ) + Config.hiddenFile || !Files.isHidden(file) ) ) { fileList.add(file.toFileModel()) } } + sortFileList(fileList) } withContext(Dispatchers.Main) { _updateListLiveData.postValue(Event(fileList)) @@ -171,10 +176,6 @@ class FilesListViewModel } } - fun setUpdateList(files: MutableList) { - _updateListLiveData.postValue(Event(files)) - } - fun cancelFileListJob() { if (fileListJob != null && fileListJob?.isActive == true) { fileListJob?.cancel() @@ -222,7 +223,9 @@ class FilesListViewModel } } job.await() - _startMoveJobLiveData.postValue(Event(Pair(operationItemList, destinationPath))) + if (operationItemList.isNotEmpty()) { + _startMoveJobLiveData.postValue(Event(Pair(operationItemList, destinationPath))) + } } } @@ -247,6 +250,26 @@ class FilesListViewModel _startDeleteJobLiveData.postValue(Event(operationItemList)) } + private fun sortFileList(fileList: MutableList) { + when (sortCriterion) { + SortCriterion.NAME -> { + if (sortOrder == SortOrder.ASCENDING) { + fileList.sortBy { it.name.lowercase(Locale.getDefault()) } + } else { + fileList.sortByDescending { it.name.lowercase(Locale.getDefault()) } + } + } + + SortCriterion.LAST_MODIFIED -> { + if (sortOrder == SortOrder.ASCENDING) { + fileList.sortBy { it.lastModified.toDate() } + } else { + fileList.sortByDescending { it.lastModified.toDate() } + } + } + } + } + private fun removeSearchCallback() { searchRunnable?.let { handler.removeCallbacks(it) } } diff --git a/app/src/main/java/com/sn/snfilemanager/feature/media/presentation/MediaFragment.kt b/app/src/main/java/com/sn/snfilemanager/feature/media/presentation/MediaFragment.kt index ecbb9be..9b1cbc3 100644 --- a/app/src/main/java/com/sn/snfilemanager/feature/media/presentation/MediaFragment.kt +++ b/app/src/main/java/com/sn/snfilemanager/feature/media/presentation/MediaFragment.kt @@ -17,6 +17,8 @@ import com.sn.snfilemanager.core.extensions.openFile import com.sn.snfilemanager.core.extensions.openFileWithOtherApp import com.sn.snfilemanager.core.extensions.shareFiles import com.sn.snfilemanager.core.extensions.warningToast +import com.sn.snfilemanager.core.util.Config.mediaSortCriterion +import com.sn.snfilemanager.core.util.Config.mediaSortOrder import com.sn.snfilemanager.core.util.DocumentType import com.sn.snfilemanager.databinding.FragmentMediaBinding import com.sn.snfilemanager.feature.media.adapter.MediaItemAdapter @@ -29,6 +31,7 @@ import com.sn.snfilemanager.view.dialog.ConflictDialog import com.sn.snfilemanager.view.dialog.FilterBottomSheetDialog import com.sn.snfilemanager.view.dialog.RenameFileDialog import com.sn.snfilemanager.view.dialog.detail.DetailDialog +import com.sn.snfilemanager.view.dialog.sort.SortDialog import dagger.hilt.android.AndroidEntryPoint import java.nio.file.Path import java.nio.file.Paths @@ -65,6 +68,10 @@ class MediaFragment : true } + R.id.sort -> { + showSortDialog() + true + } else -> super.onMenuItemSelected(menuItemId) } @@ -192,6 +199,7 @@ class MediaFragment : observe(getMediaLiveData) { event -> event.getContentIfNotHandled()?.let { data -> adapter?.setItems(data.toMutableList()) + binding.recyclerView.scrollToPosition(0) } } observe(conflictQuestionLiveData) { event -> @@ -238,6 +246,16 @@ class MediaFragment : context?.shareFiles(uris) } + private fun showSortDialog() { + SortDialog(isMedia = true, onConfirm = { sortData -> + with(viewModel) { + mediaSortCriterion = sortData.first + mediaSortOrder = sortData.second + getMedia() + } + }).showDialog(childFragmentManager) + } + private fun actionDelete() { ConfirmationDialog( getString(R.string.are_you_sure), diff --git a/app/src/main/java/com/sn/snfilemanager/feature/media/presentation/MediaViewModel.kt b/app/src/main/java/com/sn/snfilemanager/feature/media/presentation/MediaViewModel.kt index c823b55..1af2fc8 100644 --- a/app/src/main/java/com/sn/snfilemanager/feature/media/presentation/MediaViewModel.kt +++ b/app/src/main/java/com/sn/snfilemanager/feature/media/presentation/MediaViewModel.kt @@ -8,10 +8,15 @@ import androidx.lifecycle.viewModelScope import com.sn.mediastorepv.data.ConflictStrategy import com.sn.mediastorepv.data.Media import com.sn.mediastorepv.data.MediaType +import com.sn.mediastorepv.data.OrderStrategy import com.sn.snfilemanager.core.base.BaseResult +import com.sn.snfilemanager.core.util.Config.mediaSortCriterion +import com.sn.snfilemanager.core.util.Config.mediaSortOrder import com.sn.snfilemanager.core.util.DocumentType import com.sn.snfilemanager.core.util.Event import com.sn.snfilemanager.core.util.MimeTypes +import com.sn.snfilemanager.core.util.SortCriterion +import com.sn.snfilemanager.core.util.SortOrder import com.sn.snfilemanager.providers.mediastore.MediaStoreProvider import com.sn.snfilemanager.providers.preferences.MySharedPreferences import com.sn.snfilemanager.providers.preferences.PrefsTag @@ -83,11 +88,31 @@ class MediaViewModel } } + private fun getOrderStrategy(): String { + return when (mediaSortCriterion) { + SortCriterion.NAME -> { + if (mediaSortOrder == SortOrder.ASCENDING) { + OrderStrategy.name(OrderStrategy.ASC) + } else { + OrderStrategy.name(OrderStrategy.DESC) + } + } + + SortCriterion.LAST_MODIFIED -> { + if (mediaSortOrder == SortOrder.ASCENDING) { + OrderStrategy.dateModified(OrderStrategy.ASC) + } else { + OrderStrategy.dateModified(OrderStrategy.DESC) + } + } + } + } + fun getMedia() = viewModelScope.launch { val filteredMediaTypes: MutableSet? = getFilteredMediaTypes() mediaType?.let { - when (val result = mediaStoreProvider.getMedia(it, getDocumentMime())) { + when (val result = mediaStoreProvider.getMedia(it, getDocumentMime(), order = getOrderStrategy())) { is BaseResult.Success -> { fullMediaList = result.data fullMediaList?.let { mediaList -> @@ -147,7 +172,9 @@ class MediaViewModel } } job.await() - _startMoveJobLiveData.postValue(Event(Pair(operationItemList, destinationPath))) + if (operationItemList.isNotEmpty()) { + _startMoveJobLiveData.postValue(Event(Pair(operationItemList, destinationPath))) + } } } diff --git a/app/src/main/java/com/sn/snfilemanager/providers/mediastore/MediaStoreProvider.kt b/app/src/main/java/com/sn/snfilemanager/providers/mediastore/MediaStoreProvider.kt index ff4a9af..f83ebed 100644 --- a/app/src/main/java/com/sn/snfilemanager/providers/mediastore/MediaStoreProvider.kt +++ b/app/src/main/java/com/sn/snfilemanager/providers/mediastore/MediaStoreProvider.kt @@ -2,6 +2,7 @@ package com.sn.snfilemanager.providers.mediastore import com.sn.mediastorepv.MediaStoreBuilder import com.sn.mediastorepv.data.Media +import com.sn.mediastorepv.data.MediaSelectionData import com.sn.mediastorepv.data.MediaType import com.sn.snfilemanager.core.base.BaseResult import kotlinx.coroutines.Dispatchers @@ -14,10 +15,14 @@ class MediaStoreProvider suspend fun getMedia( mediaType: MediaType, ext: List?, + order: String?, ): BaseResult> { return try { withContext(Dispatchers.IO) { - val result = mediaStoreBuilder.setExtCheck(ext).build().getMedia(mediaType) + val result = + mediaStoreBuilder + .setMediaSelectionData(MediaSelectionData(sortOrder = order)) + .setExtCheck(ext).build().getMedia(mediaType) BaseResult.Success(result) } } catch (e: Exception) { diff --git a/app/src/main/java/com/sn/snfilemanager/providers/preferences/PreferencesProvider.kt b/app/src/main/java/com/sn/snfilemanager/providers/preferences/PreferencesProvider.kt index 8698eec..5326a88 100644 --- a/app/src/main/java/com/sn/snfilemanager/providers/preferences/PreferencesProvider.kt +++ b/app/src/main/java/com/sn/snfilemanager/providers/preferences/PreferencesProvider.kt @@ -14,9 +14,13 @@ enum class PrefsTag(val tag: String) { FILTER_VIDEOS("FILTER_VIDEOS"), FILTER_AUDIOS("FILTER_AUDIOS"), FILTER_DOCUMENTS("FILTER_DOCUMENTS"), + FILTER_ARCHIVES("FILTER_ARCHIVES"), PERMISSION_STORAGE("PERMISSION_STORAGE"), PERMISSION_NOTIFICATION("PERMISSION_NOTIFICATION"), - FILTER_ARCHIVES("FILTER_ARCHIVES"), + SORT_CRITERION("SORT_CRITERION"), + SORT_ORDER("SORT_ORDER"), + MEDIA_SORT_CRITERION("MEDIA_SORT_CRITERION"), + MEDIA_SORT_ORDER("MEDIA_SORT_ORDER"), } @Singleton @@ -42,7 +46,7 @@ class MySharedPreferences data: String, ) = prefs.edit().putString(prefsTag.tag, data).apply() - fun getString(prefsTag: PrefsTag): String? = prefs.getString(prefsTag.tag, "") + fun getString(prefsTag: PrefsTag): String? = prefs.getString(prefsTag.tag, null) fun putStringArray( prefsTag: PrefsTag, diff --git a/app/src/main/java/com/sn/snfilemanager/view/dialog/sort/SortDialog.kt b/app/src/main/java/com/sn/snfilemanager/view/dialog/sort/SortDialog.kt new file mode 100644 index 0000000..9cb0fce --- /dev/null +++ b/app/src/main/java/com/sn/snfilemanager/view/dialog/sort/SortDialog.kt @@ -0,0 +1,85 @@ +package com.sn.snfilemanager.view.dialog.sort + +import androidx.fragment.app.viewModels +import com.sn.snfilemanager.R +import com.sn.snfilemanager.core.base.BaseDialog +import com.sn.snfilemanager.core.extensions.click +import com.sn.snfilemanager.core.util.SortCriterion +import com.sn.snfilemanager.core.util.SortOrder +import com.sn.snfilemanager.databinding.DialogSortBinding +import dagger.hilt.android.AndroidEntryPoint + +@AndroidEntryPoint +class SortDialog( + private var isMedia: Boolean = false, + private val onConfirm: ((Pair) -> Unit)? = null, +) : BaseDialog() { + override fun getViewBinding() = DialogSortBinding.inflate(layoutInflater) + + override val dialogTag: String + get() = "SORT_DIALOG" + + private val vm: SortDialogViewModel by viewModels() + private var criterion = SortCriterion.NAME + private var sortOrder = SortOrder.ASCENDING + + override fun setupViews() { + setPrefsTag() + initFirstValues() + initRadioGroupListener() + initButtonListener() + } + + private fun setPrefsTag() { + vm.setPrefsTag(isMedia) + } + + private fun initFirstValues() { + val (loadedCriterion, loadedSortOrder) = vm.getSortData() + criterion = loadedCriterion + sortOrder = loadedSortOrder + + with(binding) { + when (criterion) { + SortCriterion.NAME -> rbName.isChecked = true + SortCriterion.LAST_MODIFIED -> rbModified.isChecked = true + } + when (sortOrder) { + SortOrder.ASCENDING -> rbAscending.isChecked = true + SortOrder.DESCENDING -> rbDescending.isChecked = true + } + } + } + + private fun initRadioGroupListener() { + with(binding) { + rgCriteria.setOnCheckedChangeListener { _, checkedId -> + criterion = + when (checkedId) { + R.id.rb_name -> SortCriterion.NAME + R.id.rb_modified -> SortCriterion.LAST_MODIFIED + else -> criterion + } + } + rgSortOrder.setOnCheckedChangeListener { _, checkedId -> + sortOrder = + when (checkedId) { + R.id.rb_ascending -> SortOrder.ASCENDING + R.id.rb_descending -> SortOrder.DESCENDING + else -> sortOrder + } + } + } + } + + private fun initButtonListener() { + with(binding) { + btnCancel.click { dismiss() } + btnConfirm.click { + vm.putSortData(criterion, sortOrder) + onConfirm?.invoke(Pair(criterion, sortOrder)) + dismiss() + } + } + } +} diff --git a/app/src/main/java/com/sn/snfilemanager/view/dialog/sort/SortDialogViewModel.kt b/app/src/main/java/com/sn/snfilemanager/view/dialog/sort/SortDialogViewModel.kt new file mode 100644 index 0000000..4afaa53 --- /dev/null +++ b/app/src/main/java/com/sn/snfilemanager/view/dialog/sort/SortDialogViewModel.kt @@ -0,0 +1,45 @@ +package com.sn.snfilemanager.view.dialog.sort + +import androidx.lifecycle.ViewModel +import com.sn.snfilemanager.core.util.SortCriterion +import com.sn.snfilemanager.core.util.SortOrder +import com.sn.snfilemanager.providers.preferences.MySharedPreferences +import com.sn.snfilemanager.providers.preferences.PrefsTag +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +@HiltViewModel +class SortDialogViewModel + @Inject + constructor( + private val sharedPreferences: MySharedPreferences, + ) : ViewModel() { + private lateinit var tags: Pair + + fun setPrefsTag(isMedia: Boolean) { + tags = + if (isMedia) { + PrefsTag.MEDIA_SORT_CRITERION to PrefsTag.MEDIA_SORT_ORDER + } else { + PrefsTag.SORT_CRITERION to PrefsTag.SORT_ORDER + } + } + + fun putSortData( + criterion: SortCriterion, + sortOrder: SortOrder, + ) { + sharedPreferences.putString(tags.first, criterion.name) + sharedPreferences.putString(tags.second, sortOrder.name) + } + + fun getSortData(): Pair { + val criterionString = sharedPreferences.getString(tags.first) + val sortOrderString = sharedPreferences.getString(tags.second) + + val criterion = SortCriterion.valueOf(criterionString ?: SortCriterion.NAME.name) + val sortOrder = SortOrder.valueOf(sortOrderString ?: SortOrder.ASCENDING.name) + + return Pair(criterion, sortOrder) + } + } diff --git a/app/src/main/res/drawable/ic_sort.xml b/app/src/main/res/drawable/ic_sort.xml new file mode 100644 index 0000000..51a6902 --- /dev/null +++ b/app/src/main/res/drawable/ic_sort.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/layout/dialog_sort.xml b/app/src/main/res/layout/dialog_sort.xml new file mode 100644 index 0000000..0f7cf3c --- /dev/null +++ b/app/src/main/res/layout/dialog_sort.xml @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_base.xml b/app/src/main/res/menu/menu_base.xml index 770f5ac..2f680e6 100644 --- a/app/src/main/res/menu/menu_base.xml +++ b/app/src/main/res/menu/menu_base.xml @@ -9,4 +9,10 @@ app:showAsAction="always|collapseActionView" app:actionViewClass="androidx.appcompat.widget.SearchView"/> + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_files.xml b/app/src/main/res/menu/menu_files.xml index d744562..91aeb55 100644 --- a/app/src/main/res/menu/menu_files.xml +++ b/app/src/main/res/menu/menu_files.xml @@ -11,6 +11,12 @@ app:showAsAction="always|collapseActionView" tools:ignore="AlwaysShowAction" /> + + + + Paylaş Detay Atla - İkisinide sakla + İkisinide tut Üstüne yaz Hepsine uygula Evet @@ -109,4 +109,8 @@ Uzantıyı değiştirmek dosyanın kullanılamaz hale gelmesine neden olabilir Mevcut dosya adını girdiniz Bu isimde dosya zaten mevcut + Sırala + Sıralama ölçütü + Artan + Azalan \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fb1373e..dfb2919 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -113,4 +113,8 @@ Changing the extension may cause the file to become unusable "You entered the current file name" The file with this name already exists + Sort + Sort by + Ascending + Descending \ No newline at end of file diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 69614a4..f0634ac 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -31,7 +31,7 @@ android:layout="@layout/item_switch_preference" android:summaryOff="@string/hidden_file_off" android:title="@string/hidden_file" - app:defaultValue="true" + app:defaultValue="false" app:key="sn.hidden.file" app:summaryOn="@string/hidden_file_on" /> diff --git a/mediastorepv b/mediastorepv index 4a38a15..20bf6eb 160000 --- a/mediastorepv +++ b/mediastorepv @@ -1 +1 @@ -Subproject commit 4a38a153e00ac4ca701debde26fece1082eedd70 +Subproject commit 20bf6ebf72bbfd3cc48632de05ae363063b04dfc