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

Migrate add to playlist dialog to BottomSheet

parent 8493802c
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="?attr/background_default" />
<corners
android:topLeftRadius="16dp"
android:topRightRadius="16dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:paddingBottom="16dp" android:layout_height="match_parent">
android:orientation="vertical"
android:background="?attr/background_default"> <LinearLayout
<TextView android:layout_width="match_parent"
android:id="@+id/ctx_title" android:layout_height="match_parent"
android:layout_height="wrap_content" android:orientation="vertical"
android:layout_width="wrap_content" android:paddingBottom="16dp">
style="@style/VLC.TextViewTitle"
android:textColor="@color/orange800" <TextView
android:layout_margin="@dimen/default_margin" /> android:id="@+id/ctx_title"
<androidx.recyclerview.widget.RecyclerView style="@style/Theme.VLC.BottomSheetTitle"
android:id="@+id/ctx_list" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent"> android:paddingLeft="16dp"
</androidx.recyclerview.widget.RecyclerView> android:paddingRight="16dp" />
</LinearLayout>
\ No newline at end of file <androidx.recyclerview.widget.RecyclerView
android:id="@+id/ctx_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:padding="@dimen/default_margin">
<!--TODO : textColorHint doesn't work --> <androidx.constraintlayout.widget.ConstraintLayout
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/dialog_playlist_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_marginTop="@dimen/half_default_margin"> android:padding="@dimen/default_margin">
<EditText
android:layout_width="match_parent"
<TextView
android:id="@+id/textView8"
style="@style/Theme.VLC.BottomSheetTitle"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true" android:text="@string/add_to_playlist"
android:hint="@string/playlist_name_hint" app:layout_constraintStart_toStartOf="parent"
android:textColorHint="?attr/font_default" app:layout_constraintTop_toTopOf="parent" />
android:inputType="text"
android:imeOptions="actionSend"/> <FrameLayout
</com.google.android.material.textfield.TextInputLayout> android:id="@+id/dialog_list_container"
<Button
android:id="@+id/dialog_playlist_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@android:string/cancel"
android:layout_below="@+id/dialog_playlist_name"
android:layout_toStartOf="@+id/dialog_playlist_save"
android:layout_marginEnd="8dp"
style="@style/Widget.MaterialComponents.Button.TextButton.Dialog" />
<Button
android:id="@+id/dialog_playlist_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="@android:string/ok"
android:layout_below="@+id/dialog_playlist_name"
style="@style/Widget.MaterialComponents.Button.TextButton.Dialog" />
<FrameLayout
android:id="@+id/dialog_list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/half_default_margin"
android:layout_marginStart="@dimen/half_default_margin"
android:layout_below="@+id/dialog_playlist_cancel">
<androidx.recyclerview.widget.RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView8">
<androidx.recyclerview.widget.RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/noplaylist" />
</FrameLayout>
<!--TODO : textColorHint doesn't work -->
<TextView <TextView
android:id="@android:id/empty" android:id="@+id/textView9"
android:layout_width="match_parent" style="@style/Theme.VLC.BottomSheetTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/add_to_new_playlist"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dialog_list_container" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/dialog_playlist_name"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:layout_marginTop="8dp"
android:text="@string/noplaylist"/> android:layout_marginEnd="8dp"
</FrameLayout> app:layout_constraintEnd_toStartOf="@+id/dialog_playlist_save"
</RelativeLayout> app:layout_constraintStart_toStartOf="parent"
\ No newline at end of file app:layout_constraintTop_toBottomOf="@+id/textView9">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="@string/playlist_name_hint"
android:imeOptions="actionSend"
android:inputType="text"
android:textColorHint="?attr/font_default" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/dialog_playlist_save"
style="@style/Widget.MaterialComponents.Button.TextButton.Dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/dialog_playlist_name"
android:layout_alignParentEnd="true"
android:text="@string/add"
app:layout_constraintBottom_toBottomOf="@+id/dialog_playlist_name"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
...@@ -5,4 +5,5 @@ ...@@ -5,4 +5,5 @@
<dimen name="mrl_panel_min_width">380dp</dimen> <dimen name="mrl_panel_min_width">380dp</dimen>
<dimen name="subs_dl_dialog_width">512dp</dimen> <dimen name="subs_dl_dialog_width">512dp</dimen>
<dimen name="wizard_dialog_width">448dp</dimen> <dimen name="wizard_dialog_width">448dp</dimen>
<dimen name="default_context_width">512dp</dimen>
</resources> </resources>
\ No newline at end of file
<resources> <resources>
<dimen name="custom_match_parent">-1px</dimen>
<dimen name="shadow_width">6px</dimen> <dimen name="shadow_width">6px</dimen>
<dimen name="widget_margin">0dp</dimen> <dimen name="widget_margin">0dp</dimen>
<dimen name="directory_browser_item_size">40dp</dimen> <dimen name="directory_browser_item_size">40dp</dimen>
...@@ -46,7 +49,7 @@ ...@@ -46,7 +49,7 @@
<dimen name="file_picker_height">-1px</dimen> <dimen name="file_picker_height">-1px</dimen>
<dimen name="default_content_width">-1px</dimen> <dimen name="default_content_width">-1px</dimen>
<dimen name="default_context_width">512dp</dimen> <dimen name="default_context_width">@dimen/custom_match_parent</dimen>
<!-- Default --> <!-- Default -->
......
...@@ -508,7 +508,7 @@ ...@@ -508,7 +508,7 @@
<string name="directory_show_medialib">Show in MediaLib</string> <string name="directory_show_medialib">Show in MediaLib</string>
<string name="directory_hide_medialib">Hide from MediaLib</string> <string name="directory_hide_medialib">Hide from MediaLib</string>
<string name="playlist_save">Save Playlist</string> <string name="playlist_save">Save Playlist</string>
<string name="playlist_name_hint">playlist name</string> <string name="playlist_name_hint">Playlist name</string>
<string name="go_to_chapter">Go to chapter…</string> <string name="go_to_chapter">Go to chapter…</string>
<string name="chapter">Chapter</string> <string name="chapter">Chapter</string>
<string name="resume_from_position">Resume from last position</string> <string name="resume_from_position">Resume from last position</string>
...@@ -691,6 +691,8 @@ ...@@ -691,6 +691,8 @@
<string name="onboarding_scan_customize">Let me choose which folders VLC will scan</string> <string name="onboarding_scan_customize">Let me choose which folders VLC will scan</string>
<string name="button_medialibrary_preferences">Go to Medialibrary preferences</string> <string name="button_medialibrary_preferences">Go to Medialibrary preferences</string>
<string name="light_theme">Light theme</string> <string name="light_theme">Light theme</string>
<string name="add">Add</string>
<string name="add_to_new_playlist">Add to new playlist</string>
<string name="theme_follow_system_mode">Follow system mode</string> <string name="theme_follow_system_mode">Follow system mode</string>
<string name="resume_card_message">Resume playback of %1$s?</string> <string name="resume_card_message">Resume playback of %1$s?</string>
</resources> </resources>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.VLC" parent="Theme.VLC.7"/> <style name="Theme.VLC" parent="Theme.VLC.7" />
<style name="Theme.VLC.7" parent="Theme.VLC.Apearance"> <style name="Theme.VLC.7" parent="Theme.VLC.Apearance">
<item name="actionBarStyle">@style/ActionBar</item> <item name="actionBarStyle">@style/ActionBar</item>
<item name="android:textViewStyle">@style/VLC.TextView</item> <item name="android:textViewStyle">@style/VLC.TextView</item>
<item name="windowActionBarOverlay">true</item> <item name="windowActionBarOverlay">true</item>
<item name="drawerArrowStyle">@style/ActionBar.ArrowToggle</item> <item name="drawerArrowStyle">@style/ActionBar.ArrowToggle</item>
<item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
</style> </style>
<style name="Theme.VLC.Apearance" parent="Theme.MaterialComponents.Light.NoActionBar"> <style name="Theme.VLC.Apearance" parent="Theme.MaterialComponents.Light.NoActionBar">
...@@ -105,7 +108,8 @@ ...@@ -105,7 +108,8 @@
<item name="android:textViewStyle">@style/VLC.TextView</item> <item name="android:textViewStyle">@style/VLC.TextView</item>
</style> </style>
<style name="Theme.VLC.Black" parent="Theme.VLC.Black.7"/> <style name="Theme.VLC.Black" parent="Theme.VLC.Black.7" />
<style name="Theme.VLC.Black.7" parent="Theme.VLC.Apearance.Black"> <style name="Theme.VLC.Black.7" parent="Theme.VLC.Apearance.Black">
<item name="actionBarStyle">@style/ActionBar</item> <item name="actionBarStyle">@style/ActionBar</item>
<item name="windowActionBarOverlay">true</item> <item name="windowActionBarOverlay">true</item>
...@@ -204,27 +208,30 @@ ...@@ -204,27 +208,30 @@
</style> </style>
<style name="Theme.VLC.TV" parent="Theme.Leanback"> <style name="Theme.VLC.TV" parent="Theme.Leanback">
<item name="colorPrimary">@color/orange800</item> <item name="colorPrimary">@color/orange800</item>
<item name="colorPrimaryDark">@color/transparent</item> <item name="colorPrimaryDark">@color/transparent</item>
<item name="colorAccent">@color/orange600</item> <item name="colorAccent">@color/orange600</item>
<item name="imageCardViewInfoAreaStyle">@style/VLCardViewInfoStyle</item> <item name="imageCardViewInfoAreaStyle">@style/VLCardViewInfoStyle</item>
<item name="imageCardViewTitleStyle">@style/VLCardViewTitleStyle</item> <item name="imageCardViewTitleStyle">@style/VLCardViewTitleStyle</item>
<item name="imageCardViewStyle">@style/VLCardView</item> <item name="imageCardViewStyle">@style/VLCardView</item>
<item name="audio_player_background_tint">@color/grey900transparent</item> <item name="audio_player_background_tint">@color/grey900transparent</item>
</style> </style>
<style name="VLCardView" parent="Widget.Leanback.ImageCardViewStyle"> <style name="VLCardView" parent="Widget.Leanback.ImageCardViewStyle">
<item name="cardType">infoUnderWithExtra</item> <item name="cardType">infoUnderWithExtra</item>
<item name="infoVisibility">always</item> <item name="infoVisibility">always</item>
</style> </style>
<style name="VLCardViewTitleStyle" parent="Widget.Leanback.ImageCardView.TitleStyle"> <style name="VLCardViewTitleStyle" parent="Widget.Leanback.ImageCardView.TitleStyle">
<item name="android:scrollHorizontally">true</item> <item name="android:scrollHorizontally">true</item>
<item name="android:singleLine">true</item> <item name="android:singleLine">true</item>
<item name="android:ellipsize">marquee</item> <item name="android:ellipsize">marquee</item>
</style> </style>
<style name="VLCardViewInfoStyle" parent="Widget.Leanback.ImageCardView.InfoAreaStyle"> <style name="VLCardViewInfoStyle" parent="Widget.Leanback.ImageCardView.InfoAreaStyle">
<item name="android:background">@color/tv_card_content</item> <item name="android:background">@color/tv_card_content</item>
</style> </style>
<style name="Theme.VLC.Leanback.Preferences" parent="Theme.Leanback"> <style name="Theme.VLC.Leanback.Preferences" parent="Theme.Leanback">
<item name="preferenceTheme">@style/PreferenceThemeOverlayLeanback</item> <item name="preferenceTheme">@style/PreferenceThemeOverlayLeanback</item>
...@@ -255,7 +262,8 @@ ...@@ -255,7 +262,8 @@
<item name="android:windowIsTranslucent">true</item> <item name="android:windowIsTranslucent">true</item>
</style> </style>
<style name="Theme.VLC.Player" parent="Theme.VLC.Player.7"/> <style name="Theme.VLC.Player" parent="Theme.VLC.Player.7" />
<style name="Theme.VLC.Player.7" parent="Theme.MaterialComponents"> <style name="Theme.VLC.Player.7" parent="Theme.MaterialComponents">
<item name="android:windowNoTitle">true</item> <item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item> <item name="android:windowFullscreen">true</item>
...@@ -397,31 +405,31 @@ ...@@ -397,31 +405,31 @@
</style> </style>
<style name="VLCEditPreferenceStyle" parent="Preference.DialogPreference.EditTextPreference.Material"> <style name="VLCEditPreferenceStyle" parent="Preference.DialogPreference.EditTextPreference.Material">
<item name="iconSpaceReserved">false</item> <item name="iconSpaceReserved">false</item>
</style> </style>
<style name="VLCSwitchPreferenceStyle" parent="Preference.SwitchPreferenceCompat.Material"> <style name="VLCSwitchPreferenceStyle" parent="Preference.SwitchPreferenceCompat.Material">
<item name="iconSpaceReserved">false</item> <item name="iconSpaceReserved">false</item>
</style> </style>
<style name="VLCDialogPreferenceStyle" parent="Preference.DialogPreference.Material"> <style name="VLCDialogPreferenceStyle" parent="Preference.DialogPreference.Material">
<item name="iconSpaceReserved">false</item> <item name="iconSpaceReserved">false</item>
</style> </style>
<style name="VLCCheckBoxPreferenceStyle" parent="Preference.CheckBoxPreference.Material"> <style name="VLCCheckBoxPreferenceStyle" parent="Preference.CheckBoxPreference.Material">
<item name="iconSpaceReserved">false</item> <item name="iconSpaceReserved">false</item>
</style> </style>
<style name="VLCPreferenceFragmentStyle" parent="PreferenceFragment.Material"> <style name="VLCPreferenceFragmentStyle" parent="PreferenceFragment.Material">
<item name="iconSpaceReserved">false</item> <item name="iconSpaceReserved">false</item>
</style> </style>
<style name="VLCPreferenceScreenStyle" parent="Preference.PreferenceScreen.Material"> <style name="VLCPreferenceScreenStyle" parent="Preference.PreferenceScreen.Material">
<item name="iconSpaceReserved">false</item> <item name="iconSpaceReserved">false</item>
</style> </style>
<style name="VLCPreferenceStyle" parent="Preference.Material"> <style name="VLCPreferenceStyle" parent="Preference.Material">
<item name="iconSpaceReserved">false</item> <item name="iconSpaceReserved">false</item>
</style> </style>
<style name="VLCPreferenceCategoryStyle" parent="Preference.Category.Material"> <style name="VLCPreferenceCategoryStyle" parent="Preference.Category.Material">
...@@ -431,11 +439,32 @@ ...@@ -431,11 +439,32 @@
<!-- Tips Apearance--> <!-- Tips Apearance-->
<style name="TipsFontStyle"> <style name="TipsFontStyle">
<item name="android:textColor">@color/orange700</item> <item name="android:textColor">@color/orange700</item>
<item name="android:textStyle">bold</item> <item name="android:textStyle">bold</item>
</style> </style>
<style name="TipsFontStyle.Small" parent="TipsFontStyle"> <style name="TipsFontStyle.Small" parent="TipsFontStyle">
<item name="android:textSize">10sp</item> <item name="android:textSize">10sp</item>
</style>
<!--BottomSheet-->
<style name="AppBottomSheetDialogTheme" parent="ThemeOverlay.MaterialComponents.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="bottomSheetStyle">@style/AppModalStyle</item>
</style>
<style name="AppModalStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@drawable/bottom_sheet_background</item>
</style>
<style name="Theme.VLC.BottomSheetTitle">
<item name="android:minHeight">56dp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textColor">?attr/colorPrimary</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">16sp</item>
</style> </style>
</resources> </resources>
...@@ -24,7 +24,6 @@ import android.os.Bundle ...@@ -24,7 +24,6 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView import android.widget.TextView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
...@@ -32,9 +31,6 @@ import androidx.lifecycle.Lifecycle ...@@ -32,9 +31,6 @@ import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.videolan.vlc.R import org.videolan.vlc.R
import org.videolan.vlc.databinding.ContextItemBinding import org.videolan.vlc.databinding.ContextItemBinding
import org.videolan.vlc.util.* import org.videolan.vlc.util.*
...@@ -43,7 +39,7 @@ const val CTX_TITLE_KEY = "CTX_TITLE_KEY" ...@@ -43,7 +39,7 @@ const val CTX_TITLE_KEY = "CTX_TITLE_KEY"
const val CTX_POSITION_KEY = "CTX_POSITION_KEY" const val CTX_POSITION_KEY = "CTX_POSITION_KEY"
const val CTX_FLAGS_KEY = "CTX_FLAGS_KEY" const val CTX_FLAGS_KEY = "CTX_FLAGS_KEY"
class ContextSheet : com.google.android.material.bottomsheet.BottomSheetDialogFragment() { class ContextSheet : VLCBottomSheetDialogFragment() {
private lateinit var options : List<CtxOption> private lateinit var options : List<CtxOption>
lateinit var receiver : CtxActionReceiver lateinit var receiver : CtxActionReceiver
...@@ -51,6 +47,7 @@ class ContextSheet : com.google.android.material.bottomsheet.BottomSheetDialogFr ...@@ -51,6 +47,7 @@ class ContextSheet : com.google.android.material.bottomsheet.BottomSheetDialogFr
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
defaultState = BottomSheetBehavior.STATE_EXPANDED
itemPosition = arguments?.getInt(CTX_POSITION_KEY) ?: -1 itemPosition = arguments?.getInt(CTX_POSITION_KEY) ?: -1
if (!this::receiver.isInitialized) restoreReceiver(savedInstanceState) if (!this::receiver.isInitialized) restoreReceiver(savedInstanceState)
} }
...@@ -73,19 +70,13 @@ class ContextSheet : com.google.android.material.bottomsheet.BottomSheetDialogFr ...@@ -73,19 +70,13 @@ class ContextSheet : com.google.android.material.bottomsheet.BottomSheetDialogFr
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<TextView>(R.id.ctx_title).text = arguments?.getString(CTX_TITLE_KEY) ?: "" view.findViewById<TextView>(R.id.ctx_title).text = arguments?.getString(CTX_TITLE_KEY) ?: ""
val list = view.findViewById<RecyclerView>(R.id.ctx_list) val list = view.findViewById<RecyclerView>(R.id.ctx_list)
list.layoutManager = LinearLayoutManager(requireContext()) list.layoutManager = LinearLayoutManager(requireContext())
list.adapter = ContextAdapter() list.adapter = ContextAdapter()
val flags = arguments?.getInt(CTX_FLAGS_KEY) ?: 0 val flags = arguments?.getInt(CTX_FLAGS_KEY) ?: 0
options = populateOptions(flags) options = populateOptions(flags)
AppScope.launch(Dispatchers.Main) {
dialog?.window?.setLayout(resources.getDimensionPixelSize(R.dimen.default_context_width), ViewGroup.LayoutParams.MATCH_PARENT)
(dialog as BottomSheetDialog).findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)?.let {
val bsb = BottomSheetBehavior.from(it)
if (bsb.state == BottomSheetBehavior.STATE_COLLAPSED) bsb.state = BottomSheetBehavior.STATE_EXPANDED
}
}
} }
private fun populateOptions(flags: Int) = mutableListOf<CtxOption>().apply { private fun populateOptions(flags: Int) = mutableListOf<CtxOption>().apply {
......
/*
* *************************************************************************
* SavePlaylist.java
* **************************************************************************
* Copyright © 2015 VLC authors and VideoLAN
* Author: Geoffrey Métais
*
* 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.app.Dialog;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.textfield.TextInputLayout;
import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.AppCompatDialog;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
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.EditText;
import android.widget.TextView;
import org.jetbrains.annotations.NotNull;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.Tools;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.medialibrary.media.Playlist;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.SimpleAdapter;
import org.videolan.vlc.util.WorkersKt;
import java.util.Arrays;
import java.util.LinkedList;
public class SavePlaylistDialog extends DialogFragment implements View.OnClickListener, TextView.OnEditorActionListener, SimpleAdapter.ClickHandler {
public final static String TAG = "VLC/SavePlaylistDialog";
public static final String KEY_TRACKS = "PLAYLIST_TRACKS";
public static final String KEY_NEW_TRACKS = "PLAYLIST_NEW_TRACKS";
EditText mEditText;
RecyclerView mListView;
TextView mEmptyView;
Button mSaveButton;
Button mCancelButton;
SimpleAdapter mAdapter;
MediaWrapper[] mTracks;
MediaWrapper[] mNewTrack;
Runnable mCallBack;
Medialibrary mMedialibrary;
long mPlaylistId;
public SavePlaylistDialog(){}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mMedialibrary = VLCApplication.getMLInstance();
mAdapter = new SimpleAdapter(this);
mTracks = (MediaWrapper[]) getArguments().getParcelableArray(KEY_TRACKS);
mNewTrack = (MediaWrapper[]) getArguments().getParcelableArray(KEY_NEW_TRACKS);
}
public void setCallBack(Runnable cb) {
mCallBack = cb;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AppCompatDialog dialog = new AppCompatDialog(getActivity(), getTheme());
dialog.setTitle(R.string.playlist_save);
return dialog;
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.dialog_playlist, container);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mListView = view.findViewById(android.R.id.list);
mSaveButton = view.findViewById(R.id.dialog_playlist_save);
mCancelButton = view.findViewById(R.id.dialog_playlist_cancel);
mEmptyView = view.findViewById(android.R.id.empty);
TextInputLayout mLayout = view.findViewById(R.id.dialog_playlist_name);
mEditText = mLayout.getEditText();
mSaveButton.setOnClickListener(this);
mCancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
mEditText.setOnEditorActionListener(this);
mListView.setLayoutManager(new LinearLayoutManager(view.getContext()));
mListView.setAdapter(mAdapter);
mAdapter.submitList(Arrays.<MediaLibraryItem>asList(mMedialibrary.getPlaylists()));
updateEmptyView();
}
void updateEmptyView() {
mEmptyView.setVisibility(mAdapter.isEmpty() ? View.VISIBLE : View.GONE);
}
@Override
public void onClick(View v) {
savePlaylist();
}
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND)
savePlaylist();
return false;
}
private void savePlaylist() {
WorkersKt.runIO(new Runnable() {
@Override
public void run() {
final String name = mEditText.getText().toString().trim();
final boolean addTracks = !Tools.isArrayEmpty(mNewTrack);
Playlist playlist = mMedialibrary.getPlaylist(mPlaylistId);
boolean exists = playlist != null;
MediaWrapper[] tracks;
if (!exists) playlist = mMedialibrary.createPlaylist(name);
if (playlist == null) return;
if (addTracks) {
tracks = mNewTrack;
} else {//Save a playlist
for (MediaWrapper mw : playlist.getTracks()) {
playlist.remove(mw.getId());
}
tracks = mTracks;
}
if (tracks == null) return;
final LinkedList<Long> ids = new LinkedList<>();
for (MediaWrapper mw : tracks) {
long id = mw.getId();
if (id == 0) {
MediaWrapper media = mMedialibrary.getMedia(mw.getUri());
if (media != null) ids.add(media.getId());
else {
media = mMedialibrary.addMedia(mw.getLocation());