From f1c5699fe649d10fbbaeb0cc4b87746de6e2e4ae Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 19 Nov 2016 19:45:38 +0100 Subject: [PATCH] add the Properties cab --- .../gallery/activities/MediaActivity.kt | 46 +------------------ .../gallery/adapters/MediaAdapter.kt | 20 +++++++- 2 files changed, 21 insertions(+), 45 deletions(-) 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 787dce047..0c74c4d0d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -355,17 +355,6 @@ class MediaActivity : SimpleActivity(), AdapterView.OnItemClickListener, View.On } } - private fun showProperties() { - /*val selectedMedia = getSelectedMedia() - if (selectedMedia.size == 1) { - PropertiesDialog(this, selectedMedia[0].path, false) - } else { - val paths = ArrayList(selectedMedia.size) - selectedMedia.mapTo(paths) { it.path } - PropertiesDialog(this, paths, false) - }*/ - } - private fun isSetWallpaperIntent() = intent.getBooleanExtra(Constants.SET_WALLPAPER_INTENT, false) private fun displayCopyDialog() { @@ -412,7 +401,7 @@ class MediaActivity : SimpleActivity(), AdapterView.OnItemClickListener, View.On WallpaperManager.getInstance(applicationContext).setBitmap(bitmap) setResult(Activity.RESULT_OK) } catch (e: IOException) { - Log.e(TAG, "item click " + e.message) + Log.e(TAG, "item click $e") } finish() @@ -432,35 +421,8 @@ class MediaActivity : SimpleActivity(), AdapterView.OnItemClickListener, View.On } } - /*override fun onItemCheckedStateChanged(mode: ActionMode, position: Int, id: Long, checked: Boolean) { - if (checked) { - mSelectedItemsCnt++ - } else { - mSelectedItemsCnt-- - } - - if (mSelectedItemsCnt > 0) - mode.title = mSelectedItemsCnt.toString() - - mode.invalidate() - } - - override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { - val inflater = mode.menuInflater - inflater.inflate(R.menu.cab_media, menu) - return true - } - - override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { - return false - } - - override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { + /*override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { when (item.itemId) { - R.id.cab_properties -> { - showProperties() - return true - } R.id.cab_share -> { shareMedia() return true @@ -476,10 +438,6 @@ class MediaActivity : SimpleActivity(), AdapterView.OnItemClickListener, View.On } else -> return false } - } - - override fun onDestroyActionMode(mode: ActionMode) { - mSelectedItemsCnt = 0 }*/ override fun onTouch(v: View, event: MotionEvent): Boolean { 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 7f4523881..1e8996a20 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -10,6 +10,7 @@ import com.bignerdranch.android.multiselector.SwappingHolder import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.signature.StringSignature +import com.simplemobiletools.fileproperties.dialogs.PropertiesDialog import com.simplemobiletools.gallery.Config import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity @@ -39,7 +40,13 @@ class MediaAdapter(val activity: SimpleActivity, val media: MutableList, val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { - return false + return when (item.itemId) { + R.id.cab_properties -> { + showProperties() + true + } + else -> false + } } override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean { @@ -57,6 +64,17 @@ class MediaAdapter(val activity: SimpleActivity, val media: MutableList, } } + private fun showProperties() { + val selections = multiSelector.selectedPositions + if (selections.size <= 1) { + PropertiesDialog(activity, media[selections[0]].path, config.showHiddenFolders) + } else { + val paths = ArrayList() + selections.forEach { paths.add(media[it].path) } + PropertiesDialog(activity, paths, config.showHiddenFolders) + } + } + override fun onBindViewHolder(holder: ViewHolder, position: Int) { views.add(holder.bindView(activity, multiSelectorMode, multiSelector, media[position])) }