diff --git a/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt index 5003aa8..ffa7d90 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt @@ -35,7 +35,7 @@ import java.io.File import java.util.* import kotlin.NoSuchElementException -class MainActivity : BaseActivity() { +class MainActivity : BaseActivity(), VolumeAdapter.Listener { companion object { const val DEFAULT_VOLUME_KEY = "default_volume" @@ -101,8 +101,7 @@ class MainActivity : BaseActivity() { volumeDatabase, !pickMode && !dropMode, !dropMode, - ::onVolumeItemClick, - ::onVolumeItemLongClick, + this, ) binding.recyclerViewVolumes.adapter = volumeAdapter binding.recyclerViewVolumes.layoutManager = LinearLayoutManager(this) @@ -147,14 +146,22 @@ class MainActivity : BaseActivity() { defaultVolumeName = sharedPrefs.getString(DEFAULT_VOLUME_KEY, null) } - private fun onVolumeItemClick(volume: Volume, position: Int) { + override fun onSelectionChanged(size: Int) { + title = if (size == 0) { + getString(R.string.app_name) + } else { + getString(R.string.elements_selected, size, volumeAdapter.volumes.size) + } + } + + override fun onVolumeItemClick(volume: Volume, position: Int) { if (volumeAdapter.selectedItems.isEmpty()) openVolume(volume, position) else invalidateOptionsMenu() } - private fun onVolumeItemLongClick() { + override fun onVolumeItemLongClick() { invalidateOptionsMenu() } @@ -174,6 +181,7 @@ class MainActivity : BaseActivity() { private fun unselect(position: Int) { volumeAdapter.selectedItems.remove(position) volumeAdapter.onVolumeChanged(position) + onSelectionChanged(0) // unselect() is always called when only one element is selected invalidateOptionsMenu() } diff --git a/app/src/main/java/sushi/hardcore/droidfs/adapters/ExplorerElementAdapter.kt b/app/src/main/java/sushi/hardcore/droidfs/adapters/ExplorerElementAdapter.kt index 55b9c72..37eab76 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/adapters/ExplorerElementAdapter.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/adapters/ExplorerElementAdapter.kt @@ -26,10 +26,9 @@ import java.util.* class ExplorerElementAdapter( val activity: AppCompatActivity, val gocryptfsVolume: GocryptfsVolume?, - val onExplorerElementClick: (Int) -> Unit, - val onExplorerElementLongClick: (Int) -> Unit, + private val listener: Listener, val thumbnailMaxSize: Long, -) : SelectableAdapter() { +) : SelectableAdapter(listener::onSelectionChanged) { val dateFormat: DateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.getDefault()) var explorerElements = listOf() @SuppressLint("NotifyDataSetChanged") @@ -47,6 +46,12 @@ class ExplorerElementAdapter( } } + interface Listener { + fun onSelectionChanged(size: Int) + fun onExplorerElementClick(position: Int) + fun onExplorerElementLongClick(position: Int) + } + override fun getItems(): List { return explorerElements } @@ -60,12 +65,12 @@ class ExplorerElementAdapter( } override fun onItemClick(position: Int): Boolean { - onExplorerElementClick(position) + listener.onExplorerElementClick(position) return super.onItemClick(position) } override fun onItemLongClick(position: Int): Boolean { - onExplorerElementLongClick(position) + listener.onExplorerElementLongClick(position) return super.onItemLongClick(position) } diff --git a/app/src/main/java/sushi/hardcore/droidfs/adapters/SelectableAdapter.kt b/app/src/main/java/sushi/hardcore/droidfs/adapters/SelectableAdapter.kt index 115035e..32cabb2 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/adapters/SelectableAdapter.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/adapters/SelectableAdapter.kt @@ -4,7 +4,7 @@ import android.view.View import androidx.recyclerview.widget.RecyclerView import sushi.hardcore.droidfs.R -abstract class SelectableAdapter : RecyclerView.Adapter() { +abstract class SelectableAdapter(private val onSelectionChanged: (Int) -> Unit) : RecyclerView.Adapter() { var selectedItems: MutableSet = HashSet() protected abstract fun getItems(): List @@ -14,13 +14,15 @@ abstract class SelectableAdapter : RecyclerView.Adapter : RecyclerView.Adapter : RecyclerView.Adapter Unit, - private val onVolumeItemLongClick: () -> Unit, -) : SelectableAdapter() { + private val listener: Listener, +) : SelectableAdapter(listener::onSelectionChanged) { private val inflater: LayoutInflater = LayoutInflater.from(context) lateinit var volumes: List @@ -27,6 +26,12 @@ class VolumeAdapter( reloadVolumes() } + interface Listener { + fun onSelectionChanged(size: Int) + fun onVolumeItemClick(volume: Volume, position: Int) + fun onVolumeItemLongClick() + } + override fun getItems(): List { return volumes } @@ -40,7 +45,7 @@ class VolumeAdapter( } override fun onItemClick(position: Int): Boolean { - onVolumeItemClick(volumes[position], position) + listener.onVolumeItemClick(volumes[position], position) return if (allowSelection) { super.onItemClick(position) } else { @@ -49,7 +54,7 @@ class VolumeAdapter( } override fun onItemLongClick(position: Int): Boolean { - onVolumeItemLongClick() + listener.onVolumeItemLongClick() return if (allowSelection) super.onItemLongClick(position) else diff --git a/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt index b20d42a..0e2662f 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt @@ -41,7 +41,7 @@ import sushi.hardcore.droidfs.util.PathUtils import sushi.hardcore.droidfs.widgets.CustomAlertDialogBuilder import sushi.hardcore.droidfs.widgets.EditTextDialog -open class BaseExplorerActivity : BaseActivity() { +open class BaseExplorerActivity : BaseActivity(), ExplorerElementAdapter.Listener { private lateinit var sortOrderEntries: Array private lateinit var sortOrderValues: Array private var foldersFirst = true @@ -100,7 +100,7 @@ open class BaseExplorerActivity : BaseActivity() { titleText = customView.findViewById(R.id.title_text) } title = "" - titleText.text = getString(R.string.volume, volumeName) + setVolumeNameTitle() explorerAdapter = ExplorerElementAdapter( this, if (sharedPrefs.getBoolean("thumbnails", true)) { @@ -108,8 +108,7 @@ open class BaseExplorerActivity : BaseActivity() { } else { null }, - ::onExplorerItemClick, - ::onExplorerItemLongClick, + this, sharedPrefs.getLong(ConstValues.THUMBNAIL_MAX_SIZE_KEY, ConstValues.DEFAULT_THUMBNAIL_MAX_SIZE)*1000, ) explorerViewModel = ViewModelProvider(this).get(ExplorerViewModel::class.java) @@ -209,7 +208,19 @@ open class BaseExplorerActivity : BaseActivity() { .show() } - protected open fun onExplorerItemClick(position: Int) { + private fun setVolumeNameTitle() { + titleText.text = getString(R.string.volume, volumeName) + } + + override fun onSelectionChanged(size: Int) { + if (size == 0) { + setVolumeNameTitle() + } else { + titleText.text = getString(R.string.elements_selected, size, explorerElements.count { !it.isParentFolder }) + } + } + + override fun onExplorerElementClick(position: Int) { if (explorerAdapter.selectedItems.isEmpty()) { val fullPath = explorerElements[position].fullPath when { @@ -240,7 +251,7 @@ open class BaseExplorerActivity : BaseActivity() { invalidateOptionsMenu() } - protected open fun onExplorerItemLongClick(position: Int) { + override fun onExplorerElementLongClick(position: Int) { invalidateOptionsMenu() } diff --git a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt index ed8491e..0d49f3f 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt @@ -217,8 +217,8 @@ class ExplorerActivity : BaseExplorerActivity() { usf_share = sharedPrefs.getBoolean("usf_share", false) } - override fun onExplorerItemLongClick(position: Int) { - super.onExplorerItemLongClick(position) + override fun onExplorerElementLongClick(position: Int) { + super.onExplorerElementLongClick(position) cancelItemAction() } diff --git a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityPick.kt b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityPick.kt index 660b305..f381529 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityPick.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityPick.kt @@ -21,7 +21,7 @@ class ExplorerActivityPick : BaseExplorerActivity() { //don't bind } - override fun onExplorerItemClick(position: Int) { + override fun onExplorerElementClick(position: Int) { val wasSelecting = explorerAdapter.selectedItems.isNotEmpty() if (explorerAdapter.selectedItems.isEmpty()) { if (!wasSelecting) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2d78ac2..c475ea7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -239,4 +239,5 @@ %d folders Open this volume when launching the application Don\'t open by default + %d/%d selected