mirror of
				https://github.com/SimpleMobileTools/Simple-File-Manager.git
				synced 2025-06-05 22:09:15 +02:00 
			
		
		
		
	add some initial sorting related things
This commit is contained in:
		| @@ -32,7 +32,7 @@ android { | |||||||
| } | } | ||||||
|  |  | ||||||
| dependencies { | dependencies { | ||||||
|     compile 'com.simplemobiletools:commons:2.13.0' |     compile 'com.simplemobiletools:commons:2.13.5' | ||||||
|     compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' |     compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' | ||||||
|     compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" |     compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||||||
| } | } | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ package com.simplemobiletools.filemanager | |||||||
| import android.content.Context | import android.content.Context | ||||||
| import com.simplemobiletools.commons.extensions.getInternalStoragePath | import com.simplemobiletools.commons.extensions.getInternalStoragePath | ||||||
| import com.simplemobiletools.commons.helpers.BaseConfig | import com.simplemobiletools.commons.helpers.BaseConfig | ||||||
|  | import com.simplemobiletools.commons.helpers.SORT_BY_NAME | ||||||
| import java.io.File | import java.io.File | ||||||
| import java.util.* | import java.util.* | ||||||
|  |  | ||||||
| @@ -40,4 +41,24 @@ class Config(context: Context) : BaseConfig(context) { | |||||||
|     var favorites: MutableSet<String> |     var favorites: MutableSet<String> | ||||||
|         get() = prefs.getStringSet(FAVORITES, HashSet<String>()) |         get() = prefs.getStringSet(FAVORITES, HashSet<String>()) | ||||||
|         set(favorites) = prefs.edit().remove(FAVORITES).putStringSet(FAVORITES, favorites).apply() |         set(favorites) = prefs.edit().remove(FAVORITES).putStringSet(FAVORITES, favorites).apply() | ||||||
|  |  | ||||||
|  |     var sorting: Int | ||||||
|  |         get() = prefs.getInt(SORT_ORDER, SORT_BY_NAME) | ||||||
|  |         set(sorting) = prefs.edit().putInt(SORT_ORDER, sorting).apply() | ||||||
|  |  | ||||||
|  |     fun saveFolderSorting(path: String, value: Int) { | ||||||
|  |         if (path.isEmpty()) { | ||||||
|  |             sorting = value | ||||||
|  |         } else { | ||||||
|  |             prefs.edit().putInt(SORT_FOLDER_PREFIX + path, value).apply() | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     fun getFolderSorting(path: String) = prefs.getInt(SORT_FOLDER_PREFIX + path, sorting) | ||||||
|  |  | ||||||
|  |     fun removeFolderSorting(path: String) { | ||||||
|  |         prefs.edit().remove(SORT_FOLDER_PREFIX + path).apply() | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     fun hasCustomSorting(path: String) = prefs.contains(SORT_FOLDER_PREFIX + path) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -7,3 +7,5 @@ val SCROLL_STATE = "scroll_state" | |||||||
| val SHOW_HIDDEN = "show_hidden" | val SHOW_HIDDEN = "show_hidden" | ||||||
| val HOME_FOLDER = "home_folder" | val HOME_FOLDER = "home_folder" | ||||||
| val FAVORITES = "favorites" | val FAVORITES = "favorites" | ||||||
|  | val SORT_ORDER = "sort_order" | ||||||
|  | val SORT_FOLDER_PREFIX = "sort_folder_" | ||||||
|   | |||||||
| @@ -22,6 +22,7 @@ import com.simplemobiletools.filemanager.BuildConfig | |||||||
| import com.simplemobiletools.filemanager.PATH | import com.simplemobiletools.filemanager.PATH | ||||||
| import com.simplemobiletools.filemanager.R | import com.simplemobiletools.filemanager.R | ||||||
| import com.simplemobiletools.filemanager.SCROLL_STATE | import com.simplemobiletools.filemanager.SCROLL_STATE | ||||||
|  | import com.simplemobiletools.filemanager.dialogs.ChangeSortingDialog | ||||||
| import com.simplemobiletools.filemanager.extensions.config | import com.simplemobiletools.filemanager.extensions.config | ||||||
| import com.simplemobiletools.filemanager.fragments.ItemsFragment | import com.simplemobiletools.filemanager.fragments.ItemsFragment | ||||||
| import kotlinx.android.synthetic.main.activity_main.* | import kotlinx.android.synthetic.main.activity_main.* | ||||||
| @@ -121,6 +122,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br | |||||||
|     override fun onOptionsItemSelected(item: MenuItem): Boolean { |     override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||||||
|         when (item.itemId) { |         when (item.itemId) { | ||||||
|             R.id.go_home -> goHome() |             R.id.go_home -> goHome() | ||||||
|  |             R.id.sort -> showSortingDialog() | ||||||
|             R.id.add_favorite -> addFavorite() |             R.id.add_favorite -> addFavorite() | ||||||
|             R.id.remove_favorite -> removeFavorite() |             R.id.remove_favorite -> removeFavorite() | ||||||
|             R.id.go_to_favorite -> goToFavorite() |             R.id.go_to_favorite -> goToFavorite() | ||||||
| @@ -136,6 +138,12 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br | |||||||
|         openPath(config.homeFolder) |         openPath(config.homeFolder) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private fun showSortingDialog() { | ||||||
|  |         ChangeSortingDialog(this, currentPath) { | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private fun addFavorite() { |     private fun addFavorite() { | ||||||
|         config.addFavorite(currentPath) |         config.addFavorite(currentPath) | ||||||
|         invalidateOptionsMenu() |         invalidateOptionsMenu() | ||||||
|   | |||||||
| @@ -0,0 +1,86 @@ | |||||||
|  | package com.simplemobiletools.filemanager.dialogs | ||||||
|  |  | ||||||
|  | import android.content.DialogInterface | ||||||
|  | import android.support.v7.app.AlertDialog | ||||||
|  | import android.view.LayoutInflater | ||||||
|  | import android.view.View | ||||||
|  | import com.simplemobiletools.commons.extensions.setupDialogStuff | ||||||
|  | import com.simplemobiletools.commons.helpers.* | ||||||
|  | import com.simplemobiletools.filemanager.Config | ||||||
|  | import com.simplemobiletools.filemanager.R | ||||||
|  | import com.simplemobiletools.filemanager.activities.SimpleActivity | ||||||
|  | import com.simplemobiletools.filemanager.extensions.config | ||||||
|  | import kotlinx.android.synthetic.main.dialog_change_sorting.view.* | ||||||
|  |  | ||||||
|  | class ChangeSortingDialog(val activity: SimpleActivity, val path: String = "", val callback: () -> Unit) : | ||||||
|  |         DialogInterface.OnClickListener { | ||||||
|  |     companion object { | ||||||
|  |         private var currSorting = 0 | ||||||
|  |  | ||||||
|  |         lateinit var config: Config | ||||||
|  |         lateinit var view: View | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     init { | ||||||
|  |         config = activity.config | ||||||
|  |         view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_sorting, null).apply { | ||||||
|  |             sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path) | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         AlertDialog.Builder(activity) | ||||||
|  |                 .setPositiveButton(R.string.ok, this) | ||||||
|  |                 .setNegativeButton(R.string.cancel, null) | ||||||
|  |                 .create().apply { | ||||||
|  |             activity.setupDialogStuff(view, this, R.string.sort_by) | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         currSorting = config.getFolderSorting(path) | ||||||
|  |         setupSortRadio() | ||||||
|  |         setupOrderRadio() | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private fun setupSortRadio() { | ||||||
|  |         val sortingRadio = view.sorting_dialog_radio_sorting | ||||||
|  |         var sortBtn = sortingRadio.sorting_dialog_radio_name | ||||||
|  |  | ||||||
|  |         if (currSorting and SORT_BY_SIZE != 0) { | ||||||
|  |             sortBtn = sortingRadio.sorting_dialog_radio_size | ||||||
|  |         } else if (currSorting and SORT_BY_DATE_MODIFIED != 0) { | ||||||
|  |             sortBtn = sortingRadio.sorting_dialog_radio_last_modified | ||||||
|  |         } else if (currSorting and SORT_BY_DATE_TAKEN != 0) | ||||||
|  |             sortBtn = sortingRadio.sorting_dialog_radio_date_taken | ||||||
|  |         sortBtn.isChecked = true | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private fun setupOrderRadio() { | ||||||
|  |         val orderRadio = view.sorting_dialog_radio_order | ||||||
|  |         var orderBtn = orderRadio.sorting_dialog_radio_ascending | ||||||
|  |  | ||||||
|  |         if (currSorting and SORT_DESCENDING != 0) { | ||||||
|  |             orderBtn = orderRadio.sorting_dialog_radio_descending | ||||||
|  |         } | ||||||
|  |         orderBtn.isChecked = true | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     override fun onClick(dialog: DialogInterface, which: Int) { | ||||||
|  |         val sortingRadio = view.sorting_dialog_radio_sorting | ||||||
|  |         var sorting = when (sortingRadio.checkedRadioButtonId) { | ||||||
|  |             R.id.sorting_dialog_radio_name -> SORT_BY_NAME | ||||||
|  |             R.id.sorting_dialog_radio_size -> SORT_BY_SIZE | ||||||
|  |             R.id.sorting_dialog_radio_last_modified -> SORT_BY_DATE_MODIFIED | ||||||
|  |             else -> SORT_BY_DATE_TAKEN | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) { | ||||||
|  |             sorting = sorting or SORT_DESCENDING | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (view.sorting_dialog_use_for_this_folder.isChecked) { | ||||||
|  |             config.saveFolderSorting(path, sorting) | ||||||
|  |         } else { | ||||||
|  |             config.removeFolderSorting(path) | ||||||
|  |             config.sorting = sorting | ||||||
|  |         } | ||||||
|  |         callback.invoke() | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										97
									
								
								app/src/main/res/layout/dialog_change_sorting.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								app/src/main/res/layout/dialog_change_sorting.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,97 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <ScrollView | ||||||
|  |     xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     android:id="@+id/sorting_dialog_scrollview" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="match_parent"> | ||||||
|  |  | ||||||
|  |     <LinearLayout | ||||||
|  |         android:id="@+id/sorting_dialog_holder" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:orientation="vertical" | ||||||
|  |         android:paddingLeft="@dimen/activity_margin" | ||||||
|  |         android:paddingRight="@dimen/activity_margin" | ||||||
|  |         android:paddingTop="@dimen/activity_margin"> | ||||||
|  |  | ||||||
|  |         <RadioGroup | ||||||
|  |             android:id="@+id/sorting_dialog_radio_sorting" | ||||||
|  |             android:layout_width="match_parent" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_marginBottom="@dimen/medium_margin"> | ||||||
|  |  | ||||||
|  |             <com.simplemobiletools.commons.views.MyCompatRadioButton | ||||||
|  |                 android:id="@+id/sorting_dialog_radio_name" | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:paddingBottom="@dimen/medium_margin" | ||||||
|  |                 android:paddingTop="@dimen/medium_margin" | ||||||
|  |                 android:text="@string/name"/> | ||||||
|  |  | ||||||
|  |             <com.simplemobiletools.commons.views.MyCompatRadioButton | ||||||
|  |                 android:id="@+id/sorting_dialog_radio_size" | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:paddingBottom="@dimen/medium_margin" | ||||||
|  |                 android:paddingTop="@dimen/medium_margin" | ||||||
|  |                 android:text="@string/size"/> | ||||||
|  |  | ||||||
|  |             <com.simplemobiletools.commons.views.MyCompatRadioButton | ||||||
|  |                 android:id="@+id/sorting_dialog_radio_last_modified" | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:paddingBottom="@dimen/medium_margin" | ||||||
|  |                 android:paddingTop="@dimen/medium_margin" | ||||||
|  |                 android:text="@string/last_modified"/> | ||||||
|  |  | ||||||
|  |             <com.simplemobiletools.commons.views.MyCompatRadioButton | ||||||
|  |                 android:id="@+id/sorting_dialog_radio_date_taken" | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:paddingBottom="@dimen/medium_margin" | ||||||
|  |                 android:paddingTop="@dimen/medium_margin" | ||||||
|  |                 android:text="@string/date_taken"/> | ||||||
|  |  | ||||||
|  |         </RadioGroup> | ||||||
|  |  | ||||||
|  |         <include | ||||||
|  |             layout="@layout/divider"/> | ||||||
|  |  | ||||||
|  |         <RadioGroup | ||||||
|  |             android:id="@+id/sorting_dialog_radio_order" | ||||||
|  |             android:layout_width="match_parent" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_marginTop="@dimen/medium_margin" | ||||||
|  |             android:paddingBottom="@dimen/medium_margin"> | ||||||
|  |  | ||||||
|  |             <com.simplemobiletools.commons.views.MyCompatRadioButton | ||||||
|  |                 android:id="@+id/sorting_dialog_radio_ascending" | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:paddingBottom="@dimen/medium_margin" | ||||||
|  |                 android:paddingTop="@dimen/medium_margin" | ||||||
|  |                 android:text="@string/ascending"/> | ||||||
|  |  | ||||||
|  |             <com.simplemobiletools.commons.views.MyCompatRadioButton | ||||||
|  |                 android:id="@+id/sorting_dialog_radio_descending" | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:paddingBottom="@dimen/medium_margin" | ||||||
|  |                 android:paddingTop="@dimen/medium_margin" | ||||||
|  |                 android:text="@string/descending"/> | ||||||
|  |         </RadioGroup> | ||||||
|  |  | ||||||
|  |         <include | ||||||
|  |             android:id="@+id/use_for_this_folder_divider" | ||||||
|  |             layout="@layout/divider"/> | ||||||
|  |  | ||||||
|  |         <com.simplemobiletools.commons.views.MyAppCompatCheckbox | ||||||
|  |             android:id="@+id/sorting_dialog_use_for_this_folder" | ||||||
|  |             android:layout_width="match_parent" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:paddingBottom="@dimen/activity_margin" | ||||||
|  |             android:paddingTop="@dimen/activity_margin" | ||||||
|  |             android:text="@string/use_for_this_folder"/> | ||||||
|  |  | ||||||
|  |     </LinearLayout> | ||||||
|  | </ScrollView> | ||||||
| @@ -6,6 +6,11 @@ | |||||||
|         android:icon="@drawable/ic_home" |         android:icon="@drawable/ic_home" | ||||||
|         android:title="@string/go_to_home_folder" |         android:title="@string/go_to_home_folder" | ||||||
|         app:showAsAction="ifRoom"/> |         app:showAsAction="ifRoom"/> | ||||||
|  |     <item | ||||||
|  |         android:id="@+id/sort" | ||||||
|  |         android:icon="@drawable/ic_sort" | ||||||
|  |         android:title="@string/sort_by" | ||||||
|  |         app:showAsAction="ifRoom"/> | ||||||
|     <item |     <item | ||||||
|         android:id="@+id/add_favorite" |         android:id="@+id/add_favorite" | ||||||
|         android:icon="@drawable/ic_star_off" |         android:icon="@drawable/ic_star_off" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user