Commit 6b711de4 authored by Geoffrey Métais's avatar Geoffrey Métais

Empty view for network browsing

parent 5ff367a1
...@@ -3,8 +3,19 @@ ...@@ -3,8 +3,19 @@
android:id="@+id/swipeLayout" android:id="@+id/swipeLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView <FrameLayout
android:id="@+id/network_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/network_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:id="@+id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/network_connection_needed"/>
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>
\ No newline at end of file
...@@ -21,17 +21,22 @@ ...@@ -21,17 +21,22 @@
*/ */
package org.videolan.vlc.gui.network; package org.videolan.vlc.gui.network;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
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.TextView;
import org.videolan.libvlc.LibVLC; import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media; import org.videolan.libvlc.Media;
...@@ -42,8 +47,8 @@ import org.videolan.vlc.R; ...@@ -42,8 +47,8 @@ import org.videolan.vlc.R;
import org.videolan.vlc.gui.BrowserFragment; import org.videolan.vlc.gui.BrowserFragment;
import org.videolan.vlc.gui.DividerItemDecoration; import org.videolan.vlc.gui.DividerItemDecoration;
import org.videolan.vlc.interfaces.IRefreshable; import org.videolan.vlc.interfaces.IRefreshable;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Strings; import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.WeakHandler; import org.videolan.vlc.util.WeakHandler;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -62,6 +67,7 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me ...@@ -62,6 +67,7 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me
private SwipeRefreshLayout mSwipeRefreshLayout; private SwipeRefreshLayout mSwipeRefreshLayout;
private NetworkAdapter mAdapter; private NetworkAdapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.LayoutManager mLayoutManager;
TextView mEmptyView;
public String mMrl; public String mMrl;
private int savedPosition = -1, mFavorites = 0; private int savedPosition = -1, mFavorites = 0;
private boolean mRoot; private boolean mRoot;
...@@ -84,6 +90,7 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me ...@@ -84,6 +90,7 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.network_browser, container, false); View v = inflater.inflate(R.layout.network_browser, container, false);
mRecyclerView = (RecyclerView) v.findViewById(R.id.network_list); mRecyclerView = (RecyclerView) v.findViewById(R.id.network_list);
mEmptyView = (TextView) v.findViewById(android.R.id.empty);
mLayoutManager = new LinearLayoutManager(getActivity()); mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST)); mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setLayoutManager(mLayoutManager);
...@@ -103,16 +110,14 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me ...@@ -103,16 +110,14 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me
} }
public void onStart(){ public void onStart(){
super.onStart(); super.onStart();
mMediaBrowser = new MediaBrowser(mLibVLC, this);
if (mAdapter.isEmpty()) { //Handle network connection state
refresh(); IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
} else { getActivity().registerReceiver(networkReceiver, filter);
updateFavorites(); if (updateEmptyView()) {
if (savedPosition > 0) updateDisplay();
mRecyclerView.scrollTo(0, savedPosition);
} }
} }
public void onSaveInstanceState(Bundle outState){ public void onSaveInstanceState(Bundle outState){
outState.putString(KEY_MRL, mMrl); outState.putString(KEY_MRL, mMrl);
outState.putInt(KEY_POSITION, mRecyclerView.getScrollY()); outState.putInt(KEY_POSITION, mRecyclerView.getScrollY());
...@@ -148,6 +153,7 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me ...@@ -148,6 +153,7 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me
@Override @Override
public void onMediaAdded(int index, Media media) { public void onMediaAdded(int index, Media media) {
mAdapter.addItem(media, mRoot, true); mAdapter.addItem(media, mRoot, true);
updateEmptyView();
if (mRoot) if (mRoot)
mHandler.sendEmptyMessage(NetworkFragmentHandler.MSG_HIDE_LOADING); mHandler.sendEmptyMessage(NetworkFragmentHandler.MSG_HIDE_LOADING);
} }
...@@ -185,6 +191,49 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me ...@@ -185,6 +191,49 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me
} }
}; };
/**
* Update views visibility and emptiness info
*
* @return True if content needs can be refreshed
*/
private boolean updateEmptyView(){
if (AndroidDevices.hasLANConnection()){
if (mAdapter.isEmpty()){
mEmptyView.setText(mRoot ? R.string.network_shares_discovery : R.string.network_empty);
mEmptyView.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
mSwipeRefreshLayout.setEnabled(false);
} else {
if (mEmptyView.getVisibility() == View.VISIBLE) {
mEmptyView.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
mSwipeRefreshLayout.setEnabled(true);
}
}
return true;
} else {
if (mEmptyView.getVisibility() == View.GONE){
mEmptyView.setText(R.string.network_connection_needed);
mEmptyView.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
mSwipeRefreshLayout.setEnabled(false);
}
return false;
}
}
private void updateDisplay(){
mMediaBrowser = new MediaBrowser(mLibVLC, this);
if (mAdapter.isEmpty()) {
refresh();
} else {
updateFavorites();
if (savedPosition > 0)
mRecyclerView.scrollTo(0, savedPosition);
}
}
@Override @Override
public void refresh() { public void refresh() {
mAdapter.clear(); mAdapter.clear();
...@@ -257,4 +306,13 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me ...@@ -257,4 +306,13 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me
} }
} }
} }
private final BroadcastReceiver networkReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action))
if (updateEmptyView())
updateDisplay();
}
};
} }
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