Commit 2aa61b68 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Video grid: ConstraintLayout & DataBinding

parent 3398ce21
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout>
<data>
<import type="android.view.View" />
<variable
name="empty"
type="boolean" />
</data>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/button_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<org.videolan.vlc.gui.view.SwipeRefreshLayout
android:id="@+id/swipeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/searchButton">
android:id="@+id/swipeLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchButton"
app:layout_constraintBottom_toBottomOf="parent"
android:visibility="@{empty ? View.GONE : View.VISIBLE}">
<org.videolan.vlc.gui.view.AutoFitRecyclerView
android:id="@id/android:list"
android:id="@+id/video_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/default_margin"
......@@ -28,78 +42,78 @@
android:gravity="center" />
</org.videolan.vlc.gui.view.SwipeRefreshLayout>
<LinearLayout
android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
<TextView
android:id="@+id/textview_nomedia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/loading_title"
app:layout_constraintVertical_chainStyle="packed"
android:layout_margin="@dimen/default_margin"
android:drawableBottom="@drawable/ic_no_media"
android:drawablePadding="@dimen/default_margin"
android:gravity="center"
android:visibility="gone"
android:orientation="vertical">
android:maxWidth="600dp"
android:text="@string/nomedia"
android:textSize="20sp"
android:visibility="@{empty ? View.VISIBLE : View.GONE}" />
<TextView
android:id="@+id/loading_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/loading_flipper"
app:layout_constraintTop_toBottomOf="@+id/textview_nomedia"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_chainStyle="packed"
android:layout_weight="1"
android:gravity="start"
android:text="@string/loading"
android:textSize="20sp"
android:visibility="@{empty ? View.VISIBLE : View.GONE}" />
<ViewFlipper
android:id="@+id/loading_flipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@+id/loading_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBaseline_toBaselineOf="@+id/loading_title"
android:layout_gravity="start"
android:autoStart="true"
android:flipInterval="1000"
android:visibility="@{empty ? View.VISIBLE : View.GONE}" >
<TextView
android:id="@+id/textview_nomedia"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/default_margin"
android:drawableBottom="@drawable/ic_no_media"
android:drawablePadding="@dimen/default_margin"
android:gravity="center"
android:maxWidth="600dp"
android:text="@string/nomedia"
android:textSize="20sp"
android:visibility="visible" />
android:layout_gravity="start"
android:text="@string/empty"
android:textSize="20sp" />
<LinearLayout
android:id="@+id/layout_flipper_loading"
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="invisible" >
android:layout_gravity="start"
android:text="@string/load_1_period"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="@string/loading"
android:textSize="20sp" />
<ViewFlipper
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="left"
android:autoStart="true"
android:flipInterval="1000" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/empty"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/load_1_period"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/load_2_period"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="@string/load_2_period"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/load_3_period"
android:textSize="20sp" />
</ViewFlipper>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="@string/load_3_period"
android:textSize="20sp" />
</ViewFlipper>
</android.support.constraint.ConstraintLayout>
</layout>
\ No newline at end of file
......@@ -73,7 +73,6 @@ public class HistoryFragment extends MediaBrowserFragment<HistoryProvider> imple
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mEmptyView = view.findViewById(android.R.id.empty);
mSwipeRefreshLayout = view.findViewById(R.id.swipeLayout);
mRecyclerView = view.findViewById(android.R.id.list);
mProvider = ViewModelProviders.of(requireActivity()).get(HistoryProvider.class);
mProvider.getDataset().observe(this, new Observer<List<MediaWrapper>>() {
......
......@@ -131,7 +131,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
mViewPager = view.findViewById(R.id.pager);
mFastScroller = view.findViewById(R.id.songs_fast_scroller);
mTabLayout = view.findViewById(R.id.sliding_tabs);
mSwipeRefreshLayout = view.findViewById(R.id.swipeLayout);
}
@Override
......
......@@ -137,7 +137,6 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment<BrowserPr
super.onViewCreated(view, savedInstanceState);
mRecyclerView = view.findViewById(R.id.network_list);
mEmptyView = view.findViewById(R.id.empty);
mSwipeRefreshLayout = view.findViewById(R.id.swipeLayout);
}
@Override
......
......@@ -92,6 +92,7 @@ public abstract class MediaBrowserFragment<T extends BaseModel> extends Fragment
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mSearchButtonView = view.findViewById(R.id.searchButton);
mSwipeRefreshLayout = view.findViewById(R.id.swipeLayout);
if (mSwipeRefreshLayout != null) mSwipeRefreshLayout.setColorSchemeResources(R.color.orange700);
mFabPlay = getActivity().findViewById(R.id.fab);
}
......
......@@ -54,11 +54,11 @@ import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.MediaParsingService;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.databinding.VideoGridBinding;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.SecondaryActivity;
import org.videolan.vlc.gui.browser.MediaBrowserFragment;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.view.AutoFitRecyclerView;
import org.videolan.vlc.gui.view.ContextMenuRecyclerView;
import org.videolan.vlc.gui.view.SwipeRefreshLayout;
import org.videolan.vlc.interfaces.IEventsHandler;
......@@ -76,9 +76,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
private final static String TAG = "VLC/VideoListFragment";
private VideoListAdapter mAdapter;
private AutoFitRecyclerView mGridView;
private View mViewNomedia;
private VideoGridBinding mBinding;
private String mGroup;
private DividerItemDecoration mDividerItemDecoration;
......@@ -115,15 +113,8 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.video_grid, container, false);
}
@Override
public void onViewCreated(View v, @Nullable Bundle savedInstanceState) {
super.onViewCreated(v, savedInstanceState);
mViewNomedia = v.findViewById(android.R.id.empty);
mGridView = v.findViewById(android.R.id.list);
mSwipeRefreshLayout = v.findViewById(R.id.swipeLayout);
mBinding = VideoGridBinding.inflate(inflater, container, false);
return mBinding.getRoot();
}
@Override
......@@ -131,15 +122,15 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
super.onActivityCreated(savedInstanceState);
mSwipeRefreshLayout.setOnRefreshListener(this);
mDividerItemDecoration = new DividerItemDecoration(requireActivity(), DividerItemDecoration.VERTICAL);
if (mAdapter.isListMode()) mGridView.addItemDecoration(mDividerItemDecoration);
mGridView.setAdapter(mAdapter);
if (mAdapter.isListMode()) mBinding.videoGrid.addItemDecoration(mDividerItemDecoration);
mBinding.videoGrid.setAdapter(mAdapter);
}
private boolean restart = false;
@Override
public void onStart() {
super.onStart();
registerForContextMenu(mGridView);
registerForContextMenu(mBinding.videoGrid);
setSearchVisibility(false);
updateViewMode();
mFabPlay.setImageResource(R.drawable.ic_fab_play);
......@@ -150,7 +141,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
@Override
public void onStop() {
super.onStop();
unregisterForContextMenu(mGridView);
unregisterForContextMenu(mBinding.videoGrid);
restart = true;
}
......@@ -183,13 +174,13 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
if (!listMode) {
final int thumbnailWidth = res.getDimensionPixelSize(R.dimen.grid_card_thumb_width);
final int margin = res.getDimensionPixelSize(R.dimen.default_margin);
mGridView.setColumnWidth(mGridView.getPerfectColumnWidth(thumbnailWidth, margin));
mAdapter.setGridCardWidth(mGridView.getColumnWidth());
mBinding.videoGrid.setColumnWidth(mBinding.videoGrid.getPerfectColumnWidth(thumbnailWidth, margin));
mAdapter.setGridCardWidth(mBinding.videoGrid.getColumnWidth());
}
mGridView.setNumColumns(listMode ? 1 : -1);
mBinding.videoGrid.setNumColumns(listMode ? 1 : -1);
if (mAdapter.isListMode() != listMode) {
if (listMode) mGridView.addItemDecoration(mDividerItemDecoration);
else mGridView.removeItemDecoration(mDividerItemDecoration);
if (listMode) mBinding.videoGrid.addItemDecoration(mDividerItemDecoration);
else mBinding.videoGrid.removeItemDecoration(mDividerItemDecoration);
mAdapter.setListMode(listMode);
}
}
......@@ -294,7 +285,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
}
void updateEmptyView() {
mViewNomedia.setVisibility(mAdapter.getItemCount() > 0 ? View.GONE : View.VISIBLE);
mBinding.setEmpty(mAdapter.isEmpty());
}
public void setGroup(String prefix) {
......@@ -447,7 +438,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosProvider> impl
@Override
public void onCtxClick(View v, int position, MediaLibraryItem item) {
if (mActionMode == null) mGridView.openContextMenu(position);
if (mActionMode == null) mBinding.videoGrid.openContextMenu(position);
}
@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