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"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:paddingBottom="16dp"
android:orientation="vertical"
android:background="?attr/background_default">
<TextView
android:id="@+id/ctx_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
style="@style/VLC.TextViewTitle"
android:textColor="@color/orange800"
android:layout_margin="@dimen/default_margin" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/ctx_list"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
\ No newline at end of file
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="16dp">
<TextView
android:id="@+id/ctx_title"
style="@style/Theme.VLC.BottomSheetTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp" />
<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"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/default_margin">
android:layout_height="match_parent">
<!--TODO : textColorHint doesn't work -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/dialog_playlist_name"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/half_default_margin">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/default_margin">
<TextView
android:id="@+id/textView8"
style="@style/Theme.VLC.BottomSheetTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="@string/playlist_name_hint"
android:textColorHint="?attr/font_default"
android:inputType="text"
android:imeOptions="actionSend"/>
</com.google.android.material.textfield.TextInputLayout>
<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:text="@string/add_to_playlist"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/dialog_list_container"
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
android:id="@android:id/empty"
android:layout_width="match_parent"
android:id="@+id/textView9"
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:gravity="center_horizontal"
android:text="@string/noplaylist"/>
</FrameLayout>
</RelativeLayout>
\ No newline at end of file
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toStartOf="@+id/dialog_playlist_save"
app:layout_constraintStart_toStartOf="parent"
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 @@
<dimen name="mrl_panel_min_width">380dp</dimen>
<dimen name="subs_dl_dialog_width">512dp</dimen>
<dimen name="wizard_dialog_width">448dp</dimen>
<dimen name="default_context_width">512dp</dimen>
</resources>
\ No newline at end of file
<resources>
<dimen name="custom_match_parent">-1px</dimen>
<dimen name="shadow_width">6px</dimen>
<dimen name="widget_margin">0dp</dimen>
<dimen name="directory_browser_item_size">40dp</dimen>
......@@ -46,7 +49,7 @@
<dimen name="file_picker_height">-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 -->
......
......@@ -508,7 +508,7 @@
<string name="directory_show_medialib">Show in MediaLib</string>
<string name="directory_hide_medialib">Hide from MediaLib</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="chapter">Chapter</string>
<string name="resume_from_position">Resume from last position</string>
......@@ -691,6 +691,8 @@
<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="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="resume_card_message">Resume playback of %1$s?</string>
</resources>
<?xml version="1.0" encoding="UTF-8"?>
<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">
<item name="actionBarStyle">@style/ActionBar</item>
<item name="android:textViewStyle">@style/VLC.TextView</item>
<item name="windowActionBarOverlay">true</item>
<item name="drawerArrowStyle">@style/ActionBar.ArrowToggle</item>
<item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
</style>
<style name="Theme.VLC.Apearance" parent="Theme.MaterialComponents.Light.NoActionBar">
......@@ -105,7 +108,8 @@
<item name="android:textViewStyle">@style/VLC.TextView</item>
</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">
<item name="actionBarStyle">@style/ActionBar</item>
<item name="windowActionBarOverlay">true</item>
......@@ -204,27 +208,30 @@
</style>
<style name="Theme.VLC.TV" parent="Theme.Leanback">
<item name="colorPrimary">@color/orange800</item>
<item name="colorPrimaryDark">@color/transparent</item>
<item name="colorAccent">@color/orange600</item>
<item name="imageCardViewInfoAreaStyle">@style/VLCardViewInfoStyle</item>
<item name="imageCardViewTitleStyle">@style/VLCardViewTitleStyle</item>
<item name="imageCardViewStyle">@style/VLCardView</item>
<item name="audio_player_background_tint">@color/grey900transparent</item>
<item name="colorPrimary">@color/orange800</item>
<item name="colorPrimaryDark">@color/transparent</item>
<item name="colorAccent">@color/orange600</item>
<item name="imageCardViewInfoAreaStyle">@style/VLCardViewInfoStyle</item>
<item name="imageCardViewTitleStyle">@style/VLCardViewTitleStyle</item>
<item name="imageCardViewStyle">@style/VLCardView</item>
<item name="audio_player_background_tint">@color/grey900transparent</item>
</style>
<style name="VLCardView" parent="Widget.Leanback.ImageCardViewStyle">
<item name="cardType">infoUnderWithExtra</item>
<item name="infoVisibility">always</item>
</style>
</style>
<style name="VLCardViewTitleStyle" parent="Widget.Leanback.ImageCardView.TitleStyle">
<item name="android:scrollHorizontally">true</item>
<item name="android:singleLine">true</item>
<item name="android:ellipsize">marquee</item>
</style>
</style>
<style name="VLCardViewInfoStyle" parent="Widget.Leanback.ImageCardView.InfoAreaStyle">
<item name="android:background">@color/tv_card_content</item>
</style>
</style>
<style name="Theme.VLC.Leanback.Preferences" parent="Theme.Leanback">
<item name="preferenceTheme">@style/PreferenceThemeOverlayLeanback</item>
......@@ -255,7 +262,8 @@
<item name="android:windowIsTranslucent">true</item>
</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">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
......@@ -397,31 +405,31 @@
</style>
<style name="VLCEditPreferenceStyle" parent="Preference.DialogPreference.EditTextPreference.Material">
<item name="iconSpaceReserved">false</item>
<item name="iconSpaceReserved">false</item>
</style>
<style name="VLCSwitchPreferenceStyle" parent="Preference.SwitchPreferenceCompat.Material">
<item name="iconSpaceReserved">false</item>
<item name="iconSpaceReserved">false</item>
</style>
<style name="VLCDialogPreferenceStyle" parent="Preference.DialogPreference.Material">
<item name="iconSpaceReserved">false</item>
<item name="iconSpaceReserved">false</item>
</style>
<style name="VLCCheckBoxPreferenceStyle" parent="Preference.CheckBoxPreference.Material">
<item name="iconSpaceReserved">false</item>
<item name="iconSpaceReserved">false</item>
</style>
<style name="VLCPreferenceFragmentStyle" parent="PreferenceFragment.Material">
<item name="iconSpaceReserved">false</item>
<item name="iconSpaceReserved">false</item>
</style>
<style name="VLCPreferenceScreenStyle" parent="Preference.PreferenceScreen.Material">
<item name="iconSpaceReserved">false</item>
<item name="iconSpaceReserved">false</item>
</style>
<style name="VLCPreferenceStyle" parent="Preference.Material">
<item name="iconSpaceReserved">false</item>
<item name="iconSpaceReserved">false</item>
</style>
<style name="VLCPreferenceCategoryStyle" parent="Preference.Category.Material">
......@@ -431,11 +439,32 @@
<!-- Tips Apearance-->
<style name="TipsFontStyle">
<item name="android:textColor">@color/orange700</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/orange700</item>
<item name="android:textStyle">bold</item>
</style>
<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>
</resources>
......@@ -24,7 +24,6 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
......@@ -32,9 +31,6 @@ import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
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.databinding.ContextItemBinding
import org.videolan.vlc.util.*
......@@ -43,7 +39,7 @@ const val CTX_TITLE_KEY = "CTX_TITLE_KEY"
const val CTX_POSITION_KEY = "CTX_POSITION_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>
lateinit var receiver : CtxActionReceiver
......@@ -51,6 +47,7 @@ class ContextSheet : com.google.android.material.bottomsheet.BottomSheetDialogFr
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
defaultState = BottomSheetBehavior.STATE_EXPANDED
itemPosition = arguments?.getInt(CTX_POSITION_KEY) ?: -1
if (!this::receiver.isInitialized) restoreReceiver(savedInstanceState)
}
......@@ -73,19 +70,13 @@ class ContextSheet : com.google.android.material.bottomsheet.BottomSheetDialogFr
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<TextView>(R.id.ctx_title).text = arguments?.getString(CTX_TITLE_KEY) ?: ""
val list = view.findViewById<RecyclerView>(R.id.ctx_list)
list.layoutManager = LinearLayoutManager(requireContext())
list.adapter = ContextAdapter()
val flags = arguments?.getInt(CTX_FLAGS_KEY) ?: 0
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 {
......
/*
* *************************************************************************
* 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());
if (media != null) ids.add(media.getId());
}
} else ids.add(id);
}
playlist.append(ids);
if (mCallBack != null) mCallBack.run();
}
});
dismiss();
}
// @Override
// public void onUpdateFinished(RecyclerView.Adapter adapter) {
// updateEmptyView();
// }
@Override
public void onClick(@NotNull MediaLibraryItem item) {
mPlaylistId = item.getId();
mEditText.setText(item.getTitle());
}
}
/*
* *************************************************************************
* 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.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.EditText
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.textfield.TextInputLayout
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.runIO
import java.util.*
class SavePlaylistDialog : VLCBottomSheetDialogFragment(), View.OnClickListener, TextView.OnEditorActionListener, SimpleAdapter.ClickHandler {
private var mEditText: EditText? = null
private lateinit var mListView: RecyclerView
private lateinit var mEmptyView: TextView
private lateinit var mSaveButton: Button
private lateinit var mAdapter: SimpleAdapter
private lateinit var mTracks: Array<MediaWrapper>
private lateinit var mNewTrack: Array<MediaWrapper>
private lateinit var mMedialibrary: Medialibrary
private var mPlaylistId: Long = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
defaultState = BottomSheetBehavior.STATE_EXPANDED
mMedialibrary = VLCApplication.getMLInstance()
mAdapter = SimpleAdapter(this)
mTracks = try {
@Suppress("UNCHECKED_CAST")
arguments!!.getParcelableArray(KEY_TRACKS) as Array<MediaWrapper>
} catch (e: Exception) {
emptyArray()
}
mNewTrack = try {
@Suppress("UNCHECKED_CAST")