remove logs and cleanup code
This commit is contained in:
parent
f342f41fbe
commit
737ecc8176
|
@ -9,7 +9,6 @@ import android.graphics.drawable.ColorDrawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.util.Log
|
|
||||||
import android.util.Range
|
import android.util.Range
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
@ -273,36 +272,22 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
|
|
||||||
layout.setOnDragListener { view, dragEvent ->
|
layout.setOnDragListener { view, dragEvent ->
|
||||||
when (dragEvent.action) {
|
when (dragEvent.action) {
|
||||||
DragEvent.ACTION_DRAG_STARTED -> {
|
DragEvent.ACTION_DRAG_STARTED -> dragEvent.clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)
|
||||||
dragEvent.clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)
|
DragEvent.ACTION_DRAG_ENTERED,
|
||||||
}
|
DragEvent.ACTION_DRAG_EXITED,
|
||||||
|
DragEvent.ACTION_DRAG_LOCATION,
|
||||||
DragEvent.ACTION_DRAG_ENTERED -> {
|
DragEvent.ACTION_DRAG_EXITED,
|
||||||
Log.w(TAG, "initGrid: ACTION_DRAG_ENTERED")
|
DragEvent.ACTION_DRAG_ENDED -> true
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
DragEvent.ACTION_DRAG_EXITED -> {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
DragEvent.ACTION_DRAG_LOCATION -> {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
DragEvent.ACTION_DROP -> {
|
DragEvent.ACTION_DROP -> {
|
||||||
try {
|
try {
|
||||||
val eventId = dragEvent.clipData.getItemAt(0).text.toString().toLong()
|
val eventId = dragEvent.clipData.getItemAt(0).text.toString().toLong()
|
||||||
val startHour = (dragEvent.y / rowHeight).toInt()
|
val startHour = (dragEvent.y / rowHeight).toInt()
|
||||||
val endHour = startHour + 1
|
val endHour = startHour + 1
|
||||||
|
|
||||||
Log.d(TAG, "Dropped event: startHour=$startHour, endHour=$endHour")
|
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val event = context?.eventsDB?.getEventWithId(eventId)
|
val event = context?.eventsDB?.getEventWithId(eventId)
|
||||||
event?.let {
|
event?.let {
|
||||||
val startTime = Formatter.getDateTimeFromTS(it.startTS)
|
val startTime = Formatter.getDateTimeFromTS(it.startTS)
|
||||||
val endTime = Formatter.getDateTimeFromTS(it.endTS)
|
val endTime = Formatter.getDateTimeFromTS(it.endTS)
|
||||||
Log.w(TAG, "initGrid: found event: $it")
|
|
||||||
context?.eventsHelper?.updateEvent(
|
context?.eventsHelper?.updateEvent(
|
||||||
it.copy(
|
it.copy(
|
||||||
startTS = Formatter.getDateTimeFromTS(weekTimestamp + index * DAY_SECONDS)
|
startTS = Formatter.getDateTimeFromTS(weekTimestamp + index * DAY_SECONDS)
|
||||||
|
@ -310,11 +295,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
endTS = Formatter.getDateTimeFromTS(weekTimestamp + index * DAY_SECONDS)
|
endTS = Formatter.getDateTimeFromTS(weekTimestamp + index * DAY_SECONDS)
|
||||||
.withTime(endHour, endTime.minuteOfHour, endTime.secondOfMinute, endTime.millisOfSecond).seconds(),
|
.withTime(endHour, endTime.minuteOfHour, endTime.secondOfMinute, endTime.millisOfSecond).seconds(),
|
||||||
flags = it.flags.removeBit(FLAG_ALL_DAY)
|
flags = it.flags.removeBit(FLAG_ALL_DAY)
|
||||||
), true, false
|
), updateAtCalDAV = true, showToasts = false
|
||||||
) {
|
) {
|
||||||
|
|
||||||
updateCalendar()
|
updateCalendar()
|
||||||
Log.w(TAG, "Updated event ${it.id}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -324,14 +307,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
DragEvent.ACTION_DRAG_ENDED -> {
|
else -> false
|
||||||
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -344,7 +320,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
selectedGrid?.beGone()
|
selectedGrid?.beGone()
|
||||||
|
|
||||||
val hour = (event.y / rowHeight).toInt()
|
val hour = (event.y / rowHeight).toInt()
|
||||||
|
|
||||||
selectedGrid = (inflater.inflate(R.layout.week_grid_item, null, false) as ImageView).apply {
|
selectedGrid = (inflater.inflate(R.layout.week_grid_item, null, false) as ImageView).apply {
|
||||||
view.addView(this)
|
view.addView(this)
|
||||||
background = ColorDrawable(primaryColor)
|
background = ColorDrawable(primaryColor)
|
||||||
|
@ -618,50 +593,27 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
allDayHolders.add(allDaysLine)
|
allDayHolders.add(allDaysLine)
|
||||||
allDaysLine.setOnDragListener { view, dragEvent ->
|
allDaysLine.setOnDragListener { view, dragEvent ->
|
||||||
when (dragEvent.action) {
|
when (dragEvent.action) {
|
||||||
DragEvent.ACTION_DRAG_STARTED -> {
|
DragEvent.ACTION_DRAG_STARTED -> dragEvent.clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)
|
||||||
dragEvent.clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)
|
DragEvent.ACTION_DRAG_ENTERED,
|
||||||
}
|
DragEvent.ACTION_DRAG_EXITED,
|
||||||
|
DragEvent.ACTION_DRAG_LOCATION,
|
||||||
DragEvent.ACTION_DRAG_ENTERED -> {
|
DragEvent.ACTION_DRAG_ENDED -> true
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DragEvent.ACTION_DRAG_EXITED -> {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DragEvent.ACTION_DRAG_LOCATION -> {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
DragEvent.ACTION_DROP -> {
|
DragEvent.ACTION_DROP -> {
|
||||||
try {
|
try {
|
||||||
val eventId = dragEvent.clipData.getItemAt(0).text.toString().toLong()
|
val eventId = dragEvent.clipData.getItemAt(0).text.toString().toLong()
|
||||||
val xPos = dragEvent.x
|
val xPos = dragEvent.x
|
||||||
val width = view.width
|
val width = view.width
|
||||||
val dayCode = getDayCodeForAllDay(width, xPos.toInt())
|
val dayCode = getDayCodeForAllDay(width, xPos.toInt())
|
||||||
Log.d(TAG, "addNewLine: dayCode=$dayCode")
|
|
||||||
val startStamp = Formatter.getDayStartTS(dayCode)
|
val startStamp = Formatter.getDayStartTS(dayCode)
|
||||||
Log.d(TAG, "addNewLine: startStamp=$startStamp")
|
|
||||||
val endStamp = Formatter.getDayEndTS(dayCode)
|
|
||||||
Log.d(TAG, "addNewLine: endStamp=$endStamp")
|
|
||||||
|
|
||||||
|
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val event = context?.eventsDB?.getEventWithId(eventId)
|
val event = context?.eventsDB?.getEventWithId(eventId)
|
||||||
event?.let {
|
event?.let {
|
||||||
Log.w(TAG, "addNewLine: found event: $it")
|
|
||||||
context?.eventsHelper?.updateEvent(
|
context?.eventsHelper?.updateEvent(
|
||||||
it.copy(
|
it.copy(startTS = startStamp, endTS = startStamp, flags = it.flags.addBit(FLAG_ALL_DAY)),
|
||||||
startTS = startStamp,
|
updateAtCalDAV = true,
|
||||||
endTS = startStamp,
|
showToasts = false
|
||||||
flags = it.flags.addBit(FLAG_ALL_DAY)
|
|
||||||
), true, false
|
|
||||||
) {
|
) {
|
||||||
updateCalendar()
|
updateCalendar()
|
||||||
Log.w(TAG, "Updated event ${it.id}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -670,29 +622,20 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DragEvent.ACTION_DRAG_ENDED -> {
|
else -> false
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDayCodeForAllDay(width: Int, xPos: Int): String {
|
private fun getDayCodeForAllDay(width: Int, xPos: Int): String {
|
||||||
Log.d(TAG, "getDayCodeForAllDay: width=$width, xPos=$xPos")
|
|
||||||
var index = 0
|
var index = 0
|
||||||
val widthPerDay = (width.toDouble() / config.weeklyViewDays.toDouble()).toInt()
|
val widthPerDay = (width.toDouble() / config.weeklyViewDays.toDouble()).toInt()
|
||||||
Log.d(TAG, "getDayCodeForAllDay: widthPerDay=$widthPerDay")
|
|
||||||
for ((valueIndex, value) in (widthPerDay until width step widthPerDay).withIndex()) {
|
for ((valueIndex, value) in (widthPerDay until width step widthPerDay).withIndex()) {
|
||||||
if (xPos < value) {
|
if (xPos < value) {
|
||||||
index = valueIndex
|
index = valueIndex
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d(TAG, "getDayCodeForAllDay: $index")
|
|
||||||
return dayColumns[index].tag.toString()
|
return dayColumns[index].tag.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,19 +704,8 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
val startDateTime = Formatter.getDateTimeFromTS(event.startTS)
|
val startDateTime = Formatter.getDateTimeFromTS(event.startTS)
|
||||||
val endDateTime = Formatter.getDateTimeFromTS(event.endTS)
|
val endDateTime = Formatter.getDateTimeFromTS(event.endTS)
|
||||||
|
|
||||||
val startDateTimeSeconds = startDateTime.seconds()
|
val minTS = Math.max(startDateTime.seconds(), weekTimestamp)
|
||||||
val endDateTimeSeconds = endDateTime.seconds()
|
val maxTS = Math.min(endDateTime.seconds(), weekTimestamp + 2 * WEEK_SECONDS)
|
||||||
val weekTimestampStart = weekTimestamp
|
|
||||||
val weekTimestampEnd = weekTimestamp + 2 * WEEK_SECONDS
|
|
||||||
val minTS = Math.max(startDateTimeSeconds, weekTimestampStart)
|
|
||||||
val maxTS = Math.min(endDateTimeSeconds, weekTimestampEnd)
|
|
||||||
|
|
||||||
Log.d(TAG, "startDateTimeSeconds: $startDateTimeSeconds")
|
|
||||||
Log.d(TAG, "weekTimestampStart: $weekTimestampStart")
|
|
||||||
Log.d(TAG, "minTS: $minTS")
|
|
||||||
Log.d(TAG, "endDateTimeSeconds: $endDateTimeSeconds")
|
|
||||||
Log.d(TAG, "weekTimestampEnd: $weekTimestampEnd")
|
|
||||||
Log.d(TAG, "maxTS: $maxTS")
|
|
||||||
|
|
||||||
// fix a visual glitch with all-day events or events lasting multiple days starting at midnight on monday, being shown the previous week too
|
// fix a visual glitch with all-day events or events lasting multiple days starting at midnight on monday, being shown the previous week too
|
||||||
if (minTS == maxTS && (minTS - weekTimestamp == WEEK_SECONDS.toLong())) {
|
if (minTS == maxTS && (minTS - weekTimestamp == WEEK_SECONDS.toLong())) {
|
||||||
|
@ -782,12 +714,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
|
|
||||||
val isStartTimeDay = Formatter.getDateTimeFromTS(maxTS) == Formatter.getDateTimeFromTS(maxTS).withTimeAtStartOfDay()
|
val isStartTimeDay = Formatter.getDateTimeFromTS(maxTS) == Formatter.getDateTimeFromTS(maxTS).withTimeAtStartOfDay()
|
||||||
val numDays = Days.daysBetween(Formatter.getDateTimeFromTS(minTS).toLocalDate(), Formatter.getDateTimeFromTS(maxTS).toLocalDate()).days
|
val numDays = Days.daysBetween(Formatter.getDateTimeFromTS(minTS).toLocalDate(), Formatter.getDateTimeFromTS(maxTS).toLocalDate()).days
|
||||||
Log.d(TAG, "numDays: $numDays")
|
|
||||||
val daysCnt = if (numDays == 1 && isStartTimeDay) 0 else numDays
|
val daysCnt = if (numDays == 1 && isStartTimeDay) 0 else numDays
|
||||||
Log.d(TAG, "daysCnt: $daysCnt")
|
|
||||||
val startDateTimeInWeek = Formatter.getDateTimeFromTS(minTS)
|
val startDateTimeInWeek = Formatter.getDateTimeFromTS(minTS)
|
||||||
val firstDayIndex = (startDateTimeInWeek.dayOfWeek - if (config.isSundayFirst) 0 else 1) % 7
|
val firstDayIndex = (startDateTimeInWeek.dayOfWeek - if (config.isSundayFirst) 0 else 1) % 7
|
||||||
Log.d(TAG, "firstDayIndex: $firstDayIndex")
|
|
||||||
|
|
||||||
var doesEventFit: Boolean
|
var doesEventFit: Boolean
|
||||||
val cnt = allDayRows.size - 1
|
val cnt = allDayRows.size - 1
|
||||||
|
@ -826,7 +755,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
val dayCodeStart = Formatter.getDayCodeFromDateTime(startDateTime).toInt()
|
val dayCodeStart = Formatter.getDayCodeFromDateTime(startDateTime).toInt()
|
||||||
val dayCodeEnd = Formatter.getDayCodeFromDateTime(endDateTime).toInt()
|
val dayCodeEnd = Formatter.getDayCodeFromDateTime(endDateTime).toInt()
|
||||||
val dayOfWeek = dayColumns.indexOfFirst { it.tag.toInt() == dayCodeStart || (it.tag.toInt() > dayCodeStart && it.tag.toInt() <= dayCodeEnd) }
|
val dayOfWeek = dayColumns.indexOfFirst { it.tag.toInt() == dayCodeStart || (it.tag.toInt() > dayCodeStart && it.tag.toInt() <= dayCodeEnd) }
|
||||||
Log.i(TAG, "dayOfWeek: $dayOfWeek")
|
|
||||||
if (dayOfWeek == -1) {
|
if (dayOfWeek == -1) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -860,7 +788,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
setOnDragListener(DragListener())
|
setOnDragListener(DragListener())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -907,10 +834,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
// handle ACTION_DRAG_LOCATION due to https://stackoverflow.com/a/19460338
|
// handle ACTION_DRAG_LOCATION due to https://stackoverflow.com/a/19460338
|
||||||
DragEvent.ACTION_DRAG_LOCATION -> {
|
DragEvent.ACTION_DRAG_LOCATION -> true
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
DragEvent.ACTION_DRAG_ENDED -> {
|
DragEvent.ACTION_DRAG_ENDED -> {
|
||||||
currentlyDraggedView = null
|
currentlyDraggedView = null
|
||||||
view.beVisible()
|
view.beVisible()
|
||||||
|
@ -920,8 +844,4 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "WeekFragment"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ import kotlinx.android.synthetic.main.fragment_week_holder.view.*
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
|
class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
|
||||||
private val PREFILLED_WEEKS = 1
|
private val PREFILLED_WEEKS = 151
|
||||||
private val MAX_SEEKBAR_VALUE = 14
|
private val MAX_SEEKBAR_VALUE = 14
|
||||||
|
|
||||||
private var viewPager: MyViewPager? = null
|
private var viewPager: MyViewPager? = null
|
||||||
|
|
Loading…
Reference in New Issue