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() { private fun checkOpenIntents() {
val dayCodeToOpen = intent.getStringExtra(DAY_CODE) ?: "" val dayCodeToOpen = intent.getStringExtra(DAY_CODE) ?: ""
val openMonth = intent.getBooleanExtra(OPEN_MONTH, false)
if (dayCodeToOpen.isNotEmpty()) { 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) 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() val fragment = getFragmentsHolder()
currentFragments.forEach { currentFragments.forEach {
supportFragmentManager.beginTransaction().remove(it).commit() supportFragmentManager.beginTransaction().remove(it).commit()
@@ -498,7 +502,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
val bundle = Bundle() val bundle = Bundle()
when (config.storedView) { 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()) 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.DAY_CODE
import com.simplemobiletools.calendar.helpers.EVENT_ID import com.simplemobiletools.calendar.helpers.EVENT_ID
import com.simplemobiletools.calendar.helpers.EVENT_OCCURRENCE_TS import com.simplemobiletools.calendar.helpers.EVENT_OCCURRENCE_TS
import com.simplemobiletools.calendar.helpers.OPEN_MONTH
import com.simplemobiletools.commons.activities.BaseSplashActivity import com.simplemobiletools.commons.activities.BaseSplashActivity
class SplashActivity : BaseSplashActivity() { class SplashActivity : BaseSplashActivity() {
@@ -11,6 +12,7 @@ class SplashActivity : BaseSplashActivity() {
when { when {
intent.extras?.containsKey(DAY_CODE) == true -> Intent(this, MainActivity::class.java).apply { intent.extras?.containsKey(DAY_CODE) == true -> Intent(this, MainActivity::class.java).apply {
putExtra(DAY_CODE, intent.getStringExtra(DAY_CODE)) putExtra(DAY_CODE, intent.getStringExtra(DAY_CODE))
putExtra(OPEN_MONTH, intent.getBooleanExtra(OPEN_MONTH, false))
startActivity(this) startActivity(this)
} }
intent.extras?.containsKey(EVENT_ID) == true -> Intent(this, MainActivity::class.java).apply { intent.extras?.containsKey(EVENT_ID) == true -> Intent(this, MainActivity::class.java).apply {

View File

@@ -66,6 +66,7 @@ class DayFragmentsHolder : MyFragmentHolder(), NavigationListener {
}) })
currentItem = defaultDaylyPage currentItem = defaultDaylyPage
} }
updateActionBarTitle()
} }
private fun getDays(code: String): List<String> { 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)) 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 mView.calendar_empty_list_placeholder.text = placeholderText
use24HourFormat = context!!.config.use24hourFormat use24HourFormat = context!!.config.use24hourFormat
updateActionBarTitle()
return mView return mView
} }

View File

@@ -66,6 +66,7 @@ class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener {
}) })
currentItem = defaultMonthlyPage currentItem = defaultMonthlyPage
} }
updateActionBarTitle()
} }
private fun getMonths(code: String): List<String> { 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 } weekHolder!!.week_view_hours_scrollview.setOnTouchListener { view, motionEvent -> true }
updateActionBarTitle()
} }
private fun getWeekTimestamps(targetSeconds: Int): List<Int> { 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 NEW_EVENT_SET_HOUR_DURATION = "new_event_set_hour_duration"
val WEEK_START_DATE_TIME = "week_start_date_time" val WEEK_START_DATE_TIME = "week_start_date_time"
val CALDAV = "Caldav" val CALDAV = "Caldav"
val OPEN_MONTH = "open_month"
val MONTHLY_VIEW = 1 val MONTHLY_VIEW = 1
val YEARLY_VIEW = 2 val YEARLY_VIEW = 2

View File

@@ -45,10 +45,13 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
} }
} }
private fun setupAppOpenIntent(context: Context, views: RemoteViews, id: Int) { private fun setupAppOpenIntent(context: Context, views: RemoteViews, id: Int, dayCode: String) {
val intent = Intent(context, SplashActivity::class.java) Intent(context, SplashActivity::class.java).apply {
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0) putExtra(DAY_CODE, dayCode)
views.setOnClickPendingIntent(id, pendingIntent) 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) { 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, PREV, R.id.top_left_arrow)
setupIntent(context, views, NEXT, R.id.top_right_arrow) setupIntent(context, views, NEXT, R.id.top_right_arrow)
setupIntent(context, views, NEW_EVENT, R.id.top_new_event) 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) appWidgetManager.updateAppWidget(it, views)
} }