Browse Source

Use a proper BottomSheet dialog for stream renaming

3.3.x
Nicolas Pomepuy 6 years ago
parent
commit
d6e738f1b5
  1. 1
      application/resources/src/main/res/values/strings.xml
  2. 87
      application/vlc-android/res/layout/dialog_rename.xml
  3. 134
      application/vlc-android/src/org/videolan/vlc/gui/dialogs/RenameDialog.kt
  4. 16
      application/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt

1
application/resources/src/main/res/values/strings.xml

@ -814,4 +814,5 @@
<string name="this_folder">Add this folder</string>
<string name="all_subfolders">Add this folder and subfolders</string>
<string name="playlist_existing">Playlist %s already exists</string>
<string name="new_title">New title</string>
</resources>

87
application/vlc-android/res/layout/dialog_rename.xml

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ *************************************************************************
~ dialog_rename.xml
~ **************************************************************************
~ Copyright © 2020 VLC authors and VideoLAN
~ Author: Nicolas POMEPUY
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
~ ***************************************************************************
~
~
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/rename_title"
style="@style/Theme.VLC.BottomSheetTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:minHeight="0dp"
android:text="@string/rename"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/media_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:fontFamily="sans-serif-light"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rename_title"
tools:text="My stream title" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/media_title">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/new_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionGo"
android:maxLines="1"
android:inputType="text"
android:hint="@string/new_title" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/rename_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:text="@string/ok"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>

134
application/vlc-android/src/org/videolan/vlc/gui/dialogs/RenameDialog.kt

@ -0,0 +1,134 @@
/*
* ************************************************************************
* RenameDialog.kt
* *************************************************************************
* Copyright © 2020 VLC authors and VideoLAN
* Author: Nicolas POMEPUY
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* **************************************************************************
*
*
*/
/**
* **************************************************************************
* PickTimeFragment.java
* ****************************************************************************
* Copyright © 2015 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* ***************************************************************************
*/
package org.videolan.vlc.gui.dialogs
import android.os.Bundle
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.widget.Button
import android.widget.TextView
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
import com.google.android.material.textfield.TextInputEditText
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.vlc.R
private const val MEDIA = "RENAME_DIALOG_MEDIA"
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
class RenameDialog(private val listener: (String) -> Unit) : VLCBottomSheetDialogFragment() {
private lateinit var renameButton: Button
private lateinit var newNameInputtext: TextInputEditText
private lateinit var media: MediaWrapper
companion object {
fun newInstance(media: MediaWrapper, listener: (String) -> Unit): RenameDialog {
return RenameDialog(listener).apply {
val args = Bundle()
args.putParcelable(MEDIA, media)
arguments = args
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
media = arguments?.getParcelable(MEDIA) ?: return
super.onCreate(savedInstanceState)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.dialog_rename, container)
newNameInputtext = view.findViewById(R.id.new_name)
renameButton = view.findViewById(R.id.rename_button)
renameButton.setOnClickListener {
performRename()
}
newNameInputtext.setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
performRename()
true
}
false
}
newNameInputtext.setOnKeyListener { view: View, keyCode: Int, keyEvent: KeyEvent ->
if (keyCode == EditorInfo.IME_ACTION_DONE ||
keyCode == EditorInfo.IME_ACTION_GO ||
keyEvent.action == KeyEvent.ACTION_DOWN && keyEvent.keyCode == KeyEvent.KEYCODE_ENTER) {
performRename()
true
}
false
}
view.findViewById<TextView>(R.id.media_title).text = media.title
return view
}
private fun performRename() {
if (newNameInputtext.text.toString().isNotEmpty()) {
listener(newNameInputtext.text.toString())
dismiss()
}
}
override fun getDefaultState(): Int {
return STATE_EXPANDED
}
override fun initialFocusedView(): View = newNameInputtext
override fun needToManageOrientation(): Boolean {
return true
}
}

16
application/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt

@ -31,9 +31,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
@ -58,6 +56,7 @@ import org.videolan.vlc.databinding.MrlPanelBinding
import org.videolan.vlc.gui.ContentActivity
import org.videolan.vlc.gui.MainActivity
import org.videolan.vlc.gui.dialogs.CtxActionReceiver
import org.videolan.vlc.gui.dialogs.RenameDialog
import org.videolan.vlc.gui.dialogs.SavePlaylistDialog
import org.videolan.vlc.gui.dialogs.showContext
import org.videolan.vlc.gui.helpers.UiTools
@ -205,16 +204,9 @@ class MRLPanelFragment : Fragment(), View.OnKeyListener, TextView.OnEditorAction
}
private fun renameStream(position: Int) {
val media = viewModel.dataset.get(position)
val edit = EditText(requireActivity())
AlertDialog.Builder(requireContext())
.setTitle(getString(R.string.rename_media, media.title))
.setView(edit)
.setPositiveButton(R.string.ok) { _, _ ->
viewModel.rename(position, edit.text.toString())
}
.setNegativeButton(R.string.cancel) { dialog, _ -> dialog.dismiss() }
.show()
RenameDialog.newInstance(viewModel.dataset.get(position)) { newName ->
viewModel.rename(position, newName)
}.show(requireActivity().supportFragmentManager, RenameDialog::class.simpleName)
}
override fun refresh() {

Loading…
Cancel
Save