fix misc things around main activity fragments
This commit is contained in:
parent
80d403f2b1
commit
1741455f15
|
@ -48,16 +48,15 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
private val CALDAV_SYNC_DELAY = 1000L
|
||||
|
||||
private var showCalDAVRefreshToast = false
|
||||
private var mIsMonthSelected = false
|
||||
private var mShouldFilterBeVisible = false
|
||||
private var mIsSearchOpen = false
|
||||
private var mLatestSearchQuery = ""
|
||||
private var mCalDAVSyncHandler = Handler()
|
||||
private var mSearchMenuItem: MenuItem? = null
|
||||
private var currentFragment: MyFragmentHolder? = null
|
||||
private var shouldGoToTodayBeVisible = false
|
||||
private var eventTypeColors = SparseIntArray()
|
||||
private var goToTodayButton: MenuItem? = null
|
||||
private var eventTypeColors = SparseIntArray()
|
||||
private var currentFragments = ArrayList<MyFragmentHolder>()
|
||||
|
||||
private var mStoredTextColor = 0
|
||||
private var mStoredBackgroundColor = 0
|
||||
|
@ -105,6 +104,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
}
|
||||
|
||||
calendar_fab.setOnClickListener { launchNewEventIntent() }
|
||||
calendar_fab.beVisibleIf(config.storedView != YEARLY_VIEW)
|
||||
checkOpenIntents()
|
||||
}
|
||||
|
||||
|
@ -183,8 +183,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (mIsMonthSelected && config.storedView == YEARLY_VIEW) {
|
||||
updateView(YEARLY_VIEW)
|
||||
if (currentFragments.size > 1) {
|
||||
removeTopFragment()
|
||||
} else {
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
@ -270,7 +270,6 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
RadioItem(EVENTS_LIST_VIEW, res.getString(R.string.simple_event_list)))
|
||||
|
||||
RadioGroupDialog(this, items, config.storedView) {
|
||||
mIsMonthSelected = false
|
||||
calendar_fab.beVisibleIf(it as Int != YEARLY_VIEW)
|
||||
resetActionBarTitle()
|
||||
closeSearch()
|
||||
|
@ -281,7 +280,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
}
|
||||
|
||||
private fun goToToday() {
|
||||
currentFragment?.goToToday()
|
||||
currentFragments.last().goToToday()
|
||||
}
|
||||
|
||||
private fun resetActionBarTitle() {
|
||||
|
@ -297,7 +296,9 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
|
||||
fun toggleGoToTodayVisibility(beVisible: Boolean) {
|
||||
shouldGoToTodayBeVisible = beVisible
|
||||
invalidateOptionsMenu()
|
||||
if (goToTodayButton?.isVisible != beVisible) {
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshCalDAVCalendars(showRefreshToast: Boolean) {
|
||||
|
@ -478,7 +479,6 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
|
||||
private fun updateView(view: Int) {
|
||||
calendar_fab.beGoneIf(view == YEARLY_VIEW)
|
||||
mIsMonthSelected = view == MONTHLY_VIEW
|
||||
config.storedView = view
|
||||
updateViewPager()
|
||||
if (goToTodayButton?.isVisible == true) {
|
||||
|
@ -489,7 +489,11 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
|
||||
private fun updateViewPager() {
|
||||
val fragment = getFragmentsHolder()
|
||||
currentFragment = fragment
|
||||
currentFragments.forEach {
|
||||
supportFragmentManager.beginTransaction().remove(it).commit()
|
||||
}
|
||||
currentFragments.clear()
|
||||
currentFragments.add(fragment)
|
||||
val bundle = Bundle()
|
||||
|
||||
when (config.storedView) {
|
||||
|
@ -498,7 +502,18 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
}
|
||||
|
||||
fragment.arguments = bundle
|
||||
supportFragmentManager.beginTransaction().replace(R.id.fragments_holder, fragment, "").commit()
|
||||
supportFragmentManager.beginTransaction().add(R.id.fragments_holder, fragment).commit()
|
||||
}
|
||||
|
||||
fun openMonthFromYearly(dateTime: DateTime) {
|
||||
val fragment = MonthFragmentsHolder()
|
||||
currentFragments.add(fragment)
|
||||
val bundle = Bundle()
|
||||
bundle.putString(DAY_CODE, Formatter.getDayCodeFromDateTime(dateTime))
|
||||
fragment.arguments = bundle
|
||||
supportFragmentManager.beginTransaction().add(R.id.fragments_holder, fragment).commit()
|
||||
resetActionBarTitle()
|
||||
calendar_fab.beVisible()
|
||||
}
|
||||
|
||||
private fun getThisWeekDateTime(): String {
|
||||
|
@ -516,8 +531,16 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
else -> WeekFragmentsHolder()
|
||||
}
|
||||
|
||||
private fun removeTopFragment() {
|
||||
supportFragmentManager.beginTransaction().remove(currentFragments.last()).commit()
|
||||
currentFragments.removeAt(currentFragments.size - 1)
|
||||
toggleGoToTodayVisibility(currentFragments.first().shouldGoToTodayBeVisible())
|
||||
currentFragments.first().updateActionBarTitle()
|
||||
calendar_fab.beGoneIf(currentFragments.size == 1 && config.storedView == YEARLY_VIEW)
|
||||
}
|
||||
|
||||
private fun refreshViewPager() {
|
||||
currentFragment?.refreshEvents()
|
||||
currentFragments.last().refreshEvents()
|
||||
}
|
||||
|
||||
private fun tryImportEvents() {
|
||||
|
@ -637,17 +660,6 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
refreshViewPager()
|
||||
}
|
||||
|
||||
fun openMonthFromYearly(dateTime: DateTime) {
|
||||
mIsMonthSelected = true
|
||||
val fragment = MonthFragmentsHolder()
|
||||
currentFragment = fragment
|
||||
val bundle = Bundle()
|
||||
bundle.putString(DAY_CODE, Formatter.getDayCodeFromDateTime(dateTime))
|
||||
fragment.arguments = bundle
|
||||
supportFragmentManager.beginTransaction().replace(R.id.fragments_holder, fragment, "").commit()
|
||||
resetActionBarTitle()
|
||||
}
|
||||
|
||||
private fun openDayAt(timestamp: Long) {
|
||||
val dayCode = Formatter.getDayCodeFromTS((timestamp / 1000).toInt())
|
||||
openDayCode(dayCode)
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.activities.EventActivity
|
||||
import com.simplemobiletools.calendar.activities.MainActivity
|
||||
import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.adapters.EventListAdapter
|
||||
import com.simplemobiletools.calendar.extensions.*
|
||||
|
@ -104,4 +105,10 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||
override fun refreshEvents() {
|
||||
checkEvents()
|
||||
}
|
||||
|
||||
override fun shouldGoToTodayBeVisible() = false
|
||||
|
||||
override fun updateActionBarTitle() {
|
||||
(activity as MainActivity).supportActionBar?.title = getString(R.string.app_launcher_name)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.calendar.fragments
|
||||
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.support.v4.view.ViewPager
|
||||
import android.view.LayoutInflater
|
||||
|
@ -8,12 +9,13 @@ import android.view.ViewGroup
|
|||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.activities.MainActivity
|
||||
import com.simplemobiletools.calendar.adapters.MyMonthPagerAdapter
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.extensions.getMonthCode
|
||||
import com.simplemobiletools.calendar.helpers.DAY_CODE
|
||||
import com.simplemobiletools.calendar.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.interfaces.NavigationListener
|
||||
import com.simplemobiletools.commons.views.MyViewPager
|
||||
import kotlinx.android.synthetic.main.fragment_viewpager_holder.view.*
|
||||
import kotlinx.android.synthetic.main.fragment_months_holder.view.*
|
||||
import org.joda.time.DateTime
|
||||
|
||||
class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener {
|
||||
|
@ -32,14 +34,13 @@ class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener {
|
|||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val view = inflater.inflate(R.layout.fragment_viewpager_holder, container, false)
|
||||
viewPager = view.fragment_viewpager
|
||||
val view = inflater.inflate(R.layout.fragment_months_holder, container, false)
|
||||
view.background = ColorDrawable(context!!.config.backgroundColor)
|
||||
viewPager = view.fragment_months_viewpager
|
||||
setupFragment()
|
||||
return view
|
||||
}
|
||||
|
||||
private fun shouldGoToTodayBeVisible() = currentDayCode.getMonthCode() != todayDayCode.getMonthCode()
|
||||
|
||||
private fun setupFragment() {
|
||||
val codes = getMonths(currentDayCode)
|
||||
val monthlyAdapter = MyMonthPagerAdapter(activity!!.supportFragmentManager, codes, this)
|
||||
|
@ -98,4 +99,10 @@ class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener {
|
|||
override fun refreshEvents() {
|
||||
setupFragment()
|
||||
}
|
||||
|
||||
override fun shouldGoToTodayBeVisible() = currentDayCode.getMonthCode() != todayDayCode.getMonthCode()
|
||||
|
||||
override fun updateActionBarTitle() {
|
||||
(activity as MainActivity).supportActionBar?.title = getString(R.string.app_launcher_name)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,4 +6,8 @@ abstract class MyFragmentHolder : Fragment() {
|
|||
abstract fun goToToday()
|
||||
|
||||
abstract fun refreshEvents()
|
||||
|
||||
abstract fun shouldGoToTodayBeVisible(): Boolean
|
||||
|
||||
abstract fun updateActionBarTitle()
|
||||
}
|
||||
|
|
|
@ -43,8 +43,6 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
|
|||
return weekHolder
|
||||
}
|
||||
|
||||
private fun shouldGoToTodayBeVisible() = currentWeekTS != thisWeekTS
|
||||
|
||||
private fun setupFragment() {
|
||||
val weekTSs = getWeekTimestamps(currentWeekTS)
|
||||
val weeklyAdapter = MyWeekPagerAdapter(activity!!.supportFragmentManager, weekTSs, this)
|
||||
|
@ -128,6 +126,12 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
|
|||
setupFragment()
|
||||
}
|
||||
|
||||
override fun shouldGoToTodayBeVisible() = currentWeekTS != thisWeekTS
|
||||
|
||||
override fun updateActionBarTitle() {
|
||||
setupWeeklyActionbarTitle(currentWeekTS)
|
||||
}
|
||||
|
||||
override fun scrollTo(y: Int) {
|
||||
weekHolder!!.week_view_hours_scrollview.scrollY = y
|
||||
weekScrollY = y
|
||||
|
|
|
@ -10,7 +10,7 @@ import com.simplemobiletools.calendar.activities.MainActivity
|
|||
import com.simplemobiletools.calendar.adapters.MyYearPagerAdapter
|
||||
import com.simplemobiletools.calendar.helpers.Formatter
|
||||
import com.simplemobiletools.commons.views.MyViewPager
|
||||
import kotlinx.android.synthetic.main.fragment_viewpager_holder.view.*
|
||||
import kotlinx.android.synthetic.main.fragment_years_holder.view.*
|
||||
import org.joda.time.DateTime
|
||||
|
||||
class YearFragmentsHolder : MyFragmentHolder() {
|
||||
|
@ -29,14 +29,12 @@ class YearFragmentsHolder : MyFragmentHolder() {
|
|||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val view = inflater.inflate(R.layout.fragment_viewpager_holder, container, false)
|
||||
viewPager = view.fragment_viewpager
|
||||
val view = inflater.inflate(R.layout.fragment_years_holder, container, false)
|
||||
viewPager = view.fragment_years_viewpager
|
||||
setupFragment()
|
||||
return view
|
||||
}
|
||||
|
||||
private fun shouldGoToTodayBeVisible() = currentYear != todayYear
|
||||
|
||||
private fun setupFragment() {
|
||||
val years = getYears(currentYear)
|
||||
val yearlyAdapter = MyYearPagerAdapter(activity!!.supportFragmentManager, years)
|
||||
|
@ -66,8 +64,7 @@ class YearFragmentsHolder : MyFragmentHolder() {
|
|||
})
|
||||
currentItem = defaultYearlyPage
|
||||
}
|
||||
|
||||
(activity as? MainActivity)?.supportActionBar?.title = "${getString(R.string.app_launcher_name)} - ${years[years.size / 2]}"
|
||||
updateActionBarTitle()
|
||||
}
|
||||
|
||||
private fun getYears(targetYear: Int): List<Int> {
|
||||
|
@ -84,4 +81,10 @@ class YearFragmentsHolder : MyFragmentHolder() {
|
|||
override fun refreshEvents() {
|
||||
setupFragment()
|
||||
}
|
||||
|
||||
override fun shouldGoToTodayBeVisible() = currentYear != todayYear
|
||||
|
||||
override fun updateActionBarTitle() {
|
||||
(activity as? MainActivity)?.supportActionBar?.title = "${getString(R.string.app_launcher_name)} - $currentYear"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.simplemobiletools.commons.views.MyViewPager
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/fragment_months_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
|
@ -1,6 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.simplemobiletools.commons.views.MyViewPager
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/fragment_viewpager"
|
||||
android:id="@+id/fragment_years_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
Loading…
Reference in New Issue