Commit 31307700 authored by Geoffrey Métais's avatar Geoffrey Métais

TV: Allow manual server setting

Fix #662
parent 8bd886d4
......@@ -8,7 +8,7 @@
android:id="@+id/server_protocol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:entries="@array/server_protocols"/>
......@@ -16,12 +16,12 @@
android:id="@+id/server_port_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/server_protocol"
android:layout_toEndOf="@+id/server_protocol"
android:layout_alignBaseline="@+id/server_protocol"
android:layout_alignTop="@+id/server_protocol"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:gravity="right"
android:gravity="end"
android:text="@string/server_port"/>
<EditText
......@@ -29,7 +29,7 @@
android:layout_width="wrap_content"
android:minWidth="30dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/server_port_text"
android:layout_toEndOf="@+id/server_port_text"
android:layout_alignParentTop="true"
android:layout_alignBaseline="@+id/server_protocol"
android:layout_alignTop="@+id/server_protocol"
......@@ -59,7 +59,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/server_domain"
android:layout_alignParentLeft="true" >
android:layout_alignParentStart="true" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -75,7 +75,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/server_username"
android:layout_alignParentLeft="true" >
android:layout_alignParentStart="true" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -98,7 +98,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/server_url"
android:layout_alignParentLeft="true" >
android:layout_alignParentStart="true" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -114,16 +114,13 @@
android:layout_height="wrap_content"
android:text="@android:string/cancel"
android:layout_below="@id/server_name"
android:layout_toLeftOf="@+id/server_save"
tools:targetApi="11"
style="?android:attr/borderlessButtonStyle"/>
android:layout_toStartOf="@+id/server_save" />
<Button
android:id="@+id/server_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="8dp"
android:text="@android:string/ok"
android:layout_below="@id/server_name"
tools:targetApi="11"
style="?android:attr/borderlessButtonStyle"/>
android:layout_below="@id/server_name" />
</RelativeLayout>
\ No newline at end of file
......@@ -27,6 +27,7 @@ import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import org.videolan.vlc.gui.dialogs.NetworkServerDialog;
import org.videolan.vlc.gui.dialogs.VlcDialog;
import org.videolan.vlc.gui.dialogs.VlcLoginDialog;
import org.videolan.vlc.gui.dialogs.VlcProgressDialog;
......@@ -39,6 +40,7 @@ public class DialogActivity extends BaseActivity {
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";
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -56,12 +58,18 @@ public class DialogActivity extends BaseActivity {
setupProgressDialog(key);
else if (KEY_STREAM.equals(key))
setupStreamDialog();
else if (KEY_SERVER.equals(key))
setupServerDialog();
}
private void setupStreamDialog() {
new MRLPanelFragment().show(getSupportFragmentManager(), "fragment_mrl");
}
private void setupServerDialog() {
new NetworkServerDialog().show(getSupportFragmentManager(), "fragment_mrl");
}
private void setupLoginDialog(String key) {
VlcLoginDialog dialog = new VlcLoginDialog();
startVlcDialog(key, dialog);
......
......@@ -8,10 +8,12 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatDialog;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -25,6 +27,7 @@ import android.widget.TextView;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.database.MediaDatabase;
import org.videolan.vlc.gui.DialogActivity;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.repository.BrowserFavRepository;
import org.videolan.vlc.util.WorkersKt;
......@@ -65,7 +68,8 @@ public class NetworkServerDialog extends DialogFragment implements AdapterView.O
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AppCompatDialog dialog = new AppCompatDialog(getActivity(), getTheme());
final FragmentActivity activity = getActivity();
final AppCompatDialog dialog = new AppCompatDialog(activity, getTheme());
dialog.setTitle(R.string.server_add_title);
dialog.setCancelable(true);
......@@ -100,17 +104,17 @@ public class NetworkServerDialog extends DialogFragment implements AdapterView.O
View v = inflater.inflate(R.layout.network_server_dialog, container, false);
mEditAddressLayout = (TextInputLayout) v.findViewById(R.id.server_domain);
mEditAddressLayout = v.findViewById(R.id.server_domain);
mEditAddress = mEditAddressLayout.getEditText();
mEditFolder = ((TextInputLayout)v.findViewById(R.id.server_folder)).getEditText();
mEditUsername = ((TextInputLayout)v.findViewById(R.id.server_username)).getEditText();
mEditServername = ((TextInputLayout)v.findViewById(R.id.server_name)).getEditText();
mSpinnerProtocol = (Spinner) v.findViewById(R.id.server_protocol);
mEditPort = (EditText) v.findViewById(R.id.server_port);
mUrl = (TextView) v.findViewById(R.id.server_url);
mSave = (Button) v.findViewById(R.id.server_save);
mCancel = (Button) v.findViewById(R.id.server_cancel);
mPortTitle = (TextView) v.findViewById(R.id.server_port_text);
mSpinnerProtocol = v.findViewById(R.id.server_protocol);
mEditPort = v.findViewById(R.id.server_port);
mUrl = v.findViewById(R.id.server_url);
mSave = v.findViewById(R.id.server_save);
mCancel = v.findViewById(R.id.server_cancel);
mPortTitle = v.findViewById(R.id.server_port_text);
mProtocols = getResources().getStringArray(R.array.server_protocols);
return v;
......@@ -120,7 +124,7 @@ public class NetworkServerDialog extends DialogFragment implements AdapterView.O
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(view.getContext(), R.layout.dropdown_item, getResources().getStringArray(R.array.server_protocols));
final ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(view.getContext(), R.layout.dropdown_item, getResources().getStringArray(R.array.server_protocols));
mSpinnerProtocol.setAdapter(spinnerArrayAdapter);
if (mUri != null) {
......@@ -151,9 +155,9 @@ public class NetworkServerDialog extends DialogFragment implements AdapterView.O
}
private void saveServer() {
String name = (TextUtils.isEmpty(mEditServername.getText().toString())) ?
final String name = (TextUtils.isEmpty(mEditServername.getText().toString())) ?
mEditAddress.getText().toString() : mEditServername.getText().toString();
Uri uri = Uri.parse(mUrl.getText().toString());
final Uri uri = Uri.parse(mUrl.getText().toString());
if (mUri != null) {
WorkersKt.runIO(new Runnable() {
@Override
......@@ -291,4 +295,11 @@ public class NetworkServerDialog extends DialogFragment implements AdapterView.O
mUri = mw.getUri();
mName = mw.getTitle();
}
@Override
public void onDestroy() {
super.onDestroy();
final Activity activity = getActivity();
if (activity instanceof DialogActivity) activity.finish();
}
}
......@@ -111,9 +111,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
browserFavRepository = BrowserFavRepository.getInstance(requireContext())
favorites = browserFavRepository.networkFavorites
favorites.observe(this, Observer{
it?.let{
updatedFavoritList = it
}
it?.let{ list -> updatedFavoritList = list }
updateBrowsers()
})
}
......@@ -215,6 +213,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
if (ExternalMonitor.isLan()) {
list.add(DummyItem(HEADER_NETWORK, getString(R.string.network_browsing), null))
list.add(DummyItem(HEADER_STREAM, getString(R.string.open_mrl), null))
list.add(DummyItem(HEADER_SERVER, getString(R.string.server_add_title), null))
updatedFavoritList.forEach{
it.description = it.uri.scheme
......
......@@ -37,6 +37,7 @@ import android.support.v17.leanback.widget.FullWidthDetailsOverviewRowPresenter;
import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v17.leanback.widget.OnActionClickedListener;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.widget.Toast;
......@@ -125,7 +126,7 @@ public class MediaItemDetailsFragment extends DetailsSupportFragment implements
// Attach your media item details presenter to the row presenter:
FullWidthDetailsOverviewRowPresenter rowPresenter = new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
final Activity activity = requireActivity();
final FragmentActivity activity = requireActivity();
final DetailsOverviewRow detailsOverview = new DetailsOverviewRow(mMedia);
final Action actionAdd = new Action(ID_FAVORITE_ADD, getString(R.string.favorites_add));
final Action actionDelete = new Action(ID_FAVORITE_DELETE, getString(R.string.favorites_remove));
......
......@@ -33,6 +33,7 @@ import android.support.v17.leanback.app.BackgroundManager
import android.support.v17.leanback.widget.DiffCallback
import android.support.v17.leanback.widget.ListRow
import android.support.v17.leanback.widget.Row
import android.support.v4.app.FragmentActivity
import android.support.v4.content.ContextCompat
import android.text.TextUtils
import android.view.View
......@@ -45,6 +46,7 @@ import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.gui.DialogActivity
import org.videolan.vlc.gui.dialogs.NetworkServerDialog
import org.videolan.vlc.gui.helpers.AudioUtil
import org.videolan.vlc.gui.helpers.BitmapUtil
import org.videolan.vlc.gui.helpers.UiTools
......@@ -107,7 +109,7 @@ object TvUtil {
MediaUtils.openMedia(activity, media)
}
fun openMedia(activity: Activity, item: Any?, row: Row?) {
fun openMedia(activity: FragmentActivity, item: Any?, row: Row?) {
when (item) {
is MediaWrapper -> when {
item.type == MediaWrapper.TYPE_AUDIO -> openAudioCategory(activity, item)
......@@ -126,13 +128,16 @@ object TvUtil {
}
else -> MediaUtils.openMedia(activity, item)
}
is DummyItem -> if (item.id == HEADER_STREAM) {
activity.startActivity(Intent(activity, DialogActivity::class.java).setAction(DialogActivity.KEY_STREAM)
is DummyItem -> when {
item.id == HEADER_STREAM -> activity.startActivity(Intent(activity, DialogActivity::class.java).setAction(DialogActivity.KEY_STREAM)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
} else {
val intent = Intent(activity, VerticalGridActivity::class.java)
intent.putExtra(MainTvActivity.BROWSER_TYPE, item.id)
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 -> {
val intent = Intent(activity, VerticalGridActivity::class.java)
intent.putExtra(MainTvActivity.BROWSER_TYPE, item.id)
activity.startActivity(intent)
}
}
is MediaLibraryItem -> openAudioCategory(activity, item)
}
......@@ -225,7 +230,7 @@ object TvUtil {
return when (mediaLibraryItem.id) {
HEADER_VIDEO -> R.drawable.ic_video_collection_big
HEADER_DIRECTORIES -> R.drawable.ic_menu_folder_big
HEADER_NETWORK -> R.drawable.ic_menu_network_big
HEADER_SERVER, HEADER_NETWORK -> R.drawable.ic_menu_network_big
HEADER_STREAM -> R.drawable.ic_menu_stream_big
ID_SETTINGS -> R.drawable.ic_menu_preferences_big
ID_ABOUT_TV, ID_LICENCE -> R.drawable.ic_default_cone
......
......@@ -35,6 +35,7 @@ import android.support.v17.leanback.widget.OnItemViewSelectedListener;
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
import android.util.Log;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
......
......@@ -20,11 +20,11 @@
*****************************************************************************/
package org.videolan.vlc.gui.tv.browser;
import android.app.Activity;
import android.os.Bundle;
import android.support.v17.leanback.app.VerticalGridSupportFragment;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.VerticalGridPresenter;
import android.support.v4.app.FragmentActivity;
import org.videolan.vlc.gui.tv.CardPresenter;
import org.videolan.vlc.gui.tv.browser.interfaces.BrowserFragmentInterface;
......@@ -36,7 +36,7 @@ public class GridFragment extends VerticalGridSupportFragment implements Browser
private static final int NUM_COLUMNS = 4;
protected ArrayObjectAdapter mAdapter;
Activity mContext;
FragmentActivity mContext;
@Override
public void onCreate(Bundle savedInstanceState) {
......
......@@ -29,11 +29,12 @@ import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.ExternalMonitor
import org.videolan.vlc.R
import org.videolan.vlc.repository.BrowserFavRepository
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.LiveDataset
class NetworkProvider(context: Context, dataset: LiveDataset<MediaLibraryItem>, url: String? = null, showHiddenFiles: Boolean): BrowserProvider(context, dataset, url, showHiddenFiles), Observer<List<MediaWrapper>> {
private val favorites = if (url == null) BrowserFavRepository.getInstance(context).networkFavorites else null
private val favorites = if (url == null && !AndroidDevices.showTvUi(context)) BrowserFavRepository.getInstance(context).networkFavorites else null
init {
favorites?.observeForever(this)
......
......@@ -108,6 +108,7 @@ const val HEADER_NETWORK = 3L
const val HEADER_DIRECTORIES = 4L
const val HEADER_MISC = 5L
const val HEADER_STREAM = 6L
const val HEADER_SERVER = 7L
const val ID_SETTINGS = 10L
const val ID_ABOUT_TV = 11L
const val ID_LICENCE = 12L
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment