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

Finer empty view management in browsers

parent 8e993663
......@@ -21,7 +21,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/network_connection_needed"/>
android:text="@string/directory_empty"/>
</FrameLayout>
</org.videolan.vlc.gui.view.SwipeRefreshLayout>
......
......@@ -221,10 +221,11 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
@Override
public void onMediaAdded(int index, Media media) {
boolean empty = mAdapter.isEmpty();
mAdapter.addItem(media, mReadyToDisplay && mRoot, mRoot);
if (mReadyToDisplay)
if (empty && mReadyToDisplay)
updateEmptyView();
if (mRoot)
if (mRoot && mSwipeRefreshLayout.isRefreshing())
mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
}
......@@ -266,13 +267,20 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
*/
protected void updateEmptyView(){
if (mAdapter.isEmpty()){
mEmptyView.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
mSwipeRefreshLayout.setEnabled(false);
if (mSwipeRefreshLayout.isRefreshing()) {
mEmptyView.setText(R.string.loading);
mEmptyView.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
} else {
mEmptyView.setText(R.string.directory_empty);
mEmptyView.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
}
} else if (mEmptyView.getVisibility() == View.VISIBLE) {
mEmptyView.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
mSwipeRefreshLayout.setEnabled(true);
mSwipeRefreshLayout.setRefreshing(false);
}
}
......@@ -344,10 +352,12 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
switch (msg.what){
case MSG_SHOW_LOADING:
fragment.mSwipeRefreshLayout.setRefreshing(true);
fragment.updateEmptyView();
break;
case MSG_HIDE_LOADING:
removeMessages(MSG_SHOW_LOADING);
fragment.mSwipeRefreshLayout.setRefreshing(false);
fragment.updateEmptyView();
break;
case MSG_REFRESH:
if (getOwner() != null && !getOwner().isDetached())
......
......@@ -67,7 +67,6 @@ public class FileBrowserFragment extends BaseBrowserFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mEmptyView.setText(getString(R.string.directory_empty));
}
@Override
......
......@@ -23,7 +23,6 @@
package org.videolan.vlc.gui.browser;
import android.app.DialogFragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
......@@ -52,8 +51,6 @@ import java.util.List;
public class NetworkBrowserFragment extends BaseBrowserFragment implements View.OnClickListener {
private DialogFragment mDialog;
public NetworkBrowserFragment() {
ROOT = "smb";
mHandler = new BrowserFragmentHandler(this);
......@@ -212,14 +209,20 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
protected void updateEmptyView() {
if (AndroidDevices.hasConnection()) {
if (mAdapter.isEmpty()) {
mEmptyView.setText(mRoot ? R.string.network_shares_discovery : R.string.network_empty);
mEmptyView.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
} else {
if (mEmptyView.getVisibility() == View.VISIBLE) {
if (mSwipeRefreshLayout.isRefreshing()) {
mEmptyView.setText(R.string.loading);
mEmptyView.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
} else {
mEmptyView.setText(mRoot ? R.string.network_shares_discovery : R.string.network_empty);
mEmptyView.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
}
} else if (mEmptyView.getVisibility() == View.VISIBLE) {
mEmptyView.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
}
mSwipeRefreshLayout.setRefreshing(false);
}
} else {
if (mEmptyView.getVisibility() == View.GONE) {
......@@ -228,7 +231,6 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
mRecyclerView.setVisibility(View.GONE);
}
}
mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
}
@Override
......
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