4 changed files with 226 additions and 12 deletions
@ -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> |
|||
@ -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 |
|||
} |
|||
} |
|||
Loading…
Reference in new issue