Commit e80b1046 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Geoffrey Métais

Add buttons to subtitle downloader dialogs

parent ea5ebcf6
......@@ -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
......@@ -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
}
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment