add some functionality to left and right arrows

This commit is contained in:
tibbi 2016-09-15 21:01:47 +02:00
parent a28d5ed2d1
commit 23652f8196
3 changed files with 36 additions and 7 deletions

View File

@ -14,6 +14,7 @@ import com.simplemobiletools.calendar.Constants;
import com.simplemobiletools.calendar.Formatter;
import com.simplemobiletools.calendar.R;
import com.simplemobiletools.calendar.adapters.MyPagerAdapter;
import com.simplemobiletools.calendar.fragments.MonthFragment;
import com.simplemobiletools.calendar.views.MyViewPager;
import org.joda.time.DateTime;
@ -27,7 +28,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends SimpleActivity {
public class MainActivity extends SimpleActivity implements MonthFragment.NavigationListener {
@BindView(R.id.view_pager) MyViewPager mPager;
@BindDimen(R.dimen.day_text_size) float mDayTextSize;
@ -43,7 +44,7 @@ public class MainActivity extends SimpleActivity {
final String today = new DateTime().toString(Formatter.DAYCODE_PATTERN);
final List<String> codes = getMonths(today);
final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), codes);
final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), codes, this);
mPager.setAdapter(adapter);
mPager.setCurrentItem(codes.size() / 2);
}
@ -134,4 +135,14 @@ public class MainActivity extends SimpleActivity {
final NumberPicker dayPicker = (picker1.getMaxValue() > picker2.getMaxValue()) ? picker1 : picker2;
dayPicker.setVisibility(View.GONE);
}
@Override
public void goLeft() {
mPager.setCurrentItem(mPager.getCurrentItem() - 1);
}
@Override
public void goRight() {
mPager.setCurrentItem(mPager.getCurrentItem() + 1);
}
}

View File

@ -12,10 +12,12 @@ import java.util.List;
public class MyPagerAdapter extends FragmentStatePagerAdapter {
private final List<String> mCodes;
private final MonthFragment.NavigationListener mListener;
public MyPagerAdapter(FragmentManager fm, List<String> codes) {
public MyPagerAdapter(FragmentManager fm, List<String> codes, MonthFragment.NavigationListener listener) {
super(fm);
mCodes = codes;
mListener = listener;
}
@Override
@ -31,6 +33,7 @@ public class MyPagerAdapter extends FragmentStatePagerAdapter {
final MonthFragment fragment = new MonthFragment();
fragment.setArguments(bundle);
fragment.setListener(mListener);
return fragment;
}
}

View File

@ -41,10 +41,11 @@ public class MonthFragment extends Fragment implements Calendar {
private View mView;
private CalendarImpl mCalendar;
private Resources mRes;
private String mPackageName;
private Config mConfig;
private NavigationListener mListener;
private String mPackageName;
private String mCode;
private int mTextColor;
private int mWeakTextColor;
private int mTextColorWithEvent;
@ -93,6 +94,10 @@ public class MonthFragment extends Fragment implements Calendar {
updateDays(days);
}
public void setListener(NavigationListener listener) {
mListener = listener;
}
private void setupColors() {
final int baseColor = mConfig.getIsDarkTheme() ? Color.WHITE : Color.BLACK;
mTextColor = Utils.adjustAlpha(baseColor, Constants.HIGH_ALPHA);
@ -101,16 +106,20 @@ public class MonthFragment extends Fragment implements Calendar {
mWeakTextColorWithEvent = Utils.adjustAlpha(mRes.getColor(R.color.colorPrimary), Constants.LOW_ALPHA);
mLeftArrow.getDrawable().mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP);
mRightArrow.getDrawable().mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP);
mLeftArrow.setBackground(null);
mRightArrow.setBackground(null);
}
@OnClick(R.id.top_left_arrow)
public void leftArrowClicked() {
if (mListener != null)
mListener.goLeft();
}
@OnClick(R.id.top_right_arrow)
public void rightArrowClicked() {
if (mListener != null)
mListener.goRight();
}
private void setupLabels() {
@ -172,4 +181,10 @@ public class MonthFragment extends Fragment implements Calendar {
intent.putExtra(Constants.DAY_CODE, code);
startActivity(intent);
}
public interface NavigationListener {
void goLeft();
void goRight();
}
}