adding Print mode at the weekly view

This commit is contained in:
tibbi 2020-10-25 20:37:02 +01:00
parent bc8c9fd1f6
commit 71f207551c
3 changed files with 62 additions and 22 deletions

View File

@ -52,4 +52,8 @@ class MyWeekPagerAdapter(fm: FragmentManager, private val mWeekTimestamps: List<
mFragments[pos + i]?.updateVisibleDaysCount(count)
}
}
fun togglePrintMode(pos: Int) {
mFragments[pos].togglePrintMode()
}
}

View File

@ -58,6 +58,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private var wasExtraHeightAdded = false
private var dimPastEvents = true
private var wasScaled = false
private var isPrintVersion = false
private var selectedGrid: View? = null
private var currentTimeView: ImageView? = null
private var fadeOutHandler = Handler()
@ -204,7 +205,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private fun setupDayLabels() {
var curDay = Formatter.getDateTimeFromTS(weekTimestamp)
val textColor = config.textColor
val textColor = if (isPrintVersion) resources.getColor(R.color.theme_light_text_color) else config.textColor
val todayCode = Formatter.getDayCodeFromDateTime(DateTime())
val screenWidth = context?.usableScreenSize?.x ?: return
val dayWidth = screenWidth / config.weeklyViewDays
@ -224,7 +225,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
val label = inflater.inflate(R.layout.weekly_view_day_letter, mView.week_letters_holder, false) as MyTextView
label.text = "$dayLetter\n${curDay.dayOfMonth}"
label.setTextColor(if (todayCode == dayCode) primaryColor else textColor)
label.setTextColor(if (todayCode == dayCode && !isPrintVersion) primaryColor else textColor)
if (todayCode == dayCode) {
todayColumnIndex = i
}
@ -437,7 +438,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
(inflater.inflate(R.layout.week_event_marker, null, false) as TextView).apply {
var backgroundColor = eventTypeColors.get(event.eventType, primaryColor)
var textColor = backgroundColor.getContrastColor()
if (dimPastEvents && event.isPastEvent) {
if (dimPastEvents && event.isPastEvent && !isPrintVersion) {
backgroundColor = backgroundColor.adjustAlpha(LOW_ALPHA)
textColor = textColor.adjustAlpha(LOW_ALPHA)
}
@ -504,6 +505,10 @@ class WeekFragment : Fragment(), WeeklyCalendar {
mView.week_events_holder.removeView(currentTimeView)
}
if (isPrintVersion) {
return
}
val weeklyViewDays = config.weeklyViewDays
currentTimeView = (inflater.inflate(R.layout.week_now_marker, null, false) as ImageView).apply {
applyColorFilter(primaryColor)
@ -538,7 +543,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
(inflater.inflate(R.layout.week_all_day_event_marker, null, false) as TextView).apply {
var backgroundColor = eventTypeColors.get(event.eventType, primaryColor)
var textColor = backgroundColor.getContrastColor()
if (dimPastEvents && event.isPastEvent) {
if (dimPastEvents && event.isPastEvent && !isPrintVersion) {
backgroundColor = backgroundColor.adjustAlpha(LOW_ALPHA)
textColor = textColor.adjustAlpha(LOW_ALPHA)
}
@ -651,4 +656,11 @@ class WeekFragment : Fragment(), WeeklyCalendar {
updateViewScale()
}
}
fun togglePrintMode() {
isPrintVersion = !isPrintVersion
updateCalendar()
setupDayLabels()
addEvents(currEvents)
}
}

View File

@ -1,7 +1,9 @@
package com.simplemobiletools.calendar.pro.fragments
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -14,9 +16,7 @@ import androidx.viewpager.widget.ViewPager
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.MainActivity
import com.simplemobiletools.calendar.pro.adapters.MyWeekPagerAdapter
import com.simplemobiletools.calendar.pro.extensions.config
import com.simplemobiletools.calendar.pro.extensions.getWeeklyViewItemHeight
import com.simplemobiletools.calendar.pro.extensions.seconds
import com.simplemobiletools.calendar.pro.extensions.*
import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.helpers.WEEK_START_DATE_TIME
import com.simplemobiletools.calendar.pro.interfaces.WeekFragmentListener
@ -62,20 +62,7 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
private fun setupFragment() {
val weekTSs = getWeekTimestamps(currentWeekTS)
val weeklyAdapter = MyWeekPagerAdapter(activity!!.supportFragmentManager, weekTSs, this)
val itemHeight = context!!.getWeeklyViewItemHeight().toInt()
val textColor = context!!.config.textColor
weekHolder!!.week_view_hours_holder.removeAllViews()
val hourDateTime = DateTime().withDate(2000, 1, 1).withTime(0, 0, 0, 0)
for (i in 1..23) {
val formattedHours = Formatter.getHours(context!!, hourDateTime.withHourOfDay(i))
(layoutInflater.inflate(R.layout.weekly_view_hour_textview, null, false) as TextView).apply {
text = formattedHours
setTextColor(textColor)
height = itemHeight
weekHolder!!.week_view_hours_holder.addView(this)
}
}
addHours()
defaultWeeklyPage = weekTSs.size / 2
viewPager!!.apply {
@ -130,6 +117,21 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
updateActionBarTitle()
}
private fun addHours(textColor: Int = context!!.config.textColor) {
val itemHeight = context!!.getWeeklyViewItemHeight().toInt()
weekHolder!!.week_view_hours_holder.removeAllViews()
val hourDateTime = DateTime().withDate(2000, 1, 1).withTime(0, 0, 0, 0)
for (i in 1..23) {
val formattedHours = Formatter.getHours(context!!, hourDateTime.withHourOfDay(i))
(layoutInflater.inflate(R.layout.weekly_view_hour_textview, null, false) as TextView).apply {
text = formattedHours
setTextColor(textColor)
height = itemHeight
weekHolder!!.week_view_hours_holder.addView(this)
}
}
}
private fun getWeekTimestamps(targetSeconds: Long): List<Long> {
val weekTSs = ArrayList<Long>(PREFILLED_WEEKS)
val dateTime = Formatter.getDateTimeFromTS(targetSeconds)
@ -259,5 +261,27 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
override fun getFullFragmentHeight() = weekHolder!!.week_view_holder.height - weekHolder!!.week_view_seekbar.height - weekHolder!!.week_view_days_count_divider.height
override fun printView() {}
override fun printView() {
weekHolder!!.apply {
week_view_days_count_divider.beGone()
week_view_seekbar.beGone()
week_view_days_count.beGone()
addHours(resources.getColor(R.color.theme_light_text_color))
background = ColorDrawable(Color.WHITE)
(viewPager?.adapter as? MyWeekPagerAdapter)?.togglePrintMode(viewPager?.currentItem ?: 0)
Handler().postDelayed({
context!!.printBitmap(weekHolder!!.week_view_holder.getViewBitmap())
Handler().postDelayed({
week_view_days_count_divider.beVisible()
week_view_seekbar.beVisible()
week_view_days_count.beVisible()
addHours()
background = ColorDrawable(context!!.config.backgroundColor)
(viewPager?.adapter as? MyWeekPagerAdapter)?.togglePrintMode(viewPager?.currentItem ?: 0)
}, 1000)
}, 1000)
}
}
}