mirror of
				https://github.com/SimpleMobileTools/Simple-File-Manager.git
				synced 2025-06-05 22:09:15 +02:00 
			
		
		
		
	updating Commons with AndroidX and recyclerview-selector
This commit is contained in:
		| @@ -22,7 +22,7 @@ android { | ||||
|  | ||||
|     buildTypes { | ||||
|         debug { | ||||
| 	        applicationIdSuffix ".debug" | ||||
|             applicationIdSuffix ".debug" | ||||
|         } | ||||
|         release { | ||||
|             minifyEnabled true | ||||
| @@ -42,7 +42,7 @@ android { | ||||
| } | ||||
|  | ||||
| dependencies { | ||||
|     implementation 'com.simplemobiletools:commons:4.8.8' | ||||
|     implementation 'com.simplemobiletools:commons:4.9.18' | ||||
|  | ||||
|     implementation files('../libs/RootTools.jar') | ||||
| } | ||||
|   | ||||
| @@ -99,7 +99,7 @@ | ||||
|             android:parentActivityName="com.simplemobiletools.commons.activities.AboutActivity"/> | ||||
|  | ||||
|         <provider | ||||
|             android:name="android.support.v4.content.FileProvider" | ||||
|             android:name="androidx.core.content.FileProvider" | ||||
|             android:authorities="${applicationId}.provider" | ||||
|             android:exported="false" | ||||
|             android:grantUriPermissions="true"> | ||||
|   | ||||
| @@ -37,6 +37,7 @@ class FavoritesActivity : SimpleActivity(), RefreshRecyclerViewListener { | ||||
|  | ||||
|         ManageFavoritesAdapter(this, favorites, this, manage_favorites_list) { }.apply { | ||||
|             manage_favorites_list.adapter = this | ||||
|             initSelectionTracker() | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -8,10 +8,10 @@ import android.content.Intent | ||||
| import android.media.RingtoneManager | ||||
| import android.os.Bundle | ||||
| import android.os.Handler | ||||
| import android.support.v4.view.MenuItemCompat | ||||
| import android.support.v7.widget.SearchView | ||||
| import android.view.Menu | ||||
| import android.view.MenuItem | ||||
| import androidx.appcompat.widget.SearchView | ||||
| import androidx.core.view.MenuItemCompat | ||||
| import com.simplemobiletools.commons.dialogs.RadioGroupDialog | ||||
| import com.simplemobiletools.commons.extensions.* | ||||
| import com.simplemobiletools.commons.helpers.* | ||||
| @@ -26,7 +26,7 @@ import com.simplemobiletools.filemanager.fragments.ItemsFragment | ||||
| import com.simplemobiletools.filemanager.helpers.RootHelpers | ||||
| import com.stericson.RootTools.RootTools | ||||
| import kotlinx.android.synthetic.main.activity_main.* | ||||
| import kotlinx.android.synthetic.main.items_fragment.* | ||||
| import kotlinx.android.synthetic.main.items_fragment.view.* | ||||
| import java.io.File | ||||
| import java.util.* | ||||
|  | ||||
| @@ -258,7 +258,7 @@ class MainActivity : SimpleActivity() { | ||||
|     } | ||||
|  | ||||
|     override fun onBackPressed() { | ||||
|         if (fragment.breadcrumbs.childCount <= 1) { | ||||
|         if (fragment.mView.breadcrumbs.childCount <= 1) { | ||||
|             if (!wasBackJustPressed) { | ||||
|                 wasBackJustPressed = true | ||||
|                 toast(R.string.press_back_again) | ||||
| @@ -269,8 +269,8 @@ class MainActivity : SimpleActivity() { | ||||
|                 finish() | ||||
|             } | ||||
|         } else { | ||||
|             fragment.breadcrumbs.removeBreadcrumb() | ||||
|             openPath(fragment.breadcrumbs.getLastItem().path) | ||||
|             fragment.mView.breadcrumbs.removeBreadcrumb() | ||||
|             openPath(fragment.mView.breadcrumbs.getLastItem().path) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -4,10 +4,10 @@ import android.app.SearchManager | ||||
| import android.content.Context | ||||
| import android.net.Uri | ||||
| import android.os.Bundle | ||||
| import android.support.v4.view.MenuItemCompat | ||||
| import android.support.v7.widget.SearchView | ||||
| import android.view.Menu | ||||
| import android.view.MenuItem | ||||
| import androidx.appcompat.widget.SearchView | ||||
| import androidx.core.view.MenuItemCompat | ||||
| import com.simplemobiletools.commons.extensions.* | ||||
| import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE | ||||
| import com.simplemobiletools.commons.helpers.REAL_FILE_PATH | ||||
| @@ -62,7 +62,7 @@ class ReadTextActivity : SimpleActivity() { | ||||
|         (searchMenuItem!!.actionView as SearchView).apply { | ||||
|             setSearchableInfo(searchManager.getSearchableInfo(componentName)) | ||||
|             isSubmitButtonEnabled = false | ||||
|             setOnQueryTextListener(object : android.support.v7.widget.SearchView.OnQueryTextListener { | ||||
|             setOnQueryTextListener(object : SearchView.OnQueryTextListener { | ||||
|                 override fun onQueryTextSubmit(query: String) = false | ||||
|  | ||||
|                 override fun onQueryTextChange(newText: String): Boolean { | ||||
|   | ||||
| @@ -17,6 +17,7 @@ import com.simplemobiletools.commons.dialogs.* | ||||
| import com.simplemobiletools.commons.extensions.* | ||||
| import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE | ||||
| import com.simplemobiletools.commons.helpers.CONFLICT_SKIP | ||||
| import com.simplemobiletools.commons.helpers.FileDirItemKeyProvider | ||||
| import com.simplemobiletools.commons.helpers.OTG_PATH | ||||
| import com.simplemobiletools.commons.models.FileDirItem | ||||
| import com.simplemobiletools.commons.models.RadioItem | ||||
| @@ -50,7 +51,6 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|     var adjustedPrimaryColor = activity.getAdjustedPrimaryColor() | ||||
|  | ||||
|     init { | ||||
|         setupDragListener(true) | ||||
|         initDrawables() | ||||
|     } | ||||
|  | ||||
| @@ -59,7 +59,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|     override fun prepareActionMode(menu: Menu) { | ||||
|         menu.apply { | ||||
|             findItem(R.id.cab_rename).isVisible = isOneItemSelected() | ||||
|             findItem(R.id.cab_decompress).isVisible = getSelectedMedia().map { it.path }.any { it.isZipFile() } | ||||
|             findItem(R.id.cab_decompress).isVisible = getSelectedFileDirItems().map { it.path }.any { it.isZipFile() } | ||||
|             findItem(R.id.cab_confirm_selection).isVisible = isPickMultipleIntent | ||||
|             findItem(R.id.cab_copy_path).isVisible = isOneItemSelected() | ||||
|             findItem(R.id.cab_open_with).isVisible = isOneFileSelected() | ||||
| @@ -70,14 +70,8 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     override fun prepareItemSelection(viewHolder: ViewHolder) {} | ||||
|  | ||||
|     override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) { | ||||
|         viewHolder?.itemView?.item_frame?.isSelected = select | ||||
|     } | ||||
|  | ||||
|     override fun actionItemPressed(id: Int) { | ||||
|         if (selectedPositions.isEmpty()) { | ||||
|         if (getSelectedKeys().isEmpty) { | ||||
|             return | ||||
|         } | ||||
|  | ||||
| @@ -105,18 +99,24 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|  | ||||
|     override fun getIsItemSelectable(position: Int) = true | ||||
|  | ||||
|     override fun getItemSelectionKey(position: Int) = fileDirItems[position].path | ||||
|  | ||||
|     override fun getItemSelectionKeyProvider() = FileDirItemKeyProvider(fileDirItems) | ||||
|  | ||||
|     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.list_item, parent) | ||||
|  | ||||
|     override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { | ||||
|         val fileDirItem = fileDirItems[position] | ||||
|         val view = holder.bindView(fileDirItem, true, true) { itemView, layoutPosition -> | ||||
|             setupView(itemView, fileDirItem) | ||||
|         holder.bindView(fileDirItem, true, true) { itemView, layoutPosition -> | ||||
|             setupView(itemView, fileDirItem, isKeySelected(fileDirItem.path)) | ||||
|         } | ||||
|         bindViewHolder(holder, position, view) | ||||
|         bindViewHolder(holder) | ||||
|     } | ||||
|  | ||||
|     override fun getItemCount() = fileDirItems.size | ||||
|  | ||||
|     private fun getItemWithKey(key: String): FileDirItem? = fileDirItems.firstOrNull { it.path == key } | ||||
|  | ||||
|     fun initDrawables() { | ||||
|         folderDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_folder, textColor) | ||||
|         fileDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_file, textColor) | ||||
| @@ -124,12 +124,12 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|         fileDrawable.alpha = 180 | ||||
|     } | ||||
|  | ||||
|     private fun isOneFileSelected() = isOneItemSelected() && !fileDirItems[selectedPositions.first()].isDirectory | ||||
|     private fun isOneFileSelected() = isOneItemSelected() && getItemWithKey(getSelectedKeys().first())?.isDirectory == false | ||||
|  | ||||
|     private fun checkHideBtnVisibility(menu: Menu) { | ||||
|         var hiddenCnt = 0 | ||||
|         var unhiddenCnt = 0 | ||||
|         selectedPositions.mapNotNull { fileDirItems.getOrNull(it)?.name }.forEach { | ||||
|         getSelectedFileDirItems().map { it.name }.forEach { | ||||
|             if (it.startsWith(".")) { | ||||
|                 hiddenCnt++ | ||||
|             } else { | ||||
| @@ -142,14 +142,14 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|     } | ||||
|  | ||||
|     private fun confirmSelection() { | ||||
|         if (selectedPositions.isNotEmpty()) { | ||||
|             val paths = getSelectedMedia().filter { !it.isDirectory }.map { it.path } as ArrayList<String> | ||||
|         if (!getSelectedKeys().isEmpty) { | ||||
|             val paths = getSelectedFileDirItems().filter { !it.isDirectory }.map { it.path } as ArrayList<String> | ||||
|             listener?.selectedPaths(paths) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun displayRenameDialog() { | ||||
|         val oldPath = getSelectedMedia()[0].path | ||||
|         val oldPath = getSelectedFileDirItems()[0].path | ||||
|         RenameItemDialog(activity, oldPath) { | ||||
|             activity.config.moveFavorite(oldPath, it) | ||||
|             activity.runOnUiThread { | ||||
| @@ -160,17 +160,16 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|     } | ||||
|  | ||||
|     private fun showProperties() { | ||||
|         if (selectedPositions.size <= 1) { | ||||
|             PropertiesDialog(activity, fileDirItems[selectedPositions.first()].path, activity.config.shouldShowHidden) | ||||
|         if (getSelectedKeys().size() <= 1) { | ||||
|             PropertiesDialog(activity, getFirstSelectedItemPath(), activity.config.shouldShowHidden) | ||||
|         } else { | ||||
|             val paths = ArrayList<String>() | ||||
|             selectedPositions.forEach { paths.add(fileDirItems[it].path) } | ||||
|             val paths = getSelectedFileDirItems().map { it.path } | ||||
|             PropertiesDialog(activity, paths, activity.config.shouldShowHidden) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun shareFiles() { | ||||
|         val selectedItems = getSelectedMedia() | ||||
|         val selectedItems = getSelectedFileDirItems() | ||||
|         val paths = ArrayList<String>(selectedItems.size) | ||||
|         selectedItems.forEach { | ||||
|             addFileUris(it.path, paths) | ||||
| @@ -180,7 +179,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|  | ||||
|     private fun toggleFileVisibility(hide: Boolean) { | ||||
|         Thread { | ||||
|             getSelectedMedia().forEach { | ||||
|             getSelectedFileDirItems().forEach { | ||||
|                 activity.toggleItemVisibility(it.path, hide) | ||||
|             } | ||||
|             activity.runOnUiThread { | ||||
| @@ -194,7 +193,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|         if (activity.getIsPathDirectory(path)) { | ||||
|             val shouldShowHidden = activity.config.shouldShowHidden | ||||
|             if (path.startsWith(OTG_PATH)) { | ||||
|                 activity.getDocumentFile(path)?.listFiles()?.filter { if (shouldShowHidden) true else !it.name.startsWith(".") }?.forEach { | ||||
|                 activity.getDocumentFile(path)?.listFiles()?.filter { if (shouldShowHidden) true else !it.name!!.startsWith(".") }?.forEach { | ||||
|                     addFileUris(it.uri.toString(), paths) | ||||
|                 } | ||||
|             } else { | ||||
| @@ -208,19 +207,18 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|     } | ||||
|  | ||||
|     private fun copyPath() { | ||||
|         val path = getSelectedMedia().first().path | ||||
|         val clip = ClipData.newPlainText(activity.getString(R.string.app_name), path) | ||||
|         val clip = ClipData.newPlainText(activity.getString(R.string.app_name), getFirstSelectedItemPath()) | ||||
|         (activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).primaryClip = clip | ||||
|         finishActMode() | ||||
|         activity.toast(R.string.path_copied) | ||||
|     } | ||||
|  | ||||
|     private fun setAs() { | ||||
|         activity.setAs(getSelectedMedia().first().path) | ||||
|         activity.setAs(getFirstSelectedItemPath()) | ||||
|     } | ||||
|  | ||||
|     private fun openWith() { | ||||
|         activity.tryOpenPathIntent(getSelectedMedia().first().path, true) | ||||
|         activity.tryOpenPathIntent(getFirstSelectedItemPath(), true) | ||||
|     } | ||||
|  | ||||
|     private fun openAs() { | ||||
| @@ -233,16 +231,12 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|                 RadioItem(OPEN_AS_OTHER, res.getString(R.string.other_file))) | ||||
|  | ||||
|         RadioGroupDialog(activity, items) { | ||||
|             activity.tryOpenPathIntent(getSelectedMedia().first().path, false, it as Int) | ||||
|             activity.tryOpenPathIntent(getFirstSelectedItemPath(), false, it as Int) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun copyMoveTo(isCopyOperation: Boolean) { | ||||
|         val files = ArrayList<FileDirItem>() | ||||
|         selectedPositions.forEach { | ||||
|             files.add(fileDirItems[it]) | ||||
|         } | ||||
|  | ||||
|         val files = getSelectedFileDirItems() | ||||
|         val firstFile = files[0] | ||||
|         val source = if (firstFile.isDirectory) firstFile.path else firstFile.getParentPath() | ||||
|         FilePickerDialog(activity, source, false, activity.config.shouldShowHidden, true) { | ||||
| @@ -277,7 +271,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|     } | ||||
|  | ||||
|     private fun compressSelection() { | ||||
|         val firstPath = fileDirItems[selectedPositions.first()].path | ||||
|         val firstPath = getFirstSelectedItemPath() | ||||
|         if (firstPath.startsWith(OTG_PATH)) { | ||||
|             activity.toast(R.string.unknown_error_occurred) | ||||
|             return | ||||
| @@ -286,7 +280,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|         CompressAsDialog(activity, firstPath) { | ||||
|             activity.handleSAFDialog(firstPath) { | ||||
|                 activity.toast(R.string.compressing) | ||||
|                 val paths = selectedPositions.map { fileDirItems[it].path } | ||||
|                 val paths = getSelectedFileDirItems().map { it.path } | ||||
|                 Thread { | ||||
|                     if (compressPaths(paths, it)) { | ||||
|                         activity.runOnUiThread { | ||||
| @@ -303,14 +297,14 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|     } | ||||
|  | ||||
|     private fun decompressSelection() { | ||||
|         val firstPath = fileDirItems[selectedPositions.first()].path | ||||
|         val firstPath = getFirstSelectedItemPath() | ||||
|         if (firstPath.startsWith(OTG_PATH)) { | ||||
|             activity.toast(R.string.unknown_error_occurred) | ||||
|             return | ||||
|         } | ||||
|  | ||||
|         activity.handleSAFDialog(firstPath) { | ||||
|             val paths = selectedPositions.map { fileDirItems[it].path }.filter { it.isZipFile() } | ||||
|             val paths = getSelectedFileDirItems().asSequence().map { it.path }.filter { it.isZipFile() }.toList() | ||||
|             tryDecompressingPaths(paths) { | ||||
|                 if (it) { | ||||
|                     activity.toast(R.string.decompression_successful) | ||||
| @@ -476,7 +470,8 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|     } | ||||
|  | ||||
|     private fun askConfirmDelete() { | ||||
|         val items = resources.getQuantityString(R.plurals.delete_items, selectedPositions.size, selectedPositions.size) | ||||
|         val selectionSize = getSelectedKeys().size() | ||||
|         val items = resources.getQuantityString(R.plurals.delete_items, selectionSize, selectionSize) | ||||
|         val question = String.format(resources.getString(R.string.deletion_confirmation), items) | ||||
|         ConfirmationDialog(activity, question) { | ||||
|             deleteFiles() | ||||
| @@ -484,37 +479,50 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|     } | ||||
|  | ||||
|     private fun deleteFiles() { | ||||
|         if (selectedPositions.isEmpty()) { | ||||
|         val selectedKeys = getSelectedKeys() | ||||
|         if (selectedKeys.isEmpty) { | ||||
|             return | ||||
|         } | ||||
|  | ||||
|         val files = ArrayList<FileDirItem>(selectedPositions.size) | ||||
|         val removeFiles = ArrayList<FileDirItem>(selectedPositions.size) | ||||
|         val SAFPath = fileDirItems[selectedPositions.first()].path | ||||
|  | ||||
|         val SAFPath = getFirstSelectedItemPath() | ||||
|         if (activity.isPathOnRoot(SAFPath) && !RootTools.isRootAvailable()) { | ||||
|             activity.toast(R.string.rooted_device_only) | ||||
|             return | ||||
|         } | ||||
|  | ||||
|         activity.handleSAFDialog(SAFPath) { | ||||
|             selectedPositions.sortedDescending().forEach { | ||||
|                 val file = fileDirItems[it] | ||||
|                 files.add(file) | ||||
|                 removeFiles.add(file) | ||||
|                 activity.config.removeFavorite(file.path) | ||||
|             val files = ArrayList<FileDirItem>(selectedKeys.size()) | ||||
|             val positions = ArrayList<Int>() | ||||
|             getSelectedKeys().forEach { | ||||
|                 activity.config.removeFavorite(it) | ||||
|                 val key = it | ||||
|                 val position = fileDirItems.indexOfFirst { it.path == key } | ||||
|                 if (position != -1) { | ||||
|                     positions.add(position) | ||||
|                     files.add(fileDirItems[position]) | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             fileDirItems.removeAll(removeFiles) | ||||
|             positions.sortDescending() | ||||
|             removeSelectedItems(positions) | ||||
|             listener?.deleteFiles(files) | ||||
|             removeSelectedItems() | ||||
|             positions.forEach { | ||||
|                 fileDirItems.removeAt(it) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun getSelectedMedia(): List<FileDirItem> { | ||||
|         val selectedMedia = ArrayList<FileDirItem>(selectedPositions.size) | ||||
|         selectedPositions.forEach { selectedMedia.add(fileDirItems[it]) } | ||||
|         return selectedMedia | ||||
|     private fun getFirstSelectedItemPath() = getSelectedFileDirItems().first().path | ||||
|  | ||||
|     private fun getSelectedFileDirItems(): ArrayList<FileDirItem> { | ||||
|         val selectedKeys = getSelectedKeys() | ||||
|         val selectedFileDirItems = ArrayList<FileDirItem>(selectedKeys.size()) | ||||
|         selectedKeys.forEach { | ||||
|             getItemWithKey(it)?.apply { | ||||
|                 selectedFileDirItems.add(this) | ||||
|             } | ||||
|         } | ||||
|         return selectedFileDirItems | ||||
|     } | ||||
|  | ||||
|     fun updateItems(newItems: ArrayList<FileDirItem>, highlightText: String = "") { | ||||
| @@ -534,12 +542,13 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|     override fun onViewRecycled(holder: ViewHolder) { | ||||
|         super.onViewRecycled(holder) | ||||
|         if (!activity.isActivityDestroyed()) { | ||||
|             Glide.with(activity).clear(holder.itemView?.item_icon!!) | ||||
|             Glide.with(activity).clear(holder.itemView.item_icon!!) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun setupView(view: View, fileDirItem: FileDirItem) { | ||||
|     private fun setupView(view: View, fileDirItem: FileDirItem, isSelected: Boolean) { | ||||
|         view.apply { | ||||
|             item_frame.isSelected = isSelected | ||||
|             val fileName = fileDirItem.name | ||||
|             item_name.text = if (textToHighlight.isEmpty()) fileName else fileName.highlightTextPart(textToHighlight, adjustedPrimaryColor) | ||||
|             item_name.setTextColor(textColor) | ||||
|   | ||||
| @@ -5,31 +5,21 @@ import android.view.View | ||||
| import android.view.ViewGroup | ||||
| import com.simplemobiletools.commons.activities.BaseSimpleActivity | ||||
| import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter | ||||
| import com.simplemobiletools.commons.helpers.StringListKeyProvider | ||||
| import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener | ||||
| import com.simplemobiletools.commons.views.MyRecyclerView | ||||
| import com.simplemobiletools.filemanager.R | ||||
| import com.simplemobiletools.filemanager.extensions.config | ||||
| import kotlinx.android.synthetic.main.item_manage_favorite.view.* | ||||
| import java.util.* | ||||
|  | ||||
| class ManageFavoritesAdapter(activity: BaseSimpleActivity, var favorites: ArrayList<String>, val listener: RefreshRecyclerViewListener?, | ||||
|                              recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) { | ||||
|  | ||||
|     private val config = activity.config | ||||
|  | ||||
|     init { | ||||
|         setupDragListener(true) | ||||
|     } | ||||
|  | ||||
|     override fun getActionMenuId() = R.menu.cab_remove_only | ||||
|  | ||||
|     override fun prepareActionMode(menu: Menu) {} | ||||
|  | ||||
|     override fun prepareItemSelection(viewHolder: ViewHolder) {} | ||||
|  | ||||
|     override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) { | ||||
|         viewHolder?.itemView?.manage_favorite_holder?.isSelected = select | ||||
|     } | ||||
|  | ||||
|     override fun actionItemPressed(id: Int) { | ||||
|         when (id) { | ||||
|             R.id.cab_remove -> removeSelection() | ||||
| @@ -40,38 +30,53 @@ class ManageFavoritesAdapter(activity: BaseSimpleActivity, var favorites: ArrayL | ||||
|  | ||||
|     override fun getIsItemSelectable(position: Int) = true | ||||
|  | ||||
|     override fun getItemSelectionKey(position: Int) = favorites[position] | ||||
|  | ||||
|     override fun getItemSelectionKeyProvider() = StringListKeyProvider(favorites) | ||||
|  | ||||
|     override fun prepareActionMode(menu: Menu) {} | ||||
|  | ||||
|     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_manage_favorite, parent) | ||||
|  | ||||
|     override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||||
|         val favorite = favorites[position] | ||||
|         val view = holder.bindView(favorite, true, true) { itemView, layoutPosition -> | ||||
|             setupView(itemView, favorite) | ||||
|         holder.bindView(favorite, true, true) { itemView, layoutPosition -> | ||||
|             setupView(itemView, favorite, isKeySelected(favorite)) | ||||
|         } | ||||
|         bindViewHolder(holder, position, view) | ||||
|         bindViewHolder(holder) | ||||
|     } | ||||
|  | ||||
|     override fun getItemCount() = favorites.size | ||||
|  | ||||
|     private fun setupView(view: View, favorite: String) { | ||||
|     private fun setupView(view: View, favorite: String, isSelected: Boolean) { | ||||
|         view.apply { | ||||
|             manage_favorite_title.apply { | ||||
|                 text = favorite | ||||
|                 setTextColor(config.textColor) | ||||
|             } | ||||
|  | ||||
|             manage_favorite_holder?.isSelected = isSelected | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun removeSelection() { | ||||
|         val removeFavorites = ArrayList<String>(selectedPositions.size) | ||||
|  | ||||
|         selectedPositions.sortedDescending().forEach { | ||||
|             val favorite = favorites[it] | ||||
|             removeFavorites.add(favorite) | ||||
|             config.removeFavorite(favorite) | ||||
|         val selectedKeys = getSelectedKeys() | ||||
|         val removeFavorites = ArrayList<String>(selectedKeys.size()) | ||||
|         val positions = java.util.ArrayList<Int>() | ||||
|         getSelectedKeys().forEach { | ||||
|             val key = it | ||||
|             val position = favorites.indexOfFirst { it == key } | ||||
|             if (position != -1) { | ||||
|                 positions.add(position) | ||||
|                 removeFavorites.add(key) | ||||
|                 config.removeFavorite(key) | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         positions.sortDescending() | ||||
|         removeSelectedItems(positions) | ||||
|  | ||||
|         favorites.removeAll(removeFavorites) | ||||
|         removeSelectedItems() | ||||
|         if (favorites.isEmpty()) { | ||||
|             listener?.refreshItems() | ||||
|         } | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| package com.simplemobiletools.filemanager.dialogs | ||||
|  | ||||
| import android.support.v7.app.AlertDialog | ||||
| import androidx.appcompat.app.AlertDialog | ||||
| import com.simplemobiletools.commons.activities.BaseSimpleActivity | ||||
| import com.simplemobiletools.commons.extensions.setupDialogStuff | ||||
| import com.simplemobiletools.commons.helpers.* | ||||
| @@ -17,7 +17,7 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val path: String = " | ||||
|         view.sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path) | ||||
|  | ||||
|         AlertDialog.Builder(activity) | ||||
|                 .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) | ||||
|                 .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } | ||||
|                 .setNegativeButton(R.string.cancel, null) | ||||
|                 .create().apply { | ||||
|                     activity.setupDialogStuff(view, this, R.string.sort_by) | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| package com.simplemobiletools.filemanager.dialogs | ||||
|  | ||||
| import android.support.v7.app.AlertDialog | ||||
| import android.view.View | ||||
| import androidx.appcompat.app.AlertDialog | ||||
| import com.simplemobiletools.commons.activities.BaseSimpleActivity | ||||
| import com.simplemobiletools.commons.dialogs.FilePickerDialog | ||||
| import com.simplemobiletools.commons.extensions.* | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| package com.simplemobiletools.filemanager.dialogs | ||||
|  | ||||
| import android.support.v7.app.AlertDialog | ||||
| import android.view.View | ||||
| import androidx.appcompat.app.AlertDialog | ||||
| import com.simplemobiletools.commons.extensions.* | ||||
| import com.simplemobiletools.filemanager.R | ||||
| import com.simplemobiletools.filemanager.activities.SimpleActivity | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| package com.simplemobiletools.filemanager.dialogs | ||||
|  | ||||
| import android.support.v7.app.AlertDialog | ||||
| import androidx.appcompat.app.AlertDialog | ||||
| import com.simplemobiletools.commons.activities.BaseSimpleActivity | ||||
| import com.simplemobiletools.commons.dialogs.ConfirmationDialog | ||||
| import com.simplemobiletools.commons.dialogs.FilePickerDialog | ||||
|   | ||||
| @@ -3,7 +3,7 @@ package com.simplemobiletools.filemanager.extensions | ||||
| import android.app.Activity | ||||
| import android.content.Intent | ||||
| import android.net.Uri | ||||
| import android.support.v4.content.FileProvider | ||||
| import androidx.core.content.FileProvider | ||||
| import com.simplemobiletools.commons.R | ||||
| import com.simplemobiletools.commons.activities.BaseSimpleActivity | ||||
| import com.simplemobiletools.commons.extensions.* | ||||
|   | ||||
| @@ -2,11 +2,10 @@ package com.simplemobiletools.filemanager.fragments | ||||
|  | ||||
| import android.os.Bundle | ||||
| import android.os.Parcelable | ||||
| import android.support.v4.app.Fragment | ||||
| import android.support.v7.widget.LinearLayoutManager | ||||
| import android.view.LayoutInflater | ||||
| import android.view.View | ||||
| import android.view.ViewGroup | ||||
| import androidx.fragment.app.Fragment | ||||
| import com.simplemobiletools.commons.activities.BaseSimpleActivity | ||||
| import com.simplemobiletools.commons.dialogs.StoragePickerDialog | ||||
| import com.simplemobiletools.commons.extensions.* | ||||
| @@ -14,6 +13,7 @@ import com.simplemobiletools.commons.helpers.OTG_PATH | ||||
| import com.simplemobiletools.commons.helpers.SORT_BY_SIZE | ||||
| import com.simplemobiletools.commons.models.FileDirItem | ||||
| import com.simplemobiletools.commons.views.Breadcrumbs | ||||
| import com.simplemobiletools.commons.views.MyLinearLayoutManager | ||||
| import com.simplemobiletools.filemanager.R | ||||
| import com.simplemobiletools.filemanager.activities.MainActivity | ||||
| import com.simplemobiletools.filemanager.activities.SimpleActivity | ||||
| @@ -25,7 +25,6 @@ import com.simplemobiletools.filemanager.extensions.tryOpenPathIntent | ||||
| import com.simplemobiletools.filemanager.helpers.PATH | ||||
| import com.simplemobiletools.filemanager.helpers.RootHelpers | ||||
| import com.simplemobiletools.filemanager.interfaces.ItemOperationsListener | ||||
| import kotlinx.android.synthetic.main.items_fragment.* | ||||
| import kotlinx.android.synthetic.main.items_fragment.view.* | ||||
| import java.io.File | ||||
| import java.util.HashMap | ||||
| @@ -46,7 +45,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb | ||||
|     private var storedItems = ArrayList<FileDirItem>() | ||||
|     private var storedTextColor = 0 | ||||
|  | ||||
|     private lateinit var mView: View | ||||
|     lateinit var mView: View | ||||
|  | ||||
|     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||||
|         mView = inflater.inflate(R.layout.items_fragment, container, false)!! | ||||
| @@ -91,8 +90,8 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb | ||||
|             storedTextColor = newTextColor | ||||
|         } | ||||
|  | ||||
|         items_fastscroller.updateBubbleColors() | ||||
|         items_fastscroller.allowBubbleDisplay = context!!.config.showInfoBubble | ||||
|         mView.items_fastscroller.updateBubbleColors() | ||||
|         mView.items_fastscroller.allowBubbleDisplay = context!!.config.showInfoBubble | ||||
|         if (!isFirstResume) { | ||||
|             refreshItems() | ||||
|         } | ||||
| @@ -121,7 +120,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb | ||||
|             realPath = "/" | ||||
|         } | ||||
|  | ||||
|         scrollStates[currentPath] = getScrollState() | ||||
|         scrollStates[currentPath] = getScrollState()!! | ||||
|         currentPath = realPath | ||||
|         showHidden = context!!.config.shouldShowHidden | ||||
|         getItems(currentPath) { originalPath, fileDirItems -> | ||||
| @@ -153,9 +152,10 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb | ||||
|                 }.apply { | ||||
|                     addVerticalDividers(true) | ||||
|                     items_list.adapter = this | ||||
|                     initSelectionTracker() | ||||
|                 } | ||||
|                 items_fastscroller.allowBubbleDisplay = context.config.showInfoBubble | ||||
|                 items_fastscroller.setViews(items_list, items_swipe_refresh) { | ||||
|                 items_fastscroller.setViews(items_list, mView.items_swipe_refresh) { | ||||
|                     items_fastscroller.updateBubbleText(storedItems.getOrNull(it)?.getBubbleText() ?: "") | ||||
|                 } | ||||
|  | ||||
| @@ -169,7 +169,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb | ||||
|  | ||||
|     fun getScrollState() = getRecyclerLayoutManager().onSaveInstanceState() | ||||
|  | ||||
|     private fun getRecyclerLayoutManager() = (mView.items_list.layoutManager as LinearLayoutManager) | ||||
|     private fun getRecyclerLayoutManager() = (mView.items_list.layoutManager as MyLinearLayoutManager) | ||||
|  | ||||
|     private fun getItems(path: String, callback: (originalPath: String, items: ArrayList<FileDirItem>) -> Unit) { | ||||
|         skipItemUpdating = false | ||||
| @@ -280,15 +280,16 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun getRecyclerAdapter() = items_list.adapter as? ItemsAdapter | ||||
|     private fun getRecyclerAdapter() = mView.items_list.adapter as? ItemsAdapter | ||||
|  | ||||
|     override fun breadcrumbClicked(id: Int) { | ||||
|         if (id == 0) { | ||||
|             StoragePickerDialog(activity as SimpleActivity, currentPath) { | ||||
|                 getRecyclerAdapter()?.finishActMode() | ||||
|                 openPath(it) | ||||
|             } | ||||
|         } else { | ||||
|             val item = breadcrumbs.getChildAt(id).tag as FileDirItem | ||||
|             val item = mView.breadcrumbs.getChildAt(id).tag as FileDirItem | ||||
|             openPath(item.path) | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -11,15 +11,15 @@ | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="match_parent" | ||||
|         android:clipToPadding="false" | ||||
|         app:layoutManager="android.support.v7.widget.LinearLayoutManager"/> | ||||
|         app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"/> | ||||
|  | ||||
|     <com.simplemobiletools.commons.views.MyTextView | ||||
|         android:id="@+id/manage_favorites_placeholder" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_centerHorizontal="true" | ||||
|         android:layout_marginBottom="@dimen/small_margin" | ||||
|         android:layout_marginTop="@dimen/activity_margin" | ||||
|         android:layout_marginBottom="@dimen/small_margin" | ||||
|         android:gravity="center" | ||||
|         android:lineSpacingExtra="@dimen/tiny_margin" | ||||
|         android:paddingLeft="@dimen/activity_margin" | ||||
|   | ||||
| @@ -1,12 +1,12 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <android.support.design.widget.CoordinatorLayout | ||||
| <androidx.coordinatorlayout.widget.CoordinatorLayout | ||||
|     xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     android:id="@+id/items_holder" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent"> | ||||
|  | ||||
|     <android.support.v4.widget.SwipeRefreshLayout | ||||
|     <androidx.swiperefreshlayout.widget.SwipeRefreshLayout | ||||
|         android:id="@+id/items_swipe_refresh" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content"> | ||||
| @@ -29,23 +29,23 @@ | ||||
|                 android:layout_below="@+id/breadcrumbs" | ||||
|                 android:clipToPadding="false" | ||||
|                 android:scrollbars="none" | ||||
|                 app:layoutManager="android.support.v7.widget.LinearLayoutManager"/> | ||||
|                 app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"/> | ||||
|  | ||||
|             <com.simplemobiletools.commons.views.FastScroller | ||||
|                 android:id="@+id/items_fastscroller" | ||||
|                 android:layout_width="wrap_content" | ||||
|                 android:layout_height="match_parent" | ||||
|                 android:layout_below="@+id/breadcrumbs" | ||||
|                 android:layout_alignParentEnd="true" | ||||
|                 android:layout_alignParentRight="true" | ||||
|                 android:layout_below="@+id/breadcrumbs" | ||||
|                 android:paddingLeft="@dimen/normal_margin" | ||||
|                 android:paddingStart="@dimen/normal_margin"> | ||||
|                 android:paddingStart="@dimen/normal_margin" | ||||
|                 android:paddingLeft="@dimen/normal_margin"> | ||||
|  | ||||
|                 <include layout="@layout/fastscroller_handle_vertical"/> | ||||
|  | ||||
|             </com.simplemobiletools.commons.views.FastScroller> | ||||
|         </RelativeLayout> | ||||
|     </android.support.v4.widget.SwipeRefreshLayout> | ||||
|     </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> | ||||
|  | ||||
|     <com.simplemobiletools.commons.views.MyFloatingActionButton | ||||
|         android:id="@+id/items_fab" | ||||
| @@ -55,4 +55,4 @@ | ||||
|         android:layout_margin="@dimen/activity_margin" | ||||
|         android:src="@drawable/ic_plus"/> | ||||
|  | ||||
| </android.support.design.widget.CoordinatorLayout> | ||||
| </androidx.coordinatorlayout.widget.CoordinatorLayout> | ||||
|   | ||||
| @@ -5,7 +5,7 @@ | ||||
|         android:id="@+id/search" | ||||
|         android:icon="@drawable/ic_search" | ||||
|         android:title="@string/search" | ||||
|         app:actionViewClass="android.support.v7.widget.SearchView" | ||||
|         app:actionViewClass="androidx.appcompat.widget.SearchView" | ||||
|         app:showAsAction="collapseActionView|ifRoom"/> | ||||
|     <item | ||||
|         android:id="@+id/go_home" | ||||
|   | ||||
| @@ -5,7 +5,7 @@ | ||||
|         android:id="@+id/search" | ||||
|         android:icon="@drawable/ic_search" | ||||
|         android:title="@string/search" | ||||
|         app:actionViewClass="android.support.v7.widget.SearchView" | ||||
|         app:actionViewClass="androidx.appcompat.widget.SearchView" | ||||
|         app:showAsAction="collapseActionView|ifRoom"/> | ||||
|     <item | ||||
|         android:id="@+id/menu_save" | ||||
|   | ||||
| @@ -4,8 +4,8 @@ buildscript { | ||||
|     ext.kotlin_version = '1.2.71' | ||||
|  | ||||
|     repositories { | ||||
|         jcenter() | ||||
|         google() | ||||
|         jcenter() | ||||
|     } | ||||
|  | ||||
|     dependencies { | ||||
| @@ -19,8 +19,8 @@ buildscript { | ||||
|  | ||||
| allprojects { | ||||
|     repositories { | ||||
|         jcenter() | ||||
|         google() | ||||
|         jcenter() | ||||
|         maven { url "https://jitpack.io" } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user