diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index ed41ca45b..1cba45262 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -25,6 +25,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.DirectoryAdapter import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog +import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Directory @@ -203,7 +204,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } private fun showFilterMediaDialog() { - + FilterMediaDialog(this) { + getDirectories() + } } private fun showAllMedia() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 87417c774..6ef580071 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -27,6 +27,7 @@ import com.simplemobiletools.gallery.adapters.MediaAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog +import com.simplemobiletools.gallery.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium @@ -235,7 +236,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun showFilterMediaDialog() { - + FilterMediaDialog(this) { + getMedia() + } } private fun toggleFilenameVisibility() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt new file mode 100644 index 000000000..f99fc98c3 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt @@ -0,0 +1,46 @@ +package com.simplemobiletools.gallery.dialogs + +import android.support.v7.app.AlertDialog +import android.view.LayoutInflater +import android.view.View +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.activities.SimpleActivity +import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.helpers.GIFS +import com.simplemobiletools.gallery.helpers.IMAGES +import com.simplemobiletools.gallery.helpers.VIDEOS +import kotlinx.android.synthetic.main.dialog_filter_media.view.* + +class FilterMediaDialog(val activity: SimpleActivity, val callback: (result: Int) -> Unit) { + private var view: View = LayoutInflater.from(activity).inflate(R.layout.dialog_filter_media, null) + + init { + val filterMedia = activity.config.filterMedia + view.apply { + filter_media_images.isChecked = filterMedia and IMAGES != 0 + filter_media_videos.isChecked = filterMedia and VIDEOS != 0 + filter_media_gifs.isChecked = filterMedia and GIFS != 0 + } + + AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this, R.string.filter_media) + } + } + + private fun dialogConfirmed() { + var result = 0 + if (view.filter_media_images.isChecked) + result += IMAGES + if (view.filter_media_videos.isChecked) + result += VIDEOS + if (view.filter_media_gifs.isChecked) + result += GIFS + + activity.config.filterMedia = result + callback(result) + } +} diff --git a/app/src/main/res/layout/dialog_filter_media.xml b/app/src/main/res/layout/dialog_filter_media.xml new file mode 100644 index 000000000..37f2aba11 --- /dev/null +++ b/app/src/main/res/layout/dialog_filter_media.xml @@ -0,0 +1,36 @@ + + + + + + + + + +