properly open day/month view from monthly widget

This commit is contained in:
tibbi 2018-01-22 16:44:06 +01:00
parent 558478c0d9
commit ccc738203b
8 changed files with 24 additions and 8 deletions

View File

@ -246,8 +246,12 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private fun checkOpenIntents() {
val dayCodeToOpen = intent.getStringExtra(DAY_CODE) ?: ""
val openMonth = intent.getBooleanExtra(OPEN_MONTH, false)
if (dayCodeToOpen.isNotEmpty()) {
openDayCode(dayCodeToOpen)
calendar_fab.beGone()
config.storedView = if (openMonth) MONTHLY_VIEW else DAILY_VIEW
updateViewPager(dayCodeToOpen)
return
}
val eventIdToOpen = intent.getIntExtra(EVENT_ID, 0)
@ -488,7 +492,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
}
private fun updateViewPager() {
private fun updateViewPager(dayCode: String? = Formatter.getTodayCode(applicationContext)) {
val fragment = getFragmentsHolder()
currentFragments.forEach {
supportFragmentManager.beginTransaction().remove(it).commit()
@ -498,7 +502,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
val bundle = Bundle()
when (config.storedView) {
DAILY_VIEW, MONTHLY_VIEW -> bundle.putString(DAY_CODE, Formatter.getTodayCode(applicationContext))
DAILY_VIEW, MONTHLY_VIEW -> bundle.putString(DAY_CODE, dayCode)
WEEKLY_VIEW -> bundle.putString(WEEK_START_DATE_TIME, getThisWeekDateTime())
}

View File

@ -4,6 +4,7 @@ import android.content.Intent
import com.simplemobiletools.calendar.helpers.DAY_CODE
import com.simplemobiletools.calendar.helpers.EVENT_ID
import com.simplemobiletools.calendar.helpers.EVENT_OCCURRENCE_TS
import com.simplemobiletools.calendar.helpers.OPEN_MONTH
import com.simplemobiletools.commons.activities.BaseSplashActivity
class SplashActivity : BaseSplashActivity() {
@ -11,6 +12,7 @@ class SplashActivity : BaseSplashActivity() {
when {
intent.extras?.containsKey(DAY_CODE) == true -> Intent(this, MainActivity::class.java).apply {
putExtra(DAY_CODE, intent.getStringExtra(DAY_CODE))
putExtra(OPEN_MONTH, intent.getBooleanExtra(OPEN_MONTH, false))
startActivity(this)
}
intent.extras?.containsKey(EVENT_ID) == true -> Intent(this, MainActivity::class.java).apply {

View File

@ -66,6 +66,7 @@ class DayFragmentsHolder : MyFragmentHolder(), NavigationListener {
})
currentItem = defaultDaylyPage
}
updateActionBarTitle()
}
private fun getDays(code: String): List<String> {

View File

@ -34,6 +34,7 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
val placeholderText = String.format(getString(R.string.two_string_placeholder), "${getString(R.string.no_upcoming_events)}\n", getString(R.string.add_some_events))
mView.calendar_empty_list_placeholder.text = placeholderText
use24HourFormat = context!!.config.use24hourFormat
updateActionBarTitle()
return mView
}

View File

@ -66,6 +66,7 @@ class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener {
})
currentItem = defaultMonthlyPage
}
updateActionBarTitle()
}
private fun getMonths(code: String): List<String> {

View File

@ -90,6 +90,7 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
}
})
weekHolder!!.week_view_hours_scrollview.setOnTouchListener { view, motionEvent -> true }
updateActionBarTitle()
}
private fun getWeekTimestamps(targetSeconds: Int): List<Int> {

View File

@ -15,6 +15,7 @@ val WEEK_START_TIMESTAMP = "week_start_timestamp"
val NEW_EVENT_SET_HOUR_DURATION = "new_event_set_hour_duration"
val WEEK_START_DATE_TIME = "week_start_date_time"
val CALDAV = "Caldav"
val OPEN_MONTH = "open_month"
val MONTHLY_VIEW = 1
val YEARLY_VIEW = 2

View File

@ -45,10 +45,13 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
}
}
private fun setupAppOpenIntent(context: Context, views: RemoteViews, id: Int) {
val intent = Intent(context, SplashActivity::class.java)
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
views.setOnClickPendingIntent(id, pendingIntent)
private fun setupAppOpenIntent(context: Context, views: RemoteViews, id: Int, dayCode: String) {
Intent(context, SplashActivity::class.java).apply {
putExtra(DAY_CODE, dayCode)
putExtra(OPEN_MONTH, true)
val pendingIntent = PendingIntent.getActivity(context, Integer.parseInt(dayCode.substring(0, 6)), this, 0)
views.setOnClickPendingIntent(id, pendingIntent)
}
}
private fun setupDayOpenIntent(context: Context, views: RemoteViews, id: Int, dayCode: String) {
@ -175,7 +178,9 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
setupIntent(context, views, PREV, R.id.top_left_arrow)
setupIntent(context, views, NEXT, R.id.top_right_arrow)
setupIntent(context, views, NEW_EVENT, R.id.top_new_event)
setupAppOpenIntent(context, views, R.id.top_value)
val monthCode = days.firstOrNull { it.code.substring(6) == "01" }?.code ?: Formatter.getTodayCode(context)
setupAppOpenIntent(context, views, R.id.top_value, monthCode)
appWidgetManager.updateAppWidget(it, views)
}