toggle the visibility of viewpager as needed

This commit is contained in:
tibbi
2016-10-22 23:23:00 +02:00
parent 2f0cf1a024
commit f58a1beba6
2 changed files with 23 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import android.os.Bundle
import android.support.v4.view.ViewPager import android.support.v4.view.ViewPager
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View
import com.simplemobiletools.calendar.Constants import com.simplemobiletools.calendar.Constants
import com.simplemobiletools.calendar.Formatter import com.simplemobiletools.calendar.Formatter
import com.simplemobiletools.calendar.NavigationListener import com.simplemobiletools.calendar.NavigationListener
@@ -92,7 +93,7 @@ class MainActivity : SimpleActivity(), NavigationListener, ChangeViewDialog.Chan
if (mConfig.view == Constants.YEARLY_VIEW) { if (mConfig.view == Constants.YEARLY_VIEW) {
fillYearlyViewPager() fillYearlyViewPager()
} else if (mConfig.view == Constants.EVENTS_LIST_VIEW) { } else if (mConfig.view == Constants.EVENTS_LIST_VIEW) {
view_pager.adapter = null fillEventsList()
} else { } else {
val targetDay = DateTime().toString(Formatter.DAYCODE_PATTERN) val targetDay = DateTime().toString(Formatter.DAYCODE_PATTERN)
fillMonthlyViewPager(targetDay) fillMonthlyViewPager(targetDay)
@@ -113,6 +114,8 @@ class MainActivity : SimpleActivity(), NavigationListener, ChangeViewDialog.Chan
view_pager.adapter = adapter view_pager.adapter = adapter
view_pager.currentItem = codes.size / 2 view_pager.currentItem = codes.size / 2
title = getString(R.string.app_launcher_name) title = getString(R.string.app_launcher_name)
view_pager.visibility = View.VISIBLE
calendar_events_list.visibility = View.GONE
} }
private fun getMonths(code: String): List<String> { private fun getMonths(code: String): List<String> {
@@ -145,6 +148,8 @@ class MainActivity : SimpleActivity(), NavigationListener, ChangeViewDialog.Chan
title = "${getString(R.string.app_launcher_name)} - ${years[position]}" title = "${getString(R.string.app_launcher_name)} - ${years[position]}"
} }
}) })
view_pager.visibility = View.VISIBLE
calendar_events_list.visibility = View.GONE
} }
private fun getYears(targetYear: Int): List<Int> { private fun getYears(targetYear: Int): List<Int> {
@@ -155,6 +160,13 @@ class MainActivity : SimpleActivity(), NavigationListener, ChangeViewDialog.Chan
return years return years
} }
private fun fillEventsList() {
title = getString(R.string.app_launcher_name)
view_pager.adapter = null
view_pager.visibility = View.GONE
calendar_events_list.visibility = View.VISIBLE
}
override fun goLeft() { override fun goLeft() {
view_pager.currentItem = view_pager.currentItem - 1 view_pager.currentItem = view_pager.currentItem - 1
} }

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout <android.support.design.widget.CoordinatorLayout
android:id="@+id/calendar_coordinator"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/calendar_coordinator"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@@ -11,6 +11,15 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"/>
<ListView
android:id="@+id/calendar_events_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoiceModal"
android:clipToPadding="false"
android:paddingLeft="@dimen/activity_margin"
android:visibility="gone"/>
<android.support.design.widget.FloatingActionButton <android.support.design.widget.FloatingActionButton
android:id="@+id/calendar_fab" android:id="@+id/calendar_fab"
android:layout_width="wrap_content" android:layout_width="wrap_content"