rewrite ExcludeFolders activity to use a recyclerview
This commit is contained in:
parent
27f00cfe3c
commit
d596829fd6
9 changed files with 161 additions and 93 deletions
|
@ -47,7 +47,7 @@ ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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.davemorrissey.labs:subsampling-scale-image-view:3.8.0'
|
||||||
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
|
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
|
||||||
compile 'com.android.support:multidex:1.0.2'
|
compile 'com.android.support:multidex:1.0.2'
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package com.simplemobiletools.gallery.activities
|
package com.simplemobiletools.gallery.activities
|
||||||
|
|
||||||
import android.graphics.PorterDuff
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||||
|
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
|
import com.simplemobiletools.gallery.adapters.ExcludedFoldersAdapter
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import kotlinx.android.synthetic.main.activity_excluded_folders.*
|
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?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_excluded_folders)
|
setContentView(R.layout.activity_excluded_folders)
|
||||||
|
@ -19,27 +19,14 @@ class ExcludedFoldersActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateExcludedFolders() {
|
private fun updateExcludedFolders() {
|
||||||
excluded_folders_holder.removeAllViews()
|
val folders = ArrayList<String>()
|
||||||
val folders = config.excludedFolders
|
config.excludedFolders.mapTo(folders, { it })
|
||||||
excluded_folders_placeholder.beVisibleIf(folders.isEmpty())
|
manage_excluded_folders_placeholder.beVisibleIf(folders.isEmpty())
|
||||||
excluded_folders_placeholder.setTextColor(config.textColor)
|
manage_excluded_folders_placeholder.setTextColor(config.textColor)
|
||||||
|
|
||||||
for (folder in folders) {
|
val adapter = ExcludedFoldersAdapter(this, folders, this, manage_exclude_folders_list) {}
|
||||||
layoutInflater.inflate(R.layout.item_manage_folder, null, false).apply {
|
adapter.setupDragListener(true)
|
||||||
managed_folder_title.apply {
|
manage_exclude_folders_list.adapter = adapter
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
|
@ -55,6 +42,10 @@ class ExcludedFoldersActivity : SimpleActivity() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun refreshItems() {
|
||||||
|
updateExcludedFolders()
|
||||||
|
}
|
||||||
|
|
||||||
private fun addExcludedFolder() {
|
private fun addExcludedFolder() {
|
||||||
FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden) {
|
FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden) {
|
||||||
config.addExcludedFolder(it)
|
config.addExcludedFolder(it)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.simplemobiletools.gallery.activities
|
package com.simplemobiletools.gallery.activities
|
||||||
|
|
||||||
import android.graphics.PorterDuff
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
@ -27,18 +26,10 @@ class IncludedFoldersActivity : SimpleActivity() {
|
||||||
|
|
||||||
for (folder in folders) {
|
for (folder in folders) {
|
||||||
layoutInflater.inflate(R.layout.item_manage_folder, null, false).apply {
|
layoutInflater.inflate(R.layout.item_manage_folder, null, false).apply {
|
||||||
managed_folder_title.apply {
|
manage_folder_title.apply {
|
||||||
text = folder
|
text = folder
|
||||||
setTextColor(config.textColor)
|
setTextColor(config.textColor)
|
||||||
}
|
}
|
||||||
managed_folders_icon.apply {
|
|
||||||
setColorFilter(config.textColor, PorterDuff.Mode.SRC_IN)
|
|
||||||
setOnClickListener {
|
|
||||||
config.removeIncludedFolder(folder)
|
|
||||||
updateIncludedFolders()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
included_folders_holder.addView(this)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,16 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
|
||||||
|
|
||||||
override fun getItemCount() = dirs.size
|
override fun getItemCount() = dirs.size
|
||||||
|
|
||||||
|
override fun prepareActionMode(menu: Menu) {
|
||||||
|
menu.apply {
|
||||||
|
findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1
|
||||||
|
findItem(R.id.cab_change_cover_image).isVisible = selectedPositions.size == 1
|
||||||
|
|
||||||
|
checkHideBtnVisibility(this)
|
||||||
|
checkPinBtnVisibility(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun actionItemPressed(id: Int) {
|
override fun actionItemPressed(id: Int) {
|
||||||
when (id) {
|
when (id) {
|
||||||
R.id.cab_properties -> showProperties()
|
R.id.cab_properties -> showProperties()
|
||||||
|
@ -83,16 +93,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun prepareActionMode(menu: Menu) {
|
|
||||||
menu.apply {
|
|
||||||
findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1
|
|
||||||
findItem(R.id.cab_change_cover_image).isVisible = selectedPositions.size == 1
|
|
||||||
|
|
||||||
checkHideBtnVisibility(this)
|
|
||||||
checkPinBtnVisibility(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkHideBtnVisibility(menu: Menu) {
|
private fun checkHideBtnVisibility(menu: Menu) {
|
||||||
var hiddenCnt = 0
|
var hiddenCnt = 0
|
||||||
var unhiddenCnt = 0
|
var unhiddenCnt = 0
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
package com.simplemobiletools.gallery.adapters
|
||||||
|
|
||||||
|
import android.util.SparseArray
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
|
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||||
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
|
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||||
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
|
import com.simplemobiletools.gallery.R
|
||||||
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
|
import kotlinx.android.synthetic.main.item_manage_folder.view.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class ExcludedFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList<String>, 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<String>(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<View>()
|
||||||
|
(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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -65,6 +65,16 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
|
|
||||||
override fun getItemCount() = media.size
|
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) {
|
override fun actionItemPressed(id: Int) {
|
||||||
when (id) {
|
when (id) {
|
||||||
R.id.cab_confirm_selection -> confirmSelection()
|
R.id.cab_confirm_selection -> confirmSelection()
|
||||||
|
@ -83,16 +93,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
private fun checkHideBtnVisibility(menu: Menu) {
|
||||||
var hiddenCnt = 0
|
var hiddenCnt = 0
|
||||||
var unhiddenCnt = 0
|
var unhiddenCnt = 0
|
||||||
|
|
|
@ -247,7 +247,6 @@ class MediaFetcher(val context: Context) {
|
||||||
private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>) =
|
private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>) =
|
||||||
includedPaths.none { path.startsWith(it) } && excludedPaths.any { path.startsWith(it) }
|
includedPaths.none { path.startsWith(it) } && excludedPaths.any { path.startsWith(it) }
|
||||||
|
|
||||||
|
|
||||||
private fun getMediaInFolder(folder: String, curMedia: ArrayList<Medium>, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int) {
|
private fun getMediaInFolder(folder: String, curMedia: ArrayList<Medium>, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int) {
|
||||||
val files = File(folder).listFiles() ?: return
|
val files = File(folder).listFiles() ?: return
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
|
@ -296,10 +295,11 @@ class MediaFetcher(val context: Context) {
|
||||||
else -> MediaStore.Images.Media.DATE_TAKEN
|
else -> MediaStore.Images.Media.DATE_TAKEN
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (sorting and SORT_DESCENDING > 0)
|
return if (sorting and SORT_DESCENDING > 0) {
|
||||||
"$sortValue DESC"
|
"$sortValue DESC"
|
||||||
else
|
} else {
|
||||||
"$sortValue ASC"
|
"$sortValue ASC"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNoMediaFolders(): ArrayList<String> {
|
private fun getNoMediaFolders(): ArrayList<String> {
|
||||||
|
|
|
@ -1,30 +1,28 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ScrollView
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/excluded_folders_scrollview"
|
android:id="@+id/manage_exclude_folders_wrapper"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<RelativeLayout
|
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
android:id="@+id/exclude_folders_wrapper"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/manage_exclude_folders_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="match_parent"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
|
||||||
|
|
||||||
<LinearLayout
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/excluded_folders_holder"
|
android:id="@+id/manage_excluded_folders_placeholder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"/>
|
android:gravity="center_horizontal"
|
||||||
|
android:paddingLeft="@dimen/big_margin"
|
||||||
|
android:paddingRight="@dimen/big_margin"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:text="@string/excluded_activity_placeholder"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
</RelativeLayout>
|
||||||
android:id="@+id/excluded_folders_placeholder"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:paddingLeft="@dimen/big_margin"
|
|
||||||
android:paddingRight="@dimen/big_margin"
|
|
||||||
android:paddingTop="@dimen/activity_margin"
|
|
||||||
android:text="@string/excluded_activity_placeholder"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
</RelativeLayout>
|
|
||||||
</ScrollView>
|
|
||||||
|
|
|
@ -1,29 +1,22 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/managed_folder_holder"
|
android:id="@+id/manage_folder_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:foreground="@drawable/selector"
|
||||||
android:padding="@dimen/activity_margin">
|
android:padding="@dimen/activity_margin">
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/managed_folder_title"
|
android:id="@+id/manage_folder_title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_marginLeft="@dimen/medium_margin"
|
android:layout_marginLeft="@dimen/medium_margin"
|
||||||
android:layout_marginRight="@dimen/medium_margin"
|
android:layout_marginRight="@dimen/medium_margin"
|
||||||
android:layout_toLeftOf="@+id/managed_folders_icon"
|
android:layout_marginTop="@dimen/medium_margin"/>
|
||||||
android:layout_toStartOf="@+id/managed_folders_icon"/>
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/managed_folders_icon"
|
|
||||||
style="@style/MyBorderlessBackgroundStyle"
|
|
||||||
android:layout_width="@dimen/normal_icon_size"
|
|
||||||
android:layout_height="@dimen/normal_icon_size"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:padding="@dimen/medium_margin"
|
|
||||||
android:src="@drawable/ic_cross"/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
Loading…
Reference in a new issue