show the reordering drag handles when appropriate
This commit is contained in:
parent
c3bcbd6174
commit
c73300ccd2
|
@ -11,6 +11,8 @@ import android.view.Menu
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.google.gson.Gson
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
|
@ -18,6 +20,9 @@ import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
|||
import com.simplemobiletools.commons.dialogs.*
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.interfaces.ItemMoveCallback
|
||||
import com.simplemobiletools.commons.interfaces.ItemTouchHelperContract
|
||||
import com.simplemobiletools.commons.interfaces.StartReorderDragListener
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
|
@ -31,6 +36,7 @@ import com.simplemobiletools.gallery.pro.helpers.*
|
|||
import com.simplemobiletools.gallery.pro.interfaces.DirectoryOperationsListener
|
||||
import com.simplemobiletools.gallery.pro.models.AlbumCover
|
||||
import com.simplemobiletools.gallery.pro.models.Directory
|
||||
import kotlinx.android.synthetic.main.directory_item_grid_square.view.*
|
||||
import kotlinx.android.synthetic.main.directory_item_grid_square.view.dir_check
|
||||
import kotlinx.android.synthetic.main.directory_item_grid_square.view.dir_location
|
||||
import kotlinx.android.synthetic.main.directory_item_grid_square.view.dir_lock
|
||||
|
@ -38,11 +44,14 @@ import kotlinx.android.synthetic.main.directory_item_grid_square.view.dir_name
|
|||
import kotlinx.android.synthetic.main.directory_item_grid_square.view.dir_pin
|
||||
import kotlinx.android.synthetic.main.directory_item_grid_square.view.dir_thumbnail
|
||||
import kotlinx.android.synthetic.main.directory_item_list.view.*
|
||||
import kotlinx.android.synthetic.main.directory_item_list.view.dir_drag_handle
|
||||
import kotlinx.android.synthetic.main.directory_item_list.view.dir_holder
|
||||
import kotlinx.android.synthetic.main.directory_item_list.view.photo_cnt
|
||||
import java.io.File
|
||||
|
||||
class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directory>, val listener: DirectoryOperationsListener?, recyclerView: MyRecyclerView,
|
||||
val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick), ItemTouchHelperContract {
|
||||
|
||||
private val config = activity.config
|
||||
private val isListViewType = config.viewTypeFolders == VIEW_TYPE_LIST
|
||||
|
@ -53,6 +62,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
private var groupDirectSubfolders = config.groupDirectSubfolders
|
||||
private var currentDirectoriesHash = dirs.hashCode()
|
||||
private var lockedFolderPaths = ArrayList<String>()
|
||||
private var isChangingOrder = false
|
||||
private var startReorderDragListener: StartReorderDragListener
|
||||
|
||||
private var showMediaCount = config.showFolderMediaCount
|
||||
private var folderStyle = config.folderStyle
|
||||
|
@ -61,6 +72,15 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
init {
|
||||
setupDragListener(true)
|
||||
fillLockedFolders()
|
||||
|
||||
val touchHelper = ItemTouchHelper(ItemMoveCallback(this, true))
|
||||
touchHelper.attachToRecyclerView(recyclerView)
|
||||
|
||||
startReorderDragListener = object : StartReorderDragListener {
|
||||
override fun requestDrag(viewHolder: RecyclerView.ViewHolder) {
|
||||
touchHelper.startDrag(viewHolder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getActionMenuId() = R.menu.cab_directories
|
||||
|
@ -119,6 +139,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
R.id.cab_rename -> renameDir()
|
||||
R.id.cab_pin -> pinFolders(true)
|
||||
R.id.cab_unpin -> pinFolders(false)
|
||||
R.id.cab_change_order -> changeOrder()
|
||||
R.id.cab_empty_recycle_bin -> tryEmptyRecycleBin(true)
|
||||
R.id.cab_empty_disable_recycle_bin -> emptyAndDisableRecycleBin()
|
||||
R.id.cab_hide -> toggleFoldersVisibility(true)
|
||||
|
@ -146,7 +167,13 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
|
||||
override fun onActionModeCreated() {}
|
||||
|
||||
override fun onActionModeDestroyed() {}
|
||||
override fun onActionModeDestroyed() {
|
||||
if (isChangingOrder) {
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
isChangingOrder = false
|
||||
}
|
||||
|
||||
override fun onViewRecycled(holder: ViewHolder) {
|
||||
super.onViewRecycled(holder)
|
||||
|
@ -426,6 +453,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
listener?.recheckPinnedFolders()
|
||||
}
|
||||
|
||||
private fun changeOrder() {
|
||||
isChangingOrder = true
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun moveFilesTo() {
|
||||
activity.handleDeletePasswordProtection {
|
||||
copyMoveTo(false)
|
||||
|
@ -759,7 +791,19 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
dir_path.setTextColor(textColor)
|
||||
dir_pin.applyColorFilter(textColor)
|
||||
dir_location.applyColorFilter(textColor)
|
||||
dir_drag_handle.beVisibleIf(isChangingOrder)
|
||||
} else {
|
||||
dir_drag_handle_wrapper.beVisibleIf(isChangingOrder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRowClear(myViewHolder: ViewHolder?) {
|
||||
}
|
||||
|
||||
override fun onRowMoved(fromPosition: Int, toPosition: Int) {
|
||||
}
|
||||
|
||||
override fun onRowSelected(myViewHolder: ViewHolder?) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,18 +42,27 @@
|
|||
android:src="@drawable/ic_check_vector"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dir_drag_handle"
|
||||
android:layout_width="@dimen/drag_handle_size"
|
||||
android:layout_height="@dimen/drag_handle_size"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_margin="@dimen/medium_margin"
|
||||
android:background="@drawable/circle_black_background"
|
||||
android:contentDescription="@string/reorder_by_dragging"
|
||||
android:padding="@dimen/small_margin"
|
||||
android:src="@drawable/ic_drag_handle_vector"
|
||||
android:visibility="gone" />
|
||||
<RelativeLayout
|
||||
android:id="@+id/dir_drag_handle_wrapper"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignStart="@+id/dir_name"
|
||||
android:layout_alignEnd="@+id/dir_name"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dir_drag_handle"
|
||||
android:layout_width="@dimen/drag_handle_size"
|
||||
android:layout_height="@dimen/drag_handle_size"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_margin="@dimen/medium_margin"
|
||||
android:background="@drawable/circle_black_background"
|
||||
android:contentDescription="@string/reorder_by_dragging"
|
||||
android:padding="@dimen/small_margin"
|
||||
android:src="@drawable/ic_drag_handle_vector" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dir_pin"
|
||||
|
|
|
@ -55,18 +55,27 @@
|
|||
android:src="@drawable/ic_pin"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dir_drag_handle"
|
||||
android:layout_width="@dimen/drag_handle_size"
|
||||
android:layout_height="@dimen/drag_handle_size"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_margin="@dimen/medium_margin"
|
||||
android:background="@drawable/circle_black_background"
|
||||
android:contentDescription="@string/reorder_by_dragging"
|
||||
android:padding="@dimen/small_margin"
|
||||
android:src="@drawable/ic_drag_handle_vector"
|
||||
android:visibility="gone" />
|
||||
<RelativeLayout
|
||||
android:id="@+id/dir_drag_handle_wrapper"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignStart="@+id/dir_shadow_holder"
|
||||
android:layout_alignEnd="@+id/dir_shadow_holder"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dir_drag_handle"
|
||||
android:layout_width="@dimen/drag_handle_size"
|
||||
android:layout_height="@dimen/drag_handle_size"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_margin="@dimen/medium_margin"
|
||||
android:background="@drawable/circle_black_background"
|
||||
android:contentDescription="@string/reorder_by_dragging"
|
||||
android:padding="@dimen/small_margin"
|
||||
android:src="@drawable/ic_drag_handle_vector" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dir_shadow_holder"
|
||||
|
|
|
@ -1,73 +1,78 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/cab_delete"
|
||||
android:icon="@drawable/ic_delete_vector"
|
||||
android:title="@string/delete"
|
||||
app:showAsAction="ifRoom"/>
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/cab_properties"
|
||||
android:icon="@drawable/ic_info"
|
||||
android:title="@string/properties"
|
||||
app:showAsAction="ifRoom"/>
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/cab_pin"
|
||||
android:icon="@drawable/ic_pin"
|
||||
android:title="@string/pin_to_the_top"
|
||||
app:showAsAction="ifRoom"/>
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/cab_unpin"
|
||||
android:icon="@drawable/ic_unpin"
|
||||
android:title="@string/unpin_folder"
|
||||
app:showAsAction="ifRoom"/>
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/cab_change_order"
|
||||
android:icon="@drawable/ic_drag_handle_vector"
|
||||
android:title="@string/reorder_by_dragging"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/cab_rename"
|
||||
android:icon="@drawable/ic_rename_new"
|
||||
android:title="@string/rename"
|
||||
app:showAsAction="ifRoom"/>
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/cab_hide"
|
||||
android:icon="@drawable/ic_hide"
|
||||
android:title="@string/hide_folder"
|
||||
app:showAsAction="ifRoom"/>
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/cab_unhide"
|
||||
android:icon="@drawable/ic_unhide_vector"
|
||||
android:title="@string/unhide_folder"
|
||||
app:showAsAction="ifRoom"/>
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/cab_copy_to"
|
||||
android:title="@string/copy_to"
|
||||
app:showAsAction="never"/>
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/cab_move_to"
|
||||
android:title="@string/move_to"
|
||||
app:showAsAction="never"/>
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/cab_create_shortcut"
|
||||
android:title="@string/create_shortcut"
|
||||
app:showAsAction="never"/>
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/cab_empty_recycle_bin"
|
||||
android:title="@string/empty_recycle_bin"
|
||||
app:showAsAction="never"/>
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/cab_empty_disable_recycle_bin"
|
||||
android:title="@string/empty_and_disable_recycle_bin"
|
||||
app:showAsAction="never"/>
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/cab_exclude"
|
||||
android:title="@string/exclude"
|
||||
app:showAsAction="never"/>
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/cab_lock"
|
||||
android:title="@string/lock_folder"
|
||||
app:showAsAction="never"/>
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/cab_unlock"
|
||||
android:title="@string/unlock_folder"
|
||||
app:showAsAction="never"/>
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/cab_change_cover_image"
|
||||
android:title="@string/change_cover_image"
|
||||
|
@ -75,15 +80,15 @@
|
|||
<menu>
|
||||
<item
|
||||
android:id="@+id/cab_select_photo"
|
||||
android:title="@string/select_photo"/>
|
||||
android:title="@string/select_photo" />
|
||||
<item
|
||||
android:id="@+id/cab_use_default"
|
||||
android:title="@string/use_default"/>
|
||||
android:title="@string/use_default" />
|
||||
</menu>
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/cab_select_all"
|
||||
android:icon="@drawable/ic_select_all_vector"
|
||||
android:title="@string/select_all"
|
||||
app:showAsAction="ifRoom"/>
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|
||||
|
|
Loading…
Reference in New Issue