From 2f9237c3353c64bf617bb0162644783b0547d43e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Jan 2017 11:42:26 +0100 Subject: [PATCH] pass the new event start timestamp to event activity --- .../calendar/activities/EventActivity.kt | 1 + .../calendar/adapters/WeekEventsAdapter.kt | 3 ++- .../calendar/fragments/WeekFragment.kt | 14 ++++++++------ .../calendar/helpers/Constants.kt | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index 42f0b0491..dae9c0379 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -48,6 +48,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { } else { mEvent = Event() val dayCode = intent.getStringExtra(DAY_CODE) + val startTS = intent.getIntExtra(NEW_EVENT_START_TS, 0) if (dayCode == null || dayCode.isEmpty()) return diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/WeekEventsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/WeekEventsAdapter.kt index d0b227476..53a94e71b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/WeekEventsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/WeekEventsAdapter.kt @@ -10,7 +10,7 @@ import android.widget.ImageView import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.extensions.config -class WeekEventsAdapter(val context: Context) : BaseAdapter() { +class WeekEventsAdapter(val context: Context, val startTS: Int, val callback: (timestamp: Int) -> Unit) : BaseAdapter() { private val mInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater private val defaultBackground = context.config.backgroundColor private val coloredBackground = context.config.primaryColor @@ -28,6 +28,7 @@ class WeekEventsAdapter(val context: Context) : BaseAdapter() { selectedGrid?.background = ColorDrawable(defaultBackground) if (selectedGrid == view) { selectedGrid = null + callback.invoke(startTS + (position / 7 * 60 * 60) + (position % 7 * 24 * 60 * 60)) } else { view!!.background = ColorDrawable(coloredBackground) (view as ImageView).setImageResource(R.drawable.ic_plus) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt index b89ce65ab..6cd3a0e00 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt @@ -17,10 +17,7 @@ import com.simplemobiletools.calendar.activities.EventActivity import com.simplemobiletools.calendar.activities.MainActivity import com.simplemobiletools.calendar.adapters.WeekEventsAdapter import com.simplemobiletools.calendar.extensions.config -import com.simplemobiletools.calendar.helpers.EVENT_ID -import com.simplemobiletools.calendar.helpers.Formatter -import com.simplemobiletools.calendar.helpers.WEEK_START_TIMESTAMP -import com.simplemobiletools.calendar.helpers.WeeklyCalendarImpl +import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.calendar.interfaces.WeeklyCalendar import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.calendar.views.MyScrollView @@ -41,6 +38,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { mRowHeight = (context.resources.getDimension(R.dimen.weekly_view_row_height)).toInt() minScrollY = mRowHeight * context.config.startWeeklyAt + mWeekTimestamp = arguments.getInt(WEEK_START_TIMESTAMP) mView = inflater.inflate(R.layout.fragment_week, container, false).apply { week_events_scrollview.setOnScrollviewListener(object : MyScrollView.ScrollViewListener { @@ -56,11 +54,15 @@ class WeekFragment : Fragment(), WeeklyCalendar { } }) - week_events_grid.adapter = WeekEventsAdapter(context) + week_events_grid.adapter = WeekEventsAdapter(context, mWeekTimestamp) { + Intent(context, EventActivity::class.java).apply { + putExtra(NEW_EVENT_START_TS, it) + startActivity(this) + } + } } mRes = resources - mWeekTimestamp = arguments.getInt(WEEK_START_TIMESTAMP) mCalendar = WeeklyCalendarImpl(this, context) setupDayLabels() return mView diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt index d800f5af9..2cdef502a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -8,6 +8,7 @@ val MEDIUM_ALPHA = .6f val DAY_CODE = "day_code" val YEAR_LABEL = "year" val EVENT_ID = "event_id" +val NEW_EVENT_START_TS = "new_event_start_ts" val WEEK_START_TIMESTAMP = "week_start_timestamp" val MONTHLY_VIEW = 1