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

Streams are now displayed in a real fragment

parent d35f7547
......@@ -575,6 +575,11 @@
android:exported="true"
android:screenOrientation="landscape"
android:theme="@style/Theme.VLC.TV" />
<activity
android:name=".gui.tv.browser.TVActivity"
android:exported="true"
android:screenOrientation="landscape"
android:theme="@style/Theme.VLC.Black" />
<activity
android:name=".gui.tv.SearchActivity"
android:exported="true"
......
......@@ -28,7 +28,7 @@
<!--Hide all borders except bottom border-->
<item android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="?background_default_darker"/>
<solid android:color="?background_default" />
</shape>
</item>
</layer-list>
......
......@@ -9,72 +9,89 @@
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="?attr/background_default_darker"
app:layout_behavior="org.videolan.vlc.gui.helpers.BottomSheetBehavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/mrl_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/background_default_darker"
android:layoutDirection="ltr"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:minWidth="@dimen/mrl_panel_min_width">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="ltr">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/mrl_edit"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/mrlbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dip"
android:paddingEnd="4dp"
app:layout_constraintEnd_toStartOf="@+id/play"
android:background="?attr/background_default"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlSymmetry">
android:elevation="4dp"
app:elevation="4dp"
android:paddingBottom="8dp"
android:paddingTop="8dp"
app:layout_constraintTop_toTopOf="parent">
<!--android:paddingTop ==> Space between cursor and top hint-->
<!--android:paddingBottom ==> Space between cursor and bottom border-->
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/mrl_edit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="8dp"
android:background="@drawable/edittext_bottom_border"
android:hint="@string/open_mrl_dialog_msg"
android:imeOptions="actionGo"
android:inputType="textUri"
android:maxLines="2"
android:paddingTop="8dp"
android:paddingBottom="4dp"
android:text="@={viewmodel.observableSearchText}"
android:textColor="?font_default"
android:textCursorDrawable="@drawable/cursor_o" />
</com.google.android.material.textfield.TextInputLayout>
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:paddingEnd="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/play"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlSymmetry">
<ImageView
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:contentDescription="@string/play_button"
android:scaleType="center"
android:src="@drawable/ic_send"
app:layout_constraintBottom_toBottomOf="@+id/mrl_edit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/mrl_edit" />
<!--android:paddingTop ==> Space between cursor and top hint-->
<!--android:paddingBottom ==> Space between cursor and bottom border-->
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="8dp"
android:background="@drawable/edittext_bottom_border"
android:hint="@string/open_mrl_dialog_msg"
android:imeOptions="actionGo"
android:inputType="textUri"
android:maxLines="2"
android:paddingTop="8dp"
android:paddingBottom="4dp"
android:text="@={viewmodel.observableSearchText}"
android:textColor="?font_default"
android:textCursorDrawable="@drawable/cursor_o" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:contentDescription="@string/play_button"
android:scaleType="center"
android:src="@drawable/ic_send"
android:background="?attr/selectableItemBackgroundBorderless"
app:layout_constraintBottom_toBottomOf="@+id/mrl_edit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/mrl_edit" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/mrl_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_height="match_parent"
android:layout_marginStart="4dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="4dp"
android:background="?attr/background_default"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mrl_edit" />
app:layout_constraintTop_toBottomOf="@+id/mrlbar" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</layout>
......@@ -6,13 +6,13 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:maxLines="1"
android:background="?attr/background_default"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:paddingRight="10dp"
android:paddingEnd="10dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:background="?attr/selectableItemBackground"
android:focusable="true"
android:clickable="true" >
<TextView
......@@ -23,6 +23,7 @@
app:layout_constraintEnd_toStartOf="@+id/mrl_ctx"
app:layout_constraintTop_toTopOf="parent"
android:maxLines="2"
android:textColor="?attr/font_default"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>
<TextView
android:id="@+id/mrl_item_uri"
......@@ -36,8 +37,7 @@
android:gravity="center_vertical"
android:maxLines="1"
android:singleLine="true"
android:fontFamily="sans-serif"
android:textColor="?attr/font_default"/>
android:fontFamily="sans-serif" />
<ImageView
android:id="@+id/mrl_ctx"
android:layout_width="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="viewmodel"
......@@ -8,69 +9,86 @@
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="?attr/background_default_darker"
app:layout_behavior="org.videolan.vlc.gui.helpers.BottomSheetBehavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/mrl_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/background_default_darker"
android:layoutDirection="ltr"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:minWidth="@dimen/mrl_panel_min_width">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="ltr">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/mrl_edit"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/mrlbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dip"
android:paddingEnd="4dp"
app:layout_constraintEnd_toStartOf="@+id/play"
android:background="?attr/background_default"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:elevation="4dp"
app:elevation="4dp"
android:paddingBottom="8dp"
android:paddingTop="8dp"
app:layout_constraintTop_toTopOf="parent">
<!--android:paddingTop ==> Space between cursor and top hint-->
<!--android:paddingBottom ==> Space between cursor and bottom border-->
<EditText
android:layout_width="match_parent"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/mrl_edit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="8dp"
android:hint="@string/open_mrl_dialog_msg"
android:imeOptions="actionGo"
android:inputType="textUri"
android:maxLines="2"
android:paddingTop="8dp"
android:paddingBottom="4dp"
android:text="@={viewmodel.observableSearchText}"
android:textColor="?font_default" />
</com.google.android.material.textfield.TextInputLayout>
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:paddingEnd="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/play"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:contentDescription="@string/play_button"
android:scaleType="center"
android:src="@drawable/ic_send"
app:layout_constraintBottom_toBottomOf="@+id/mrl_edit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/mrl_edit" />
<!--android:paddingTop ==> Space between cursor and top hint-->
<!--android:paddingBottom ==> Space between cursor and bottom border-->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="8dp"
android:hint="@string/open_mrl_dialog_msg"
android:imeOptions="actionGo"
android:inputType="textUri"
android:maxLines="2"
android:paddingTop="8dp"
android:paddingBottom="4dp"
android:text="@={viewmodel.observableSearchText}"
android:textColor="?font_default" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:contentDescription="@string/play_button"
android:scaleType="center"
android:src="@drawable/ic_send"
android:background="?attr/selectableItemBackgroundBorderless"
app:layout_constraintBottom_toBottomOf="@+id/mrl_edit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/mrl_edit" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/mrl_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="4dp"
android:layout_height="match_parent"
android:layout_marginStart="4dp"
android:background="?attr/background_default"
android:layout_marginTop="24dp"
android:layout_marginEnd="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mrl_edit" />
app:layout_constraintTop_toBottomOf="@+id/mrlbar" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</layout>
......@@ -18,6 +18,11 @@
<dimen name="info_appbar_height">150dp</dimen>
<dimen name="audioplayer_controls_margin">0dp</dimen>
<!--Keylines-->
<dimen name="kl_half">4dp</dimen>
<dimen name="kl_small">8dp</dimen>
<dimen name="kl_normal">16dp</dimen>
<!-- Video Player -->
<dimen name="overlay_padding_bottom">8dip</dimen>
<dimen name="overlay_padding_top">10dip</dimen>
......
......@@ -208,13 +208,15 @@
</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>
<item name="background_default_darker">@color/grey875</item>
<item name="background_default">@color/grey850</item>
</style>
<style name="VLCardView" parent="Widget.Leanback.ImageCardViewStyle">
......
......@@ -35,7 +35,6 @@ import org.videolan.vlc.gui.dialogs.VlcDialog;
import org.videolan.vlc.gui.dialogs.VlcLoginDialog;
import org.videolan.vlc.gui.dialogs.VlcProgressDialog;
import org.videolan.vlc.gui.dialogs.VlcQuestionDialog;
import org.videolan.vlc.gui.network.MRLPanelFragment;
import org.videolan.vlc.media.MediaUtils;
import java.util.List;
......@@ -47,7 +46,6 @@ public class DialogActivity extends BaseActivity {
public static final String KEY_LOGIN = "LoginDialog";
public static final String KEY_QUESTION = "QuestionDialog";
public static final String KEY_PROGRESS = "ProgressDialog";
public static final String KEY_STREAM = "streamDialog";
public static final String KEY_SERVER = "serverDialog";
public static final String KEY_SUBS_DL = "subsdlDialog";
public static final String KEY_DEVICE = "deviceDialog";
......@@ -69,7 +67,6 @@ public class DialogActivity extends BaseActivity {
if (key.startsWith(KEY_LOGIN)) setupLoginDialog(key);
else if (key.startsWith(KEY_QUESTION)) setupQuestionDialog(key);
else if (key.startsWith(KEY_PROGRESS)) setupProgressDialog(key);
else if (KEY_STREAM.equals(key)) setupStreamDialog();
else if (KEY_SERVER.equals(key)) setupServerDialog();
else if (KEY_SUBS_DL.equals(key)) setupSubsDialog();
else if (KEY_DEVICE.equals(key)) setupDeviceDialog();
......@@ -83,9 +80,6 @@ public class DialogActivity extends BaseActivity {
dialog.show(getSupportFragmentManager(), "device_dialog");
}
private void setupStreamDialog() {
new MRLPanelFragment().show(getSupportFragmentManager(), "fragment_mrl");
}
private void setupServerDialog() {
new NetworkServerDialog().show(getSupportFragmentManager(), "fragment_mrl");
......
......@@ -36,7 +36,6 @@ import com.google.android.material.navigation.NavigationView;
import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.MediaParsingService;
import org.videolan.vlc.MediaParsingServiceKt;
import org.videolan.vlc.R;
import org.videolan.vlc.StartActivity;
......@@ -50,7 +49,6 @@ import org.videolan.vlc.gui.browser.BaseBrowserFragment;
import org.videolan.vlc.gui.browser.ExtensionBrowser;
import org.videolan.vlc.gui.helpers.Navigator;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.onboarding.OnboardingActivityKt;
import org.videolan.vlc.gui.preferences.PreferencesActivity;
import org.videolan.vlc.gui.preferences.PreferencesFragment;
import org.videolan.vlc.gui.video.VideoGridFragment;
......@@ -61,7 +59,6 @@ import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Permissions;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.WorkersKt;
import java.util.List;
......@@ -404,7 +401,6 @@ public class MainActivity extends ContentActivity implements ExtensionManagerSer
public void updateCheckedItem(int id) {
switch (id) {
case R.id.nav_mrl:
case R.id.nav_settings:
case R.id.nav_about:
return;
......
......@@ -90,6 +90,7 @@ class Navigator(private val activity: MainActivity,
R.id.nav_playlists -> PlaylistFragment()
R.id.nav_history -> HistoryFragment()
R.id.nav_network -> NetworkBrowserFragment()
R.id.nav_mrl -> MRLPanelFragment()
else -> {
val group = Integer.valueOf(Settings.getInstance(activity.applicationContext).getString("video_min_group_length", "6")!!)
if (group == 0) FoldersFragment()
......@@ -203,7 +204,7 @@ class Navigator(private val activity: MainActivity,
} else when (id) {
R.id.nav_about -> showSecondaryFragment(SecondaryActivity.ABOUT)
R.id.nav_settings -> activity.startActivityForResult(Intent(activity, PreferencesActivity::class.java), ACTIVITY_RESULT_PREFERENCES)
R.id.nav_mrl -> MRLPanelFragment().show(activity.supportFragmentManager, "fragment_mrl")
// R.id.nav_mrl -> MRLPanelFragment().show(activity.supportFragmentManager, "fragment_mrl")
else -> {
activity.slideDownAudioPlayer()
showFragment(id)
......
......@@ -20,19 +20,19 @@
*/
package org.videolan.vlc.gui.network
import androidx.databinding.DataBindingUtil
import android.net.Uri
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.channels.SendChannel
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.R
import org.videolan.vlc.databinding.MrlItemBinding
internal class MRLAdapter(private val eventActor: SendChannel<MrlAction>) : RecyclerView.Adapter<MRLAdapter.ViewHolder>() {
private var dataset: Array<MediaWrapper>? = null
private var dataset: List<MediaWrapper>? = null
val isEmpty: Boolean
get() = itemCount == 0
......@@ -49,7 +49,7 @@ internal class MRLAdapter(private val eventActor: SendChannel<MrlAction>) : Recy
holder.binding.mrlItemTitle.text = Uri.decode(item?.title)
}
fun setList(list: Array<MediaWrapper>?) {
fun setList(list: List<MediaWrapper>?) {
dataset = list
notifyDataSetChanged()
}
......
......@@ -20,6 +20,7 @@
*/
package org.videolan.vlc.gui.network
import android.graphics.Rect
import android.net.Uri
import android.os.Bundle
import android.text.TextUtils
......@@ -31,11 +32,14 @@ import android.view.inputmethod.EditorInfo
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.channels.actor
......@@ -43,12 +47,13 @@ import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.tools.coroutineScope
import org.videolan.vlc.R
import org.videolan.vlc.databinding.MrlPanelBinding
import org.videolan.vlc.gui.DialogActivity
import org.videolan.vlc.gui.dialogs.CtxActionReceiver
import org.videolan.vlc.gui.dialogs.SavePlaylistDialog
import org.videolan.vlc.gui.dialogs.showContext
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.tv.browser.interfaces.BrowserFragmentInterface
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.CTX_ADD_TO_PLAYLIST
import org.videolan.vlc.util.CTX_APPEND
import org.videolan.vlc.util.CTX_RENAME
......@@ -58,14 +63,14 @@ const val TAG = "VLC/MrlPanelFragment"
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
class MRLPanelFragment : DialogFragment(), View.OnKeyListener, TextView.OnEditorActionListener, View.OnClickListener, CtxActionReceiver {
class MRLPanelFragment : Fragment(), View.OnKeyListener, TextView.OnEditorActionListener, View.OnClickListener, CtxActionReceiver, BrowserFragmentInterface {
private lateinit var adapter: MRLAdapter
private lateinit var editText: com.google.android.material.textfield.TextInputLayout
private lateinit var viewModel: StreamsModel
private val listEventActor = coroutineScope.actor<MrlAction> {
for (event in channel) when(event) {
for (event in channel) when (event) {
is Playmedia -> playMedia(event.media)
is ShowContext -> showContext(event.position)
}
......@@ -73,8 +78,7 @@ class MRLPanelFragment : DialogFragment(), View.OnKeyListener, TextView.OnEditor
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NORMAL, 0)
viewModel = ViewModelProviders.of(this).get(StreamsModel::class.java)
viewModel = ViewModelProviders.of(requireActivity(), StreamsModel.Factory(requireContext())).get<StreamsModel>(StreamsModel::class.java)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
......@@ -86,21 +90,45 @@ class MRLPanelFragment : DialogFragment(), View.OnKeyListener, TextView.OnEditor
adapter = MRLAdapter(listEventActor)
val recyclerView = binding.mrlList
recyclerView.addItemDecoration(DividerItemDecoration(activity, DividerItemDecoration.VERTICAL))
recyclerView.layoutManager = LinearLayoutManager(activity)
if (AndroidDevices.showTvUi(requireActivity())) {
val gridLayoutManager = GridLayoutManager(activity, 2)
recyclerView.addItemDecoration(object : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
outRect.left = resources.getDimension(R.dimen.kl_half).toInt()
outRect.right = resources.getDimension(R.dimen.kl_half).toInt()
super.getItemOffsets(outRect, view, parent, state)
}
})
recyclerView.layoutManager = gridLayoutManager
} else {
recyclerView.layoutManager = LinearLayoutManager(activity)
recyclerView.addItemDecoration(DividerItemDecoration(activity, DividerItemDecoration.VERTICAL))
}
recyclerView.adapter = adapter
viewModel.observableHistory.observe(this, Observer { adapter.setList(it) })
binding.play.setOnClickListener(this)
dialog?.setTitle(R.string.open_mrl_dialog_title)
// dialog?.setTitle(R.string.open_mrl_dialog_title)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.dataset.observe(this, Observer { adapter.setList(it) })
}
override fun onStart() {
super.onStart()
viewModel.updateHistory()
viewModel.refresh()
val activity = activity as AppCompatActivity? ?: return
if (activity.supportActionBar != null) {
activity.supportActionBar!!.setTitle(R.string.open_mrl)
}
}
override fun onKey(v: View, keyCode: Int, event: KeyEvent): Boolean {
return (keyCode == EditorInfo.IME_ACTION_DONE ||
keyCode == EditorInfo.IME_ACTION_GO ||
......@@ -120,10 +148,9 @@ class MRLPanelFragment : DialogFragment(), View.OnKeyListener, TextView.OnEditor
private fun playMedia(mw: MediaWrapper) {
mw.type = MediaWrapper.TYPE_STREAM
MediaUtils.openMedia(activity, mw)
viewModel.updateHistory()
viewModel.refresh()
activity?.invalidateOptionsMenu()
UiTools.setKeyboardVisibility(editText, false)
dismiss()
}
override fun onEditorAction(v: TextView, actionId: Int, event: KeyEvent?) = false
......@@ -134,7 +161,7 @@ class MRLPanelFragment : DialogFragment(), View.OnKeyListener, TextView.OnEditor
private fun showContext(position: Int) {
val flags = CTX_RENAME or CTX_APPEND or CTX_ADD_TO_PLAYLIST
val media = viewModel.observableHistory.value?.get(position) ?: return
val media = viewModel.dataset.value.get(position) ?: return
showContext(requireActivity(), this, position, media.title, flags)
}
......@@ -142,18 +169,18 @@ class MRLPanelFragment : DialogFragment(), View.OnKeyListener, TextView.OnEditor
when (option) {
CTX_RENAME -> renameStream(position)
CTX_APPEND -> {
val media = viewModel.observableHistory.value?.get(position) ?: return
val media = viewModel.dataset.value.get(position) ?: return
MediaUtils.appendMedia(requireContext(), media)
}
CTX_ADD_TO_PLAYLIST -> {
val media = viewModel.observableHistory.value?.get(position) ?: return
val media = viewModel.dataset.value.get(position) ?: return
UiTools.addToPlaylist(requireActivity(), media.tracks, SavePlaylistDialog.KEY_NEW_TRACKS)
}
}
}
private fun renameStream(position: Int) {
val media = viewModel.observableHistory.value?.get(position) ?: return
val media = viewModel.dataset.value.get(position) ?: return
val edit = EditText(requireActivity())
AlertDialog.Builder(requireContext())
.setTitle(getString(R.string.rename_media, media.title))
......@@ -165,9 +192,8 @@ class MRLPanelFragment : DialogFragment(), View.OnKeyListener, TextView.OnEditor
.show()
}
override fun onDestroy() {
super.onDestroy()
// TV
(activity as? DialogActivity)?.finish()
override fun refresh() {
refresh()
}
}
......@@ -48,6 +48,7 @@ import org.videolan.vlc.gui.helpers.AudioUtil
import org.videolan.vlc.gui.helpers.BitmapUtil
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity
import org.videolan.vlc.gui.tv.browser.TVActivity
import org.videolan.vlc.gui.tv.browser.VerticalGridActivity
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.util.*
......@@ -138,8 +139,11 @@ object TvUtil {
}
}
is DummyItem -> when {
item.id == HEADER_STREAM -> activity.startActivity(Intent(activity, DialogActivity::class.java).setAction(DialogActivity.KEY_STREAM)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
item.id == HEADER_STREAM -> {
val intent = Intent(activity, TVActivity::class.java)
intent.putExtra(MainTvActivity.BROWSER_TYPE, HEADER_STREAM)
activity.startActivity(intent)
}
item.id == HEADER_SERVER -> activity.startActivity(Intent(activity, DialogActivity::class.java).setAction(DialogActivity.KEY_SERVER)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
else -> {
......
package org.videolan.vlc.gui.tv.browser
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import org.videolan.vlc.R
import org.videolan.vlc.gui.network.MRLPanelFragment
import org.videolan.vlc.gui.tv.MainTvActivity
import org.videolan.vlc.util.HEADER_STREAM
class TVActivity : AppCompatActivity() {
private lateinit var fragment: Fragment
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.tv_vertical_grid)
if (savedInstanceState == null) {
val type = intent.getLongExtra(MainTvActivity.BROWSER_TYPE, -1)
if (type == HEADER_STREAM) {
fragment = MRLPanelFragment()
} else {
finish()
return
}
supportFragmentManager.beginTransaction()
.add(R.id.tv_fragment_placeholder, fragment)
.commit()
}
}
}
\ No newline at end of file
......@@ -20,27 +20,38 @@
package org.videolan.vlc.viewmodels
import androidx.lifecycle.MutableLiveData
import android.content.Context
import androidx.databinding.ObservableField
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider