diff --git a/app/build.gradle b/app/build.gradle index 8ab505b18..ebbea3a28 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - compile 'com.simplemobiletools:commons:2.39.9' + compile 'com.simplemobiletools:commons:2.39.10' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.8.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.android.support:multidex:1.0.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ExcludedFoldersActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ExcludedFoldersActivity.kt index a37f6d452..b05f8fbcd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ExcludedFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ExcludedFoldersActivity.kt @@ -1,17 +1,17 @@ package com.simplemobiletools.gallery.activities -import android.graphics.PorterDuff import android.os.Bundle import android.view.Menu import android.view.MenuItem import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.beVisibleIf +import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.adapters.ExcludedFoldersAdapter import com.simplemobiletools.gallery.extensions.config import kotlinx.android.synthetic.main.activity_excluded_folders.* -import kotlinx.android.synthetic.main.item_manage_folder.view.* -class ExcludedFoldersActivity : SimpleActivity() { +class ExcludedFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_excluded_folders) @@ -19,27 +19,14 @@ class ExcludedFoldersActivity : SimpleActivity() { } private fun updateExcludedFolders() { - excluded_folders_holder.removeAllViews() - val folders = config.excludedFolders - excluded_folders_placeholder.beVisibleIf(folders.isEmpty()) - excluded_folders_placeholder.setTextColor(config.textColor) + val folders = ArrayList() + config.excludedFolders.mapTo(folders, { it }) + manage_excluded_folders_placeholder.beVisibleIf(folders.isEmpty()) + manage_excluded_folders_placeholder.setTextColor(config.textColor) - for (folder in folders) { - layoutInflater.inflate(R.layout.item_manage_folder, null, false).apply { - managed_folder_title.apply { - text = folder - setTextColor(config.textColor) - } - managed_folders_icon.apply { - setColorFilter(config.textColor, PorterDuff.Mode.SRC_IN) - setOnClickListener { - config.removeExcludedFolder(folder) - updateExcludedFolders() - } - } - excluded_folders_holder.addView(this) - } - } + val adapter = ExcludedFoldersAdapter(this, folders, this, manage_exclude_folders_list) {} + adapter.setupDragListener(true) + manage_exclude_folders_list.adapter = adapter } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -55,6 +42,10 @@ class ExcludedFoldersActivity : SimpleActivity() { return true } + override fun refreshItems() { + updateExcludedFolders() + } + private fun addExcludedFolder() { FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden) { config.addExcludedFolder(it) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt index c6ccb0437..2ddc9aaa7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt @@ -1,6 +1,5 @@ package com.simplemobiletools.gallery.activities -import android.graphics.PorterDuff import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -27,18 +26,10 @@ class IncludedFoldersActivity : SimpleActivity() { for (folder in folders) { layoutInflater.inflate(R.layout.item_manage_folder, null, false).apply { - managed_folder_title.apply { + manage_folder_title.apply { text = folder setTextColor(config.textColor) } - managed_folders_icon.apply { - setColorFilter(config.textColor, PorterDuff.Mode.SRC_IN) - setOnClickListener { - config.removeIncludedFolder(folder) - updateIncludedFolders() - } - } - included_folders_holder.addView(this) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 45ef0b575..74a25b4a9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -65,6 +65,16 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList showProperties() @@ -83,16 +93,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList, val listener: RefreshRecyclerViewListener?, recyclerView: MyRecyclerView, + itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) { + + private val config = activity.config + + init { + selectableItemCount = folders.size + } + + override fun getActionMenuId() = R.menu.cab_delete_only + + override fun prepareActionMode(menu: Menu) {} + + override fun prepareItemSelection(view: View) {} + + override fun markItemSelection(select: Boolean, view: View?) { + view?.manage_folder_holder?.isSelected = select + } + + override fun actionItemPressed(id: Int) { + when (id) { + R.id.cab_delete -> askConfirmDelete() + } + } + + override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int) = createViewHolder(R.layout.item_manage_folder, parent) + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val folder = folders[position] + val view = holder.bindView(folder) { + setupView(it, folder) + } + bindViewHolder(holder, position, view) + } + + override fun getItemCount() = folders.size + + private fun setupView(view: View, folder: String) { + view.apply { + manage_folder_title.apply { + text = folder + setTextColor(config.textColor) + } + } + } + + private fun askConfirmDelete() { + ConfirmationDialog(activity) { + deleteSelection() + } + } + + private fun deleteSelection() { + val removeFolders = ArrayList(selectedPositions.size) + + selectedPositions.sortedDescending().forEach { + val folder = folders[it] + removeFolders.add(folder) + notifyItemRemoved(it) + itemViews.put(it, null) + config.removeExcludedFolder(folder) + } + + folders.removeAll(removeFolders) + selectedPositions.clear() + + val newItems = SparseArray() + (0 until itemViews.size()) + .filter { itemViews[it] != null } + .forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) } + + itemViews = newItems + selectableItemCount = folders.size + finishActMode() + if (folders.isEmpty()) { + listener?.refreshItems() + } + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 25839994a..c1a4a2c1d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -65,6 +65,16 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, override fun getItemCount() = media.size + override fun prepareActionMode(menu: Menu) { + menu.apply { + findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1 + findItem(R.id.cab_open_with).isVisible = selectedPositions.size == 1 + findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedPositions.size > 0 + + checkHideBtnVisibility(this) + } + } + override fun actionItemPressed(id: Int) { when (id) { R.id.cab_confirm_selection -> confirmSelection() @@ -83,16 +93,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, } } - override fun prepareActionMode(menu: Menu) { - menu.apply { - findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1 - findItem(R.id.cab_open_with).isVisible = selectedPositions.size == 1 - findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedPositions.size > 0 - - checkHideBtnVisibility(this) - } - } - private fun checkHideBtnVisibility(menu: Menu) { var hiddenCnt = 0 var unhiddenCnt = 0 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 33e1fa98c..cce57aa36 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -247,7 +247,6 @@ class MediaFetcher(val context: Context) { private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet, includedPaths: MutableSet) = includedPaths.none { path.startsWith(it) } && excludedPaths.any { path.startsWith(it) } - private fun getMediaInFolder(folder: String, curMedia: ArrayList, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int) { val files = File(folder).listFiles() ?: return for (file in files) { @@ -296,10 +295,11 @@ class MediaFetcher(val context: Context) { else -> MediaStore.Images.Media.DATE_TAKEN } - return if (sorting and SORT_DESCENDING > 0) + return if (sorting and SORT_DESCENDING > 0) { "$sortValue DESC" - else + } else { "$sortValue ASC" + } } private fun getNoMediaFolders(): ArrayList { diff --git a/app/src/main/res/layout/activity_excluded_folders.xml b/app/src/main/res/layout/activity_excluded_folders.xml index 64df37244..62e36ecb6 100644 --- a/app/src/main/res/layout/activity_excluded_folders.xml +++ b/app/src/main/res/layout/activity_excluded_folders.xml @@ -1,30 +1,28 @@ - - + android:layout_height="match_parent" + android:clipToPadding="false" + app:layoutManager="android.support.v7.widget.LinearLayoutManager"/> - + - - - + diff --git a/app/src/main/res/layout/item_manage_folder.xml b/app/src/main/res/layout/item_manage_folder.xml index ac706585a..594e3a45b 100644 --- a/app/src/main/res/layout/item_manage_folder.xml +++ b/app/src/main/res/layout/item_manage_folder.xml @@ -1,29 +1,22 @@ - - + android:layout_marginTop="@dimen/medium_margin"/>