Create GridLayoutManager for TimersFragment in landscape

This commit is contained in:
Phillip Hsu
2016-08-30 02:39:18 -07:00
parent be9aca1ede
commit 2dc411f999
3 changed files with 102 additions and 1 deletions
@@ -3,9 +3,12 @@ package com.philliphsu.clock2.timers;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.Loader;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import com.philliphsu.clock2.AsyncTimersTableUpdateHandler;
import com.philliphsu.clock2.RecyclerViewFragment;
@@ -19,6 +22,8 @@ public class TimersFragment extends RecyclerViewFragment<
TimerViewHolder,
TimerCursor,
TimersCursorAdapter> {
private static final int LANDSCAPE_LAYOUT_COLUMNS = 2;
public static final int REQUEST_CREATE_TIMER = 0;
private AsyncTimersTableUpdateHandler mAsyncTimersTableUpdateHandler;
@@ -67,6 +72,16 @@ public class TimersFragment extends RecyclerViewFragment<
return new TimersCursorAdapter(this, mAsyncTimersTableUpdateHandler);
}
@Override
protected RecyclerView.LayoutManager getLayoutManager() {
switch (getResources().getConfiguration().orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
return new GridLayoutManager(getActivity(), LANDSCAPE_LAYOUT_COLUMNS);
default:
return super.getLayoutManager();
}
}
@Override
public Loader<TimerCursor> onCreateLoader(int id, Bundle args) {
return new TimersListCursorLoader(getActivity());