pass the new event start timestamp to event activity

This commit is contained in:
tibbi 2017-01-22 11:42:26 +01:00
parent 6ad9819ef3
commit 2f9237c335
4 changed files with 12 additions and 7 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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