[Android] Add buttons to subtitle downloader dialogs
Nicolas Pomepuy
git at videolan.org
Mon Jul 15 17:39:10 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Mon Jul 15 09:23:53 2019 +0200| [e80b104640fce4729d25a673d016396a75c2133f] | committer: Geoffrey Métais
Add buttons to subtitle downloader dialogs
> https://code.videolan.org/videolan/vlc-android/commit/e80b104640fce4729d25a673d016396a75c2133f
---
.../res/layout/subtitle_downloader_dialog.xml | 31 +++++++++++++++-------
.../org/videolan/vlc/gui/MultiSelectionSpinner.kt | 20 ++++++++------
.../dialogs/SubtitleDownloaderDialogFragment.kt | 10 ++++++-
3 files changed, 43 insertions(+), 18 deletions(-)
diff --git a/vlc-android/res/layout/subtitle_downloader_dialog.xml b/vlc-android/res/layout/subtitle_downloader_dialog.xml
index 2621fc483..c845c0727 100644
--- a/vlc-android/res/layout/subtitle_downloader_dialog.xml
+++ b/vlc-android/res/layout/subtitle_downloader_dialog.xml
@@ -9,15 +9,17 @@
android:layout_height="wrap_content">
<TextView
- android:id="@+id/movieName"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginTop="@dimen/default_margin"
- android:gravity="center_horizontal"
- android:singleLine="true"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintEnd_toEndOf="parent"/>
+ android:id="@+id/movieName"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="@dimen/default_margin"
+ android:gravity="center_horizontal"
+ android:singleLine="true"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ android:layout_marginStart="8dp"
+ android:layout_marginEnd="8dp"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/pager"
@@ -52,5 +54,16 @@
app:layout_constraintBottom_toBottomOf="parent"
style="@style/Widget.MaterialComponents.Button.TextButton.Dialog" />
+ <Button
+ android:id="@+id/doneButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="@dimen/default_margin"
+ android:text="@string/done"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/pager"
+ app:layout_constraintBottom_toBottomOf="parent"
+ style="@style/Widget.MaterialComponents.Button.TextButton.Dialog"/>
+
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/MultiSelectionSpinner.kt b/vlc-android/src/org/videolan/vlc/gui/MultiSelectionSpinner.kt
index ac1c89fa1..85e625092 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MultiSelectionSpinner.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/MultiSelectionSpinner.kt
@@ -8,18 +8,18 @@ import android.util.AttributeSet
import android.widget.ArrayAdapter
import android.widget.SpinnerAdapter
import androidx.appcompat.widget.AppCompatSpinner
+import org.videolan.vlc.R
-
-class MultiSelectionSpinner : AppCompatSpinner, OnMultiChoiceClickListener, DialogInterface.OnDismissListener{
+class MultiSelectionSpinner : AppCompatSpinner, OnMultiChoiceClickListener, DialogInterface.OnDismissListener {
private var items = mutableListOf<String>()
private var selection = mutableListOf<Boolean>()
private var adapter: ArrayAdapter<String>
- private var listener: org.videolan.vlc.gui.OnItemSelectListener? = null
+ private var listener: OnItemSelectListener? = null
- val selectedIndices: List<Int>
+ private val selectedIndices: List<Int>
get() {
- return selection.mapIndexed { index, b -> Pair(index, b)}.filter { it.second }.map { it.first }
+ return selection.mapIndexed { index, b -> Pair(index, b) }.filter { it.second }.map { it.first }
}
constructor(context: Context) : super(context) {
@@ -47,7 +47,11 @@ class MultiSelectionSpinner : AppCompatSpinner, OnMultiChoiceClickListener, Dial
override fun performClick(): Boolean {
val builder = AlertDialog.Builder(context)
builder.setOnDismissListener(this)
- builder.setMultiChoiceItems(items.toTypedArray(), selection.toBooleanArray(), this).show()
+ builder.setMultiChoiceItems(items.toTypedArray(), selection.toBooleanArray(), this)
+ .setPositiveButton(R.string.done) { dialogInterface: DialogInterface, i: Int ->
+ dialogInterface.dismiss()
+ }
+ .show()
return true
}
@@ -64,7 +68,7 @@ class MultiSelectionSpinner : AppCompatSpinner, OnMultiChoiceClickListener, Dial
this.items = items.toMutableList()
adapter.clear()
adapter.add(items[0])
- selection.addAll(items.map{false})
+ selection.addAll(items.map { false })
}
override fun setSelection(index: Int) {
@@ -100,7 +104,7 @@ class MultiSelectionSpinner : AppCompatSpinner, OnMultiChoiceClickListener, Dial
return sb.toString()
}
- fun setOnItemsSelectListener(l: org.videolan.vlc.gui.OnItemSelectListener) {
+ fun setOnItemsSelectListener(l: OnItemSelectListener) {
listener = l
}
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloaderDialogFragment.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloaderDialogFragment.kt
index fe48e700a..8e347df3d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloaderDialogFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloaderDialogFragment.kt
@@ -78,13 +78,21 @@ class SubtitleDownloaderDialogFragment : DialogFragment() {
binding.pager.adapter = adapter
binding.tabLayout.setupWithViewPager(binding.pager)
- if (uris.size < 2) binding.nextButton.visibility = View.GONE
+ if (uris.size < 2) {
+ binding.nextButton.visibility = View.GONE
+ binding.doneButton.visibility = View.VISIBLE
+ } else {
+ binding.doneButton.visibility = View.GONE
+ }
binding.nextButton.setOnClickListener {
if (uris.size > 1)
MediaUtils.showSubtitleDownloaderDialogFragment(requireActivity(), uris.takeLast(uris.size - 1))
dismiss()
}
+ binding.doneButton.setOnClickListener {
+ dismiss()
+ }
binding.movieName.text = uris[0].lastPathSegment
More information about the Android
mailing list