implement creating a new event at double clicking a grid at weekly view

This commit is contained in:
tibbi 2017-01-22 12:48:55 +01:00
parent 2f9237c335
commit d9f6228a96
6 changed files with 15 additions and 12 deletions

View File

@ -8,9 +8,11 @@ import android.support.v4.view.ViewPager
import android.view.View
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.adapters.MyDayPagerAdapter
import com.simplemobiletools.calendar.extensions.getNewEventTimestampFromCode
import com.simplemobiletools.calendar.fragments.DayFragment
import com.simplemobiletools.calendar.helpers.DAY_CODE
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.helpers.NEW_EVENT_START_TS
import com.simplemobiletools.commons.extensions.updateTextColors
import kotlinx.android.synthetic.main.activity_day.*
import org.joda.time.DateTime
@ -56,7 +58,7 @@ class DayActivity : SimpleActivity(), DayFragment.DeleteListener, ViewPager.OnPa
private fun addNewEvent() {
Intent(applicationContext, EventActivity::class.java).apply {
putExtra(DAY_CODE, mPagerDays?.get(view_pager.currentItem))
putExtra(NEW_EVENT_START_TS, getNewEventTimestampFromCode(mPagerDays?.get(view_pager.currentItem).toString()))
startActivity(this)
}
}

View File

@ -19,7 +19,6 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.activity_event.*
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
private var mWasReminderInit = false
@ -47,12 +46,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
setupReminder()
} else {
mEvent = Event()
val dayCode = intent.getStringExtra(DAY_CODE)
val startTS = intent.getIntExtra(NEW_EVENT_START_TS, 0)
if (dayCode == null || dayCode.isEmpty())
if (startTS == 0)
return
setupNewEvent(dayCode)
setupNewEvent(Formatter.getDateTimeFromTS(startTS))
setupDefaultReminderType()
}
@ -94,10 +92,10 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
event_description.setText(mEvent.description)
}
private fun setupNewEvent(dayCode: String) {
private fun setupNewEvent(dateTime: DateTime) {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
title = resources.getString(R.string.new_event)
mEventStartDateTime = Formatter.getDateTimeFromCode(dayCode).withZoneRetainFields(DateTimeZone.getDefault()).withHourOfDay(13)
mEventStartDateTime = dateTime
mEventEndDateTime = mEventStartDateTime
setupDefaultReminderType()
}

View File

@ -15,10 +15,7 @@ import com.simplemobiletools.calendar.adapters.MyMonthPagerAdapter
import com.simplemobiletools.calendar.adapters.MyWeekPagerAdapter
import com.simplemobiletools.calendar.adapters.MyYearPagerAdapter
import com.simplemobiletools.calendar.dialogs.ChangeViewDialog
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.extensions.secondsInWeek
import com.simplemobiletools.calendar.extensions.updateWidgets
import com.simplemobiletools.calendar.extensions.*
import com.simplemobiletools.calendar.fragments.EventListFragment
import com.simplemobiletools.calendar.fragments.WeekFragment
import com.simplemobiletools.calendar.helpers.*
@ -141,7 +138,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
private fun addNewEvent() {
val tomorrowCode = Formatter.getDayCodeFromDateTime(DateTime(DateTimeZone.getDefault()).plusDays(1))
Intent(applicationContext, EventActivity::class.java).apply {
putExtra(DAY_CODE, tomorrowCode)
putExtra(NEW_EVENT_START_TS, getNewEventTimestampFromCode(tomorrowCode))
startActivity(this)
}
}

View File

@ -25,6 +25,7 @@ class WeekEventsAdapter(val context: Context, val startTS: Int, val callback: (t
}
view.setOnClickListener {
selectedGrid?.setImageDrawable(null)
selectedGrid?.background = ColorDrawable(defaultBackground)
if (selectedGrid == view) {
selectedGrid = null

View File

@ -98,6 +98,8 @@ fun Context.getAppropriateTheme(): Int {
return if (config.backgroundColor.getContrastColor() == Color.WHITE) R.style.MyDialogTheme_Dark else R.style.MyDialogTheme
}
fun Context.getNewEventTimestampFromCode(dayCode: String) = Formatter.getLocalDateTimeFromCode(dayCode).withTime(13, 0, 0, 0).seconds()
val Context.config: Config get() = Config.newInstance(this)
val Context.secondsInWeek: Int get() = 7 * 24 * 60 * 60

View File

@ -74,6 +74,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
mView.week_events_scrollview.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
if (context == null)
return
mView.week_events_scrollview.viewTreeObserver.removeOnGlobalLayoutListener(this)
minScrollY = mRowHeight * context.config.startWeeklyAt
maxScrollY = mRowHeight * context.config.endWeeklyAt