mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
show the reordering drag handles when appropriate
This commit is contained in:
parent
c3bcbd6174
commit
c73300ccd2
4 changed files with 112 additions and 45 deletions
|
@ -11,6 +11,8 @@ import android.view.Menu
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
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.dialogs.*
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
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.models.FileDirItem
|
||||||
import com.simplemobiletools.commons.views.FastScroller
|
import com.simplemobiletools.commons.views.FastScroller
|
||||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
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.interfaces.DirectoryOperationsListener
|
||||||
import com.simplemobiletools.gallery.pro.models.AlbumCover
|
import com.simplemobiletools.gallery.pro.models.AlbumCover
|
||||||
import com.simplemobiletools.gallery.pro.models.Directory
|
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_check
|
||||||
import kotlinx.android.synthetic.main.directory_item_grid_square.view.dir_location
|
import kotlinx.android.synthetic.main.directory_item_grid_square.view.dir_location
|
||||||
import kotlinx.android.synthetic.main.directory_item_grid_square.view.dir_lock
|
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_pin
|
||||||
import kotlinx.android.synthetic.main.directory_item_grid_square.view.dir_thumbnail
|
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.*
|
||||||
|
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
|
import java.io.File
|
||||||
|
|
||||||
class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directory>, val listener: DirectoryOperationsListener?, recyclerView: MyRecyclerView,
|
class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directory>, val listener: DirectoryOperationsListener?, recyclerView: MyRecyclerView,
|
||||||
val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) :
|
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 config = activity.config
|
||||||
private val isListViewType = config.viewTypeFolders == VIEW_TYPE_LIST
|
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 groupDirectSubfolders = config.groupDirectSubfolders
|
||||||
private var currentDirectoriesHash = dirs.hashCode()
|
private var currentDirectoriesHash = dirs.hashCode()
|
||||||
private var lockedFolderPaths = ArrayList<String>()
|
private var lockedFolderPaths = ArrayList<String>()
|
||||||
|
private var isChangingOrder = false
|
||||||
|
private var startReorderDragListener: StartReorderDragListener
|
||||||
|
|
||||||
private var showMediaCount = config.showFolderMediaCount
|
private var showMediaCount = config.showFolderMediaCount
|
||||||
private var folderStyle = config.folderStyle
|
private var folderStyle = config.folderStyle
|
||||||
|
@ -61,6 +72,15 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
init {
|
init {
|
||||||
setupDragListener(true)
|
setupDragListener(true)
|
||||||
fillLockedFolders()
|
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
|
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_rename -> renameDir()
|
||||||
R.id.cab_pin -> pinFolders(true)
|
R.id.cab_pin -> pinFolders(true)
|
||||||
R.id.cab_unpin -> pinFolders(false)
|
R.id.cab_unpin -> pinFolders(false)
|
||||||
|
R.id.cab_change_order -> changeOrder()
|
||||||
R.id.cab_empty_recycle_bin -> tryEmptyRecycleBin(true)
|
R.id.cab_empty_recycle_bin -> tryEmptyRecycleBin(true)
|
||||||
R.id.cab_empty_disable_recycle_bin -> emptyAndDisableRecycleBin()
|
R.id.cab_empty_disable_recycle_bin -> emptyAndDisableRecycleBin()
|
||||||
R.id.cab_hide -> toggleFoldersVisibility(true)
|
R.id.cab_hide -> toggleFoldersVisibility(true)
|
||||||
|
@ -146,7 +167,13 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
|
|
||||||
override fun onActionModeCreated() {}
|
override fun onActionModeCreated() {}
|
||||||
|
|
||||||
override fun onActionModeDestroyed() {}
|
override fun onActionModeDestroyed() {
|
||||||
|
if (isChangingOrder) {
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
isChangingOrder = false
|
||||||
|
}
|
||||||
|
|
||||||
override fun onViewRecycled(holder: ViewHolder) {
|
override fun onViewRecycled(holder: ViewHolder) {
|
||||||
super.onViewRecycled(holder)
|
super.onViewRecycled(holder)
|
||||||
|
@ -426,6 +453,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
listener?.recheckPinnedFolders()
|
listener?.recheckPinnedFolders()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun changeOrder() {
|
||||||
|
isChangingOrder = true
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
private fun moveFilesTo() {
|
private fun moveFilesTo() {
|
||||||
activity.handleDeletePasswordProtection {
|
activity.handleDeletePasswordProtection {
|
||||||
copyMoveTo(false)
|
copyMoveTo(false)
|
||||||
|
@ -759,7 +791,19 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
dir_path.setTextColor(textColor)
|
dir_path.setTextColor(textColor)
|
||||||
dir_pin.applyColorFilter(textColor)
|
dir_pin.applyColorFilter(textColor)
|
||||||
dir_location.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,6 +42,14 @@
|
||||||
android:src="@drawable/ic_check_vector"
|
android:src="@drawable/ic_check_vector"
|
||||||
android:visibility="gone" />
|
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
|
<ImageView
|
||||||
android:id="@+id/dir_drag_handle"
|
android:id="@+id/dir_drag_handle"
|
||||||
android:layout_width="@dimen/drag_handle_size"
|
android:layout_width="@dimen/drag_handle_size"
|
||||||
|
@ -52,8 +60,9 @@
|
||||||
android:background="@drawable/circle_black_background"
|
android:background="@drawable/circle_black_background"
|
||||||
android:contentDescription="@string/reorder_by_dragging"
|
android:contentDescription="@string/reorder_by_dragging"
|
||||||
android:padding="@dimen/small_margin"
|
android:padding="@dimen/small_margin"
|
||||||
android:src="@drawable/ic_drag_handle_vector"
|
android:src="@drawable/ic_drag_handle_vector" />
|
||||||
android:visibility="gone" />
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/dir_pin"
|
android:id="@+id/dir_pin"
|
||||||
|
|
|
@ -55,6 +55,14 @@
|
||||||
android:src="@drawable/ic_pin"
|
android:src="@drawable/ic_pin"
|
||||||
android:visibility="gone" />
|
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
|
<ImageView
|
||||||
android:id="@+id/dir_drag_handle"
|
android:id="@+id/dir_drag_handle"
|
||||||
android:layout_width="@dimen/drag_handle_size"
|
android:layout_width="@dimen/drag_handle_size"
|
||||||
|
@ -65,8 +73,9 @@
|
||||||
android:background="@drawable/circle_black_background"
|
android:background="@drawable/circle_black_background"
|
||||||
android:contentDescription="@string/reorder_by_dragging"
|
android:contentDescription="@string/reorder_by_dragging"
|
||||||
android:padding="@dimen/small_margin"
|
android:padding="@dimen/small_margin"
|
||||||
android:src="@drawable/ic_drag_handle_vector"
|
android:src="@drawable/ic_drag_handle_vector" />
|
||||||
android:visibility="gone" />
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/dir_shadow_holder"
|
android:id="@+id/dir_shadow_holder"
|
||||||
|
|
|
@ -5,69 +5,74 @@
|
||||||
android:id="@+id/cab_delete"
|
android:id="@+id/cab_delete"
|
||||||
android:icon="@drawable/ic_delete_vector"
|
android:icon="@drawable/ic_delete_vector"
|
||||||
android:title="@string/delete"
|
android:title="@string/delete"
|
||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_properties"
|
android:id="@+id/cab_properties"
|
||||||
android:icon="@drawable/ic_info"
|
android:icon="@drawable/ic_info"
|
||||||
android:title="@string/properties"
|
android:title="@string/properties"
|
||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_pin"
|
android:id="@+id/cab_pin"
|
||||||
android:icon="@drawable/ic_pin"
|
android:icon="@drawable/ic_pin"
|
||||||
android:title="@string/pin_to_the_top"
|
android:title="@string/pin_to_the_top"
|
||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_unpin"
|
android:id="@+id/cab_unpin"
|
||||||
android:icon="@drawable/ic_unpin"
|
android:icon="@drawable/ic_unpin"
|
||||||
android:title="@string/unpin_folder"
|
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
|
<item
|
||||||
android:id="@+id/cab_rename"
|
android:id="@+id/cab_rename"
|
||||||
android:icon="@drawable/ic_rename_new"
|
android:icon="@drawable/ic_rename_new"
|
||||||
android:title="@string/rename"
|
android:title="@string/rename"
|
||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_hide"
|
android:id="@+id/cab_hide"
|
||||||
android:icon="@drawable/ic_hide"
|
android:icon="@drawable/ic_hide"
|
||||||
android:title="@string/hide_folder"
|
android:title="@string/hide_folder"
|
||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_unhide"
|
android:id="@+id/cab_unhide"
|
||||||
android:icon="@drawable/ic_unhide_vector"
|
android:icon="@drawable/ic_unhide_vector"
|
||||||
android:title="@string/unhide_folder"
|
android:title="@string/unhide_folder"
|
||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_copy_to"
|
android:id="@+id/cab_copy_to"
|
||||||
android:title="@string/copy_to"
|
android:title="@string/copy_to"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_move_to"
|
android:id="@+id/cab_move_to"
|
||||||
android:title="@string/move_to"
|
android:title="@string/move_to"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_create_shortcut"
|
android:id="@+id/cab_create_shortcut"
|
||||||
android:title="@string/create_shortcut"
|
android:title="@string/create_shortcut"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_empty_recycle_bin"
|
android:id="@+id/cab_empty_recycle_bin"
|
||||||
android:title="@string/empty_recycle_bin"
|
android:title="@string/empty_recycle_bin"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_empty_disable_recycle_bin"
|
android:id="@+id/cab_empty_disable_recycle_bin"
|
||||||
android:title="@string/empty_and_disable_recycle_bin"
|
android:title="@string/empty_and_disable_recycle_bin"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_exclude"
|
android:id="@+id/cab_exclude"
|
||||||
android:title="@string/exclude"
|
android:title="@string/exclude"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_lock"
|
android:id="@+id/cab_lock"
|
||||||
android:title="@string/lock_folder"
|
android:title="@string/lock_folder"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_unlock"
|
android:id="@+id/cab_unlock"
|
||||||
android:title="@string/unlock_folder"
|
android:title="@string/unlock_folder"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_change_cover_image"
|
android:id="@+id/cab_change_cover_image"
|
||||||
android:title="@string/change_cover_image"
|
android:title="@string/change_cover_image"
|
||||||
|
@ -75,15 +80,15 @@
|
||||||
<menu>
|
<menu>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_select_photo"
|
android:id="@+id/cab_select_photo"
|
||||||
android:title="@string/select_photo"/>
|
android:title="@string/select_photo" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_use_default"
|
android:id="@+id/cab_use_default"
|
||||||
android:title="@string/use_default"/>
|
android:title="@string/use_default" />
|
||||||
</menu>
|
</menu>
|
||||||
</item>
|
</item>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_select_all"
|
android:id="@+id/cab_select_all"
|
||||||
android:icon="@drawable/ic_select_all_vector"
|
android:icon="@drawable/ic_select_all_vector"
|
||||||
android:title="@string/select_all"
|
android:title="@string/select_all"
|
||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom" />
|
||||||
</menu>
|
</menu>
|
||||||
|
|
Loading…
Reference in a new issue