store view type

This commit is contained in:
tibbi 2016-10-17 18:49:25 +02:00
parent 1866bf1f8f
commit 019d3aa1c3
4 changed files with 43 additions and 5 deletions

View file

@ -56,4 +56,12 @@ public class Config {
public void setLastOtherReminderMins(int lastMins) {
mPrefs.edit().putInt(Constants.LAST_OTHER_REMINDER_MINS, lastMins).apply();
}
public int getView() {
return mPrefs.getInt(Constants.VIEW, Constants.MONTHLY_VIEW);
}
public void setView(int view) {
mPrefs.edit().putInt(Constants.VIEW, view).apply();
}
}

View file

@ -7,6 +7,9 @@ public class Constants {
public static final String DAY_CODE = "day_code";
public static final String EVENT = "event";
public static final int MONTHLY_VIEW = 1;
public static final int YEARLY_VIEW = 2;
public static final int DAY = 86400;
public static final int WEEK = 604800;
public static final int BIWEEK = 1209600;
@ -19,6 +22,7 @@ public class Constants {
public static final String IS_DARK_THEME = "is_dark_theme";
public static final String SUNDAY_FIRST = "sunday_first";
public static final String WEEK_NUMBERS = "week_numbers";
public static final String VIEW = "view";
public static final String WIDGET_BG_COLOR = "widget_bg_color";
public static final String WIDGET_TEXT_COLOR = "widget_text_color";
public static final String LAST_OTHER_REMINDER_MINS = "last_other_reminder_mins";

View file

@ -19,9 +19,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val today = DateTime().toString(Formatter.DAYCODE_PATTERN)
fillViewPager(today)
updateViewPager()
calendar_fab.setOnClickListener { addNewEvent() }
}
@ -38,12 +36,21 @@ class MainActivity : SimpleActivity(), NavigationListener {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu, menu)
menu.findItem(R.id.yearly_view).isVisible = mConfig.view == Constants.MONTHLY_VIEW
menu.findItem(R.id.monthly_view).isVisible = mConfig.view == Constants.YEARLY_VIEW
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.monthly_view -> {
updateView(Constants.MONTHLY_VIEW)
return true
}
R.id.yearly_view -> {
updateView(Constants.YEARLY_VIEW)
return true
}
R.id.settings -> {
@ -58,6 +65,21 @@ class MainActivity : SimpleActivity(), NavigationListener {
}
}
private fun updateView(view: Int) {
mConfig.view = view
updateViewPager()
invalidateOptionsMenu()
}
private fun updateViewPager() {
if (mConfig.view == Constants.MONTHLY_VIEW) {
val today = DateTime().toString(Formatter.DAYCODE_PATTERN)
fillMonthlyViewPager(today)
} else {
}
}
private fun addNewEvent() {
val intent = Intent(applicationContext, EventActivity::class.java)
val tomorrowCode = Formatter.getDayCodeFromDateTime(DateTime(DateTimeZone.getDefault()).plusDays(1))
@ -65,7 +87,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
startActivity(intent)
}
private fun fillViewPager(targetMonth: String) {
private fun fillMonthlyViewPager(targetMonth: String) {
val codes = getMonths(targetMonth)
val adapter = MyMonthPagerAdapter(supportFragmentManager, codes, this)
view_pager.adapter = adapter
@ -91,6 +113,6 @@ class MainActivity : SimpleActivity(), NavigationListener {
}
override fun goToDateTime(dateTime: DateTime) {
fillViewPager(Formatter.getDayCodeFromDateTime(dateTime))
fillMonthlyViewPager(Formatter.getDayCodeFromDateTime(dateTime))
}
}

View file

@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/monthly_view"
android:title="@string/monthly_view"
app:showAsAction="never"/>
<item
android:id="@+id/yearly_view"
android:title="@string/yearly_view"