switch to the day fragment at opening a day from month fragment

This commit is contained in:
tibbi 2018-01-22 15:53:42 +01:00
parent 1390acd4ec
commit 558478c0d9
2 changed files with 15 additions and 14 deletions

View File

@ -517,6 +517,15 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
calendar_fab.beVisible()
}
fun openDayFromMonthly(dateTime: DateTime) {
val fragment = DayFragmentsHolder()
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()
}
private fun getThisWeekDateTime(): String {
var thisweek = DateTime().withDayOfWeek(1).withTimeAtStartOfDay().minusDays(if (config.isSundayFirst) 1 else 0)
if (DateTime().minusDays(7).seconds() > thisweek.seconds()) {
@ -536,8 +545,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private fun removeTopFragment() {
supportFragmentManager.beginTransaction().remove(currentFragments.last()).commit()
currentFragments.removeAt(currentFragments.size - 1)
toggleGoToTodayVisibility(currentFragments.first().shouldGoToTodayBeVisible())
currentFragments.first().updateActionBarTitle()
toggleGoToTodayVisibility(currentFragments.last().shouldGoToTodayBeVisible())
currentFragments.last().updateActionBarTitle()
calendar_fab.beGoneIf(currentFragments.size == 1 && config.storedView == YEARLY_VIEW)
}

View File

@ -1,7 +1,6 @@
package com.simplemobiletools.calendar.fragments
import android.content.Context
import android.content.Intent
import android.content.res.Resources
import android.os.Bundle
import android.support.v4.app.Fragment
@ -14,7 +13,7 @@ import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.DayActivity
import com.simplemobiletools.calendar.activities.MainActivity
import com.simplemobiletools.calendar.extensions.addDayEvents
import com.simplemobiletools.calendar.extensions.addDayNumber
import com.simplemobiletools.calendar.extensions.config
@ -188,7 +187,9 @@ class MonthFragment : Fragment(), MonthlyCalendar {
for (i in 0 until len) {
mHolder.findViewById<LinearLayout>(mRes.getIdentifier("day_$i", "id", mPackageName)).apply {
val day = days[i]
setOnClickListener { openDay(day.code) }
setOnClickListener {
(activity as MainActivity).openDayFromMonthly(Formatter.getDateTimeFromCode(day.code))
}
removeAllViews()
context.addDayNumber(mTextColor, day, this, mDayLabelHeight) { mDayLabelHeight = it }
@ -196,13 +197,4 @@ class MonthFragment : Fragment(), MonthlyCalendar {
}
}
}
private fun openDay(code: String) {
if (code.isNotEmpty()) {
Intent(context, DayActivity::class.java).apply {
putExtra(DAY_CODE, code)
startActivity(this)
}
}
}
}