Commit 7a5c3cda authored by Geoffrey Métais's avatar Geoffrey Métais

Swipe to refresh

parent 52fa8067
......@@ -20,40 +20,44 @@
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<org.videolan.vlc.widget.FlingViewGroup
android:id="@+id/fling_view_group"
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/albums"
android:layout_height="match_parent">
<org.videolan.vlc.widget.FlingViewGroup
android:id="@+id/fling_view_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:nextFocusUp="@+id/ml_menu_search"
android:nextFocusDown="@id/albums"
android:nextFocusLeft="@id/albums"
android:nextFocusRight="@id/albums" />
android:layout_height="match_parent" >
<ListView
android:id="@+id/songs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:nextFocusUp="@+id/ml_menu_search"
android:nextFocusDown="@id/songs"
android:nextFocusLeft="@id/songs"
android:nextFocusRight="@id/songs" />
</org.videolan.vlc.widget.FlingViewGroup>
<ListView
android:id="@+id/albums"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:nextFocusUp="@+id/ml_menu_search"
android:nextFocusDown="@id/albums"
android:nextFocusLeft="@id/albums"
android:nextFocusRight="@id/albums" />
<ListView
android:id="@+id/songs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:nextFocusUp="@+id/ml_menu_search"
android:nextFocusDown="@id/songs"
android:nextFocusLeft="@id/songs"
android:nextFocusRight="@id/songs" />
</org.videolan.vlc.widget.FlingViewGroup>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
</LinearLayout>
......
......@@ -8,75 +8,75 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<org.videolan.vlc.widget.HeaderScrollView
android:id="@+id/header"
android:scrollbars="none"
android:fadingEdge="none"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_header_item"
android:nextFocusUp="@+id/ml_menu_search"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/header"
android:nextFocusRight="@id/header" >
<LinearLayout
android:id="@+id/header_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/header"
android:scrollbars="none"
android:fadingEdge="none"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_header_item"
android:nextFocusUp="@+id/ml_menu_search"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/header"
android:nextFocusRight="@id/header" >
<LinearLayout
android:id="@+id/header_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="5sp"
android:paddingBottom="5sp" >
<TextView
android:text="@string/artists"
android:textAllCaps="true"
android:textSize="16sp"
android:textColor="?attr/font_light"
android:id="@+id/artists"
android:layout_width="80sp"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
<TextView
android:text="@string/albums"
android:textAllCaps="true"
android:textSize="16sp"
android:textColor="?attr/font_light"
android:id="@+id/albums"
android:layout_width="80sp"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
<TextView
android:text="@string/songs"
android:textAllCaps="true"
android:textSize="16sp"
android:textColor="?attr/font_light"
android:id="@+id/songs"
android:layout_width="80sp"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
<TextView
android:text="@string/genres"
android:textAllCaps="true"
android:textSize="16sp"
android:textColor="?attr/font_light"
android:id="@+id/genres"
android:layout_width="80sp"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
</LinearLayout>
</org.videolan.vlc.widget.HeaderScrollView>
<View
android:layout_width="20dip"
android:layout_height="10dip"
android:layout_alignBottom="@+id/header"
android:layout_alignLeft="@+id/header"
android:layout_alignTop="@+id/header"
android:background="?attr/header_fadein_overlay" />
<View
android:layout_width="20dip"
android:layout_height="10dip"
android:layout_alignBottom="@+id/header"
android:layout_alignRight="@+id/header"
android:layout_alignTop="@+id/header"
android:background="?attr/header_fadeout_overlay" />
android:text="@string/artists"
android:textAllCaps="true"
android:textSize="16sp"
android:textColor="?attr/font_light"
android:id="@+id/artists"
android:layout_width="80sp"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
<TextView
android:text="@string/albums"
android:textAllCaps="true"
android:textSize="16sp"
android:textColor="?attr/font_light"
android:id="@+id/albums"
android:layout_width="80sp"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
<TextView
android:text="@string/songs"
android:textAllCaps="true"
android:textSize="16sp"
android:textColor="?attr/font_light"
android:id="@+id/songs"
android:layout_width="80sp"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
<TextView
android:text="@string/genres"
android:textAllCaps="true"
android:textSize="16sp"
android:textColor="?attr/font_light"
android:id="@+id/genres"
android:layout_width="80sp"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
</LinearLayout>
</org.videolan.vlc.widget.HeaderScrollView>
<View
android:layout_width="20dip"
android:layout_height="10dip"
android:layout_alignBottom="@+id/header"
android:layout_alignLeft="@+id/header"
android:layout_alignTop="@+id/header"
android:background="?attr/header_fadein_overlay" />
<View
android:layout_width="20dip"
android:layout_height="10dip"
android:layout_alignBottom="@+id/header"
android:layout_alignRight="@+id/header"
android:layout_alignTop="@+id/header"
android:background="?attr/header_fadeout_overlay" />
</RelativeLayout>
<TextView
......@@ -88,66 +88,71 @@
android:textSize="20sp"
android:visibility="gone" />
<org.videolan.vlc.widget.FlingViewGroup
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.videolan.vlc.widget.FlingViewGroup
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/artists_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false"
android:focusable="true"
android:nextFocusUp="@id/header"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/artists_list"
android:nextFocusRight="@+id/albums_list" />
<ListView
android:id="@+id/albums_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false"
android:focusable="true"
android:nextFocusUp="@id/header"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/artists_list"
android:nextFocusRight="@+id/songs_list" />
<ListView
android:id="@+id/songs_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false"
android:focusable="true"
android:nextFocusUp="@id/header"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/albums_list"
android:nextFocusRight="@+id/genres_list" />
<ListView
android:id="@+id/genres_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false"
android:focusable="true"
android:nextFocusUp="@id/header"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/songs_list"
android:nextFocusRight="@+id/genres_list" />
</org.videolan.vlc.widget.FlingViewGroup>
<ListView
android:id="@+id/artists_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false"
android:focusable="true"
android:nextFocusUp="@id/header"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/artists_list"
android:nextFocusRight="@+id/albums_list" />
<ListView
android:id="@+id/albums_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false"
android:focusable="true"
android:nextFocusUp="@id/header"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/artists_list"
android:nextFocusRight="@+id/songs_list" />
<ListView
android:id="@+id/songs_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false"
android:focusable="true"
android:nextFocusUp="@id/header"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/albums_list"
android:nextFocusRight="@+id/genres_list" />
<ListView
android:id="@+id/genres_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false"
android:focusable="true"
android:nextFocusUp="@id/header"
android:nextFocusDown="@id/header"
android:nextFocusLeft="@id/songs_list"
android:nextFocusRight="@+id/genres_list" />
</org.videolan.vlc.widget.FlingViewGroup>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false"
android:divider="?attr/background_menu_divider"
android:dividerHeight="0.1dp" >
</ListView>
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false"
android:divider="?attr/background_menu_divider"
android:dividerHeight="0.1dp" >
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
......@@ -4,22 +4,26 @@
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="@dimen/listview_bottom_padding"
android:paddingLeft="20dp"
android:paddingRight="20dp" />
<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:paddingTop="30dip"
android:text="@string/nohistory"
android:textSize="20sp" />
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="@dimen/listview_bottom_padding"
android:paddingLeft="20dp"
android:paddingRight="20dp" />
<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:paddingTop="30dip"
android:text="@string/nohistory"
android:textSize="20sp" />
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="20dip">
<GridView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:clipToPadding="false"
android:scrollbarStyle="outsideInset"
android:numColumns="auto_fit"
android:fastScrollEnabled="true"
android:fadingEdge="none"
android:gravity="center"
android:nextFocusUp="@+id/ml_menu_search"
android:nextFocusDown="@id/android:list"
android:nextFocusLeft="@id/android:list"
android:nextFocusRight="@id/android:list" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:clipToPadding="false"
android:scrollbarStyle="outsideInset"
android:numColumns="auto_fit"
android:fastScrollEnabled="true"
android:fadingEdge="none"
android:gravity="center"
android:nextFocusUp="@+id/ml_menu_search"
android:nextFocusDown="@id/android:list"
android:nextFocusLeft="@id/android:list"
android:nextFocusRight="@id/android:list" />
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@id/android:empty"
......
......@@ -42,6 +42,7 @@ import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.PopupMenu.OnMenuItemClickListener;
......@@ -52,15 +53,17 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
public class DirectoryViewFragment extends ListFragment implements IRefreshable, ISortable {
public class DirectoryViewFragment extends ListFragment implements IRefreshable, ISortable, SwipeRefreshLayout.OnRefreshListener {
public final static String TAG = "VLC/DirectoryViewFragment";
private DirectoryAdapter mDirectoryAdapter;
private SwipeRefreshLayout mSwipeRefreshLayout;
/* All subclasses of Fragment must include a public empty constructor. */
public DirectoryViewFragment() { }
......@@ -119,6 +122,19 @@ public class DirectoryViewFragment extends ListFragment implements IRefreshable,
}
}
});
mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipeLayout);
mSwipeRefreshLayout.setColorSchemeResources(R.color.darkerorange);
mSwipeRefreshLayout.setOnRefreshListener(this);
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
mSwipeRefreshLayout.setEnabled(firstVisibleItem == 0);
}
});
registerForContextMenu(listView);
return v;
......@@ -230,6 +246,7 @@ public class DirectoryViewFragment extends ListFragment implements IRefreshable,
focusHelper(mDirectoryAdapter.getCount() == 0);
} else
focusHelper(true);
mSwipeRefreshLayout.setRefreshing(false);
}
private final BroadcastReceiver messageReceiver = new BroadcastReceiver() {
......@@ -270,4 +287,9 @@ public class DirectoryViewFragment extends ListFragment implements IRefreshable,
}
};
@Override
public void onRefresh() {
refresh();
}
}
......@@ -28,8 +28,8 @@ import org.videolan.vlc.interfaces.IRefreshable;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
......@@ -37,13 +37,15 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
public class HistoryFragment extends ListFragment implements IRefreshable {
public class HistoryFragment extends ListFragment implements IRefreshable, SwipeRefreshLayout.OnRefreshListener {
public final static String TAG = "VLC/HistoryFragment";
private HistoryAdapter mHistoryAdapter;
private SwipeRefreshLayout mSwipeRefreshLayout;
/* All subclasses of Fragment must include a public empty constructor. */
public HistoryFragment() { }
......@@ -53,7 +55,6 @@ public class HistoryFragment extends ListFragment implements IRefreshable {
super.onCreate(savedInstanceState);
mHistoryAdapter = new HistoryAdapter(getActivity());
Log.d(TAG, "HistoryFragment()");
}
private void focusHelper(boolean idIsEmpty) {
......@@ -81,6 +82,20 @@ public class HistoryFragment extends ListFragment implements IRefreshable {
focusHelper(mHistoryAdapter.getCount() == 0);
listView.requestFocus();
registerForContextMenu(listView);
mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipeLayout);
mSwipeRefreshLayout.setColorSchemeColors(R.color.darkerorange/*, R.attr.colorPrimary, R.attr.colorPrimaryDark*/);
mSwipeRefreshLayout.setOnRefreshListener(this);
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
mSwipeRefreshLayout.setEnabled(firstVisibleItem == 0);
}
});
return v;
}
......@@ -124,11 +139,16 @@ public class HistoryFragment extends ListFragment implements IRefreshable {
@Override
public void refresh() {
Log.d(TAG, "Refreshing view!");
if( mHistoryAdapter != null ) {
mHistoryAdapter.refresh();
focusHelper(mHistoryAdapter.getCount() == 0);
} else
focusHelper(true);
mSwipeRefreshLayout.setRefreshing(false);
}
@Override
public void onRefresh() {
refresh();
}
}
......@@ -42,6 +42,7 @@ import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarActivity;