2018-11-09 17:12:02 +01:00
|
|
|
package com.simplemobiletools.calendar.pro.fragments
|
2016-09-16 23:01:46 +02:00
|
|
|
|
2016-09-18 10:45:21 +02:00
|
|
|
import android.content.Intent
|
2016-09-16 23:01:46 +02:00
|
|
|
import android.os.Bundle
|
2020-10-25 20:40:47 +01:00
|
|
|
import android.os.Handler
|
2016-11-23 20:48:32 +01:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2018-10-16 13:03:29 +02:00
|
|
|
import androidx.fragment.app.Fragment
|
2019-03-06 20:18:18 +01:00
|
|
|
import com.simplemobiletools.calendar.pro.activities.MainActivity
|
2018-11-09 17:12:02 +01:00
|
|
|
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
|
|
|
import com.simplemobiletools.calendar.pro.adapters.DayEventsAdapter
|
2023-09-03 15:25:41 +02:00
|
|
|
import com.simplemobiletools.calendar.pro.databinding.FragmentDayBinding
|
|
|
|
import com.simplemobiletools.calendar.pro.databinding.TopNavigationBinding
|
2018-11-09 17:12:02 +01:00
|
|
|
import com.simplemobiletools.calendar.pro.extensions.config
|
2018-11-15 11:09:09 +01:00
|
|
|
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
2020-10-25 20:05:23 +01:00
|
|
|
import com.simplemobiletools.calendar.pro.extensions.getViewBitmap
|
|
|
|
import com.simplemobiletools.calendar.pro.extensions.printBitmap
|
2022-02-24 16:30:55 +01:00
|
|
|
import com.simplemobiletools.calendar.pro.helpers.*
|
2018-11-09 17:12:02 +01:00
|
|
|
import com.simplemobiletools.calendar.pro.interfaces.NavigationListener
|
|
|
|
import com.simplemobiletools.calendar.pro.models.Event
|
2022-04-06 23:49:04 +02:00
|
|
|
import com.simplemobiletools.commons.extensions.*
|
2016-09-16 23:01:46 +02:00
|
|
|
|
2018-01-22 17:36:11 +01:00
|
|
|
class DayFragment : Fragment() {
|
2017-10-21 19:17:34 +02:00
|
|
|
var mListener: NavigationListener? = null
|
2016-10-19 23:43:56 +02:00
|
|
|
private var mTextColor = 0
|
|
|
|
private var mDayCode = ""
|
2017-10-21 18:14:01 +02:00
|
|
|
private var lastHash = 0
|
2016-09-17 11:43:24 +02:00
|
|
|
|
2023-09-03 15:25:41 +02:00
|
|
|
private lateinit var binding: FragmentDayBinding
|
|
|
|
private lateinit var topNavigationBinding: TopNavigationBinding
|
2016-09-17 23:31:07 +02:00
|
|
|
|
2023-09-03 15:25:41 +02:00
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
|
|
|
binding = FragmentDayBinding.inflate(inflater, container, false)
|
|
|
|
topNavigationBinding = TopNavigationBinding.bind(binding.root)
|
2021-11-21 15:10:20 +01:00
|
|
|
mDayCode = requireArguments().getString(DAY_CODE)!!
|
2016-09-17 23:31:07 +02:00
|
|
|
setupButtons()
|
2023-09-03 15:25:41 +02:00
|
|
|
return binding.root
|
2016-09-17 23:31:07 +02:00
|
|
|
}
|
|
|
|
|
2016-09-18 20:52:38 +02:00
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
2018-02-10 13:16:15 +01:00
|
|
|
updateCalendar()
|
2016-09-17 23:31:07 +02:00
|
|
|
}
|
2016-09-17 21:53:17 +02:00
|
|
|
|
2016-09-17 23:31:07 +02:00
|
|
|
private fun setupButtons() {
|
2022-04-06 23:49:04 +02:00
|
|
|
mTextColor = requireContext().getProperTextColor()
|
2016-09-17 23:31:07 +02:00
|
|
|
|
2023-09-03 15:25:41 +02:00
|
|
|
topNavigationBinding.topLeftArrow.apply {
|
2018-01-19 23:48:07 +01:00
|
|
|
applyColorFilter(mTextColor)
|
|
|
|
background = null
|
|
|
|
setOnClickListener {
|
2016-09-17 23:31:07 +02:00
|
|
|
mListener?.goLeft()
|
|
|
|
}
|
2019-02-07 18:42:50 +01:00
|
|
|
|
2023-09-04 12:13:10 +02:00
|
|
|
val pointerLeft = requireContext().getDrawable(com.simplemobiletools.commons.R.drawable.ic_chevron_left_vector)
|
2019-02-07 18:42:50 +01:00
|
|
|
pointerLeft?.isAutoMirrored = true
|
|
|
|
setImageDrawable(pointerLeft)
|
2018-01-19 23:48:07 +01:00
|
|
|
}
|
2016-09-17 23:31:07 +02:00
|
|
|
|
2023-09-03 15:25:41 +02:00
|
|
|
topNavigationBinding.topRightArrow.apply {
|
2018-01-19 23:48:07 +01:00
|
|
|
applyColorFilter(mTextColor)
|
|
|
|
background = null
|
|
|
|
setOnClickListener {
|
2016-09-17 23:31:07 +02:00
|
|
|
mListener?.goRight()
|
|
|
|
}
|
2019-02-07 18:42:50 +01:00
|
|
|
|
2023-09-04 12:13:10 +02:00
|
|
|
val pointerRight = requireContext().getDrawable(com.simplemobiletools.commons.R.drawable.ic_chevron_right_vector)
|
2019-02-07 18:42:50 +01:00
|
|
|
pointerRight?.isAutoMirrored = true
|
|
|
|
setImageDrawable(pointerRight)
|
2016-09-17 23:31:07 +02:00
|
|
|
}
|
2018-01-19 23:48:07 +01:00
|
|
|
|
2021-11-21 15:10:20 +01:00
|
|
|
val day = Formatter.getDayTitle(requireContext(), mDayCode)
|
2023-09-03 15:25:41 +02:00
|
|
|
topNavigationBinding.topValue.apply {
|
2018-01-19 23:48:07 +01:00
|
|
|
text = day
|
2019-02-22 23:30:21 +01:00
|
|
|
contentDescription = text
|
2019-03-06 20:18:18 +01:00
|
|
|
setOnClickListener {
|
|
|
|
(activity as MainActivity).showGoToDateDialog()
|
|
|
|
}
|
2022-04-06 23:49:04 +02:00
|
|
|
setTextColor(context.getProperTextColor())
|
2018-01-19 23:48:07 +01:00
|
|
|
}
|
2016-09-16 23:01:46 +02:00
|
|
|
}
|
2016-09-17 11:43:24 +02:00
|
|
|
|
2018-02-10 13:16:15 +01:00
|
|
|
fun updateCalendar() {
|
2016-09-17 21:53:17 +02:00
|
|
|
val startTS = Formatter.getDayStartTS(mDayCode)
|
|
|
|
val endTS = Formatter.getDayEndTS(mDayCode)
|
2018-11-15 11:09:09 +01:00
|
|
|
context?.eventsHelper?.getEvents(startTS, endTS) {
|
2017-04-02 22:07:02 +02:00
|
|
|
receivedEvents(it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun receivedEvents(events: List<Event>) {
|
2018-10-24 13:59:33 +02:00
|
|
|
val newHash = events.hashCode()
|
2017-10-25 19:55:23 +02:00
|
|
|
if (newHash == lastHash || !isAdded) {
|
2017-10-21 18:14:01 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
lastHash = newHash
|
|
|
|
|
2021-11-21 15:10:20 +01:00
|
|
|
val replaceDescription = requireContext().config.replaceDescription
|
2020-10-25 20:05:23 +01:00
|
|
|
val sorted = ArrayList(events.sortedWith(compareBy({ !it.getIsAllDay() }, { it.startTS }, { it.endTS }, { it.title }, {
|
2017-10-21 12:03:45 +02:00
|
|
|
if (replaceDescription) it.location else it.description
|
|
|
|
})))
|
|
|
|
|
2017-04-02 22:07:02 +02:00
|
|
|
activity?.runOnUiThread {
|
2017-11-13 20:28:10 +01:00
|
|
|
updateEvents(sorted)
|
2017-04-02 22:07:02 +02:00
|
|
|
}
|
2016-09-17 21:53:17 +02:00
|
|
|
}
|
|
|
|
|
2017-11-30 18:13:17 +01:00
|
|
|
private fun updateEvents(events: ArrayList<Event>) {
|
2016-09-19 22:18:19 +02:00
|
|
|
if (activity == null)
|
|
|
|
return
|
|
|
|
|
2023-09-03 15:25:41 +02:00
|
|
|
DayEventsAdapter(activity as SimpleActivity, events, binding.dayEvents, mDayCode) {
|
2017-11-13 16:09:05 +01:00
|
|
|
editEvent(it as Event)
|
2017-11-30 13:47:02 +01:00
|
|
|
}.apply {
|
2023-09-03 15:25:41 +02:00
|
|
|
binding.dayEvents.adapter = this
|
2016-09-17 21:53:17 +02:00
|
|
|
}
|
2021-11-19 22:23:56 +01:00
|
|
|
|
|
|
|
if (requireContext().areSystemAnimationsEnabled) {
|
2023-09-03 15:25:41 +02:00
|
|
|
binding.dayEvents.scheduleLayoutAnimation()
|
2021-11-19 22:23:56 +01:00
|
|
|
}
|
2016-09-17 21:53:17 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 18:54:06 +01:00
|
|
|
private fun editEvent(event: Event) {
|
2022-02-24 16:30:55 +01:00
|
|
|
Intent(context, getActivityToOpen(event.isTask())).apply {
|
2017-03-05 18:54:06 +01:00
|
|
|
putExtra(EVENT_ID, event.id)
|
2017-06-14 21:30:29 +02:00
|
|
|
putExtra(EVENT_OCCURRENCE_TS, event.startTS)
|
2022-07-20 10:41:10 +02:00
|
|
|
putExtra(IS_TASK_COMPLETED, event.isTaskCompleted())
|
2016-11-30 20:51:04 +01:00
|
|
|
startActivity(this)
|
2016-09-18 15:13:03 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-25 20:05:23 +01:00
|
|
|
|
|
|
|
fun printCurrentView() {
|
2023-09-03 15:25:41 +02:00
|
|
|
topNavigationBinding.apply {
|
|
|
|
topLeftArrow.beGone()
|
|
|
|
topRightArrow.beGone()
|
2023-09-04 12:13:10 +02:00
|
|
|
topValue.setTextColor(resources.getColor(com.simplemobiletools.commons.R.color.theme_light_text_color))
|
2023-09-03 15:25:41 +02:00
|
|
|
(binding.dayEvents.adapter as? DayEventsAdapter)?.togglePrintMode()
|
2020-10-25 20:05:23 +01:00
|
|
|
|
2020-10-25 20:40:47 +01:00
|
|
|
Handler().postDelayed({
|
2023-09-03 15:25:41 +02:00
|
|
|
requireContext().printBitmap(binding.dayHolder.getViewBitmap())
|
2020-10-25 20:05:23 +01:00
|
|
|
|
2020-10-25 20:40:47 +01:00
|
|
|
Handler().postDelayed({
|
2023-09-03 15:25:41 +02:00
|
|
|
topLeftArrow.beVisible()
|
|
|
|
topRightArrow.beVisible()
|
|
|
|
topValue.setTextColor(requireContext().getProperTextColor())
|
|
|
|
(binding.dayEvents.adapter as? DayEventsAdapter)?.togglePrintMode()
|
2020-10-25 20:40:47 +01:00
|
|
|
}, 1000)
|
|
|
|
}, 1000)
|
2020-10-25 20:05:23 +01:00
|
|
|
}
|
|
|
|
}
|
2016-09-16 23:01:46 +02:00
|
|
|
}
|