create a new event on Plus click
This commit is contained in:
parent
8f14755215
commit
fab1bc254d
|
@ -1,48 +0,0 @@
|
|||
package com.simplemobiletools.calendar.adapters
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.BaseAdapter
|
||||
import android.widget.ImageView
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
|
||||
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
|
||||
private var selectedGrid: ImageView? = null
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
|
||||
var view = convertView
|
||||
|
||||
if (view == null) {
|
||||
view = mInflater.inflate(R.layout.week_grid_item, parent, false) as ImageView
|
||||
view.background = ColorDrawable(defaultBackground)
|
||||
}
|
||||
|
||||
view.setOnClickListener {
|
||||
selectedGrid?.setImageDrawable(null)
|
||||
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)
|
||||
selectedGrid = view as ImageView
|
||||
}
|
||||
}
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
override fun getItem(position: Int) = null
|
||||
|
||||
override fun getItemId(position: Int) = 0L
|
||||
|
||||
override fun getCount() = 24 * 7
|
||||
}
|
|
@ -151,4 +151,6 @@ fun Context.getNewEventTimestampFromCode(dayCode: String) = Formatter.getLocalDa
|
|||
|
||||
val Context.config: Config get() = Config.newInstance(this)
|
||||
|
||||
val Context.secondsInWeek: Int get() = 7 * 24 * 60 * 60
|
||||
val Context.secondsInDay: Int get() = 24 * 60 * 60
|
||||
|
||||
val Context.secondsInWeek: Int get() = 7 * secondsInDay
|
||||
|
|
|
@ -7,7 +7,6 @@ import android.graphics.drawable.ColorDrawable
|
|||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import android.view.*
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
|
@ -16,11 +15,9 @@ import com.simplemobiletools.calendar.activities.EventActivity
|
|||
import com.simplemobiletools.calendar.activities.MainActivity
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.extensions.seconds
|
||||
import com.simplemobiletools.calendar.extensions.secondsInDay
|
||||
import com.simplemobiletools.calendar.extensions.secondsInWeek
|
||||
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
|
||||
|
@ -44,8 +41,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
private var wasFragmentInit = false
|
||||
private var wasExtraHeightAdded = false
|
||||
private var clickStartTime = 0L
|
||||
lateinit var inflater: LayoutInflater
|
||||
private var selectedGrid: View? = null
|
||||
|
||||
lateinit var inflater: LayoutInflater
|
||||
lateinit var mView: View
|
||||
lateinit var mCalendar: WeeklyCalendarImpl
|
||||
lateinit var mRes: Resources
|
||||
|
@ -160,28 +158,38 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
|||
|
||||
private fun initGrid() {
|
||||
(0..6).map { getColumnWithId(it) }
|
||||
.forEach {
|
||||
activity.runOnUiThread { it.removeAllViews() }
|
||||
it.setOnTouchListener { view, motionEvent ->
|
||||
checkGridClick(motionEvent, it)
|
||||
.forEachIndexed { index, layout ->
|
||||
activity.runOnUiThread { layout.removeAllViews() }
|
||||
layout.setOnTouchListener { view, motionEvent ->
|
||||
checkGridClick(motionEvent, index, layout)
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkGridClick(event: MotionEvent, view: ViewGroup) {
|
||||
private fun checkGridClick(event: MotionEvent, index: Int, view: ViewGroup) {
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> clickStartTime = System.currentTimeMillis()
|
||||
MotionEvent.ACTION_UP -> {
|
||||
if (System.currentTimeMillis() - clickStartTime < CLICK_DURATION_THRESHOLD) {
|
||||
selectedGrid?.visibility = View.GONE
|
||||
|
||||
val rowHeight = resources.getDimension(R.dimen.weekly_view_row_height)
|
||||
val hour = (event.y / rowHeight).toInt()
|
||||
(inflater.inflate(R.layout.week_grid_item, null, false) as ImageView).apply {
|
||||
selectedGrid = (inflater.inflate(R.layout.week_grid_item, null, false) as View).apply {
|
||||
view.addView(this)
|
||||
background = ColorDrawable(primaryColor)
|
||||
layoutParams.width = view.width
|
||||
layoutParams.height = rowHeight.toInt()
|
||||
y = hour * rowHeight
|
||||
|
||||
setOnClickListener {
|
||||
val timestamp = mWeekTimestamp + index * context.secondsInDay + hour * 60 * 60
|
||||
Intent(context, EventActivity::class.java).apply {
|
||||
putExtra(NEW_EVENT_START_TS, timestamp)
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
<dimen name="yearly_padding_full">6dp</dimen>
|
||||
|
||||
<dimen name="weekly_view_row_height">60dp</dimen>
|
||||
<dimen name="weekly_view_row_minus_one_height">59dp</dimen>
|
||||
<dimen name="weekly_view_events_height">1440dp</dimen> <!-- weekly_view_row_height * 24 hours -->
|
||||
<dimen name="weekly_view_minimal_event_height">10dp</dimen>
|
||||
|
||||
|
|
Loading…
Reference in New Issue